Package com.sun.source.tree

Examples of com.sun.source.tree.MethodInvocationTree


  @Override
  public Description matchWhileLoop(WhileLoopTree tree, VisitorState state) {
    JCWhileLoop whileLoop = (JCWhileLoop) tree;
    JCExpression whileExpression = ((JCParens) whileLoop.getCondition()).getExpression();
    if (whileExpression instanceof MethodInvocationTree) {
      MethodInvocationTree methodInvocation = (MethodInvocationTree) whileExpression;
      if (methodSelect(isDescendantOfMethod("java.util.Iterator", "hasNext()")).matches(
          methodInvocation, state)) {
        IdentifierTree identifier = getIncrementedIdentifer(extractSingleStatement(whileLoop.body));
        if (identifier != null) {
          return describeMatch(tree);
View Full Code Here


  public boolean matches(ExpressionTree t, VisitorState state) {
    if (t.getKind() != Kind.METHOD_INVOCATION) {
      return false
    }
   
    MethodInvocationTree methodInvocation = (MethodInvocationTree) t;
    return methodSelectMatcher.matches(methodInvocation.getMethodSelect(), state);
  }
View Full Code Here

    MemberSelectTree method =
        (MemberSelectTree) methodInvocationTree.getMethodSelect();

    List<? extends ExpressionTree> arguments =
        methodInvocationTree.getArguments();
    MethodInvocationTree stringFormat = (MethodInvocationTree) arguments.get(1);

    // TODO(user): Figure out how to get a suggested fix. Basically we
    // remove the String.format() wrapper, but I don't know how to express
    // this.
    return describeMatch(arguments.get(1));
View Full Code Here

    @Override
    public boolean matches(ExpressionTree t, VisitorState state) {
      if (!(t instanceof MethodInvocationTree)) {
        return false;
      }
      MethodInvocationTree stringFormatInvocation = (MethodInvocationTree) t;
      if (!(stringFormatInvocation.getArguments().get(0)
          instanceof LiteralTree)) {
        return false;
      }
      LiteralTree firstArg = (LiteralTree)
          stringFormatInvocation.getArguments().get(0);
      String literal = firstArg.getValue().toString();
      return !invalidFormatCharacters.matcher(literal).find();
    }
View Full Code Here

   */
  public static Supplier<Type> receiverType() {
    return new Supplier<Type>() {
      @Override
      public Type get(VisitorState state) {
        MethodInvocationTree methodInvocation = (MethodInvocationTree) state.getPath().getLeaf();
        return ASTHelpers.getReceiverType(methodInvocation.getMethodSelect());
      }
    };
  }
View Full Code Here

   */
  public static Supplier<ExpressionTree> receiverInstance() {
    return new Supplier<ExpressionTree>() {
      @Override
      public ExpressionTree get(VisitorState state) {
        MethodInvocationTree method = (MethodInvocationTree) state.getPath().getLeaf();
        return ((JCFieldAccess) method.getMethodSelect()).getExpression();
      }
    };
  }
View Full Code Here

  private static boolean isFieldGetMethod(String methodName) {
    return methodName.startsWith("get");
  }

  private static String getMethodName(ExpressionTree tree) {
    MethodInvocationTree method = (MethodInvocationTree) tree;
    ExpressionTree expressionTree = method.getMethodSelect();
    JCFieldAccess access = (JCFieldAccess) expressionTree;
    return access.sym.getQualifiedName().toString();
  }
View Full Code Here

    return access.sym.getQualifiedName().toString();
  }

  private static boolean isGetListMethodInvocation(ExpressionTree tree, VisitorState state) {
    if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
      MethodInvocationTree method = (MethodInvocationTree) tree;
      if (!method.getArguments().isEmpty()) {
        return false;
      }
      if (!returnsListMatcher.matches(method, state)) {
        return false;
      }
      ExpressionTree expressionTree = method.getMethodSelect();
      if (expressionTree instanceof JCFieldAccess) {
        JCFieldAccess access = (JCFieldAccess) expressionTree;
        String methodName = access.sym.getQualifiedName().toString();
        return isFieldGetMethod(methodName);
      }
View Full Code Here

    return false;
  }

  private static boolean isGetMethodInvocation(ExpressionTree tree, VisitorState state) {
    if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
      MethodInvocationTree method = (MethodInvocationTree) tree;
      if (!method.getArguments().isEmpty()) {
        return false;
      }
      if (returnsListMatcher.matches(method, state)) {
        return false;
      }
      ExpressionTree expressionTree = method.getMethodSelect();
      if (expressionTree instanceof JCFieldAccess) {
        JCFieldAccess access = (JCFieldAccess) expressionTree;
        String methodName = access.sym.getQualifiedName().toString();
        return isFieldGetMethod(methodName);
      }
View Full Code Here

      return NO_MATCH;
    }

    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
       * supplied, p[n] = ditto, etc.). For now, we settle for not crashing in the face of a
       * mismatch between the number of parameters declared and the number supplied.
       *
       * (Use MethodSymbol.isVarArgs.)
       */
      for (int i = 0; i < paramTypes.size() && i < invocation.getArguments().size(); i++) {
        VariableTree formalParam = paramTypes.get(i);
        String formalParamName = formalParam.getName().toString();
        Type formalParamType = getType(formalParam.getType());

        Type availableParamType = availableParams.get(formalParamName);

        ExpressionTree actualParam = invocation.getArguments().get(i);

        if (
            /*
             * The caller has no param of this type. (Or if it did, we couldn't determine the type.
             * Does that ever happen?) If the param doesn't exist, the caller can't be failing to
View Full Code Here

TOP

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

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.