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);
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations