Package com.sun.source.tree

Examples of com.sun.source.tree.Tree


      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;
View Full Code Here


  @BugPattern(name = "SuperCallMatcher", explanation = "",
      category = ONE_OFF, maturity = EXPERIMENTAL, severity = ERROR, summary = "")
  private static class SuperCallMatcher extends BugChecker implements MethodInvocationTreeMatcher {
    @Override
    public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
      Tree select = tree.getMethodSelect();
      Name name;
      if (select instanceof MemberSelectTree) {
        name = ((MemberSelectTree) select).getIdentifier();
      } else if (select instanceof IdentifierTree) {
        name = ((IdentifierTree) select).getName();
View Full Code Here

    this.treeMatcher = treeMatcher;
  }

  @Override
  public boolean matches(Tree tree, VisitorState state) {
    Tree parent = state.getPath().getParentPath().getLeaf();
    try {
      return treeMatcher.matches(parent, state.withPath(state.getPath().getParentPath()));
    } catch (ClassCastException e) {
      return false;
    }
View Full Code Here

   * Otherwise, delete the checkNotNull call. E.g.:
   *   Preconditions.checkNotNull(foo); ==> [delete the line]
   */
  public Description describe(MethodInvocationTree methodInvocationTree, VisitorState state) {
    ExpressionTree arg1 = methodInvocationTree.getArguments().get(0);
    Tree parent = state.getPath().getParentPath().getLeaf();

    // Assignment, return, etc.
    if (parent.getKind() != Kind.EXPRESSION_STATEMENT) {
      return describeMatch(arg1,
          SuggestedFix.replace(methodInvocationTree, arg1.toString()));
    }

    // Comparison to null
View Full Code Here

    // The current method is inconsistent with all of its supermethods, so flip the varargs-ness
    // of the current method.

    List<? extends VariableTree> parameterTree = methodTree.getParameters();
    Tree paramType = parameterTree.get(parameterTree.size() - 1).getType();
    CharSequence paramTypeSource = state.getSourceForNode((JCTree) paramType);
    if (paramTypeSource == null) {
      // No fix if we don't have tree end positions.
      return describeMatch(methodTree);
    }
View Full Code Here

        }
      };

  @Override
  public final Description matchAnnotation(AnnotationTree annotationTree, VisitorState state) {
    Tree modified = getCurrentlyAnnotatedNode(state);
    if (SCOPE_ANNOTATION_MATCHER.matches(annotationTree, state) &&
        modified instanceof ClassTree &&
        INTERFACE_AND_ABSTRACT_TYPE_MATCHER.matches((ClassTree) modified, state)) {
      return describeMatch(annotationTree, SuggestedFix.delete(annotationTree));
    }
View Full Code Here

  @Override
  public Description matchAnnotation(AnnotationTree annotationTree, VisitorState state) {
    if (!javaxInjectAnnotationMatcher.matches(annotationTree, state)) {
      return Description.NO_MATCH;
    }
    Tree annotatedNode = state.getPath().getParentPath().getParentPath().getLeaf();
    if (isMethod(annotatedNode) && isAbstract(annotatedNode)) {
      return describeMatch(annotationTree, SuggestedFix.delete(annotationTree));
    }
    return Description.NO_MATCH;
  }
View Full Code Here

   * - for all contexts, the analysis result is the same.
   */
  public static <A extends AbstractValue<A>, S extends Store<S>,
                 T extends TransferFunction<A, S>> Result<A, S, T>
      methodDataflow(TreePath methodPath, Context context, T transfer) {
    final Tree leaf = methodPath.getLeaf();
    Preconditions.checkArgument(leaf instanceof MethodTree,
        "Leaf of methodPath must be of type MethodTree, but was %s", leaf.getClass().getName());

    final MethodTree method = (MethodTree) leaf;
    Preconditions.checkNotNull(method.getBody(),
        "Method to analyze must have a body. Method passed in: %s() in file %s",
        method.getName(),
View Full Code Here

   * which is the leaf of {@code exprPath}.
   */
  public static <A extends AbstractValue<A>, S extends Store<S>,
                 T extends TransferFunction<A, S>> A
      expressionDataflow(TreePath exprPath, Context context, T transfer) {
    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);

View Full Code Here

  private Matcher<ClassTree> constructorsWithInjectAndAssistedInjectMatcher =
      Matchers.<ClassTree>allOf(constructorWithInjectMatcher, constructorWithAssistedInjectMatcher);

  @Override
  public final Description matchAnnotation(AnnotationTree annotationTree, VisitorState state) {
    Tree modified = state.getPath().getParentPath().getParentPath().getLeaf();
    if (ASTHelpers.getSymbol(modified).isConstructor()) {
      Symbol annotationSymbol = ASTHelpers.getSymbol(annotationTree);
      if (annotationSymbol.equals(state.getSymbolFromString(JAVAX_INJECT_ANNOTATION))
          || annotationSymbol.equals(state.getSymbolFromString(GUICE_INJECT_ANNOTATION))
          || annotationSymbol.equals(state.getSymbolFromString(ASSISTED_INJECT_ANNOTATION))) {
View Full Code Here

TOP

Related Classes of com.sun.source.tree.Tree

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.