Java 类com.sun.source.tree.MethodInvocationTree 实例源码

项目:incubator-netbeans    文件:WorkingCopy.java   
private void addSyntheticTrees(DiffContext diffContext, Tree node) {
    if (node == null) return ;

    if (((JCTree) node).pos == (-1)) {
        diffContext.syntheticTrees.add(node);
        return ;
    }

    if (node.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionTree est = ((ExpressionStatementTree) node).getExpression();

        if (est.getKind() == Kind.METHOD_INVOCATION) {
            ExpressionTree select = ((MethodInvocationTree) est).getMethodSelect();

            if (select.getKind() == Kind.IDENTIFIER && ((IdentifierTree) select).getName().contentEquals("super")) {
                if (getTreeUtilities().isSynthetic(diffContext.origUnit, node)) {
                    diffContext.syntheticTrees.add(node);
                }
            }
        }
    }
}
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
/**
 * Returns default body for the test method. The generated body will
 * contains the following lines:
 * <pre><code>
 * // TODO review the generated test code and remove the default call to fail.
 * fail("The test case is a prototype.");
 * </code></pre>
 * @param maker the tree maker
 * @return an {@literal ExpressionStatementTree} for the generated body.
 * @throws MissingResourceException
 * @throws IllegalStateException
 */
private ExpressionStatementTree generateDefMethodBody(TreeMaker maker)
                    throws MissingResourceException, IllegalStateException {
    String failMsg = NbBundle.getMessage(TestCreator.class,
                               "TestCreator.variantMethods.defaultFailMsg");
    MethodInvocationTree failMethodCall =
        maker.MethodInvocation(
            Collections.<ExpressionTree>emptyList(),
            maker.Identifier("fail"),
            Collections.<ExpressionTree>singletonList(
                                                   maker.Literal(failMsg)));
    ExpressionStatementTree exprStatement =
        maker.ExpressionStatement(failMethodCall);
    if (setup.isGenerateMethodBodyComment()) {
        Comment comment =
            Comment.create(Comment.Style.LINE, -2, -2, -2,
                           NbBundle.getMessage(AbstractTestGenerator.class,
                              "TestCreator.variantMethods.defaultComment"));
        maker.addComment(exprStatement, comment, true);
    }
    return exprStatement;
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
@Override
public Boolean visitMethodInvocation(MethodInvocationTree tree, Stack<Tree> d) {
    Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), tree.getMethodSelect()));

    if (el == null) {
        System.err.println("Warning: decl == null");
        System.err.println("tree=" + tree);
    }

    if (el != null && el.getKind() == ElementKind.METHOD) {
        for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) {
            addToExceptionsMap(m, tree);
        }
    }

    super.visitMethodInvocation(tree, d);
    return null;
}
项目:incubator-netbeans    文件:CreateElementUtilities.java   
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;

    for (Tree param : nat.getArguments()) {
        errorInRealArguments |= param == error;
    }

    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);

        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }

        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);

        return proposedTypes;
    }

    return null;
}
项目:incubator-netbeans    文件:ForbiddenMethod.java   
@TriggerTreeKind(Tree.Kind.METHOD_INVOCATION)
    public static ErrorDescription hint(HintContext ctx) {
        MethodInvocationTree mit = (MethodInvocationTree) ctx.getPath().getLeaf();

        CompilationInfo info = ctx.getInfo();
        Element e = info.getTrees().getElement(new TreePath(ctx.getPath(), mit.getMethodSelect()));

        if (e == null || e.getKind() != ElementKind.METHOD) {
            return null;
        }
        String simpleName = e.getSimpleName().toString();
        String parent = e.getEnclosingElement().getSimpleName().toString();

        Pair<String, String> pair = map.get(simpleName);
        if (pair != null && pair.first().equals(parent)) {
            return ErrorDescriptionFactory.forName(ctx, mit, pair.second());
        }


        return null;
//        return ErrorDescriptionFactory.forName(ctx, mit, "Use of forbidden method");
    }
