Search in sources :

Example 66 with JCTree

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

the class TreeCopier method visitCompoundAssignment.

public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
    JCAssignOp t = (JCAssignOp) node;
    JCTree lhs = copy(t.lhs, p);
    JCTree rhs = copy(t.rhs, p);
    return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree)

Example 67 with JCTree

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

the class JavacParser method annotation.

/** Annotation              = "@" Qualident [ "(" AnnotationFieldValues ")" ]
     * @param pos position of "@" token
     */
JCAnnotation annotation(int pos) {
    // accept(AT); // AT consumed by caller
    checkAnnotations();
    JCTree ident = qualident();
    List<JCExpression> fieldValues = annotationFieldValuesOpt();
    JCAnnotation ann = F.at(pos).Annotation(ident, fieldValues);
    storeEnd(ann, S.prevEndPos());
    return ann;
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree)

Example 68 with JCTree

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

the class T6406771 method process.

public boolean process(Set<? extends TypeElement> elems, RoundEnvironment rEnv) {
    // avoid matching this string
    final String LINE = "line" + ':';
    final String COLUMN = "col" + ':';
    final Messager messager = processingEnv.getMessager();
    final Trees trees = Trees.instance(processingEnv);
    TreeScanner<Void, LineMap> s = new TreeScanner<Void, LineMap>() {

        public Void visitLiteral(LiteralTree tree, LineMap lineMap) {
            if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
                String s = (String) tree.getValue();
                // can't get through public api, bug 6412669 filed
                int pos = ((JCTree) tree).pos;
                String prefix;
                long found;
                if (s.startsWith(LINE)) {
                    prefix = LINE;
                    found = lineMap.getLineNumber(pos);
                } else if (s.startsWith(COLUMN)) {
                    prefix = COLUMN;
                    found = lineMap.getColumnNumber(pos);
                } else
                    return null;
                int expect = Integer.parseInt(s.substring(prefix.length()));
                if (expect != found) {
                    messager.printMessage(Diagnostic.Kind.ERROR, "Error: " + prefix + " pos=" + pos + " expect=" + expect + " found=" + found);
                }
            }
            return null;
        }
    };
    for (Element e : rEnv.getRootElements()) {
        System.err.println(e);
        Tree t = trees.getTree(e);
        TreePath p = trees.getPath(e);
        s.scan(p.getLeaf(), p.getCompilationUnit().getLineMap());
    }
    return true;
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree) JCTree(com.sun.tools.javac.tree.JCTree)

Example 69 with JCTree

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

the class CheckAttributedTree method read.

/**
     * Read a file.
     * @param file the file to be read
     * @return the tree for the content of the file
     * @throws IOException if any IO errors occur
     * @throws TreePosTest.ParseException if any errors occur while parsing the file
     */
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
    JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
    final List<Element> analyzedElems = new ArrayList<>();
    task.setTaskListener(new TaskListener() {

        public void started(TaskEvent e) {
            if (e.getKind() == TaskEvent.Kind.ANALYZE)
                analyzedElems.add(e.getTypeElement());
        }

        public void finished(TaskEvent e) {
        }
    });
    try {
        Iterable<? extends CompilationUnitTree> trees = task.parse();
        task.analyze();
        List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
        //System.out.println("Try to add pairs. Elems are " + analyzedElems);
        for (CompilationUnitTree t : trees) {
            JCCompilationUnit cu = (JCCompilationUnit) t;
            for (JCTree def : cu.defs) {
                if (def.getTag() == JCTree.CLASSDEF && analyzedElems.contains(((JCTree.JCClassDecl) def).sym)) {
                    //System.out.println("Adding pair...");
                    res.add(new Pair<>(cu, def));
                }
            }
        }
        return res;
    } catch (Throwable t) {
        throw new AttributionException("Exception while attributing file: " + file);
    }
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) JCClassDecl(com.sun.tools.javac.tree.JCTree.JCClassDecl) JavacTool(com.sun.tools.javac.api.JavacTool) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList) JCTree(com.sun.tools.javac.tree.JCTree) TaskListener(com.sun.source.util.TaskListener) TaskEvent(com.sun.source.util.TaskEvent) JavacTask(com.sun.source.util.JavacTask) Pair(com.sun.tools.javac.util.Pair)

Example 70 with JCTree

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

the class Anno method testElement.

void testElement(Trees trees, Element e) {
    trees.getClass();
    e.getClass();
    System.err.println("testElement: " + e);
    Tree tree = trees.getTree(e);
    if (TreeInfo.symbolFor((JCTree) tree) != e)
        error("bad result from getTree");
    TreePath path = trees.getPath(e);
    if (path == null) {
        error("getPath returned null");
        return;
    }
    if (path.getLeaf() != tree)
        error("bad result from getPath");
    Element e2 = trees.getElement(path);
    if (e2 == null) {
        error("getElement returned null");
        return;
    }
    if (e2 != e)
        error("bad result from getElement");
    // The TypeMirror is not available yet when annotation processing;
    // it is set up later during ANALYSE.
    TypeMirror t = trees.getTypeMirror(path);
    if (t != null && t.getKind() == TypeKind.DECLARED && ((DeclaredType) t).asElement() != e2)
        error("bad result from getTypeMirror");
    for (AnnotationMirror m : e.getAnnotationMirrors()) {
        testAnnotation(trees, e, m);
    }
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree) JCTree(com.sun.tools.javac.tree.JCTree)

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