Search in sources :

Example 46 with ClassSymbol

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

the class Attr method attribDiamond.

Type attribDiamond(Env<AttrContext> env, JCNewClass tree, Type clazztype, Pair<Scope, Scope> mapping, List<Type> argtypes, List<Type> typeargtypes) {
    if (clazztype.isErroneous() || clazztype.isInterface() || mapping == erroneousMapping) {
        //mapping, return the (possibly erroneous) type unchanged
        return clazztype;
    }
    //dup attribution environment and augment the set of inference variables
    Env<AttrContext> localEnv = env.dup(tree);
    localEnv.info.tvars = clazztype.tsym.type.getTypeArguments();
    //if the type of the instance creation expression is a class type
    //apply method resolution inference (JLS 15.12.2.7). The return type
    //of the resolved constructor will be a partially instantiated type
    ((ClassSymbol) clazztype.tsym).members_field = mapping.snd;
    Symbol constructor;
    try {
        constructor = rs.resolveDiamond(tree.pos(), localEnv, clazztype.tsym.type, argtypes, typeargtypes);
    } finally {
        ((ClassSymbol) clazztype.tsym).members_field = mapping.fst;
    }
    if (constructor.kind == MTH) {
        ClassType ct = new ClassType(clazztype.getEnclosingType(), clazztype.tsym.type.getTypeArguments(), clazztype.tsym);
        clazztype = checkMethod(ct, constructor, localEnv, tree.args, argtypes, typeargtypes, localEnv.info.varArgs).getReturnType();
    } else {
        clazztype = syms.errType;
    }
    if (clazztype.tag == FORALL && !pt.isErroneous()) {
        //bounds (JLS 15.12.2.8).
        try {
            clazztype = infer.instantiateExpr((ForAll) clazztype, pt.tag == NONE ? syms.objectType : pt, Warner.noWarnings);
        } catch (Infer.InferenceException ex) {
            //an error occurred while inferring uninstantiated type-variables
            log.error(tree.clazz.pos(), "cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), ex.diagnostic);
        }
    }
    return chk.checkClassType(tree.clazz.pos(), clazztype, true);
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol) ClassType(com.sun.tools.javac.code.Type.ClassType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) ForAll(com.sun.tools.javac.code.Type.ForAll)

Example 47 with ClassSymbol

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

the class Attr method checkEnumInitializer.

/**
         * Check for illegal references to static members of enum.  In
         * an enum type, constructors and initializers may not
         * reference its static members unless they are constant.
         *
         * @param tree    The tree making up the variable reference.
         * @param env     The current environment.
         * @param v       The variable's symbol.
         * @jls  section 8.9 Enums
         */
private void checkEnumInitializer(JCTree tree, Env<AttrContext> env, VarSymbol v) {
    // is declared to the right of e."
    if (isStaticEnumField(v)) {
        ClassSymbol enclClass = env.info.scope.owner.enclClass();
        if (enclClass == null || enclClass.owner == null)
            return;
        // reference is OK.
        if (v.owner != enclClass && !types.isSubtype(enclClass.type, v.owner.type))
            return;
        // the reference is OK.
        if (!Resolve.isInitializer(env))
            return;
        log.error(tree.pos(), "illegal.enum.static.ref");
    }
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol)

Example 48 with ClassSymbol

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

the class ConstructorDocImpl method name.

/**
     * Get the name.
     *
     * @return the name of the member qualified by class (but not package)
     */
public String name() {
    ClassSymbol c = sym.enclClass();
    String n = c.name.toString();
    for (c = c.owner.enclClass(); c != null; c = c.owner.enclClass()) {
        n = c.name.toString() + "." + n;
    }
    return n;
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol)

Example 49 with ClassSymbol

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

the class TypesImpl method getDeclaredType.

/**
     * {@inheritDoc}
     */
public DeclaredType getDeclaredType(DeclaredType containing, TypeDeclaration decl, TypeMirror... typeArgs) {
    if (containing == null)
        return getDeclaredType(decl, typeArgs);
    ClassSymbol sym = ((TypeDeclarationImpl) decl).sym;
    Type outer = ((TypeMirrorImpl) containing).type;
    if (outer.tsym != sym.owner.enclClass())
        throw new IllegalArgumentException(containing.toString());
    if (!outer.isParameterized())
        return getDeclaredType(decl, typeArgs);
    return getDeclaredType(outer, sym, typeArgs);
}
Also used : Type(com.sun.tools.javac.code.Type) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeMirrorImpl(com.sun.tools.apt.mirror.type.TypeMirrorImpl)

Aggregations

ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)49 Symbol (com.sun.tools.javac.code.Symbol)20 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)20 Type (com.sun.tools.javac.code.Type)17 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)10 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)9 ClassType (com.sun.tools.javac.code.Type.ClassType)9 ClassTree (com.sun.source.tree.ClassTree)8 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)8 MethodTree (com.sun.source.tree.MethodTree)6 Tree (com.sun.source.tree.Tree)6 ArrayType (com.sun.tools.javac.code.Type.ArrayType)5 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)4 VariableTree (com.sun.source.tree.VariableTree)4 Name (com.sun.tools.javac.util.Name)4 ArrayList (java.util.ArrayList)4 Violation (com.google.errorprone.bugpatterns.threadsafety.ImmutableAnalysis.Violation)3 BlockTree (com.sun.source.tree.BlockTree)3 EnhancedForLoopTree (com.sun.source.tree.EnhancedForLoopTree)3 ForLoopTree (com.sun.source.tree.ForLoopTree)3