本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCMethodInvocation类的典型用法代码示例。如果您正苦于以下问题:Java JCMethodInvocation类的具体用法?Java JCMethodInvocation怎么用?Java JCMethodInvocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCMethodInvocation类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCMethodInvocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createField
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) {
JavacTreeMaker maker = typeNode.getTreeMaker();
// private static final <loggerType> log = <factoryMethod>(<parameter>);
JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName());
JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName());
JCExpression loggerName;
if (loggerTopic == null || loggerTopic.trim().length() == 0) {
loggerName = framework.createFactoryParameter(typeNode, loggingType);
} else {
loggerName = maker.Literal(loggerTopic);
}
JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName));
JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)),
typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext());
injectFieldAndMarkGenerated(typeNode, fieldDecl);
return true;
}
示例2: visitApply
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
@Override
public void visitApply(JCMethodInvocation tree) {
boolean prevCheckThis = checkThis;
try {
Symbol meth = TreeInfo.symbol(tree.meth);
Name methName = TreeInfo.name(tree.meth);
if (meth != null && meth.name == names.init) {
Symbol c = meth.owner;
if (c.hasOuterInstance()) {
checkThis = false;
if (tree.meth.getTag() != JCTree.Tag.SELECT && (c.isLocal() || methName == names._this)) {
checkThis(tree.meth.pos(), c.type.getEnclosingType().tsym);
}
}
}
super.visitApply(tree);
} finally {
checkThis = prevCheckThis;
}
}
示例3: visitMethodInvocation
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
super.visitMethodInvocation(node, p);
JCMethodInvocation apply = (JCMethodInvocation)node;
JCIdent ident = (JCIdent)apply.meth;
Symbol oldSym = ident.sym;
if (!oldSym.isConstructor()) {
Object[] staticArgs = new Object[arity.arity];
for (int i = 0; i < arity.arity ; i++) {
staticArgs[i] = saks[i].getValue(syms, names, types);
}
ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
}
return null;
}
示例4: suppress
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
private boolean suppress(JCTree tree) {
if (tree instanceof JCBlock) {
JCBlock block = (JCBlock) tree;
return (Position.NOPOS == block.pos) && block.stats.isEmpty();
}
if (tree instanceof JCExpressionStatement) {
JCExpression expr = ((JCExpressionStatement)tree).expr;
if (expr instanceof JCMethodInvocation) {
JCMethodInvocation inv = (JCMethodInvocation) expr;
if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
if (!(inv.meth instanceof JCIdent)) return false;
return ((JCIdent) inv.meth).name.toString().equals("super");
}
}
return false;
}
示例5: visitApply
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
@Override public void visitApply(JCMethodInvocation tree) {
if (tree.typeargs.nonEmpty()) {
if (tree.meth instanceof JCFieldAccess) {
JCFieldAccess fa = (JCFieldAccess) tree.meth;
print(fa.selected);
print(".<");
print(tree.typeargs, ", ");
print(">");
print(fa.name);
} else {
print("<");
print(tree.typeargs, ", ");
print(">");
print(tree.meth);
}
} else {
print(tree.meth);
}
print("(");
print(tree.args, ", ");
print(")");
}
示例6: isConstructorCall
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
public static boolean isConstructorCall(final JCStatement statement) {
if (!(statement instanceof JCExpressionStatement)) return false;
JCExpression expr = ((JCExpressionStatement) statement).expr;
if (!(expr instanceof JCMethodInvocation)) return false;
JCExpression invocation = ((JCMethodInvocation) expr).meth;
String name;
if (invocation instanceof JCFieldAccess) {
name = ((JCFieldAccess) invocation).name.toString();
} else if (invocation instanceof JCIdent) {
name = ((JCIdent) invocation).name.toString();
} else {
name = "";
}
return "super".equals(name) || "this".equals(name);
}
示例7: visitApply
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
public void visitApply(JCMethodInvocation tree) {
try {
if (!tree.typeargs.isEmpty()) {
if (SELECT.equals(treeTag(tree.meth))) {
JCFieldAccess left = (JCFieldAccess)tree.meth;
printExpr(left.selected);
print(".<");
printExprs(tree.typeargs);
print(">" + left.name);
} else {
print("<");
printExprs(tree.typeargs);
print(">");
printExpr(tree.meth);
}
} else {
printExpr(tree.meth);
}
print("(");
printExprs(tree.args);
print(")");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例8: getSymbol
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
/**
* Gets the symbol for a tree. Returns null if this tree does not have a symbol because it is of
* the wrong type, if {@code tree} is null, or if the symbol cannot be found due to a compilation
* error.
*/
// TODO(eaftan): refactor other code that accesses symbols to use this method
public static Symbol getSymbol(Tree tree) {
if (tree instanceof JCFieldAccess) {
return ((JCFieldAccess) tree).sym;
}
if (tree instanceof JCIdent) {
return ((JCIdent) tree).sym;
}
if (tree instanceof JCMethodInvocation) {
return ASTHelpers.getSymbol((MethodInvocationTree) tree);
}
if (tree instanceof JCNewClass) {
return ASTHelpers.getSymbol((NewClassTree) tree);
}
if (tree instanceof MemberReferenceTree) {
return ((JCMemberReference) tree).sym;
}
if (tree instanceof JCAnnotatedType) {
return getSymbol(((JCAnnotatedType) tree).underlyingType);
}
return getDeclaredSymbol(tree);
}
示例9: getReceiverType
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
/**
* Returns the type of a receiver of a method call expression. Precondition: the expressionTree
* corresponds to a method call.
*
* <p>Examples:
*
* <pre>{@code
* a.b.foo() ==> type of a.b
* a.bar().foo() ==> type of a.bar()
* this.foo() ==> type of this
* foo() ==> type of this
* TheClass.aStaticMethod() ==> TheClass
* aStaticMethod() ==> type of class in which method is defined
* }</pre>
*/
public static Type getReceiverType(ExpressionTree expressionTree) {
if (expressionTree instanceof JCFieldAccess) {
JCFieldAccess methodSelectFieldAccess = (JCFieldAccess) expressionTree;
return methodSelectFieldAccess.selected.type;
} else if (expressionTree instanceof JCIdent) {
JCIdent methodCall = (JCIdent) expressionTree;
return methodCall.sym.owner.type;
} else if (expressionTree instanceof JCMethodInvocation) {
return getReceiverType(((JCMethodInvocation) expressionTree).getMethodSelect());
} else if (expressionTree instanceof JCMemberReference) {
return ((JCMemberReference) expressionTree).getQualifierExpression().type;
}
throw new IllegalArgumentException(
"Expected a JCFieldAccess or JCIdent from expression " + expressionTree);
}
示例10: matchMethodInvocation
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(
MethodInvocationTree methodInvocationTree, VisitorState state) {
if (!MATCHER.matches(methodInvocationTree, state)) {
return Description.NO_MATCH;
}
if (methodInvocationTree.getArguments().size() % 2 == 0) {
return Description.NO_MATCH;
}
JCMethodInvocation methodInvocation = (JCMethodInvocation) methodInvocationTree;
List<JCExpression> arguments = methodInvocation.getArguments();
Type typeVargs = methodInvocation.varargsElement;
if (typeVargs == null) {
return Description.NO_MATCH;
}
Type typeVarargsArr = state.arrayTypeForType(typeVargs);
Type lastArgType = ASTHelpers.getType(Iterables.getLast(arguments));
if (typeVarargsArr.equals(lastArgType)) {
return Description.NO_MATCH;
}
return describeMatch(methodInvocationTree);
}
示例11: getQueryCallExpression
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
/**
* Returns a {@link JCMethodInvocation} node which calls the query call method defined
* by the defineQueryCallMethod method.
* <p>
* The returned node is intended to replace the {@link JCSqlQuery} node, as it is a normal
* method call that can be handled appropriately.
* @param memberEnter The current MemberEnter instance to enter live-generated code.
* @return A {@link JCMethodInvocation} node which is intended to replace the {@link JCSqlQuery} node.
*/
public JCMethodInvocation getQueryCallExpression(MemberEnter memberEnter) {
MethodCallCodeGenerator codeGenerator = new MethodCallCodeGenerator();
String queryCall = codeGenerator.getQueryCall(this);
// create expression parse node from string
JCExpression queryCallExpression = Reifier.getInstance().reifyExpression(queryCall);
if (queryCallExpression instanceof JCMethodInvocation) {
// enter it to symbol table
queryCallExpression.accept(memberEnter);
// note: attribution will happen in the calling method in the Attr
// class, as this will need the expected type
return (JCMethodInvocation) queryCallExpression;
}
// tbd: checked exception handling
throw new RuntimeException("Parsed query call expression is no method invocation");
}
示例12: visitApply
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
public void visitApply(JCMethodInvocation tree) {
try {
if (!tree.typeargs.isEmpty()) {
if (tree.meth.getTag() == JCTree.SELECT) {
JCFieldAccess left = (JCFieldAccess)tree.meth;
printExpr(left.selected);
print(".<");
printExprs(tree.typeargs);
print(">" + left.name);
} else {
print("<");
printExprs(tree.typeargs);
print(">");
printExpr(tree.meth);
}
} else {
printExpr(tree.meth);
}
print("(");
printExprs(tree.args);
print(")");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例13: delegatingConstructor
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
private static boolean delegatingConstructor(List<JCStatement> stats) {
if (stats.isEmpty()) {
return false;
}
JCStatement stat = stats.get(0);
if (stat.getKind() != Kind.EXPRESSION_STATEMENT) {
return false;
}
JCExpression expr = ((JCExpressionStatement) stat).getExpression();
if (expr.getKind() != Kind.METHOD_INVOCATION) {
return false;
}
JCExpression method = ((JCMethodInvocation) expr).getMethodSelect();
Name name;
switch (method.getKind()) {
case IDENTIFIER:
name = ((JCIdent) method).getName();
break;
case MEMBER_SELECT:
name = ((JCFieldAccess) method).getIdentifier();
break;
default:
return false;
}
return name.contentEquals("this") || name.contentEquals("super");
}
示例14: getInvocationTargetType
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
@Override
public IsType getInvocationTargetType(CompilationUnitTree cup, MethodInvocationTree node) {
if (node instanceof JCMethodInvocation) {
final TreePath path = trees.getPath(cup, node);
final TreePath parent = path.getParentPath();
final Tree target = parent.getLeaf();
switch (target.getKind()) {
case VARIABLE:
JCVariableDecl var = (JCVariableDecl) target;
final JCTree type = var.getType();
final JavacScope scope = trees.getScope(path);
final IsType cls = getTypeOf(cup, scope, type);
return cls;
default:
X_Log.error(getClass(), "Unhandled invocation target type: ", target.getKind(), target);
}
} else {
X_Log.warn(getClass(), "Does not support MethodInvocationTree ", node);
}
return null;
}
示例15: visitApply
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; //导入依赖的package包/类
public void visitApply(JCMethodInvocation tree) {
try {
if (!tree.typeargs.isEmpty()) {
if (getTag(tree.meth) == SELECT) {
JCFieldAccess left = (JCFieldAccess)tree.meth;
printExpr(left.selected);
print(".<");
printExprs(tree.typeargs);
print(">" + left.name);
} else {
print("<");
printExprs(tree.typeargs);
print(">");
printExpr(tree.meth);
}
} else {
printExpr(tree.meth);
}
print("(");
printExprs(tree.args);
print(")");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}