Search in sources :

Example 11 with AttrContext

use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.

the class ClassDocImpl method importedClasses.

/**
     * Get the list of classes declared as imported.
     * These are called "single-type-import declarations" in the JLS.
     * This method is deprecated in the ClassDoc interface.
     *
     * @return an array of ClassDocImpl representing the imported classes.
     *
     * @deprecated  Import declarations are implementation details that
     *          should not be exposed here.  In addition, not all imported
     *          classes are imported through single-type-import declarations.
     */
@Deprecated
public ClassDoc[] importedClasses() {
    // information is not available for binary classfiles
    if (tsym.sourcefile == null)
        return new ClassDoc[0];
    ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<ClassDocImpl>();
    Env<AttrContext> compenv = env.enter.getEnv(tsym);
    if (compenv == null)
        return new ClassDocImpl[0];
    Name asterisk = tsym.name.table.names.asterisk;
    for (JCTree t : compenv.toplevel.defs) {
        if (t.getTag() == JCTree.IMPORT) {
            JCTree imp = ((JCImport) t).qualid;
            if ((TreeInfo.name(imp) != asterisk) && (imp.type.tsym.kind & Kinds.TYP) != 0) {
                importedClasses.append(env.getClassDoc((ClassSymbol) imp.type.tsym));
            }
        }
    }
    return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]);
}
Also used : JCImport(com.sun.tools.javac.tree.JCTree.JCImport) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) AttrContext(com.sun.tools.javac.comp.AttrContext) Name(com.sun.tools.javac.util.Name)

Example 12 with AttrContext

use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.

the class ClassDocImpl method searchClass.

private ClassDoc searchClass(String className) {
    Names names = tsym.name.table.names;
    // search by qualified name first
    ClassDoc cd = env.lookupClass(className);
    if (cd != null) {
        return cd;
    }
    // search inner classes
    //### Add private entry point to avoid creating array?
    //### Replicate code in innerClasses here to avoid consing?
    ClassDoc[] innerClasses = innerClasses();
    for (int i = 0; i < innerClasses.length; i++) {
        if (innerClasses[i].name().equals(className) || //### 'name' of the inner class, rather than the true simple name.
        innerClasses[i].name().endsWith(className)) {
            return innerClasses[i];
        } else {
            ClassDoc innercd = ((ClassDocImpl) innerClasses[i]).searchClass(className);
            if (innercd != null) {
                return innercd;
            }
        }
    }
    // check in this package
    cd = containingPackage().findClass(className);
    if (cd != null) {
        return cd;
    }
    // make sure that this symbol has been completed
    if (tsym.completer != null) {
        tsym.complete();
    }
    if (tsym.sourcefile != null) {
        //### This information is available only for source classes.
        Env<AttrContext> compenv = env.enter.getEnv(tsym);
        if (compenv == null)
            return null;
        Scope s = compenv.toplevel.namedImportScope;
        for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
            if (e.sym.kind == Kinds.TYP) {
                ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
                return c;
            }
        }
        s = compenv.toplevel.starImportScope;
        for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
            if (e.sym.kind == Kinds.TYP) {
                ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
                return c;
            }
        }
    }
    // not found
    return null;
}
Also used : Names(com.sun.tools.javac.util.Names) Scope(com.sun.tools.javac.code.Scope) AttrContext(com.sun.tools.javac.comp.AttrContext)

Example 13 with AttrContext

use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.

the class JavacElements method getTreeAndTopLevel.

/**
     * Returns the tree node and compilation unit corresponding to this
     * element, or null if they can't be found.
     */
private Pair<JCTree, JCCompilationUnit> getTreeAndTopLevel(Element e) {
    Symbol sym = cast(Symbol.class, e);
    Env<AttrContext> enterEnv = getEnterEnv(sym);
    if (enterEnv == null)
        return null;
    JCTree tree = TreeInfo.declarationFor(sym, enterEnv.tree);
    if (tree == null || enterEnv.toplevel == null)
        return null;
    return new Pair<JCTree, JCCompilationUnit>(tree, enterEnv.toplevel);
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) JCTree(com.sun.tools.javac.tree.JCTree) AttrContext(com.sun.tools.javac.comp.AttrContext)

Aggregations

AttrContext (com.sun.tools.javac.comp.AttrContext)13 JCTree (com.sun.tools.javac.tree.JCTree)6 Symbol (com.sun.tools.javac.code.Symbol)4 Log (com.sun.tools.javac.util.Log)4 JavacScope (com.sun.tools.javac.api.JavacScope)3 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)2 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)2 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)2 Type (com.sun.tools.javac.code.Type)2 JCImport (com.sun.tools.javac.tree.JCTree.JCImport)2 ListBuffer (com.sun.tools.javac.util.ListBuffer)2 Name (com.sun.tools.javac.util.Name)2 Names (com.sun.tools.javac.util.Names)2 Element (javax.lang.model.element.Element)2 VariableElement (javax.lang.model.element.VariableElement)2 CatchTree (com.sun.source.tree.CatchTree)1 ClassTree (com.sun.source.tree.ClassTree)1 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 MethodTree (com.sun.source.tree.MethodTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1