Java Code Examples for com.sun.tools.javac.code.Types#isSubtype()

The following examples show how to use com.sun.tools.javac.code.Types#isSubtype() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
/** Expand a boxing or unboxing conversion if needed. */
<T extends JCTree> T boxUnboxIfNeeded( Types types, TreeMaker make, Names names, 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(types, make, names, (JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive(types, make, names, (JCExpression)tree);
    }
  } else {
    tree = (T)unbox(types, make, names, (JCExpression)tree, type);
  }
  return tree;
}
 
Example 2
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
/** Unbox an object to a primitive value. */
private JCExpression unbox( Types types, TreeMaker make, Names names, 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 = resolveMethod(tree.pos(),
    unboxedType.tsym.name.append(names.Value), // x.intValue()
    tree.type,
    List.<Type>nil());
  return make.App(make.Select(tree, valueSym));
}
 
Example 3
Source File: ApacheThriftIsSetHandler.java    From NullAway with MIT License 5 votes vote down vote up
private boolean thriftIsSetCall(Symbol.MethodSymbol symbol, Types types) {
  Preconditions.checkNotNull(tbaseType);
  // noinspection ConstantConditions
  return tbaseType.isPresent()
      && symbol.getSimpleName().toString().startsWith("isSet")
      // weeds out the isSet() method in TBase itself
      && symbol.getParameters().length() == 0
      && types.isSubtype(symbol.owner.type, tbaseType.get());
}
 
Example 4
Source File: OptionalEmptinessHandler.java    From NullAway with MIT License 5 votes vote down vote up
private boolean optionalIsPresentCall(Symbol.MethodSymbol symbol, Types types) {
  for (Type optionalType : optionalTypes) {
    if (symbol.getSimpleName().toString().equals("isPresent")
        && symbol.getParameters().length() == 0
        && types.isSubtype(symbol.owner.type, optionalType)) return true;
  }
  return false;
}
 
Example 5
Source File: OptionalEmptinessHandler.java    From NullAway with MIT License 5 votes vote down vote up
private boolean optionalIsGetCall(Symbol.MethodSymbol symbol, Types types) {
  for (Type optionalType : optionalTypes) {
    if (symbol.getSimpleName().toString().equals("get")
        && symbol.getParameters().length() == 0
        && types.isSubtype(symbol.owner.type, optionalType)) return true;
  }
  return false;
}