Search in sources :

Example 41 with VarSymbol

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

the class JavacClass method getDirectFields.

@Override
public List<FieldMirror> getDirectFields() {
    if (fields == null) {
        List<FieldMirror> ret = new LinkedList<FieldMirror>();
        for (Symbol sym : classSymbol.getEnclosedElements()) {
            if (sym instanceof VarSymbol && (sym.flags() & Flags.PRIVATE) == 0) {
                ret.add(new JavacField((VarSymbol) sym));
            }
        }
        fields = Collections.unmodifiableList(ret);
    }
    return fields;
}
Also used : FieldMirror(com.redhat.ceylon.model.loader.mirror.FieldMirror) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) Symbol(com.sun.tools.javac.code.Symbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) LinkedList(java.util.LinkedList)

Example 42 with VarSymbol

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

the class JavacMethod method getParameters.

@Override
public List<VariableMirror> getParameters() {
    if (parameters == null) {
        com.sun.tools.javac.util.List<VarSymbol> params = methodSymbol.getParameters();
        List<VariableMirror> ret = new ArrayList<VariableMirror>(params.size());
        for (VarSymbol parameter : params) ret.add(new JavacVariable(parameter));
        parameters = Collections.unmodifiableList(ret);
    }
    return parameters;
}
Also used : VariableMirror(com.redhat.ceylon.model.loader.mirror.VariableMirror) ArrayList(java.util.ArrayList) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Example 43 with VarSymbol

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

the class Attr method checkSerialVersionUID.

/** Check that an appropriate serialVersionUID member is defined. */
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
    // check for presence of serialVersionUID
    Scope.Entry e = c.members().lookup(names.serialVersionUID);
    while (e.scope != null && e.sym.kind != VAR) e = e.next();
    if (e.scope == null) {
        log.warning(LintCategory.SERIAL, tree.pos(), "missing.SVUID", c);
        return;
    }
    // check that it is static final
    VarSymbol svuid = (VarSymbol) e.sym;
    if ((svuid.flags() & (STATIC | FINAL)) != (STATIC | FINAL))
        log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
    else // check that it is long
    if (svuid.type.tag != TypeTags.LONG)
        log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
    else // check constant
    if (svuid.getConstValue() == null)
        log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
}
Also used : Scope(com.sun.tools.javac.code.Scope) DelegatedScope(com.sun.tools.javac.code.Scope.DelegatedScope) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Example 44 with VarSymbol

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

the class Attr method checkId.

/** Determine type of identifier or select expression and check that
         *  (1) the referenced symbol is not deprecated
         *  (2) the symbol's type is safe (@see checkSafe)
         *  (3) if symbol is a variable, check that its type and kind are
         *      compatible with the prototype and protokind.
         *  (4) if symbol is an instance field of a raw type,
         *      which is being assigned to, issue an unchecked warning if its
         *      type changes under erasure.
         *  (5) if symbol is an instance method of a raw type, issue an
         *      unchecked warning if its argument types change under erasure.
         *  If checks succeed:
         *    If symbol is a constant, return its constant type
         *    else if symbol is a method, return its result type
         *    otherwise return its type.
         *  Otherwise return errType.
         *
         *  @param tree       The syntax tree representing the identifier
         *  @param site       If this is a select, the type of the selected
         *                    expression, otherwise the type of the current class.
         *  @param sym        The symbol representing the identifier.
         *  @param env        The current environment.
         *  @param pkind      The set of expected kinds.
         *  @param pt         The expected type.
         */
