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

The following examples show how to use com.sun.tools.javac.code.Type#hasTag() . 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: JavacTrees.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Boolean visitType(Type t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    switch (t.getTag()) {
    case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
    case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
        return t.hasTag(s.getTag());
    default:
        throw new AssertionError("fuzzyMatcher " + t.getTag());
    }
}
 
Example 2
Source File: JavacTrees.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Boolean visitType(Type t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    switch (t.getTag()) {
    case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
    case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
        return t.hasTag(s.getTag());
    default:
        throw new AssertionError("fuzzyMatcher " + t.getTag());
    }
}
 
Example 3
Source File: JavacTrees.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Boolean visitType(Type t, Type s) {
    if (t == s)
        return true;

    if (s.isPartial())
        return visit(s, t);

    switch (t.getTag()) {
    case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
    case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
        return t.hasTag(s.getTag());
    default:
        throw new AssertionError("fuzzyMatcher " + t.getTag());
    }
}
 
Example 4
Source File: TypeMaker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 5
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 6
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns all annotations of an element, whether
 * inherited or directly present.
 *
 * @param e  the element being examined
 * @return all annotations of the element
 */
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public List<Attribute.Compound> getAllAnnotationMirrors(Element e) {
    Symbol sym = cast(Symbol.class, e);
    List<Attribute.Compound> annos = sym.getAnnotationMirrors();
    while (sym.getKind() == ElementKind.CLASS) {
        Type sup = ((ClassSymbol) sym).getSuperclass();
        if (!sup.hasTag(CLASS) || sup.isErroneous() ||
                sup.tsym == syms.objectType.tsym) {
            break;
        }
        sym = sup.tsym;
        List<Attribute.Compound> oldAnnos = annos;
        List<Attribute.Compound> newAnnos = sym.getAnnotationMirrors();
        for (Attribute.Compound anno : newAnnos) {
            if (isInherited(anno.type) &&
                    !containsAnnoOfType(oldAnnos, anno.type)) {
                annos = annos.prepend(anno);
            }
        }
    }
    return annos;
}
 
Example 7
Source File: TypeMaker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the string representation of a type use.  Bounds of type
 * variables are not included; bounds of wildcard types are.
 * Class names are qualified if "full" is true.
 */
static String getTypeString(DocEnv env, Type t, boolean full) {
    // TODO: should annotations be included here?
    if (t.isAnnotated()) {
        t = t.unannotatedType();
    }
    switch (t.getTag()) {
    case ARRAY:
        StringBuilder s = new StringBuilder();
        while (t.hasTag(ARRAY)) {
            s.append("[]");
            t = env.types.elemtype(t);
        }
        s.insert(0, getTypeString(env, t, full));
        return s.toString();
    case CLASS:
        return ParameterizedTypeImpl.
                    parameterizedTypeToString(env, (ClassType)t, full);
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return WildcardTypeImpl.wildcardTypeToString(env, a, full);
    default:
        return t.tsym.getQualifiedName().toString();
    }
}
 
Example 8
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitUndetVar(UndetVar t, Void _unused) {
    if (min.add(t.qtype)) {
        Set<Type> deps = minMap.getOrDefault(t.qtype, new HashSet<>(Collections.singleton(t.qtype)));
        for (InferenceBound boundKind : InferenceBound.values()) {
            for (Type b : t.getBounds(boundKind)) {
                Type undet = asUndetVar(b);
                if (!undet.hasTag(TypeTag.UNDETVAR)) {
                    visit(undet);
                } else if (isEquiv(t, b, boundKind)) {
                    deps.add(b);
                    equiv.add(b);
                } else {
                    visit(undet);
                }
            }
        }
        minMap.put(t.qtype, deps);
    }
    return null;
}
 
Example 9
Source File: ClassWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Given a type t, return the extended class name of its erasure in
 *  external representation.
 */
public Name xClassName(Type t) {
    if (t.hasTag(CLASS)) {
        return names.fromUtf(externalize(t.tsym.flatName()));
    } else if (t.hasTag(ARRAY)) {
        return typeSig(types.erasure(t));
    } else {
        throw new AssertionError("xClassName expects class or array type, got " + t);
    }
}
 
