use of com.sun.source.util.TreePath in project ceylon-compiler by ceylon.
the class JavacTrees method getElement.
public Element getElement(TreePath path) {
JCTree tree = (JCTree) path.getLeaf();
Symbol sym = TreeInfo.symbolFor(tree);
if (sym == null && TreeInfo.isDeclaration(tree)) {
for (TreePath p = path; p != null; p = p.getParentPath()) {
JCTree t = (JCTree) p.getLeaf();
if (t.getTag() == JCTree.CLASSDEF) {
JCClassDecl ct = (JCClassDecl) t;
if (ct.sym != null) {
if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
attr.attribClass(ct.pos(), ct.sym);
sym = TreeInfo.symbolFor(tree);
}
break;
}
}
}
}
return sym;
}
use of com.sun.source.util.TreePath in project ceylon-compiler by ceylon.
the class ModelChecker method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver())
return true;
Trees trees = Trees.instance(processingEnv);
TypeElement testAnno = elements.getTypeElement("Check");
for (Element elem : roundEnv.getElementsAnnotatedWith(testAnno)) {
TreePath p = trees.getPath(elem);
new MulticatchParamTester(trees).scan(p, null);
}
return true;
}
use of com.sun.source.util.TreePath in project robolectric by robolectric.
the class DeprecatedMethodsCheck method getSurroundingMethodCall.
private static MethodCall getSurroundingMethodCall(Tree node, VisitorState state) {
TreePath nodePath = TreePath.getPath(state.getPath(), node);
TreePath parentPath = nodePath.getParentPath();
if (parentPath.getLeaf().getKind() == Kind.MEMBER_SELECT) {
Tree grandparentNode = parentPath.getParentPath().getLeaf();
if (grandparentNode.getKind() == Kind.METHOD_INVOCATION) {
return new MethodCall((JCMethodInvocation) grandparentNode);
}
}
return null;
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertMethodDeclaration.
private TreeNode convertMethodDeclaration(MethodTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
ExecutableElement element = (ExecutableElement) getElement(path);
MethodDeclaration newNode = new MethodDeclaration();
// JCMethodDecl's preferred diagnostic position is the beginning of the method name.
int methodStartPosition = ((JCMethodDecl) node).pos().getPreferredPosition();
int length = ElementUtil.isConstructor(element) ? element.toString().indexOf('(') : node.getName().length();
Name name = Name.newName(null, /* qualifier */
element);
name.setPosition(new SourcePosition(methodStartPosition, length));
convertBodyDeclaration(node, parent, node.getModifiers(), newNode);
for (VariableTree param : node.getParameters()) {
newNode.addParameter((SingleVariableDeclaration) convert(param, path));
}
return newNode.setIsConstructor(ElementUtil.isConstructor(element)).setExecutableElement(element).setBody((Block) convert(node.getBody(), path)).setName(name);
}
use of com.sun.source.util.TreePath in project j2objc by google.
the class TreeConverter method convertNewArray.
private TreeNode convertNewArray(NewArrayTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
ArrayCreation newNode = new ArrayCreation();
List<Expression> dimensions = new ArrayList<>();
for (ExpressionTree dimension : node.getDimensions()) {
dimensions.add((Expression) convert(dimension, path));
}
javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) getTypeMirror(path);
if (node.getInitializers() != null) {
ArrayInitializer initializers = new ArrayInitializer(type);
for (ExpressionTree initializer : node.getInitializers()) {
initializers.addExpression((Expression) convert(initializer, path));
}
newNode.setInitializer(initializers);
}
return newNode.setType((ArrayType) new ArrayType(type).setPosition(getPosition(node))).setDimensions(dimensions);
}
Aggregations