Java Code Examples for com.sun.tools.javac.code.Type#isIntersection()

The following examples show how to use com.sun.tools.javac.code.Type#isIntersection() . 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: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    tree.clazz = translate(tree.clazz, null);
    Type originalTarget = tree.type;
    tree.type = erasure(tree.type);
    JCExpression newExpression = translate(tree.expr, tree.type);
    if (newExpression != tree.expr) {
        JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST)
            ? (JCTypeCast) newExpression
            : null;
        tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true)
            ? typeCast.expr
            : newExpression;
    }
    if (originalTarget.isIntersection()) {
        Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget;
        for (Type c : ict.getExplicitComponents()) {
            Type ec = erasure(c);
            if (!types.isSameType(ec, tree.type)) {
                tree.expr = coerce(tree.expr, ec);
            }
        }
    }
    result = tree;
}
 
Example 2
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<Pair<Type, Type>> getParameterizedSupers(Type t, Type s) {
    Type lubResult = types.lub(t, s);
    if (lubResult == syms.errType || lubResult == syms.botType) {
        return List.nil();
    }
    List<Type> supertypesToCheck = lubResult.isIntersection() ?
            ((IntersectionClassType)lubResult).getComponents() :
            List.of(lubResult);
    ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>();
    for (Type sup : supertypesToCheck) {
        if (sup.isParameterized()) {
            Type asSuperOfT = asSuper(t, sup);
            Type asSuperOfS = asSuper(s, sup);
            commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS));
        }
    }
    return commonSupertypes.toList();
}
 
Example 3
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 6 votes vote down vote up
private MethodDeclarationPair getFunctionalInterfaceMethodPair(TypeMirror typeMirror) {
  Type type = (Type) typeMirror;
  if (!internalTypes.isFunctionalInterface(type)) {
    return null;
  }
  if (type.isIntersection()) {

    return ((IntersectionType) type)
        .getBounds().stream()
            .filter(this::isFunctionalInterface)
            .map(this::getFunctionalInterfaceMethodPair)
            .findFirst()
            .orElse(null);
  }
  return getMethods((ClassType) type).stream()
      .filter(
          p ->
              isAbstract(p.getDeclarationMethodSymbol())
                  && !isJavaLangObjectOverride(p.getDeclarationMethodSymbol()))
      .findFirst()
      .orElse(null);
}
 
Example 4
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private TypeMirror getFunctionalInterface(Type type) {
  if (type.isIntersection()) {
    return ((IntersectionType) type)
        .getBounds().stream().filter(this::isFunctionalInterface).findFirst().orElse(null);
  }
  checkArgument(isFunctionalInterface(type));
  return type;
}