Example 10
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private JCBlock makeLambdaExpressionBody(JCExpression expr, JCMethodDecl lambdaMethodDecl) {
    Type restype = lambdaMethodDecl.type.getReturnType();
    boolean isLambda_void = expr.type.hasTag(VOID);
    boolean isTarget_void = restype.hasTag(VOID);
    boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type);
    int prevPos = make.pos;
    try {
        if (isTarget_void) {
            //target is void:
            // BODY;
            JCStatement stat = make.at(expr).Exec(expr);
            return make.Block(0, List.<JCStatement>of(stat));
        } else if (isLambda_void && isTarget_Void) {
            //void to Void conversion:
            // BODY; return null;
            ListBuffer<JCStatement> stats = new ListBuffer<>();
            stats.append(make.at(expr).Exec(expr));
            stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType)));
            return make.Block(0, stats.toList());
        } else {
            //non-void to non-void conversion:
            // return (TYPE)BODY;
            JCExpression retExpr = transTypes.coerce(attrEnv, expr, restype);
            return make.at(retExpr).Block(0, List.<JCStatement>of(make.Return(retExpr)));
        }
    } finally {
        make.at(prevPos);
    }
}
 
Example 11
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Type visitType(Type t, Void _unused) {
    if (!t.hasTag(DEFERRED)) {
        return super.visitType(t, null);
    } else {
        DeferredType dt = (DeferredType)t;
        return typeOf(dt);
    }
}
 
Example 12
Source File: TypeMaker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private com.sun.javadoc.Type skipArrays() {
    if (skipArraysCache == null) {
        Type t;
        for (t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) { }
        skipArraysCache = TypeMaker.getType(env, t);
    }
    return skipArraysCache;
}
 
Example 13
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
Type solve(UndetVar uv, InferenceContext inferenceContext) {
    Infer infer = inferenceContext.infer;
    List<Type> lobounds = filterBounds(uv, inferenceContext);
    //note: lobounds should have at least one element
    Type owntype = lobounds.tail.tail == null  ? lobounds.head : infer.types.lub(lobounds);
    if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
        throw infer.inferenceException
            .setMessage("no.unique.minimal.instance.exists",
                        uv.qtype, lobounds);
    } else {
        return owntype;
    }
}
 
Example 14
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Note that we found an inheritance cycle. */
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
    log.error(pos, Errors.CyclicInheritance(c));
    for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
        l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
    Type st = types.supertype(c.type);
    if (st.hasTag(CLASS))
        ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
    c.type = types.createErrorType(c, c.type);
    c.flags_field |= ACYCLIC;
}
 
Example 15
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Add all necessary bridges to some class appending them to list buffer.
     *  @param pos     The source code position to be used for the bridges.
     *  @param origin  The class in which the bridges go.
     *  @param bridges The list buffer to which the bridges are added.
     */
    void addBridges(DiagnosticPosition pos, ClassSymbol origin, ListBuffer<JCTree> bridges) {
        Type st = types.supertype(origin.type);
        while (st.hasTag(CLASS)) {
//          if (isSpecialization(st))
            addBridges(pos, st.tsym, origin, bridges);
            st = types.supertype(st);
        }
        for (List<Type> l = types.interfaces(origin.type); l.nonEmpty(); l = l.tail)
//          if (isSpecialization(l.head))
            addBridges(pos, l.head.tsym, origin, bridges);
    }
 
Example 16
Source File: ArgumentAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Check lambda against given target result */
private void checkLambdaCompatible(Type descriptor, ResultInfo resultInfo) {
    CheckContext checkContext = resultInfo.checkContext;
    ResultInfo bodyResultInfo = attr.lambdaBodyResult(speculativeTree, descriptor, resultInfo);
    for (JCReturn ret : returnExpressions()) {
        Type t = getReturnType(ret);
        if (speculativeTree.getBodyKind() == BodyKind.EXPRESSION || !t.hasTag(VOID)) {
            checkSpeculative(ret.expr, t, bodyResultInfo);
        }
    }

    attr.checkLambdaCompatible(speculativeTree, descriptor, checkContext);
}
 
