本文整理汇总了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);
}
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}