Search in sources :

Example 61 with TreePath

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;
}
Also used : TreePath(com.sun.source.util.TreePath) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) JCTree(com.sun.tools.javac.tree.JCTree)

Example 62 with TreePath

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;
}
Also used : Trees(com.sun.source.util.Trees) TreePath(com.sun.source.util.TreePath) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement)

Example 63 with TreePath

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;
}
Also used : TreePath(com.sun.source.util.TreePath) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ImportTree(com.sun.source.tree.ImportTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree)

Example 64 with TreePath

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);
}
Also used : TreePath(com.sun.source.util.TreePath) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) SourcePosition(com.google.devtools.j2objc.ast.SourcePosition) VariableTree(com.sun.source.tree.VariableTree) Block(com.google.devtools.j2objc.ast.Block) SimpleName(com.google.devtools.j2objc.ast.SimpleName) Name(com.google.devtools.j2objc.ast.Name) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName)

Example 65 with TreePath

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);
}
Also used : ArrayList(java.util.ArrayList) ArrayType(com.google.devtools.j2objc.ast.ArrayType) TreePath(com.sun.source.util.TreePath) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) JCFunctionalExpression(com.sun.tools.javac.tree.JCTree.JCFunctionalExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) ArrayCreation(com.google.devtools.j2objc.ast.ArrayCreation) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) ExpressionTree(com.sun.source.tree.ExpressionTree) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Aggregations

TreePath (com.sun.source.util.TreePath)151 ExpressionTree (com.sun.source.tree.ExpressionTree)60 Tree (com.sun.source.tree.Tree)60 VariableTree (com.sun.source.tree.VariableTree)50 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)46 MethodTree (com.sun.source.tree.MethodTree)46 ClassTree (com.sun.source.tree.ClassTree)45 MemberSelectTree (com.sun.source.tree.MemberSelectTree)39 IdentifierTree (com.sun.source.tree.IdentifierTree)37 BlockTree (com.sun.source.tree.BlockTree)36 NewClassTree (com.sun.source.tree.NewClassTree)32 StatementTree (com.sun.source.tree.StatementTree)32 JCTree (com.sun.tools.javac.tree.JCTree)31 AssignmentTree (com.sun.source.tree.AssignmentTree)27 BinaryTree (com.sun.source.tree.BinaryTree)27 TypeCastTree (com.sun.source.tree.TypeCastTree)26 ExpressionStatementTree (com.sun.source.tree.ExpressionStatementTree)25 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)25 LiteralTree (com.sun.source.tree.LiteralTree)25 CompoundAssignmentTree (com.sun.source.tree.CompoundAssignmentTree)23