Package com.sun.source.util

Examples of com.sun.source.util.TreePath


    ScannerTest test = new ScannerTest() {
      private boolean matched = false;

      @Override
      public Void visitAnnotation(AnnotationTree node, VisitorState visitorState) {
        TreePath currPath = getCurrentPath().getParentPath();
        Tree parent = currPath.getLeaf();
        if (parent.getKind() == Kind.MODIFIERS) {
          currPath = currPath.getParentPath();
          parent = currPath.getLeaf();
        }
        if (toMatch.matches(parent, visitorState)) {
          matched = true;
        }
        return super.visitAnnotation(node, visitorState);
View Full Code Here


              .setMessage(AMBIGUOUS_CALL_MESSAGE).build();
        }
        return NO_MATCH;
      }

      TreePath root = state.getPath();
      List<Object> values = new ArrayList<>();
      for (Tree arg : methodInvocation.getArguments()) {
        TreePath argPath = new TreePath(root, arg);
        values.add(expressionDataflow(argPath, state.context, NULLNESS_PROPAGATION));
      }

      String fixString = "(" + Joiner.on(", ").join(values) + ")";
      return describeMatch(methodInvocation, replace(methodInvocation, fixString));
View Full Code Here

      // sees each class once, and (2) that they haven't been desugared yet.
      if (!seen.add(env.tree)) {
        return;
      }

      TreePath path;
      if (env.toplevel != env.tree) {
        // The current tree is a class decl, so construct a TreePath rooted at the enclosing
        // compilation unit.
        path = TreePath.getPath(env.toplevel, env.tree);
      } else {
        // The current tree is a compilation unit. Wrap the compilation unit to hide its class
        // decls, since (1) we've already visited them, and (2) the bodies of all but the last class
        // decl have been lowered out of them.
        path = new TreePath(new DeclFreeCompilationUnitWrapper(env.toplevel));
      }
      errorProneScanner.scan(path, createVisitorState(env));
    } catch (CompletionFailure e) {
      // A CompletionFailure can be triggered when error-prone tries to complete a symbol
      // that isn't on the compilation classpath. This can occur when a check performs an
View Full Code Here

   * @param <T>
   * @return the node, or null if there is no enclosing tree node of this type
   */
  @SafeVarargs
  public final <T extends Tree> T findEnclosing(java.lang.Class<? extends T>... classes) {
    TreePath enclosingPath = getPath();
    while (enclosingPath != null) {
      for (java.lang.Class<? extends T> aClass : classes) {
        if (aClass.isInstance(enclosingPath.getLeaf())) {
          return aClass.cast(enclosingPath.getLeaf());
        }
      }
      enclosingPath = enclosingPath.getParentPath();
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }
 
  public <T extends Tree> T findEnclosing(java.lang.Class<T> aClass) {
    TreePath enclosingPath = getPath();
    while (enclosingPath != null) {
      if (aClass.isInstance(enclosingPath.getLeaf())) {
        return aClass.cast(enclosingPath.getLeaf());
      }
      enclosingPath = enclosingPath.getParentPath();
    }
    return null;
  }
View Full Code Here

    Trees treeUtils = Trees.instance(processingEnv);
    if (treeUtils == null) {
      return Collections.emptyList();
    }

    TreePath path = treeUtils.getPath(element, annotation);
    if (path == null) {
      return Collections.emptyList();
    }

    CompilationUnitTree unitTree = path.getCompilationUnit();
    LineMap lineMap = unitTree.getLineMap();
    SourcePositions positions = treeUtils.getSourcePositions();

    AnnotationTree annotationTree = (AnnotationTree) path.getLeaf();
    AssignmentTree assignTree =
        (AssignmentTree) annotationTree.getArguments().get(0);
    ExpressionTree exprTree = assignTree.getExpression();

    ArrayList<Long> lines = new ArrayList<Long>();
View Full Code Here

    Trees treeUtils = Trees.instance(processingEnv);
    if (treeUtils == null) {
      return Collections.emptySet();
    }

    TreePath path = treeUtils.getPath(element);
    if (path == null) {
      return Collections.emptySet();
    }

    CompilationUnitTree unitTree = path.getCompilationUnit();

    HashSet<String> importNames = new HashSet<String>();
    for (ImportTree importTree : unitTree.getImports()) {
      StringBuilder buffer = new StringBuilder();
      if (importTree.isStatic()) {
View Full Code Here

    R r = f.apply(a, b);
    return r == null ? f.apply(b, a) : r;
  }

  private static boolean isNonNull(ExpressionTree expr, VisitorState state) {
    return JDKCompatible.isDefinitelyNonNull(new TreePath(state.getPath(), expr), state.context);
  }
View Full Code Here

    final Tree leaf = exprPath.getLeaf();
    Preconditions.checkArgument(leaf instanceof ExpressionTree,
        "Leaf of exprPath must be of type ExpressionTree, but was %s", leaf.getClass().getName());

    final ExpressionTree expr = (ExpressionTree) leaf;
    final TreePath enclosingMethodPath =
        findPathFromEnclosingNodeToTopLevel(exprPath, MethodTree.class);

    if (enclosingMethodPath == null) {
      // TODO(user) this can happen in field initialization.
      // Currently not supported because it only happens in ~2% of cases.
      return null;
    }

    final MethodTree method = (MethodTree) enclosingMethodPath.getLeaf();
    if (method.getBody() == null) {
      // expressions can occur in abstract methods, for example {@code Map.Entry} in:
      //
      //   abstract Set<Map.Entry<K, V>> entries();
      return null;
View Full Code Here

  public static <T extends Tree> Matcher<Tree> enclosingNode(final Matcher<T> matcher) {
    return new Matcher<Tree>() {
      @SuppressWarnings("unchecked"// TODO(user): this should take a Class<T>
      @Override
      public boolean matches(Tree t, VisitorState state) {
        TreePath path = state.getPath().getParentPath();
        while (path != null) {
          Tree node = path.getLeaf();
          if (matcher.matches((T) node, state)) {
            return true;
          }
          path = path.getParentPath();
        }
        return false;
      }

    };
View Full Code Here

TOP

Related Classes of com.sun.source.util.TreePath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.