Search in sources :

Example 66 with Symbol

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

the class ClassDocImpl method importedPackages.

/**
     * Get the list of packages declared as imported.
     * These are called "type-import-on-demand declarations" in the JLS.
     * This method is deprecated in the ClassDoc interface.
     *
     * @return an array of PackageDocImpl representing the imported packages.
     *
     * ###NOTE: the syntax supports importing all inner classes from a class as well.
     * @deprecated  Import declarations are implementation details that
     *          should not be exposed here.  In addition, this method's
     *          return type does not allow for all type-import-on-demand
     *          declarations to be returned.
     */
@Deprecated
public PackageDoc[] importedPackages() {
    // information is not available for binary classfiles
    if (tsym.sourcefile == null)
        return new PackageDoc[0];
    ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<PackageDocImpl>();
    //### Add the implicit "import java.lang.*" to the result
    Names names = tsym.name.table.names;
    importedPackages.append(env.getPackageDoc(env.reader.enterPackage(names.java_lang)));
    Env<AttrContext> compenv = env.enter.getEnv(tsym);
    if (compenv == null)
        return new PackageDocImpl[0];
    for (JCTree t : compenv.toplevel.defs) {
        if (t.getTag() == JCTree.IMPORT) {
            JCTree imp = ((JCImport) t).qualid;
            if (TreeInfo.name(imp) == names.asterisk) {
                JCFieldAccess sel = (JCFieldAccess) imp;
                Symbol s = sel.selected.type.tsym;
                PackageDocImpl pdoc = env.getPackageDoc(s.packge());
                if (!importedPackages.contains(pdoc))
                    importedPackages.append(pdoc);
            }
        }
    }
    return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]);
}
Also used : Names(com.sun.tools.javac.util.Names) JCImport(com.sun.tools.javac.tree.JCTree.JCImport) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) Symbol(com.sun.tools.javac.code.Symbol) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) AttrContext(com.sun.tools.javac.comp.AttrContext)

Example 67 with Symbol

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

the class TypeVariableImpl method owner.

/**
     * Return the class, interface, method, or constructor within
     * which this type variable is declared.
     */
public ProgramElementDoc owner() {
    Symbol osym = type.tsym.owner;
    if ((osym.kind & Kinds.TYP) != 0) {
        return env.getClassDoc((ClassSymbol) osym);
    }
    Names names = osym.name.table.names;
    if (osym.name == names.init) {
        return env.getConstructorDoc((MethodSymbol) osym);
    } else {
        return env.getMethodDoc((MethodSymbol) osym);
    }
}
Also used : Names(com.sun.tools.javac.util.Names) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) Symbol(com.sun.tools.javac.code.Symbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol)

Example 68 with Symbol

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

the class Annotate method enterAnnotation.

/* ********************************************************************
 * Compute an attribute from its annotation.
 *********************************************************************/
/** Process a single compound annotation, returning its
     *  Attribute. Used from MemberEnter for attaching the attributes
     *  to the annotated symbol.
     */
