Search in sources :

Example 66 with Type

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

the class Attr method visitTypeTest.

public void visitTypeTest(JCInstanceOf tree) {
    Type exprtype = chk.checkNullOrRefType(tree.expr.pos(), attribExpr(tree.expr, env));
    Type clazztype = chk.checkReifiableReferenceType(tree.clazz.pos(), attribType(tree.clazz, env));
    chk.validate(tree.clazz, env, false);
    chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
    result = check(tree, syms.booleanType, VAL, pkind, pt);
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType)

Example 67 with Type

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

the class Attr method getSyntheticScopeMapping.

/** Creates a synthetic scope containing fake generic constructors.
     *  Assuming that the original scope contains a constructor of the kind:
     *  Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
     *  the synthetic scope is added a generic constructor of the kind:
     *  <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
     *  inference. The inferred return type of the synthetic constructor IS
     *  the inferred type for the diamond operator.
     */
private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
    if (ctype.tag != CLASS) {
        return erroneousMapping;
    }
    Pair<Scope, Scope> mapping = new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
    //declared, and insert it into the new scope.
    for (Scope.Entry e = mapping.fst.lookup(names.init); e.scope != null; e = e.next()) {
        Type synthRestype = new ClassType(ctype.getEnclosingType(), ctype.tsym.type.getTypeArguments(), ctype.tsym);
        MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(), names.init, types.createMethodTypeWithReturn(e.sym.type, synthRestype), e.sym.owner);
        mapping.snd.enter(synhConstr);
    }
    return mapping;
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) Scope(com.sun.tools.javac.code.Scope) DelegatedScope(com.sun.tools.javac.code.Scope.DelegatedScope) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassType(com.sun.tools.javac.code.Type.ClassType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) Pair(com.sun.tools.javac.util.Pair)

Example 68 with Type

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

the class Attr method visitTry.

public void visitTry(JCTry tree) {
    // Create a new local environment with a local
    Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
    boolean isTryWithResource = tree.resources.nonEmpty();
    // Create a nested environment for attributing the try block if needed
    Env<AttrContext> tryEnv = isTryWithResource ? env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : localEnv;
    // Attribute resource declarations
    for (JCTree resource : tree.resources) {
        if (resource.getTag() == JCTree.VARDEF) {
            attribStat(resource, tryEnv);
            chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type");
            //check that resource type cannot throw InterruptedException
            checkAutoCloseable(resource.pos(), localEnv, resource.type);
            VarSymbol var = (VarSymbol) TreeInfo.symbolFor(resource);
            var.setData(ElementKind.RESOURCE_VARIABLE);
        } else {
            attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
        }
    }
    // Attribute body
    attribStat(tree.body, tryEnv);
    if (isTryWithResource)
        tryEnv.info.scope.leave();
    // Attribute catch clauses
    for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
        JCCatch c = l.head;
        Env<AttrContext> catchEnv = localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
        Type ctype = attribStat(c.param, catchEnv);
        if (TreeInfo.isMultiCatch(c)) {
            //multi-catch parameter is implicitly marked as final
            c.param.sym.flags_field |= FINAL | UNION;
        }
        if (c.param.sym.kind == Kinds.VAR) {
            c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
        }
        chk.checkType(c.param.vartype.pos(), chk.checkClassType(c.param.vartype.pos(), ctype), syms.throwableType);
        attribStat(c.body, catchEnv);
        catchEnv.info.scope.leave();
    }
    // Attribute finalizer
    if (tree.finalizer != null)
        attribStat(tree.finalizer, localEnv);
    localEnv.info.scope.leave();
    result = null;
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) JCTree(com.sun.tools.javac.tree.JCTree) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) JCCatch(com.sun.tools.javac.tree.JCTree.JCCatch)

Example 69 with Type

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

the class Check method checkNonCyclicInternal.

/** Check for cyclic references. Issue an error if the
     *  symbol of the type referred to has a LOCKED flag set.
     *
     *  @param pos      Position to be used for error reporting.
     *  @param t        The type referred to.
     *  @returns        True if the check completed on all attributed classes
     */
private boolean checkNonCyclicInternal(DiagnosticPosition pos, Type t) {
    // was the check complete?
    boolean complete = true;
    //- System.err.println("checkNonCyclicInternal("+t+");");//DEBUG
    Symbol c = t.tsym;
    if ((c.flags_field & ACYCLIC) != 0)
        return true;
    if ((c.flags_field & LOCKED) != 0) {
        noteCyclic(pos, (ClassSymbol) c);
    } else if (!c.type.isErroneous()) {
        try {
            c.flags_field |= LOCKED;
            if (c.type.tag == CLASS) {
                ClassType clazz = (ClassType) c.type;
                if (clazz.interfaces_field != null)
                    for (List<Type> l = clazz.interfaces_field; l.nonEmpty(); l = l.tail) complete &= checkNonCyclicInternal(pos, l.head);
                if (clazz.supertype_field != null) {
                    Type st = clazz.supertype_field;
                    if (st != null && st.tag == CLASS)
                        complete &= checkNonCyclicInternal(pos, st);
                }
                if (c.owner.kind == TYP)
                    complete &= checkNonCyclicInternal(pos, c.owner.type);
            }
        } finally {
            c.flags_field &= ~LOCKED;
        }
    }
    if (complete)
        complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.completer == null;
    if (complete)
        c.flags_field |= ACYCLIC;
    return complete;
}
Also used : Type(com.sun.tools.javac.code.Type) Symbol(com.sun.tools.javac.code.Symbol)

Example 70 with Type

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

the class Check method firstIncompatibility.

/** Return the first method which is defined with same args
     *  but different return types in two given interfaces, or null if none
     *  exists.
     *  @param t1     The first type.
     *  @param t2     The second type.
     *  @param site   The most derived type.
     *  @returns symbol from t2 that conflicts with one in t1.
     */
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    Map<TypeSymbol, Type> interfaces1 = new HashMap<TypeSymbol, Type>();
    closure(t1, interfaces1);
    Map<TypeSymbol, Type> interfaces2;
    if (t1 == t2)
        interfaces2 = interfaces1;
    else
        closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol, Type>());
    for (Type t3 : interfaces1.values()) {
        for (Type t4 : interfaces2.values()) {
            Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
            if (s != null)
                return s;
        }
    }
    return null;
}
Also used : Type(com.sun.tools.javac.code.Type) Symbol(com.sun.tools.javac.code.Symbol)

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