Search in sources :

Example 91 with Type

use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.

the class Printer method className.

/**
     * Converts a class name into a (possibly localized) string. Anonymous
     * inner classes gets converted into a localized string.
     *
     * @param t the type of the class whose name is to be rendered
     * @param longform if set, the class' fullname is displayed - if unset the
     * short name is chosen (w/o package)
     * @param locale the locale in which the string is to be rendered
     * @return localized string representation
     */
protected String className(ClassType t, boolean longform, Locale locale) {
    Symbol sym = t.tsym;
    if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
        StringBuffer s = new StringBuffer(visit(t.supertype_field, locale));
        for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
            s.append("&");
            s.append(visit(is.head, locale));
        }
        return s.toString();
    } else if (sym.name.length() == 0) {
        String s;
        ClassType norm = (ClassType) t.tsym.type;
        if (norm == null) {
            s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
        } else if (norm.interfaces_field.nonEmpty()) {
            s = localize(locale, "compiler.misc.anonymous.class", visit(norm.interfaces_field.head, locale));
        } else {
            s = localize(locale, "compiler.misc.anonymous.class", visit(norm.supertype_field, locale));
        }
        return s;
    } else if (longform) {
        return sym.getQualifiedName().toString();
    } else {
        return sym.name.toString();
    }
}
Also used : Type(com.sun.tools.javac.code.Type) Symbol(com.sun.tools.javac.code.Symbol)

Example 92 with Type

use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.

the class Symbol method hiddenIn.

/** Check for hiding.  Note that this doesn't handle multiple
     *  (interface) inheritance. */
private boolean hiddenIn(ClassSymbol clazz, Types types) {
    if (kind == MTH && (flags() & STATIC) == 0)
        return false;
    while (true) {
        if (owner == clazz)
            return false;
        Scope.Entry e = clazz.members().lookup(name);
        while (e.scope != null) {
            if (e.sym == this)
                return false;
            if (e.sym.kind == kind && (kind != MTH || (e.sym.flags() & STATIC) != 0 && types.isSubSignature(e.sym.type, type)))
                return true;
            e = e.next();
        }
        Type superType = types.supertype(clazz.type);
        if (superType.tag != TypeTags.CLASS)
            return false;
        clazz = (ClassSymbol) superType.tsym;
    }
}
Also used : Type(com.sun.tools.javac.code.Type)

Example 93 with Type

use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.

the class Types method setBounds.

/**
     * Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that
     * third parameter is computed directly, as follows: if all
     * all bounds are interface types, the computed supertype is Object,
     * otherwise the supertype is simply left null (in this case, the supertype
     * is assumed to be the head of the bound list passed as second argument).
     * Note that this check might cause a symbol completion. Hence, this version of
     * setBounds may not be called during a classfile read.
     */
public void setBounds(TypeVar t, List<Type> bounds) {
    Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? syms.objectType : null;
    setBounds(t, bounds, supertype);
    t.rank_field = -1;
}
Also used : Type(com.sun.tools.javac.code.Type)

Example 94 with Type

use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.

the class Types method sideCastFinal.

private boolean sideCastFinal(Type from, Type to, Warner warn) {
    // We are casting from type $from$ to type $to$, which are
    // unrelated types one of which is final and the other of
    // which is an interface.  This method
    // tries to reject a cast by transferring type parameters
    // from the final class to the interface.
    boolean reverse = false;
    Type target = to;
    if ((to.tsym.flags() & INTERFACE) == 0) {
        Assert.check((from.tsym.flags() & INTERFACE) != 0);
        reverse = true;
        to = from;
        from = target;
    }
    Assert.check((from.tsym.flags() & FINAL) != 0);
    Type t1 = asSuper(from, to.tsym);
    if (t1 == null)
        return false;
    Type t2 = to;
    if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments()))
        return false;
    if (!allowCovariantReturns)
        // reject if there is a common method signature with
        // incompatible return types.
        chk.checkCompatibleAbstracts(warn.pos(), from, to);
    if (!isReifiable(target) && (reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)))
        warn.warn(LintCategory.UNCHECKED);
    return true;
}
Also used : Type(com.sun.tools.javac.code.Type)

Example 95 with Type

use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.

the class Types method closure.

/**
     * Returns the closure of a class or interface type.
     */
public List<Type> closure(Type t) {
    List<Type> cl = closureCache.get(t);
    if (cl == null) {
        Type st = supertype(t);
        if (!t.isCompound()) {
            if (st.tag == CLASS) {
                cl = insert(closure(st), t);
            } else if (st.tag == TYPEVAR) {
                cl = closure(st).prepend(t);
            } else {
                cl = List.of(t);
            }
        } else {
            cl = closure(supertype(t));
        }
        for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) cl = union(cl, closure(l.head));
        closureCache.put(t, cl);
    }
    return cl;
}
Also used : Type(com.sun.tools.javac.code.Type)

Aggregations

Type (com.sun.tools.javac.code.Type)254 Symbol (com.sun.tools.javac.code.Symbol)64 ClassType (com.sun.tools.javac.code.Type.ClassType)55 ArrayType (com.sun.tools.javac.code.Type.ArrayType)47 MethodType (com.sun.tools.javac.code.Type.MethodType)42 WildcardType (com.sun.tools.javac.code.Type.WildcardType)42 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)36 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)33 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)32 JCTree (com.sun.tools.javac.tree.JCTree)27 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)24 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)23 Types (com.sun.tools.javac.code.Types)22 ExpressionTree (com.sun.source.tree.ExpressionTree)21 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)17 ArrayList (java.util.ArrayList)17 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)16 Tree (com.sun.source.tree.Tree)14 Name (com.sun.tools.javac.util.Name)14 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)13