Example 17
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Type firstIncompatibleTypeArg(Type type) {
    List<Type> formals = type.tsym.type.allparams();
    List<Type> actuals = type.allparams();
    List<Type> args = type.getTypeArguments();
    List<Type> forms = type.tsym.type.getTypeArguments();
    ListBuffer<Type> bounds_buf = new ListBuffer<>();

    // For matching pairs of actual argument types `a' and
    // formal type parameters with declared bound `b' ...
    while (args.nonEmpty() && forms.nonEmpty()) {
        // exact type arguments needs to know their
        // bounds (for upper and lower bound
        // calculations).  So we create new bounds where
        // type-parameters are replaced with actuals argument types.
        bounds_buf.append(types.subst(forms.head.getUpperBound(), formals, actuals));
        args = args.tail;
        forms = forms.tail;
    }

    args = type.getTypeArguments();
    List<Type> tvars_cap = types.substBounds(formals,
                              formals,
                              types.capture(type).allparams());
    while (args.nonEmpty() && tvars_cap.nonEmpty()) {
        // Let the actual arguments know their bound
        args.head.withTypeVar((TypeVar)tvars_cap.head);
        args = args.tail;
        tvars_cap = tvars_cap.tail;
    }

    args = type.getTypeArguments();
    List<Type> bounds = bounds_buf.toList();

    while (args.nonEmpty() && bounds.nonEmpty()) {
        Type actual = args.head;
        if (!isTypeArgErroneous(actual) &&
                !bounds.head.isErroneous() &&
                !checkExtends(actual, bounds.head)) {
            return args.head;
        }
        args = args.tail;
        bounds = bounds.tail;
    }

    args = type.getTypeArguments();
    bounds = bounds_buf.toList();

    for (Type arg : types.capture(type).getTypeArguments()) {
        if (arg.hasTag(TYPEVAR) &&
                arg.getUpperBound().isErroneous() &&
                !bounds.head.isErroneous() &&
                !isTypeArgErroneous(args.head)) {
            return args.head;
        }
        bounds = bounds.tail;
        args = args.tail;
    }

    return null;
}
 
Example 18
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Type asSuper(Type t, Type sup) {
    return (sup.hasTag(ARRAY)) ?
            new ArrayType(asSuper(types.elemtype(t), types.elemtype(sup)), syms.arrayClass) :
            types.asSuper(t, sup.tsym);
}
 
Example 19
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitLambda(JCLambda tree) {
    Check.CheckContext checkContext = resultInfo.checkContext;
    Type pt = resultInfo.pt;
    if (!inferenceContext.inferencevars.contains(pt)) {
        //must be a functional descriptor
        Type descriptorType = null;
        try {
            descriptorType = types.findDescriptorType(pt);
        } catch (Types.FunctionDescriptorLookupError ex) {
            checkContext.report(null, ex.getDiagnostic());
        }

        if (descriptorType.getParameterTypes().length() != tree.params.length()) {
            checkContext.report(tree,
                    diags.fragment(Fragments.IncompatibleArgTypesInLambda));
        }

        Type currentReturnType = descriptorType.getReturnType();
        boolean returnTypeIsVoid = currentReturnType.hasTag(VOID);
        if (tree.getBodyKind() == BodyKind.EXPRESSION) {
            boolean isExpressionCompatible = !returnTypeIsVoid ||
                TreeInfo.isExpressionStatement((JCExpression)tree.getBody());
            if (!isExpressionCompatible) {
                resultInfo.checkContext.report(tree.pos(),
                    diags.fragment(Fragments.IncompatibleRetTypeInLambda(Fragments.MissingRetVal(currentReturnType))));
            }
        } else {
            LambdaBodyStructChecker lambdaBodyChecker =
                    new LambdaBodyStructChecker();

            tree.body.accept(lambdaBodyChecker);
            boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible;

            if (returnTypeIsVoid) {
                if (!isVoidCompatible) {
                    resultInfo.checkContext.report(tree.pos(),
                        diags.fragment(Fragments.UnexpectedRetVal));
                }
            } else {
                boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible
                    && !canLambdaBodyCompleteNormally(tree);
                if (!isValueCompatible && !isVoidCompatible) {
                    log.error(tree.body.pos(),
                              Errors.LambdaBodyNeitherValueNorVoidCompatible);
                }

                if (!isValueCompatible) {
                    resultInfo.checkContext.report(tree.pos(),
                        diags.fragment(Fragments.IncompatibleRetTypeInLambda(Fragments.MissingRetVal(currentReturnType))));
                }
            }
        }
    }
}
 
Example 20
Source File: JavacTrees.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Boolean visitErrorType(ErrorType t, Type s) {
    return s.hasTag(CLASS)
            && t.tsym.name == ((ClassType) s).tsym.name;
}