项目:incubator-netbeans    文件:FileToURL.java   
@TriggerTreeKind(Kind.METHOD_INVOCATION)
public static ErrorDescription computeTreeKind(HintContext ctx) {
    MethodInvocationTree mit = (MethodInvocationTree) ctx.getPath().getLeaf();

    if (!mit.getArguments().isEmpty() || !mit.getTypeArguments().isEmpty()) {
        return null;
    }

    CompilationInfo info = ctx.getInfo();
    Element e = info.getTrees().getElement(new TreePath(ctx.getPath(), mit.getMethodSelect()));

    if (e == null || e.getKind() != ElementKind.METHOD) {
        return null;
    }

    if (e.getSimpleName().contentEquals("toURL") && info.getElementUtilities().enclosingTypeElement(e).getQualifiedName().contentEquals("java.io.File")) {
        ErrorDescription w = ErrorDescriptionFactory.forName(ctx, mit, "Use of java.io.File.toURL()");

        return w;
    }

    return null;
}
项目:incubator-netbeans    文件:LoggerStringConcat.java   
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath invocation = ctx.getPath();
    TreePath message    = FixImpl.this.message.resolve(wc);
    MethodInvocationTree mit = (MethodInvocationTree) invocation.getLeaf();
    ExpressionTree level = null;

    if (logMethodName != null) {
        String logMethodNameUpper = logMethodName.toUpperCase();
        VariableElement c = findConstant(wc, logMethodNameUpper);

        level = wc.getTreeMaker().QualIdent(c);
    } else {
        level = mit.getArguments().get(0);
    }

    rewrite(wc, level, mit, message);
}
项目:javaide    文件:JavaInputAstVisitor.java   
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case MEMBER_SELECT:
            MemberSelectTree fieldAccess = (MemberSelectTree) expression;
            visit(fieldAccess.getIdentifier());
            break;
        case METHOD_INVOCATION:
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            if (!methodInvocation.getTypeArguments().isEmpty()) {
                builder.open(plusFour);
                addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
                // TODO(jdd): Should indent the name -4.
                builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
                builder.close();
            }
            visit(getMethodName(methodInvocation));
            break;
        case IDENTIFIER:
            visit(((IdentifierTree) expression).getName());
            break;
        default:
            scan(expression, null);
            break;
    }
}
项目:javaide    文件:JavaInputAstVisitor.java   
private void dotExpressionArgsAndParen(
        ExpressionTree expression, Indent tyargIndent, Indent indent) {
    Deque<ExpressionTree> indices = getArrayIndices(expression);
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case METHOD_INVOCATION:
            builder.open(tyargIndent);
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            addArguments(methodInvocation.getArguments(), indent);
            builder.close();
            break;
        default:
            break;
    }
    formatArrayIndices(indices);
}
项目:incubator-netbeans    文件:Tiny.java   
@Override
protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    Tree t = ctx.getPath().getLeaf();
    if (t.getKind() != Tree.Kind.METHOD_INVOCATION) {
        return;
    }
    MethodInvocationTree mi = (MethodInvocationTree)t;
    if (mi.getMethodSelect().getKind() != Tree.Kind.MEMBER_SELECT) {
        return;
    }
    MemberSelectTree selector = ((MemberSelectTree)mi.getMethodSelect());
    TreeMaker maker = ctx.getWorkingCopy().getTreeMaker();
    ExpressionTree ms = maker.MemberSelect(maker.QualIdent("java.util.Arrays"), deep ? "deepHashCode" : "hashCode"); // NOI18N
    Tree nue = maker.MethodInvocation(
                    Collections.<ExpressionTree>emptyList(), 
                    ms, 
                    Collections.singletonList(selector.getExpression())
    );
    ctx.getWorkingCopy().rewrite(t, nue);
}
项目:incubator-netbeans    文件:ReplaceBufferByString.java   
@Override
public Boolean visitMethodInvocation(MethodInvocationTree node, Void p) {
    Boolean expr = scan(node.getMethodSelect(), p);
    if (expr == Boolean.TRUE) {
        // check invoked methods
        incompatibleMethodCalled = true;
        return expr;
    } else {
        for (ExpressionTree et : node.getArguments()) {
            Boolean used = scan(et, p);
            if (used == Boolean.TRUE) {
                passedToMethod = true;
            }
        }
    }

    return false;
}
项目:incubator-netbeans    文件:FinalizeDoesNotCallSuper.java   
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    if (!node.getArguments().isEmpty()) {
        return null;
    }
    final ExpressionTree et = node.getMethodSelect();
    if (et.getKind() != Tree.Kind.MEMBER_SELECT) {
        return null;
    }
    final MemberSelectTree mst = (MemberSelectTree) et;
    if (!FINALIZE.contentEquals(mst.getIdentifier())) {
        return null;
    }
    if (mst.getExpression().getKind() != Tree.Kind.IDENTIFIER) {
        return null;
    }
    if (!SUPER.contentEquals(((IdentifierTree)mst.getExpression()).getName())) {
        return null;
    }
    found = true;
    return null;
}
项目:incubator-netbeans    文件:EqualsMethodHint.java   
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    if (node.getArguments().isEmpty()) {
        if (node.getMethodSelect().getKind() == Kind.MEMBER_SELECT) {
            MemberSelectTree mst = (MemberSelectTree) node.getMethodSelect();
            Element e = info.getTrees().getElement(new TreePath(new TreePath(getCurrentPath(), mst), mst.getExpression()));

            if (parameter.equals(e) && mst.getIdentifier().contentEquals("getClass")) { // NOI18N
                throw new Found();
            }
        } else if (node.getMethodSelect().getKind() == Kind.IDENTIFIER) {
            IdentifierTree it = (IdentifierTree) node.getMethodSelect();

            if (it.getName().contentEquals("getClass")) { // NOI18N
                throw new Found();
            }
        }
    }

    return super.visitMethodInvocation(node, p);
}
项目:incubator-netbeans    文件:UncaughtException.java   
/**
    * Detects if we are parameter of this() or super() call
    * @return true if yes
    */ 
   private boolean isThisParameter(TreePath path) {
//anonymous class must not be on the path to top
while(!TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind()) && path.getLeaf().getKind() != Kind.COMPILATION_UNIT) {
    if (path.getParentPath().getLeaf().getKind() == Kind.METHOD_INVOCATION) {
    MethodInvocationTree mi = (MethodInvocationTree) path.getParentPath().getLeaf();
    if(mi.getMethodSelect().getKind() == Kind.IDENTIFIER) {
        String id = ((IdentifierTree) mi.getMethodSelect()).getName().toString();
        if ("super".equals(id) || "this".equals(id))
        return true;
    }
    }
    path = path.getParentPath();
}
return false;
   }
