Package com.sun.source.util

Examples of com.sun.source.util.TreePath


   *
   * @param treePath
   * @return the assignment context as described.
   */
  public static Tree getAssignmentContext(final TreePath treePath) {
    TreePath path = treePath.getParentPath();

    if (path == null) {
      return null;
    }
    Tree node = path.getLeaf();
    if ((node instanceof AssignmentTree) || (node instanceof CompoundAssignmentTree) || (node instanceof MethodInvocationTree)
        || (node instanceof NewArrayTree) || (node instanceof NewClassTree) || (node instanceof ReturnTree)
        || (node instanceof VariableTree)) {
      return node;
    }
View Full Code Here


   * @param kinds
   *            the set of kinds of the desired tree
   * @return the enclosing tree of the given type as given by the path
   */
  public static Tree enclosingOfKind(final TreePath path, final Set<Tree.Kind> kinds) {
    TreePath p = path;

    while (p != null) {
      Tree leaf = p.getLeaf();
      assert leaf != null; /* nninvariant */
      if (kinds.contains(leaf.getKind())) {
        return leaf;
      }
      p = p.getParentPath();
    }

    return null;
  }
View Full Code Here

   * @param kinds
   *            the set of kinds of the desired tree
   * @return the enclosing tree of the given type as given by the path
   */
  public static <T extends Tree> TreePath enclosingPathOfType(final TreePath path, final Class<T> clz) {
    TreePath p = path;

    while (p != null) {
      Tree leaf = p.getLeaf();
      assert leaf != null; /* nninvariant */
      if (clz.isAssignableFrom(leaf.getClass())) {
        return p;
      }
      p = p.getParentPath();
    }

    return null;
  }
View Full Code Here

   * @param kinds
   *            the set of kinds of the desired tree
   * @return the path to the enclosing tree of the given type
   */
  public static TreePath pathTillOfKind(final TreePath path, final Set<Tree.Kind> kinds) {
    TreePath p = path;

    while (p != null) {
      Tree leaf = p.getLeaf();
      assert leaf != null; /* nninvariant */
      if (kinds.contains(leaf.getKind())) {
        return p;
      }
      p = p.getParentPath();
    }

    return null;
  }
View Full Code Here

   * @param treeClass
   *            the class of the desired tree
   * @return the enclosing tree of the given type as given by the path
   */
  public static <T extends Tree> T enclosingOfClass(final TreePath path, final Class<T> treeClass) {
    TreePath p = path;

    while (p != null) {
      Tree leaf = p.getLeaf();
      if (treeClass.isInstance(leaf)) {
        return treeClass.cast(leaf);
      }
      p = p.getParentPath();
    }

    return null;
  }
View Full Code Here

    }
    return null;
  }

  private boolean isVarArg(GenerationContext<Void> context) {
    TreePath path = context.getCurrentPath();
    if (!(path.getParentPath().getLeaf() instanceof VariableTree)) {
      return false;
    }
    return InternalUtils.isVarArg(path.getParentPath().getLeaf());
  }
View Full Code Here

    }
    return InternalUtils.isVarArg(path.getParentPath().getLeaf());
  }

  private boolean argOfMainMethod(GenerationContext<Void> context) {
    TreePath path = context.getCurrentPath();
    if (!(path.getParentPath().getLeaf() instanceof VariableTree)) {
      return false;
    }
    if (!(path.getParentPath().getParentPath().getLeaf() instanceof MethodTree)) {
      return false;
    }
    MethodTree method = (MethodTree) path.getParentPath().getParentPath().getLeaf();
    if (!(method.getParameters().size() == 1 && method.getParameters().get(0) == path.getParentPath().getLeaf())) {
      // make sure we reference the first parameter
      return false;
    }
    return ClassWriter.isMainMethod(method);
  }
View Full Code Here

  public boolean isInnerType() {
    return element.getEnclosingElement().getKind() != ElementKind.PACKAGE;
  }

  public <C extends Tree> TreeWrapper<C, JS> child(C child) {
    return context.wrap(new TreePath(path, child));
  }
View Full Code Here

  public TreeWrapper<ClassTree, JS> getEnclosingType() {
    return context.wrap(element.getEnclosingElement());
  }

  public TreeWrapper<ClassTree, JS> getCurrentType() {
    TreePath classPath = TreeUtils.enclosingPathOfType(path, ClassTree.class);
    if (classPath == null) {
      return null;
    }

    return context.wrap(classPath);
View Full Code Here

import com.sun.source.util.TreePath;

public class IdentifierAccessOuterScopeCheck implements CheckContributor<IdentifierTree> {

  private static boolean isInsideInizializerBlock(TreePath path) {
    TreePath p = path;
    while (p != null) {
      if (p.getLeaf() instanceof BlockTree && p.getParentPath().getLeaf() instanceof ClassTree) {
        return true;
      }
      if (p.getLeaf() instanceof MethodTree) {
        return false;
      }
      p = p.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.