Package com.sun.source.tree

Examples of com.sun.source.tree.MethodTree


      path = path.getParentPath();
    }
    if (path == null) {
      throw new IllegalStateException("Should have an enclosing method declaration");
    }
    MethodTree methodDecl = (MethodTree) path.getLeaf();
    for (VariableTree param : methodDecl.getParameters()) {
      if (symbols.contains(ASTHelpers.getSymbol(param))) {
        return true;
      }
    }
View Full Code Here


      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(),
        methodPath.getCompilationUnit().getSourceFile().getName());

    final ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
    final ControlFlowGraph cfg = cfgCache.getUnchecked(new CFGParams(methodPath, env));
    final AnalysisParams aparams = new AnalysisParams(transfer, cfg, env);
View Full Code Here

      // 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

            ASTHelpers.findEnclosingNode(state.getPath(), SynchronizedTree.class);
        if (synchronizedTree != null) {
          return true;
        }

        MethodTree methodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
        return methodTree != null
            && methodTree.getModifiers().getFlags().contains(Modifier.SYNCHRONIZED);

      }
    };
  }
View Full Code Here

    public boolean matches(ClassTree classTree, VisitorState state) {
      for (Tree member : classTree.getMembers()) {
        if (member.getKind() != Tree.Kind.METHOD) {
          continue;
        }
        MethodTree methodTree = (MethodTree) member;
        if (hasAnnotationOnAnyOverriddenMethod(JUNIT4_TEST_ANNOTATION).matches(methodTree, state)) {
          return true;
        }
      }
      return false;
View Full Code Here

    for (Caller caller : callersToEvaluate.removeAll(symbol)) {
      VisitorState state = caller.state;
      MethodInvocationTree invocation = caller.tree;

      MethodTree callerConstructor = state.findEnclosing(MethodTree.class);
      if (callerConstructor == null) {
        continue; // impossible, at least in compilable code?
      }
      Map<String, Type> availableParams = indexTypeByName(callerConstructor.getParameters());

      /*
       * TODO(cpovirk): Better handling of varargs: If the last parameter type is varargs and it is
       * called as varargs (rather than by passing an array), then rewrite the parameter types to
       * (p0, p1, ..., p[n-2], p[n-1] = element type of varargs parameter if an argument is
View Full Code Here

        if (((TypeElement) c.getAnnotationType().asElement()).getQualifiedName()
            .contentEquals(ASSISTED_ANNOTATION)) {
          thisParamsAssisted = c;
        }
      }
      MethodTree enclosingMethod = (MethodTree) state.getPath().getParentPath().getLeaf();
      // count the number of parameters of this type and value. One is expected since we
      // will be iterating through all parameters including the one we're matching.
      int numIdentical = 0;
      for (VariableTree parameter : enclosingMethod.getParameters()) {
        if (Matchers.<VariableTree>isSameType(variableTree).matches(parameter, state)) {
          Compound otherParamsAssisted = null;
          for (Compound c : ASTHelpers.getSymbol(parameter).getAnnotationMirrors()) {
            if (((TypeElement) c.getAnnotationType().asElement()).getQualifiedName()
                .contentEquals(ASSISTED_ANNOTATION)) {
View Full Code Here

      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

    }
    return null;
  }

  private static void findVariablesInMethod(final String name, final GenerationContext<Void> context) {
    MethodTree enclosingMethod = getEnclosingMethod(context.getCurrentPath());

    if (enclosingMethod == null) {
      // don't see a reason why!?
      return;
    }
    enclosingMethod.accept(new TreeScanner<Void, Void>() {
      private boolean checkStopped;

      @Override
      public Void visitClass(ClassTree arg0, Void arg1) {
        // stop the checks if a new type is encountered
View Full Code Here

  private boolean isAbstractInstanceMethod(Tree member) {
    if (!(member instanceof MethodTree)) {
      return false;
    }
    MethodTree methodTree = (MethodTree) member;
    return methodTree.getBody() == null;
  }
View Full Code Here

TOP

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

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.