本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.getArguments方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.getArguments方法的具体用法?Java MethodCallExpression.getArguments怎么用?Java MethodCallExpression.getArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.getArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inspectMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private void inspectMethodCallExpression(MethodCallExpression mc, int childIndent, String in) {
String name = mc.getMethodAsString();
System.out.println(in+"-method as string:"+name);
System.out.println("- generic types:"+ mc.getGenericsTypes());
System.out.println("- type:"+mc.getType().getName());
Expression method = mc.getMethod();
inspect(method, childIndent);
// System.out.println(in+"-type:"+mc.getType());
Expression args = mc.getArguments();
System.out.println(in + "-arguments:");
inspect(args, childIndent);
// System.out.println(in + "-method:");
// System.out.println(in + "-target:");
// inspect(mc.getMethodTarget(), childIndent);
ASTNode receiver = mc.getReceiver();
if (receiver!=null){
System.out.println(in+"// Receiver found ...");
inspect(receiver, childIndent);
}
}
示例2: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
boolean old = inBuilderMethod;
inBuilderMethod = false;
if (call.isImplicitThis() && call.getArguments() instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) call.getArguments()).getExpressions();
if (!expressions.isEmpty()) {
Expression lastArg = expressions.get(expressions.size() - 1);
if (lastArg instanceof ClosureExpression) {
call.getObjectExpression().visit(this);
call.getMethod().visit(this);
for (Expression expression : expressions) {
inBuilderMethod = (expression == lastArg);
expression.visit(this);
}
}
}
} else {
super.visitMethodCallExpression(call);
}
inBuilderMethod = old;
}
示例3: getMacroArguments
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
protected static TupleExpression getMacroArguments(SourceUnit source, MethodCallExpression call) {
Expression macroCallArguments = call.getArguments();
if (macroCallArguments == null) {
source.addError(new SyntaxException("Call should have arguments" + '\n', call));
return null;
}
if (!(macroCallArguments instanceof TupleExpression)) {
source.addError(new SyntaxException("Call should have TupleExpression as arguments" + '\n', macroCallArguments));
return null;
}
TupleExpression tupleArguments = (TupleExpression) macroCallArguments;
if (tupleArguments.getExpressions() == null) {
source.addError(new SyntaxException("Call arguments should have expressions" + '\n', tupleArguments));
return null;
}
return tupleArguments;
}
示例4: transformToMopSuperCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static MethodCallExpression transformToMopSuperCall(final ClassNode superCallReceiver, final MethodCallExpression expr) {
MethodNode mn = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
String mopName = MopWriter.getMopMethodName(mn, false);
MethodNode direct = new MethodNode(
mopName,
ACC_PUBLIC | ACC_SYNTHETIC,
mn.getReturnType(),
mn.getParameters(),
mn.getExceptions(),
EmptyStatement.INSTANCE
);
direct.setDeclaringClass(superCallReceiver);
MethodCallExpression result = new MethodCallExpression(
new VariableExpression("this"),
mopName,
expr.getArguments()
);
result.setImplicitThis(true);
result.setSpreadSafe(false);
result.setSafe(false);
result.setSourcePosition(expr);
result.setMethodTarget(direct);
return result;
}
示例5: tryTransformIsToCompareIdentity
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
* Identifies a method call expression on {@link DefaultGroovyMethods#is(Object, Object)} and if recognized, transforms it into a {@link CompareIdentityExpression}.
* @param call a method call to be transformed
* @return null if the method call is not DGM#is, or {@link CompareIdentityExpression}
*/
private static Expression tryTransformIsToCompareIdentity(MethodCallExpression call) {
if (call.isSafe()) return null;
MethodNode methodTarget = call.getMethodTarget();
if (methodTarget instanceof ExtensionMethodNode && "is".equals(methodTarget.getName()) && methodTarget.getParameters().length==1) {
methodTarget = ((ExtensionMethodNode) methodTarget).getExtensionMethodNode();
ClassNode owner = methodTarget.getDeclaringClass();
if (DGM_CLASSNODE.equals(owner)) {
Expression args = call.getArguments();
if (args instanceof ArgumentListExpression) {
ArgumentListExpression arguments = (ArgumentListExpression) args;
List<Expression> exprs = arguments.getExpressions();
if (exprs.size() == 1) {
CompareIdentityExpression cid = new CompareIdentityExpression(call.getObjectExpression(), exprs.get(0));
cid.setSourcePosition(call);
return cid;
}
}
}
}
return null;
}
示例6: transformMethodCallOnThis
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThis(final MethodCallExpression call) {
Expression method = call.getMethod();
Expression arguments = call.getArguments();
if (method instanceof ConstantExpression) {
String methodName = method.getText();
List<MethodNode> methods = traitClass.getMethods(methodName);
for (MethodNode methodNode : methods) {
if (methodName.equals(methodNode.getName()) && methodNode.isPrivate()) {
if (inClosure) {
return transformPrivateMethodCallOnThisInClosure(call, arguments, methodName);
}
return transformPrivateMethodCallOnThis(call, arguments, methodName);
}
}
}
if (inClosure) {
return transformMethodCallOnThisInClosure(call);
}
return transformMethodCallOnThisFallBack(call, method, arguments);
}
示例7: isClosureCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private boolean isClosureCall(MethodCallExpression call) {
// are we a local variable?
// it should not be an explicitly "this" qualified method call
// and the current class should have a possible method
ClassNode classNode = controller.getClassNode();
String methodName = call.getMethodAsString();
if (methodName==null) return false;
if (!call.isImplicitThis()) return false;
if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false;
FieldNode field = classNode.getDeclaredField(methodName);
if (field == null) return false;
if (isStaticInvocation(call) && !field.isStatic()) return false;
Expression arguments = call.getArguments();
return ! classNode.hasPossibleMethod(methodName, arguments);
}
示例8: tryTransformInclude
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression tryTransformInclude(final MethodCallExpression exp) {
Expression arguments = exp.getArguments();
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
if (expressions.size() == 1 && expressions.get(0) instanceof MapExpression) {
MapExpression map = (MapExpression) expressions.get(0);
List<MapEntryExpression> entries = map.getMapEntryExpressions();
if (entries.size() == 1) {
MapEntryExpression mapEntry = entries.get(0);
Expression keyExpression = mapEntry.getKeyExpression();
try {
IncludeType includeType = IncludeType.valueOf(keyExpression.getText().toLowerCase());
MethodCallExpression call = new MethodCallExpression(
exp.getObjectExpression(),
includeType.getMethodName(),
new ArgumentListExpression(
mapEntry.getValueExpression()
)
);
call.setImplicitThis(true);
call.setSafe(exp.isSafe());
call.setSpreadSafe(exp.isSpreadSafe());
call.setSourcePosition(exp);
return call;
} catch (IllegalArgumentException e) {
// not a valid import type, do not modify the code
}
}
}
}
return super.transform(exp);
}
示例9: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(MethodCallExpression call) {
super.visitMethodCallExpression(call);
final List<Expression> callArguments;
if (call.getArguments() instanceof TupleExpression) {
callArguments = ((TupleExpression) call.getArguments()).getExpressions();
} else {
callArguments = Collections.singletonList(call.getArguments());
}
List<MethodNode> macroMethods = findMacroMethods(call.getMethodAsString(), callArguments);
if (macroMethods.isEmpty()) {
// Early return to avoid macro context and arguments creation
return;
}
MacroContext macroContext = new MacroContext(unit, sourceUnit, call);
Object[] macroArguments = new Object[callArguments.size() + 1];
macroArguments[0] = macroContext;
System.arraycopy(callArguments.toArray(), 0, macroArguments, 1, callArguments.size());
for (MethodNode macroMethodNode : macroMethods) {
if (!(macroMethodNode instanceof ExtensionMethodNode)) {
throw new IllegalStateException(macroMethodNode + " is not an instance of ExtensionMethodNode");
}
if (tryMacroMethod(call, (ExtensionMethodNode) macroMethodNode, macroArguments)) {
break;
}
}
}
示例10: transformMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallExpression(final MethodCallExpression exp) {
if (isTraitSuperPropertyExpression(exp.getObjectExpression())) {
Expression objectExpression = exp.getObjectExpression();
ClassNode traitReceiver = ((PropertyExpression) objectExpression).getObjectExpression().getType();
if (traitReceiver != null) {
// (SomeTrait.super).foo() --> SomeTrait$Helper.foo(this)
ClassExpression receiver = new ClassExpression(
getHelper(traitReceiver)
);
ArgumentListExpression newArgs = new ArgumentListExpression();
Expression arguments = exp.getArguments();
newArgs.addExpression(new VariableExpression("this"));
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
for (Expression expression : expressions) {
newArgs.addExpression(transform(expression));
}
} else {
newArgs.addExpression(transform(arguments));
}
MethodCallExpression result = new MethodCallExpression(
receiver,
transform(exp.getMethod()),
newArgs
);
result.setImplicitThis(false);
result.setSpreadSafe(exp.isSpreadSafe());
result.setSafe(exp.isSafe());
result.setSourcePosition(exp);
return result;
}
}
return super.transform(exp);
}
示例11: getNonClosureArguments
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static List<Expression> getNonClosureArguments(MethodCallExpression call) {
List<Expression> result = new ArrayList<Expression>();
if (call.getArguments() instanceof TupleExpression) {
for (ASTNode node : ((TupleExpression) call.getArguments()).getExpressions()) {
if (!(node instanceof ClosureExpression)) {
result.add((Expression) node);
}
}
}
return result;
}
示例12: getClosureArgument
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static ClosureExpression getClosureArgument(MethodCallExpression call) {
if (call.getArguments() instanceof TupleExpression) {
for (ASTNode node : ((TupleExpression) call.getArguments()).getExpressions()) {
if (node instanceof ClosureExpression) {
return (ClosureExpression) node;
}
}
}
return null;
}
示例13: isBuildInvocation
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
* Looks for method calls on the AstBuilder class called build that take
* a Closure as parameter. This is all needed b/c build is overloaded.
*
* @param call the method call expression, may not be null
*/
@Override
protected boolean isBuildInvocation(MethodCallExpression call) {
if (call == null) throw new IllegalArgumentException("Null: call");
// is method name correct?
if (call.getMethod() instanceof ConstantExpression && "buildFromCode".equals(((ConstantExpression) call.getMethod()).getValue())) {
// is method object correct type?
if (call.getObjectExpression() != null && call.getObjectExpression().getType() != null) {
String name = call.getObjectExpression().getType().getName();
if (name != null && !"".equals(name) && factoryTargets.contains(name)) {
// is one of the arguments a closure?
if (call.getArguments() != null && call.getArguments() instanceof TupleExpression) {
if (((TupleExpression) call.getArguments()).getExpressions() != null) {
for (ASTNode node : ((TupleExpression) call.getArguments()).getExpressions()) {
if (node instanceof ClosureExpression) {
return true;
}
}
}
}
}
}
}
return false;
}
示例14: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void visitMethodCallExpression(MethodCallExpression mce) {
super.visitMethodCallExpression(mce);
Expression aexp = mce.getArguments();
if (aexp instanceof TupleExpression) {
TupleExpression arguments = (TupleExpression) aexp;
for (Expression e : arguments.getExpressions()) {
checkForInvalidDeclaration(e);
}
} else {
checkForInvalidDeclaration(aexp);
}
}
示例15: detectScriptBlock
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private ScriptBlock detectScriptBlock(Statement statement) {
if (!(statement instanceof ExpressionStatement)) {
return null;
}
ExpressionStatement expressionStatement = (ExpressionStatement) statement;
if (!(expressionStatement.getExpression() instanceof MethodCallExpression)) {
return null;
}
MethodCallExpression methodCall = (MethodCallExpression) expressionStatement.getExpression();
if (!AstUtils.targetIsThis(methodCall)) {
return null;
}
if (!(methodCall.getMethod() instanceof ConstantExpression)) {
return null;
}
String methodName = methodCall.getMethod().getText();
if (methodName.equals(PLUGINS) || methodName.equals(classpathBlockName)) {
if (!(methodCall.getArguments() instanceof ArgumentListExpression)) {
return null;
}
ArgumentListExpression args = (ArgumentListExpression) methodCall.getArguments();
if (args.getExpressions().size() == 1 && args.getExpression(0) instanceof ClosureExpression) {
return new ScriptBlock(methodName, (ClosureExpression) args.getExpression(0));
} else {
return null;
}
} else {
return null;
}
}