com.sun.tools.javac.code.Types.unboxedType()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中com.sun.tools.javac.code.Types.unboxedType()方法的一些代码示例,展示了Types.unboxedType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.unboxedType()方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:unboxedType

Types.unboxedType介绍

[英]Return the primitive type corresponding to a boxed type.
[中]返回与装箱类型对应的基元类型。

代码示例

代码示例来源:origin: sc.fiji/javac

public PrimitiveType unboxedType(TypeMirror t) {
  if (t.getKind() != TypeKind.DECLARED)
    throw new IllegalArgumentException(t.toString());
  Type unboxed = types.unboxedType((Type) t);
  if (! unboxed.isPrimitive())    // only true primitives, not void
    throw new IllegalArgumentException(t.toString());
  return unboxed;
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

public PrimitiveType unboxedType(TypeMirror t) {
if (t.getKind() != TypeKind.DECLARED)
  throw new IllegalArgumentException(t.toString());
Type unboxed = types.unboxedType((Type) t);
if (! unboxed.isPrimitive())	// only true primitives, not void
  throw new IllegalArgumentException(t.toString());
return unboxed;
}

代码示例来源:origin: konsoletyper/teavm-javac

/**
 * Return the unboxed type if 't' is a boxed class, otherwise return 't' itself.
 */
public Type unboxedTypeOrType(Type t) {
  Type unboxedType = unboxedType(t);
  return unboxedType.hasTag(NONE) ? t : unboxedType;
}
// </editor-fold>

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/**
 * Return the unboxed type if 't' is a boxed class, otherwise return 't' itself.
 */
public Type unboxedTypeOrType(Type t) {
  Type unboxedType = unboxedType(t);
  return unboxedType.hasTag(NONE) ? t : unboxedType;
}
// </editor-fold>

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public PrimitiveType unboxedType(TypeMirror t) {
  if (t.getKind() != TypeKind.DECLARED)
    throw new IllegalArgumentException(t.toString());
  Type unboxed = types.unboxedType((Type) t);
  if (! unboxed.isPrimitive())    // only true primitives, not void
    throw new IllegalArgumentException(t.toString());
  return (PrimitiveType)unboxed;
}

代码示例来源:origin: konsoletyper/teavm-javac

public PrimitiveType unboxedType(TypeMirror t) {
  if (t.getKind() != TypeKind.DECLARED)
    throw new IllegalArgumentException(t.toString());
  Type unboxed = types.unboxedType((Type) t);
  if (! unboxed.isPrimitive())    // only true primitives, not void
    throw new IllegalArgumentException(t.toString());
  return (PrimitiveType)unboxed;
}

代码示例来源:origin: sc.fiji/javac

/**
 * Is t a subtype of or convertiable via boxing/unboxing
 * convertions to s?
 */
public boolean isConvertible(Type t, Type s, Warner warn) {
  boolean tPrimitive = t.isPrimitive();
  boolean sPrimitive = s.isPrimitive();
  if (tPrimitive == sPrimitive)
    return isSubtypeUnchecked(t, s, warn);
  if (!allowBoxing) return false;
  return tPrimitive
    ? isSubtype(boxedClass(t).type, s)
    : isSubtype(unboxedType(t), s);
}

代码示例来源:origin: konsoletyper/teavm-javac

private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from,
    Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) {
  if (!allowGraphInference) {
    //if legacy, just return boxed type
    return types.boxedClass(to).type;
  }
  //if graph inference we need to skip conflicting boxed bounds...
  for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER,
      InferenceBound.LOWER)) {
    Type boundAsPrimitive = types.unboxedType(t);
    if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) {
      continue;
    }
    return generateReferenceToTargetConstraint(tree, from, to,
        resultInfo, inferenceContext);
  }
  return types.boxedClass(to).type;
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

/**
 * Is t a subtype of or convertiable via boxing/unboxing
 * convertions to s?
 */