项目:incubator-netbeans    文件:Utilities.java   
/**
 * Attempts to resolve a method or a constructor call with an altered argument tree.
 * 
 * @param ci the context
 * @param invPath path to the method invocation node
 * @param origPath path to the Tree within method's arguments which should be replaced
 * @param valPath the replacement tree
 * @return 
 */
public static boolean checkAlternativeInvocation(CompilationInfo ci, TreePath invPath, 
        TreePath origPath,
        TreePath valPath, String customPrefix) {
    Tree l = invPath.getLeaf();
    Tree sel;

    if (l.getKind() == Tree.Kind.NEW_CLASS) {
        NewClassTree nct = (NewClassTree)invPath.getLeaf();
        sel = nct.getIdentifier();
    } else if (l.getKind() == Tree.Kind.METHOD_INVOCATION) {
        MethodInvocationTree mit = (MethodInvocationTree)invPath.getLeaf();
        sel = mit.getMethodSelect();
    } else {
        return false;
    }

    return resolveAlternativeInvocation(ci, invPath, 
            origPath, sel, valPath, customPrefix);
}
项目:incubator-netbeans    文件:OverridableMethodCallInConstructor.java   
private static boolean invocationOnThis(MethodInvocationTree mit) {
    Tree select = mit.getMethodSelect();

    switch (select.getKind()) {
        case IDENTIFIER:
            return true;
        case MEMBER_SELECT:
            if (((MemberSelectTree) select).getExpression().getKind() == Kind.IDENTIFIER) {
                IdentifierTree ident = (IdentifierTree) ((MemberSelectTree) select).getExpression();

                return ident.getName().contentEquals("this");
            }
    }

    return false;
}
项目:incubator-netbeans    文件:TooStrongCast.java   
/**
 * Checks whether a method or constructor call would become ambiguous if the parameter type changes.
 * 
 * @param info compilation context
 * @param parentExec path to the constructor or method invocation
 * @param argIndex
 * @param casteeType
 * @return 
 */