Type checkId(JCTree tree, Type site, Symbol sym, Env<AttrContext> env, int pkind, Type pt, boolean useVarargs) {
    if (pt.isErroneous())
        return types.createErrorType(site);
    // The computed type of this identifier occurrence.
    Type owntype;
    switch(sym.kind) {
        case TYP:
            // For types, the computed type equals the symbol's type,
            // except for two situations:
            owntype = sym.type;
            if (owntype.tag == CLASS) {
                Type ownOuter = owntype.getEnclosingType();
                // We recover generic outer type later in visitTypeApply.
                if (owntype.tsym.type.getTypeArguments().nonEmpty()) {
                    owntype = types.erasure(owntype);
                } else // Tree<Point>.Visitor.
                if (ownOuter.tag == CLASS && site != ownOuter) {
                    Type normOuter = site;
                    if (normOuter.tag == CLASS)
                        normOuter = types.asEnclosingSuper(site, ownOuter.tsym);
                    if (// perhaps from an import
                    normOuter == null)
                        normOuter = types.erasure(ownOuter);
                    if (normOuter != ownOuter)
                        owntype = new ClassType(normOuter, List.<Type>nil(), owntype.tsym);
                }
            }
            break;
        case VAR:
            VarSymbol v = (VarSymbol) sym;
            // its type changes under erasure.
            if (allowGenerics && pkind == VAR && v.owner.kind == TYP && (v.flags() & STATIC) == 0 && (site.tag == CLASS || site.tag == TYPEVAR)) {
                Type s = types.asOuterSuper(site, v.owner);
                if (s != null && s.isRaw() && !types.isSameType(v.type, v.erasure(types))) {
                    chk.warnUnchecked(tree.pos(), "unchecked.assign.to.var", v, s);
                }
            }
            // The computed type of a variable is the type of the
            // variable symbol, taken as a member of the site type.
            owntype = (sym.owner.kind == TYP && sym.name != names._this && sym.name != names._super) ? types.memberType(site, sym) : sym.type;
            if (env.info.tvars.nonEmpty()) {
                Type owntype1 = new ForAll(env.info.tvars, owntype);
                for (List<Type> l = env.info.tvars; l.nonEmpty(); l = l.tail) if (!owntype.contains(l.head)) {
                    log.error(tree.pos(), "undetermined.type", owntype1);
                    owntype1 = types.createErrorType(owntype1);
                }
                owntype = owntype1;
            }
            // computed type.
            if (v.getConstValue() != null && isStaticReference(tree))
                owntype = owntype.constType(v.getConstValue());
            if (pkind == VAL) {
                // capture "names as expressions"
                owntype = capture(owntype);
            }
            break;
        case MTH:
            {
                JCMethodInvocation app = (JCMethodInvocation) env.tree;
                owntype = checkMethod(site, sym, env, app.args, pt.getParameterTypes(), pt.getTypeArguments(), env.info.varArgs);
                break;
            }
        case PCK:
        case ERR:
            owntype = sym.type;
            break;
        default:
            throw new AssertionError("unexpected kind: " + sym.kind + " in tree " + tree);
    }
    if (sym.name != names.init) {
        chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym);
        chk.checkSunAPI(tree.pos(), sym);
    }
    // kind are compatible with the prototype and protokind.
    return check(tree, owntype, sym.kind, pkind, pt);
}
Also used : JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) 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) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) 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 45 with VarSymbol

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

the class SerializedForm method computeDefaultSerializableFields.

/*
     * Compute default Serializable fields from all members of ClassSymbol.
     *
     * Since the fields of ClassDocImpl might not contain private or
     * package accessible fields, must walk over all members of ClassSymbol.
     */
private void computeDefaultSerializableFields(DocEnv env, ClassSymbol def, ClassDocImpl cd) {
    for (Scope.Entry e = def.members().elems; e != null; e = e.sibling) {
        if (e.sym != null && e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol) e.sym;
            if ((f.flags() & Flags.STATIC) == 0 && (f.flags() & Flags.TRANSIENT) == 0) {
                //### No modifier filtering applied here.
                FieldDocImpl fd = env.getFieldDoc(f);
                //### Add to beginning.
                //### Preserve order used by old 'javadoc'.
                fields.prepend(fd);
            }
        }
    }
}
Also used : Scope(com.sun.tools.javac.code.Scope) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Aggregations

VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)45 Symbol (com.sun.tools.javac.code.Symbol)24 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)21 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)16 Type (com.sun.tools.javac.code.Type)12 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)11 ExpressionTree (com.sun.source.tree.ExpressionTree)10 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)10 Tree (com.sun.source.tree.Tree)9 IdentifierTree (com.sun.source.tree.IdentifierTree)7 MemberSelectTree (com.sun.source.tree.MemberSelectTree)7 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)7 ClassType (com.sun.tools.javac.code.Type.ClassType)7 ClassTree (com.sun.source.tree.ClassTree)6 NewClassTree (com.sun.source.tree.NewClassTree)6 VariableTree (com.sun.source.tree.VariableTree)6 BlockTree (com.sun.source.tree.BlockTree)5 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)5 EnhancedForLoopTree (com.sun.source.tree.EnhancedForLoopTree)5 ForLoopTree (com.sun.source.tree.ForLoopTree)5