Attribute.Compound enterAnnotation(JCAnnotation a, Type expected, Env<AttrContext> env) {
    // The annotation might have had its type attributed (but not checked)
    // by attr.attribAnnotationTypes during MemberEnter, in which case we do not
    // need to do it again.
    Type at = (a.annotationType.type != null ? a.annotationType.type : attr.attribType(a.annotationType, env));
    a.type = chk.checkType(a.annotationType.pos(), at, expected);
    if (a.type.isErroneous())
        return new Attribute.Compound(a.type, List.<Pair<MethodSymbol, Attribute>>nil());
    if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) {
        log.error(a.annotationType.pos(), "not.annotation.type", a.type.toString());
        return new Attribute.Compound(a.type, List.<Pair<MethodSymbol, Attribute>>nil());
    }
    List<JCExpression> args = a.args;
    if (args.length() == 1 && args.head.getTag() != JCTree.ASSIGN) {
        // special case: elided "value=" assumed
        args.head = make.at(args.head.pos).Assign(make.Ident(names.value), args.head);
    }
    ListBuffer<Pair<MethodSymbol, Attribute>> buf = new ListBuffer<Pair<MethodSymbol, Attribute>>();
    for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
        JCExpression t = tl.head;
        if (t.getTag() != JCTree.ASSIGN) {
            log.error(t.pos(), "annotation.value.must.be.name.value");
            continue;
        }
        JCAssign assign = (JCAssign) t;
        if (assign.lhs.getTag() != JCTree.IDENT) {
            log.error(t.pos(), "annotation.value.must.be.name.value");
            continue;
        }
        JCIdent left = (JCIdent) assign.lhs;
        Symbol method = rs.resolveQualifiedMethod(left.pos(), env, a.type, left.name, List.<Type>nil(), null);
        left.sym = method;
        left.type = method.type;
        if (method.owner != a.type.tsym)
            log.error(left.pos(), "no.annotation.member", left.name, a.type);
        Type result = method.type.getReturnType();
        Attribute value = enterAttributeValue(result, assign.rhs, env);
        if (!method.type.isErroneous())
            buf.append(new Pair<MethodSymbol, Attribute>((MethodSymbol) method, value));
        t.type = result;
    }
    return new Attribute.Compound(a.type, buf.toList());
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Example 69 with Symbol

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

the class Attr method visitSelect.

public void visitSelect(JCFieldAccess tree) {
    // Determine the expected kind of the qualifier expression.
    int skind = 0;
    if (tree.name == names._this || tree.name == names._super || tree.name == names._class) {
        skind = TYP;
    } else {
        if ((pkind & PCK) != 0)
            skind = skind | PCK;
        if ((pkind & TYP) != 0)
            skind = skind | TYP | PCK;
        if ((pkind & (VAL | MTH)) != 0)
            skind = skind | VAL | TYP;
    }
    // Attribute the qualifier expression, and determine its symbol (if any).
    Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
    if ((pkind & (PCK | TYP)) == 0)
        // Capture field access
        site = capture(site);
    // don't allow T.class T[].class, etc
    if (skind == TYP) {
        Type elt = site;
        while (elt.tag == ARRAY) elt = ((ArrayType) elt).elemtype;
        if (elt.tag == TYPEVAR) {
            log.error(tree.pos(), "type.var.cant.be.deref");
            result = types.createErrorType(tree.type);
            return;
        }
    }
    // If qualifier symbol is a type or `super', assert `selectSuper'
    // for the selection. This is relevant for determining whether
    // protected symbols are accessible.
    Symbol sitesym = TreeInfo.symbol(tree.selected);
    boolean selectSuperPrev = env.info.selectSuper;
    env.info.selectSuper = sitesym != null && sitesym.name == names._super;
    // they can be added later (in Attr.checkId and Infer.instantiateMethod).
    if (tree.selected.type.tag == FORALL) {
        ForAll pstype = (ForAll) tree.selected.type;
        env.info.tvars = pstype.tvars;
        site = tree.selected.type = pstype.qtype;
    }
    // Determine the symbol represented by the selection.
    env.info.varArgs = false;
    Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
    if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
        site = capture(site);
        sym = selectSym(tree, sitesym, site, env, pt, pkind);
    }
    boolean varArgs = env.info.varArgs;
    tree.sym = sym;
    if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) {
        while (site.tag == TYPEVAR) site = site.getUpperBound();
        site = capture(site);
    }
    // If that symbol is a variable, ...
    if (sym.kind == VAR) {
        VarSymbol v = (VarSymbol) sym;
        // ..., evaluate its initializer, if it has one, and check for
        // illegal forward reference.
        checkInit(tree, env, v, true);
        // that the variable is assignable in the current environment.
        if (pkind == VAR)
            checkAssignable(tree.pos(), v, tree.selected, env);
    }
    if (sitesym != null && sitesym.kind == VAR && ((VarSymbol) sitesym).isResourceVariable() && sym.kind == MTH && sym.name.equals(names.close) && sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && env.info.lint.isEnabled(LintCategory.TRY)) {
        log.warning(LintCategory.TRY, tree, "try.explicit.close.call");
    }
    // Disallow selecting a type from an expression
    if (isType(sym) && (sitesym == null || (sitesym.kind & (TYP | PCK)) == 0)) {
        tree.type = check(tree.selected, pt, sitesym == null ? VAL : sitesym.kind, TYP | PCK, pt);
    }
    if (isType(sitesym)) {
        if (sym.name == names._this) {
            // C.this' does not appear in a call to a super(...)
            if (env.info.isSelfCall && site.tsym == env.enclClass.sym) {
                chk.earlyRefError(tree.pos(), sym);
            }
        } else {
            // Check if type-qualified fields or methods are static (JLS)
            if ((sym.flags() & STATIC) == 0 && sym.name != names._super && (sym.kind == VAR || sym.kind == MTH)) {
                rs.access(rs.new StaticError(sym), tree.pos(), site, sym.name, true);
            }
        }
    } else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) {
        // If the qualified item is not a type and the selected item is static, report
        // a warning. Make allowance for the class of an array type e.g. Object[].class)
        chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner);
    }
    // If we are selecting an instance member via a `super', ...
    if (env.info.selectSuper && (sym.flags() & STATIC) == 0) {
        // Check that super-qualified symbols are not abstract (JLS)
        rs.checkNonAbstract(tree.pos(), sym);
        if (site.isRaw()) {
            // Determine argument types for site.
            Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym);
            if (site1 != null)
                site = site1;
        }
    }
    // Ceylon: error if we try to select an interface static in < 1.8
    if (sym != null && sym.isStatic() && (sym.kind & Kinds.MTH) != 0 && sitesym != null && sitesym.isInterface()) {
        chk.checkStaticInterfaceMethodCall(tree);
    }
    env.info.selectSuper = selectSuperPrev;
    result = checkId(tree, site, sym, env, pkind, pt, varArgs);
    env.info.tvars = List.nil();
}
Also used : ArrayType(com.sun.tools.javac.code.Type.ArrayType) 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) 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) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) ForAll(com.sun.tools.javac.code.Type.ForAll) Lint(com.sun.tools.javac.code.Lint)