private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) {
    CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN);
    String prefix = null;
    if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) {
        prefix = "(" + altType + ")"; // NOI18N
    }
    Tree leaf = parentExec.getLeaf();
    List<? extends Tree> arguments;
    if (leaf instanceof MethodInvocationTree) {
        MethodInvocationTree mi = (MethodInvocationTree)leaf;
        arguments = mi.getArguments();
    } else {
        arguments = ((NewClassTree)leaf).getArguments();
    }
    Tree argTree = arguments.get(argIndex);
    TreePath argPath = new TreePath(parentExec, argTree);
    return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix);
}
项目:incubator-netbeans    文件:ResourceStringFoldProvider.java   
private String getBundleName(MethodInvocationTree n, int index, String bfn) {
    if (n.getArguments().size() <= index) {
        return null;
    }
    ExpressionTree t = n.getArguments().get(index);
    // recognize just string literals + .class references
    if (t.getKind() == Tree.Kind.STRING_LITERAL) {
        Object o = ((LiteralTree)t).getValue();
        return o == null ? null : o.toString();
    } else if (t.getKind() == Tree.Kind.MEMBER_SELECT) {
        MemberSelectTree mst = (MemberSelectTree)t;
        if (!mst.getIdentifier().contentEquals("class")) {
            return null;
        }
        return bundleFileFromClass(new TreePath(getCurrentPath(), mst.getExpression()), bfn);
    }
    return null;
}
项目:incubator-netbeans    文件:MethodArgumentsScanner.java   
@Override
public MethodArgument[] visitMethodInvocation(MethodInvocationTree node, Object p) {
    if (!methodInvocation || offset != positions.getEndPosition(tree, node.getMethodSelect())) {
        return super.visitMethodInvocation(node, p);
        /*MethodArgument[] r = scan(node.getTypeArguments(), p);
        r = scanAndReduce(node.getMethodSelect(), p, r);
        r = scanAndReduce(node.getArguments(), p, r);
        return r;*/
    }
    List<? extends ExpressionTree> args = node.getArguments();
    List<? extends Tree> argTypes = node.getTypeArguments();
    /*int n = args.size();
    arguments = new MethodArgument[n];
    for (int i = 0; i < n; i++) {
        arguments[i] = new MethodArgument(args.get(i).toString(), argTypes.get(i).toString());
    }
    return arguments;*/
    arguments = composeArguments(args, argTypes);
    return arguments;
}
项目:RIBs    文件:RxJavaMissingAutodisposeErrorChecker.java   
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
  if (!(tree instanceof MethodInvocationTree)) {
    return false;
  }
  MethodInvocationTree invTree = (MethodInvocationTree) tree;

  final MemberSelectTree memberTree = (MemberSelectTree) invTree.getMethodSelect();
  if (!memberTree.getIdentifier().contentEquals(TO)) {
    return false;
  }

  for (MethodMatchers.MethodNameMatcher nameMatcher : METHOD_NAME_MATCHERS) {
    if (nameMatcher.matches(invTree, state)) {
      ExpressionTree arg = invTree.getArguments().get(0);
      final Type scoper = state.getTypeFromString("com.uber.autodispose.Scoper");
      return ASTHelpers.isSubtype(ASTHelpers.getType(arg), scoper, state);
    }
  }
  return false;
}
项目:affinechecker    文件:AffinePointerTransfer.java   
private Element elementOf(Node n) {
    Tree t = n.getTree();
    if (t instanceof ExpressionTree) {
        return TreeUtils.elementFromUse((ExpressionTree)t);
    } else if (t instanceof MethodInvocationTree) {
        return TreeUtils.elementFromUse((MethodInvocationTree)t);
    } else if (t instanceof NewClassTree) {
        return TreeUtils.elementFromUse((NewClassTree)t);
    } else if (t instanceof VariableTree) {
        return TreeUtils.elementFromDeclaration((VariableTree)t);
    } else if (t instanceof MethodTree) {
        return TreeUtils.elementFromDeclaration((MethodTree)t);
    } else if (t instanceof ClassTree) {
        return TreeUtils.elementFromDeclaration((ClassTree)t);
    } else {
        throw new RuntimeException("Unsupported tree type " + t.getClass());
    }
}
项目:traute    文件:ParameterInstrumentator.java   
private static boolean isFirstStatementThisOrSuperCall(@NotNull JCTree.JCBlock body) {
    List<JCTree.JCStatement> statements = body.getStatements();
    if (statements.isEmpty()) {
        return false;
    }
    JCTree.JCStatement expressionCandidate = statements.get(0);
    if (expressionCandidate instanceof ExpressionStatementTree) {
        ExpressionStatementTree expression = (ExpressionStatementTree) expressionCandidate;
        ExpressionTree methodInvocationCandidate = expression.getExpression();
        if (methodInvocationCandidate instanceof MethodInvocationTree) {
            MethodInvocationTree methodInvocation = (MethodInvocationTree) methodInvocationCandidate;
            ExpressionTree methodSelect = methodInvocation.getMethodSelect();
            if (methodSelect != null) {
                String select = methodSelect.toString();
                return "this".equals(select) || "super".equals(select);
            }
        }
    }
    return false;
}
项目:NullAway    文件:RxNullabilityPropagator.java   
private void handleChainFromFilter(
    StreamTypeRecord streamType,
    MethodInvocationTree observableDotFilter,
    Tree filterMethodOrLambda,
    VisitorState state) {
  // Traverse the observable call chain out through any pass-through methods
  MethodInvocationTree outerCallInChain = observableOuterCallInChain.get(observableDotFilter);
  while (outerCallInChain != null
      && streamType.matchesType(ASTHelpers.getReceiverType(outerCallInChain), state)
      && streamType.isPassthroughMethod(ASTHelpers.getSymbol(outerCallInChain))) {
    outerCallInChain = observableOuterCallInChain.get(outerCallInChain);
  }
  // Check for a map method
  MethodInvocationTree mapCallsite = observableOuterCallInChain.get(observableDotFilter);
  if (outerCallInChain != null
      && observableCallToInnerMethodOrLambda.containsKey(outerCallInChain)) {
    // Update mapToFilterMap
    Symbol.MethodSymbol mapMethod = ASTHelpers.getSymbol(outerCallInChain);
    if (streamType.isMapMethod(mapMethod)) {
      MaplikeToFilterInstanceRecord record =
          new MaplikeToFilterInstanceRecord(
              streamType.getMaplikeMethodRecord(mapMethod), filterMethodOrLambda);
      mapToFilterMap.put(observableCallToInnerMethodOrLambda.get(outerCallInChain), record);
    }
  }
}
项目:NullAway    文件:NullAway.java   
@SuppressWarnings("unused")
private int depth(ExpressionTree expression) {
  switch (expression.getKind()) {
    case MEMBER_SELECT:
      MemberSelectTree selectTree = (MemberSelectTree) expression;
      return 1 + depth(selectTree.getExpression());
    case METHOD_INVOCATION:
      MethodInvocationTree invTree = (MethodInvocationTree) expression;
      return depth(invTree.getMethodSelect());
    case IDENTIFIER:
      IdentifierTree varTree = (IdentifierTree) expression;
      Symbol symbol = ASTHelpers.getSymbol(varTree);
      return (symbol.getKind().equals(ElementKind.FIELD)) ? 2 : 1;
    default:
      return 0;
  }
}
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
/**
     * Returns default body for the test method. The generated body will
     * contains the following lines:
     * <pre><code>
     * // TODO review the generated test code and remove the default call to fail.
     * fail("The test case is a prototype.");
     * </code></pre>
     * @param maker the tree maker
     * @return an {@code ExpressionStatementTree} for the generated body.
     * @throws MissingResourceException
     * @throws IllegalStateException
     */
    @NbBundle.Messages({"TestCreator.variantMethods.defaultFailMsg=The test case is a prototype.",
        "TestCreator.variantMethods.defaultComment=TODO review the generated test code and remove the default call to fail."})
    private ExpressionStatementTree generateDefMethodBody(TreeMaker maker)
                        throws MissingResourceException, IllegalStateException {
//        String failMsg = NbBundle.getMessage(TestCreator.class,
//                                   "TestCreator.variantMethods.defaultFailMsg");
        String failMsg = Bundle.TestCreator_variantMethods_defaultFailMsg();
        MethodInvocationTree failMethodCall =
            maker.MethodInvocation(
                Collections.<ExpressionTree>emptyList(),
                maker.Identifier("fail"),
                Collections.<ExpressionTree>singletonList(
                                                       maker.Literal(failMsg)));
        ExpressionStatementTree exprStatement =
            maker.ExpressionStatement(failMethodCall);
        if (setup.isGenerateMethodBodyComment()) {
//            Comment comment =
//                Comment.create(Comment.Style.LINE, -2, -2, -2,
//                               NbBundle.getMessage(AbstractTestGenerator.class,
//                                  "TestCreator.variantMethods.defaultComment"));
            Comment comment =
                Comment.create(Comment.Style.LINE, -2, -2, -2,
                               Bundle.TestCreator_variantMethods_defaultComment());
            maker.addComment(exprStatement, comment, true);
        }
        return exprStatement;
    }
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
/**
 */
