当前位置: 首页>>代码示例>>Java>>正文


Java MethodInvocationTree类代码示例

本文整理汇总了Java中com.sun.source.tree.MethodInvocationTree的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocationTree类的具体用法?Java MethodInvocationTree怎么用?Java MethodInvocationTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodInvocationTree类属于com.sun.source.tree包,在下文中一共展示了MethodInvocationTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addSyntheticTrees

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
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);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:WorkingCopy.java

示例2: generateDefMethodBody

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:AbstractTestGenerator.java

示例3: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:MethodExitDetector.java

示例4: computeMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CreateElementUtilities.java

示例5: hint

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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");
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ForbiddenMethod.java

示例6: computeTreeKind

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FileToURL.java

示例7: performRewrite

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:LoggerStringConcat.java

示例8: dotExpressionUpToArgs

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
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;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:27,代码来源:JavaInputAstVisitor.java

示例9: dotExpressionArgsAndParen

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:JavaInputAstVisitor.java

示例10: performRewrite

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Tiny.java

示例11: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ReplaceBufferByString.java

示例12: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:FinalizeDoesNotCallSuper.java

示例13: visitMethodInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:EqualsMethodHint.java

示例14: isThisParameter

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
/**
    * 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;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:UncaughtException.java

示例15: checkAlternativeInvocation

import com.sun.source.tree.MethodInvocationTree; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:Utilities.java


注:本文中的com.sun.source.tree.MethodInvocationTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。