Example 70 with Symbol

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

the class Attr method checkAutoCloseable.

void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
    if (!resource.isErroneous() && types.asSuper(resource, syms.autoCloseableType.tsym) != null) {
        Symbol close = syms.noSymbol;
        boolean prevDeferDiags = log.deferDiagnostics;
        Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics;
        try {
            log.deferDiagnostics = true;
            log.deferredDiagnostics = ListBuffer.lb();
            close = rs.resolveQualifiedMethod(pos, env, resource, names.close, List.<Type>nil(), List.<Type>nil());
        } finally {
            log.deferDiagnostics = prevDeferDiags;
            log.deferredDiagnostics = prevDeferredDiags;
        }
        if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && env.info.lint.isEnabled(LintCategory.TRY)) {
            log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource);
        }
    }
}
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) JCDiagnostic(com.sun.tools.javac.util.JCDiagnostic) 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)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)195 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)56 Type (com.sun.tools.javac.code.Type)54 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)53 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)45 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)36 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)29 JCTree (com.sun.tools.javac.tree.JCTree)28 ClassType (com.sun.tools.javac.code.Type.ClassType)18 Tree (com.sun.source.tree.Tree)17 ExpressionTree (com.sun.source.tree.ExpressionTree)15 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)15 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)15 ClassTree (com.sun.source.tree.ClassTree)14 MethodTree (com.sun.source.tree.MethodTree)14 Name (com.sun.tools.javac.util.Name)14 IdentifierTree (com.sun.source.tree.IdentifierTree)13 ArrayType (com.sun.tools.javac.code.Type.ArrayType)12 MethodType (com.sun.tools.javac.code.Type.MethodType)12 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)12