private StatementTree generateSystemOutPrintln(TreeMaker maker,
                                               String arg) {
    MethodInvocationTree methodInvocation = maker.MethodInvocation(
            Collections.<ExpressionTree>emptyList(),        //type args
            maker.MemberSelect(
                    maker.MemberSelect(
                            maker.Identifier("System"), "out"), "println"),//NOI18N
            Collections.<LiteralTree>singletonList(
                    maker.Literal(arg)));                   //args.
    return maker.ExpressionStatement(methodInvocation);
}
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
private StatementTree generateEJBCleanUpCode(TreeMaker maker) {
    IdentifierTree container = maker.Identifier(CONTAINER_VAR_NAME);
    MethodInvocationTree invocation = maker.MethodInvocation(
        Collections.<ExpressionTree>emptyList(),
        maker.MemberSelect(container, "close"), // NOI18N
        Collections.<ExpressionTree>emptyList()
    );
    return maker.ExpressionStatement(invocation);
}
项目:incubator-netbeans    文件:TreeDuplicator.java   
@Override
public Tree visitMethodInvocation(MethodInvocationTree tree, Void p) {
    MethodInvocationTree n = make.MethodInvocation((List<? extends ExpressionTree>)tree.getTypeArguments(), tree.getMethodSelect(), tree.getArguments());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
项目:incubator-netbeans    文件:CopyFinder.java   
public Boolean visitMethodInvocation(MethodInvocationTree node, TreePath p) {
    if (p == null)
        return super.visitMethodInvocation(node, p);

    MethodInvocationTree t = (MethodInvocationTree) p.getLeaf();

    if (!scan(node.getMethodSelect(), t.getMethodSelect(), p))
        return false;

    if (!checkLists(node.getTypeArguments(), t.getTypeArguments(), p))
        return false;

    return checkLists(node.getArguments(), t.getArguments(), p);
}
项目:incubator-netbeans    文件:CommanAndWhitespaceTest.java   
public void testNewClassToFactory() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public void taragui() {\n" +
        "        tests(Integer.MAX_VALUE, new Integer(1));\n" +
        "    }" +
        "    private void test(Integer i1, Integer i2) {}\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public void taragui() {\n" +
        "        tests(Integer.MAX_VALUE, Integer.valueOf(1));\n" +
        "    }" +
        "    private void test(Integer i1, Integer i2) {}\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);

    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree method = (MethodTree) clazz.getMembers().get(1);
            MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) method.getBody().getStatements().get(0)).getExpression();
            MethodInvocationTree valueOf = make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(make.Identifier("Integer"), "valueOf"), Collections.singletonList(make.Literal(1)));
            workingCopy.rewrite(mit.getArguments().get(1), valueOf);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
