Java Code Examples for com.sun.source.util.Trees#getTree()

The following examples show how to use com.sun.source.util.Trees#getTree() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeTypeInternal.java    From vertx-codegen with Apache License 2.0 6 votes vote down vote up
public TypeUse.TypeInternal forReturn(ProcessingEnvironment env, ExecutableElement methodElt) {
  Trees trees = Trees.instance(env);
  if (trees == null) {
    return null;
  }
  JCTree.JCMethodDecl tree = (JCTree.JCMethodDecl) trees.getTree(methodElt);
  if (tree == null) {
    return null;
  }
  JCTree type = tree.getReturnType();
  boolean nullable = isNullable(type);
  if (!nullable) {
    JCTree.JCModifiers mods = tree.mods;
    for (JCTree.JCAnnotation jca : mods.annotations) {
      if (jca.type.toString().equals(TypeUse.NULLABLE)) {
        nullable = true;
        break;
      }
    }
  }
  return new TreeTypeInternal(type, nullable);
}
 
Example 2
Source File: TestGetTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 3
Source File: TestGetTree.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 4
Source File: TestGetTree.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 5
Source File: ChangeParamsTransformer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * special treatment for anonymous classes to resolve the proper constructor
 * of extended class instead of the synthetic one.
 * @see <a href="https://netbeans.org/bugzilla/show_bug.cgi?id=168775">#168775</a>
 */
private Element resolveAnonymousClassConstructor(Element el, NewClassTree tree, final Trees trees) {
    if (el != null && tree.getClassBody() != null) {
        Tree t = trees.getTree(el);
        if (t != null && t.getKind() == Tree.Kind.METHOD) {
            MethodTree constructorTree = (MethodTree) t;
            Tree superCall = constructorTree.getBody().getStatements().get(0);
            TreePath superCallPath = trees.getPath(
                    getCurrentPath().getCompilationUnit(),
                    ((ExpressionStatementTree) superCall).getExpression());
            el = trees.getElement(superCallPath);
        }
    }
    return el;
}
 
Example 6
Source File: ElementVisitor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private long[] getPosition( Element e ) {
    Trees trees = cc.getTrees();
    CompilationUnitTree cut = cc.getCompilationUnit();
    Tree t = trees.getTree(e);        
    if ( t == null ) {            
        return new long[]{-1,-1};
    }        
    SourcePositions sourcePositions = trees.getSourcePositions();        
    return new long[] {sourcePositions.getStartPosition(cut, t),sourcePositions.getEndPosition(cut, t)};
}
 
Example 7
Source File: NullAway.java    From NullAway with MIT License 5 votes vote down vote up
private void addGuaranteedNonNullFromInvokes(
    VisitorState state,
    Trees trees,
    Set<Element> safeInitMethods,
    AccessPathNullnessAnalysis nullnessAnalysis,
    ImmutableSet.Builder<Element> guaranteedNonNullBuilder) {
  for (Element invoked : safeInitMethods) {
    Tree invokedTree = trees.getTree(invoked);
    guaranteedNonNullBuilder.addAll(
        nullnessAnalysis.getNonnullFieldsOfReceiverAtExit(
            new TreePath(state.getPath(), invokedTree), state.context));
  }
}
 
Example 8
Source File: TestGetTree.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 9
Source File: TestGetTree.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 10
Source File: TestGetTree.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 11
Source File: TestGetTree.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 12
Source File: TestGetTree.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment)
{
    final Trees trees = Trees.instance(processingEnv);
    for (TypeElement e : typesIn(roundEnvironment.getRootElements())) {
        ClassTree node = trees.getTree(e);
        System.out.println(node.toString());
    }
    return true;
}
 
Example 13
Source File: TreeTypeInternal.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
public TypeUse.TypeInternal forParam(ProcessingEnvironment env, ExecutableElement methodElt, int paramIndex) {
  Trees trees = Trees.instance(env);
  if (trees == null) {
    return null;
  }
  MethodTree tree = trees.getTree(methodElt);
  if (tree == null) {
    return null;
  }
  Tree type = tree.getParameters().get(paramIndex).getType();
  return new TreeTypeInternal(type, isNullable(type));
}