Search in sources :

Example 46 with JCTree

use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.

the class Flow method addVars.

// where
/** Add any variables defined in stats to inits and uninits. */
private static void addVars(List<JCStatement> stats, Bits inits, Bits uninits) {
    for (; stats.nonEmpty(); stats = stats.tail) {
        JCTree stat = stats.head;
        if (stat.getTag() == JCTree.VARDEF) {
            int adr = ((JCVariableDecl) stat).sym.adr;
            inits.excl(adr);
            uninits.incl(adr);
        }
    }
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree)

Example 47 with JCTree

use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.

the class Check method checkCyclicConstructors.

/* *************************************************************************
 * Check for cycles in the constructor call graph.
 **************************************************************************/
/** Check for cycles in the graph of constructors calling other
     *  constructors.
     */
void checkCyclicConstructors(JCClassDecl tree) {
    Map<Symbol, Symbol> callMap = new HashMap<Symbol, Symbol>();
    // enter each constructor this-call into the map
    for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
        JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head);
        if (app == null)
            continue;
        JCMethodDecl meth = (JCMethodDecl) l.head;
        if (TreeInfo.name(app.meth) == names._this) {
            callMap.put(meth.sym, TreeInfo.symbol(app.meth));
        } else {
            meth.sym.flags_field |= ACYCLIC;
        }
    }
    // Check for cycles in the map
    Symbol[] ctors = new Symbol[0];
    ctors = callMap.keySet().toArray(ctors);
    for (Symbol caller : ctors) {
        checkCyclicConstructor(tree, caller, callMap);
    }
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) JCTree(com.sun.tools.javac.tree.JCTree)

Example 48 with JCTree

use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.

the class Check method checkNonCyclicElements.

/* *************************************************************************
 * Check for recursive annotation elements.
 **************************************************************************/
/** Check for cycles in the graph of annotation elements.
     */
void checkNonCyclicElements(JCClassDecl tree) {
    if ((tree.sym.flags_field & ANNOTATION) == 0)
        return;
    Assert.check((tree.sym.flags_field & LOCKED) == 0);
    try {
        tree.sym.flags_field |= LOCKED;
        for (JCTree def : tree.defs) {
            if (def.getTag() != JCTree.METHODDEF)
                continue;
            JCMethodDecl meth = (JCMethodDecl) def;
            checkAnnotationResType(meth.pos(), meth.restype.type);
        }
    } finally {
        tree.sym.flags_field &= ~LOCKED;
        tree.sym.flags_field |= ACYCLIC_ANN;
    }
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree)

Example 49 with JCTree

use of com.sun.tools.javac.tree.JCTree 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 50 with JCTree

use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.

the class JavacTaskImpl method parseType.

/**
     * For internal use only.  This method will be
     * removed without warning.
     */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        CharBuffer buf = CharBuffer.wrap((expr + "").toCharArray(), 0, expr.length());
        Parser parser = parserFactory.newParser(buf, false, false, false);
        JCTree tree = parser.parseType();
        return attr.attribType(tree, (Symbol.TypeSymbol) scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) CharBuffer(java.nio.CharBuffer) JCTree(com.sun.tools.javac.tree.JCTree) ParserFactory(com.sun.tools.javac.parser.ParserFactory) Parser(com.sun.tools.javac.parser.Parser)

Aggregations

JCTree (com.sun.tools.javac.tree.JCTree)183 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)28 Symbol (com.sun.tools.javac.code.Symbol)22 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)22 Type (com.sun.tools.javac.code.Type)19 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)17 Tree (com.sun.source.tree.Tree)15 ExpressionTree (com.sun.source.tree.ExpressionTree)14 JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)14 SuggestedFix (com.google.errorprone.fixes.SuggestedFix)11 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)10 ArrayList (java.util.ArrayList)10 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)9 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)9 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)8 ListBuffer (com.sun.tools.javac.util.ListBuffer)8 Type (com.redhat.ceylon.model.typechecker.model.Type)7 ClassTree (com.sun.source.tree.ClassTree)7 MemberSelectTree (com.sun.source.tree.MemberSelectTree)7