/**
 */
private StatementTree generateSystemOutPrintln(TreeMaker maker,
                                               String arg) {
    MethodInvocationTree methodInvocation = maker.MethodInvocation(
            Collections.<ExpressionTree>emptyList(),        //type args
            maker.MemberSelect(
                    maker.MemberSelect(
                            maker.Identifier("System"), "out"), "println"),//NOI18N
            Collections.<LiteralTree>singletonList(
                    maker.Literal(arg)));                   //args.
    return maker.ExpressionStatement(methodInvocation);
}
项目:incubator-netbeans    文件:AbstractTestGenerator.java   
private StatementTree generateEJBCleanUpCode(TreeMaker maker) {
    IdentifierTree container = maker.Identifier(CONTAINER_VAR_NAME);
    MethodInvocationTree invocation = maker.MethodInvocation(
        Collections.<ExpressionTree>emptyList(),
        maker.MemberSelect(container, "close"), // NOI18N
        Collections.<ExpressionTree>emptyList()
    );
    return maker.ExpressionStatement(invocation);
}
项目:incubator-netbeans    文件:Utilities.java   
private static boolean isSynthetic(CompilationUnitTree cut, Tree leaf) throws NullPointerException {
    JCTree tree = (JCTree) leaf;

    if (tree.pos == (-1))
        return true;

    if (leaf.getKind() == Kind.METHOD) {
        //check for synthetic constructor:
        return (((JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L;
    }

    //check for synthetic superconstructor call:
    if (cut != null && leaf.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionStatementTree est = (ExpressionStatementTree) leaf;

        if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) {
            MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();

            if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) {
                IdentifierTree it = (IdentifierTree) mit.getMethodSelect();

                if ("super".equals(it.getName().toString())) {
                    return ((JCCompilationUnit) cut).endPositions.getEndPos(tree) == (-1);
                }
            }
        }
    }

    return false;
}
项目:incubator-netbeans    文件:JavaFixUtilities.java   
@Override
public Number visitMethodInvocation(MethodInvocationTree node, Void p) {
    List<? extends ExpressionTree> typeArgs = (List<? extends ExpressionTree>) resolveMultiParameters(node.getTypeArguments());
    List<? extends ExpressionTree> args = resolveMultiParameters(node.getArguments());
    MethodInvocationTree nue = make.MethodInvocation(typeArgs, node.getMethodSelect(), args);

    rewrite(node, nue);

    return super.visitMethodInvocation(nue, p);
}
项目:incubator-netbeans    文件:NCLOCVisitor.java   
@Override
public Object visitMethodInvocation(MethodInvocationTree node, Object p) {
    TreePath parentPath = getCurrentPath().getParentPath();
    if (parentPath != null) {
        Tree t = parentPath.getLeaf();
        // do not count invocations that are a part of expression (expression statement is counted already)
        if (!ExpressionTree.class.isAssignableFrom(t.getKind().asInterface()) &&
            !ExpressionStatementTree.class.isAssignableFrom(t.getKind().asInterface())) {
            statements++;
        }
    }
    return super.visitMethodInvocation(node, p);
}
项目:incubator-netbeans    文件:TreeNode.java   
@Override
public Void visitMethodInvocation(MethodInvocationTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();

    addCorrespondingElement(below);
    addCorrespondingType(below);
    addCorrespondingComments(below);

    super.visitMethodInvocation(tree, below);

    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
项目:incubator-netbeans    文件:StringBuilderAppend.java   
private static ErrorDescription hint(HintContext ctx, String clazzName) {
    CompilationInfo info = ctx.getInfo();
    MethodInvocationTree mit = (MethodInvocationTree) ctx.getPath().getLeaf();
    ExpressionTree param = mit.getArguments().get(0);
    List<List<TreePath>> sorted = Utilities.splitStringConcatenationToElements(info, new TreePath(ctx.getPath(), param));

    if (sorted.size() > 1) {
        String error = NbBundle.getMessage(StringBuilderAppend.class, "ERR_StringBuilderAppend", clazzName);
        return ErrorDescriptionFactory.forTree(ctx, param, error, new FixImpl(info, ctx.getPath()).toEditorFix());
    }

    return null;
}
项目:incubator-netbeans    文件:ConvertToLambdaPreconditionChecker.java   
@Override
public Tree visitMethodInvocation(MethodInvocationTree methodInvocationTree, Trees trees) {
    String nameSuggestion = org.netbeans.modules.editor.java.Utilities.varNameSuggestion(methodInvocationTree.getMethodSelect());
    //check for recursion
    if (nameSuggestion != null && lambdaMethodTree.getName().contentEquals(nameSuggestion)) {
        ExpressionTree selector = getSelector(methodInvocationTree);
        if (selector == null || (org.netbeans.modules.editor.java.Utilities.varNameSuggestion(selector) != null
                && org.netbeans.modules.editor.java.Utilities.varNameSuggestion(selector).contentEquals("this"))) {
            foundRecursiveCall = true;
        }
    }
    if (singleStatementLambdaMethodBody == getCurrentPath().getParentPath().getParentPath().getLeaf()) {
        Tree parent = getCurrentPath().getParentPath().getLeaf();
        if (parent.getKind() == Tree.Kind.EXPRESSION_STATEMENT || parent.getKind() == Tree.Kind.RETURN) {
            boolean check = true;
            Iterator<? extends VariableTree> paramsIt = lambdaMethodTree.getParameters().iterator();
            ExpressionTree methodSelect = methodInvocationTree.getMethodSelect();
            if (paramsIt.hasNext() && methodSelect.getKind() == Tree.Kind.MEMBER_SELECT) {
                ExpressionTree expr = ((MemberSelectTree) methodSelect).getExpression();
                if (expr.getKind() == Tree.Kind.IDENTIFIER) {
                    if (!((IdentifierTree)expr).getName().contentEquals(paramsIt.next().getName())) {
                        paramsIt = lambdaMethodTree.getParameters().iterator();
                    }
                }
            }
            Iterator<? extends ExpressionTree> argsIt = methodInvocationTree.getArguments().iterator();
            while (check && argsIt.hasNext() && paramsIt.hasNext()) {
                ExpressionTree arg = argsIt.next();
                if (arg.getKind() != Tree.Kind.IDENTIFIER || !paramsIt.next().getName().contentEquals(((IdentifierTree)arg).getName())) {
                    check = false;
                }
            }
            if (check && !paramsIt.hasNext() && !argsIt.hasNext()) {
                foundMemberReferenceCandidate = true;
            }
        }
    }
    return super.visitMethodInvocation(methodInvocationTree, trees);
}
项目:incubator-netbeans    文件:ConvertToLambdaPreconditionChecker.java   
private ExpressionTree getSelector(Tree tree) {
    switch (tree.getKind()) {
        case MEMBER_SELECT:
            return ((MemberSelectTree) tree).getExpression();
        case METHOD_INVOCATION:
            return getSelector(((MethodInvocationTree) tree).getMethodSelect());
        case NEW_CLASS:
            return getSelector(((NewClassTree) tree).getIdentifier());
        default:
            return null;
    }
}
项目:incubator-netbeans    文件:ConvertToLambdaPreconditionChecker.java   
private ExecutableElement getElementFromInvokingTree(TreePath treePath) {
    Tree invokingTree = treePath.getLeaf();
    Element result;
    if (invokingTree.getKind() == Tree.Kind.METHOD_INVOCATION) {
        MethodInvocationTree invokingMethTree = ((MethodInvocationTree) invokingTree);
        TreePath methodTreePath = new TreePath(treePath, invokingMethTree);
        result = getElementFromTreePath(methodTreePath);
    } else {
        result = getElementFromTreePath(treePath);
    }
    if (result != null && (result.getKind() == ElementKind.CONSTRUCTOR || result.getKind() == ElementKind.METHOD)) {
        return (ExecutableElement) result;
    }
    return null;
}