public boolean isConvertible(Type t, Type s, Warner warn) {
  boolean tPrimitive = t.isPrimitive();
  boolean sPrimitive = s.isPrimitive();
  if (tPrimitive == sPrimitive)
    return isSubtypeUnchecked(t, s, warn);
  if (!allowBoxing) return false;
  return tPrimitive
    ? isSubtype(boxedClass(t).type, s)
    : isSubtype(unboxedType(t), s);
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

/** Expand a boxing or unboxing conversion if needed. */
@SuppressWarnings("unchecked") // XXX unchecked
<T extends JCTree> T boxIfNeeded(T tree, Type type) {
boolean havePrimitive = tree.type.isPrimitive();
if (havePrimitive == type.isPrimitive())
  return tree;
if (havePrimitive) {
    Type unboxedTarget = types.unboxedType(type);
    if (unboxedTarget.tag != NONE) {
      if (!types.isSubtype(tree.type, unboxedTarget))
        tree.type = unboxedTarget; // e.g. Character c = 89;
      return (T)boxPrimitive((JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive((JCExpression)tree);
    }
} else {
  tree = (T)unbox((JCExpression)tree, type);
}
return tree;
}

代码示例来源:origin: sc.fiji/javac

/** Unbox an object to a primitive value. */
JCExpression unbox(JCExpression tree, Type primitive) {
  Type unboxedType = types.unboxedType(tree.type);
  // note: the "primitive" parameter is not used.  There muse be
  // a conversion from unboxedType to primitive.
  make_at(tree.pos());
  Symbol valueSym = lookupMethod(tree.pos(),
                  unboxedType.tsym.name.append(names.Value), // x.intValue()
                  tree.type,
                  List.<Type>nil());
  return make.App(make.Select(tree, valueSym));
}

代码示例来源:origin: sc.fiji/javac

/** Expand a boxing or unboxing conversion if needed. */
@SuppressWarnings("unchecked") // XXX unchecked
<T extends JCTree> T boxIfNeeded(T tree, Type type) {
  boolean havePrimitive = tree.type.isPrimitive();
  if (havePrimitive == type.isPrimitive())
    return tree;
  if (havePrimitive) {
    Type unboxedTarget = types.unboxedType(type);
    if (unboxedTarget.tag != NONE) {
      if (!types.isSubtype(tree.type, unboxedTarget))
        tree.type = unboxedTarget; // e.g. Character c = 89;
      return (T)boxPrimitive((JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive((JCExpression)tree);
    }
  } else {
    tree = (T)unbox((JCExpression)tree, type);
  }
  return tree;
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

/** Unbox an object to a primitive value. */
JCExpression unbox(JCExpression tree, Type primitive) {
Type unboxedType = types.unboxedType(tree.type);
// note: the "primitive" parameter is not used.  There muse be
// a conversion from unboxedType to primitive.
make_at(tree.pos());
Symbol valueSym = lookupMethod(tree.pos(),
          unboxedType.tsym.name.append(names.Value), // x.intValue()
          tree.type,
          List.<Type>nil());
return make.App(make.Select(tree, valueSym));
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/**
 * Is t a subtype of or convertible via boxing/unboxing
 * conversion to s?
 */
public boolean isConvertible(Type t, Type s, Warner warn) {
  if (t.hasTag(ERROR)) {
    return true;
  }
  boolean tPrimitive = t.isPrimitive();
  boolean sPrimitive = s.isPrimitive();
  if (tPrimitive == sPrimitive) {
    return isSubtypeUnchecked(t, s, warn);
  }
  if (!allowBoxing) return false;
  return tPrimitive
    ? isSubtype(boxedClass(t).type, s)
    : isSubtype(unboxedType(t), s);
}

代码示例来源:origin: konsoletyper/teavm-javac

/**
 * Is t a subtype of or convertible via boxing/unboxing
 * conversion to s?
 */
public boolean isConvertible(Type t, Type s, Warner warn) {
  if (t.hasTag(ERROR)) {
    return true;
  }
  boolean tPrimitive = t.isPrimitive();
  boolean sPrimitive = s.isPrimitive();
  if (tPrimitive == sPrimitive) {
    return isSubtypeUnchecked(t, s, warn);
  }
  if (!allowBoxing) return false;
  return tPrimitive
    ? isSubtype(boxedClass(t).type, s)
    : isSubtype(unboxedType(t), s);
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/** Unbox an object to a primitive value. */
JCExpression unbox(JCExpression tree, Type primitive) {
  Type unboxedType = types.unboxedType(tree.type);
  if (unboxedType.hasTag(NONE)) {
    unboxedType = primitive;
    if (!unboxedType.isPrimitive())
      throw new AssertionError(unboxedType);
    make_at(tree.pos());
    tree = make.TypeCast(types.boxedClass(unboxedType).type, tree);
  } else {
    // There must be a conversion from unboxedType to primitive.
    if (!types.isSubtype(unboxedType, primitive))
      throw new AssertionError(tree);
  }
  make_at(tree.pos());
  Symbol valueSym = lookupMethod(tree.pos(),
                  unboxedType.tsym.name.append(names.Value), // x.intValue()
                  tree.type,
                  List.<Type>nil());
  return make.App(make.Select(tree, valueSym));
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

public JCTree build(final JCTree lhs) {
  int newTag = tree.tag - JCTree.ASGOffset;
  // Erasure (TransTypes) can change the type of
  // tree.lhs.  However, we can still get the
  // unerased type of tree.lhs as it is stored
  // in tree.type in Attr.
  Symbol newOperator = rs.resolveBinaryOperator(tree.pos(),
               newTag,
               attrEnv,
               tree.type,
               tree.rhs.type);
  JCExpression expr = (JCExpression)lhs;
  if (expr.type != tree.type)
    expr = make.TypeCast(tree.type, expr);
  JCBinary opResult = make.Binary(newTag, expr, tree.rhs);
  opResult.operator = newOperator;
  opResult.type = newOperator.type.getReturnType();
  JCTypeCast newRhs = make.TypeCast(types.unboxedType(tree.type),
           opResult);
  return make.Assign((JCExpression)lhs, newRhs).setType(tree.type);
  }
});

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/** Expand a boxing or unboxing conversion if needed. */
@SuppressWarnings("unchecked") // XXX unchecked
<T extends JCTree> T boxIfNeeded(T tree, Type type) {
  boolean havePrimitive = tree.type.isPrimitive();
  if (havePrimitive == type.isPrimitive())
    return tree;
  if (havePrimitive) {
    Type unboxedTarget = types.unboxedType(type);
    if (!unboxedTarget.hasTag(NONE)) {
      if (!types.isSubtype(tree.type, unboxedTarget)) //e.g. Character c = 89;
        tree.type = unboxedTarget.constType(tree.type.constValue());
      return (T)boxPrimitive((JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive((JCExpression)tree);
    }
  } else {
    tree = (T)unbox((JCExpression)tree, type);
  }
  return tree;
}

代码示例来源:origin: sc.fiji/javac

public JCTree build(final JCTree lhs) {
    int newTag = tree.getTag() - JCTree.ASGOffset;
    // Erasure (TransTypes) can change the type of
    // tree.lhs.  However, we can still get the
    // unerased type of tree.lhs as it is stored
    // in tree.type in Attr.
    Symbol newOperator = rs.resolveBinaryOperator(tree.pos(),
                           newTag,
                           attrEnv,
                           tree.type,
                           tree.rhs.type);
    JCExpression expr = (JCExpression)lhs;
    if (expr.type != tree.type)
      expr = make.TypeCast(tree.type, expr);
    JCBinary opResult = make.Binary(newTag, expr, tree.rhs);
    opResult.operator = newOperator;
    opResult.type = newOperator.type.getReturnType();
    JCTypeCast newRhs = make.TypeCast(types.unboxedType(tree.type),
                     opResult);
    return make.Assign((JCExpression)lhs, newRhs).setType(tree.type);
  }
});

代码示例来源:origin: konsoletyper/teavm-javac

/** Expand a boxing or unboxing conversion if needed. */
@SuppressWarnings("unchecked") // XXX unchecked
<T extends JCTree> T boxIfNeeded(T tree, Type type) {
  boolean havePrimitive = tree.type.isPrimitive();
  if (havePrimitive == type.isPrimitive())
    return tree;
  if (havePrimitive) {
    Type unboxedTarget = types.unboxedType(type);
    if (!unboxedTarget.hasTag(NONE)) {
      if (!types.isSubtype(tree.type, unboxedTarget)) //e.g. Character c = 89;
        tree.type = unboxedTarget.constType(tree.type.constValue());
      return (T)boxPrimitive((JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive((JCExpression)tree);
    }
  } else {
    tree = (T)unbox((JCExpression)tree, type);
  }
  return tree;
}

相关文章

Types类方法