本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression类的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression类的具体用法?Java MethodCallExpression怎么用?Java MethodCallExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodCallExpression类属于org.codehaus.groovy.ast.expr包,在下文中一共展示了MethodCallExpression类的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: getClosure
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
/**
* Extract a top-level {@code name} closure from inside this block if there is one,
* optionally removing it from the block at the same time.
* @param block a block statement (class definition)
* @param name the name to look for
* @param remove whether or not the extracted closure should be removed
* @return a beans Closure if one can be found, null otherwise
*/
public static ClosureExpression getClosure(BlockStatement block, String name,
boolean remove) {
for (ExpressionStatement statement : getExpressionStatements(block)) {
Expression expression = statement.getExpression();
if (expression instanceof MethodCallExpression) {
ClosureExpression closure = getClosure(name,
(MethodCallExpression) expression);
if (closure != null) {
if (remove) {
block.getStatements().remove(statement);
}
return closure;
}
}
}
return null;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:AstUtils.java
示例3: 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);
}
示例4: 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;
}
示例5: tryMacroMethod
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
/**
* Attempts to call given macroMethod
* @param call MethodCallExpression before the transformation
* @param macroMethod a macro method candidate
* @param macroArguments arguments to pass to
* @return true if call succeeded and current call was transformed
*/
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) {
Expression result = (Expression) InvokerHelper.invokeStaticMethod(
macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(),
macroMethod.getName(),
macroArguments
);
if (result == null) {
// Allow macro methods to return null as an indicator that they didn't match a method call
return false;
}
call.setObjectExpression(MACRO_STUB_INSTANCE);
call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME));
// TODO check that we reset everything here
call.setSpreadSafe(false);
call.setSafe(false);
call.setImplicitThis(false);
call.setArguments(result);
call.setGenericsTypes(new GenericsType[0]);
return true;
}
示例6: 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;
}
示例7: createMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
private MethodCallExpression createMethodCallExpression(PropertyExpression propertyExpression, Expression arguments) {
MethodCallExpression methodCallExpression =
new MethodCallExpression(
propertyExpression.getObjectExpression(),
propertyExpression.getProperty(),
arguments
);
methodCallExpression.setImplicitThis(false);
methodCallExpression.setSafe(propertyExpression.isSafe());
methodCallExpression.setSpreadSafe(propertyExpression.isSpreadSafe());
// method call obj*.m(): "safe"(false) and "spreadSafe"(true)
// property access obj*.p: "safe"(true) and "spreadSafe"(true)
// so we have to reset safe here.
if (propertyExpression.isSpreadSafe()) {
methodCallExpression.setSafe(false);
}
// if the generics types meta data is not empty, it is a generic method call, e.g. obj.<Integer>a(1, 2)
methodCallExpression.setGenericsTypes(
propertyExpression.getNodeMetaData(PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES));
return methodCallExpression;
}
示例8: transform
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
public Expression transform(Expression exp) {
if (exp == null) return null;
Expression ret = null;
if (exp instanceof VariableExpression) {
ret = transformVariableExpression((VariableExpression) exp);
} else if (exp.getClass() == PropertyExpression.class) {
ret = transformPropertyExpression((PropertyExpression) exp);
} else if (exp instanceof DeclarationExpression) {
ret = transformDeclarationExpression((DeclarationExpression) exp);
} else if (exp instanceof BinaryExpression) {
ret = transformBinaryExpression((BinaryExpression) exp);
} else if (exp instanceof MethodCallExpression) {
ret = transformMethodCallExpression((MethodCallExpression) exp);
} else if (exp instanceof ClosureExpression) {
ret = transformClosureExpression((ClosureExpression) exp);
} else if (exp instanceof ConstructorCallExpression) {
ret = transformConstructorCallExpression((ConstructorCallExpression) exp);
} else if (exp instanceof AnnotationConstantExpression) {
ret = transformAnnotationConstantExpression((AnnotationConstantExpression) exp);
} else {
resolveOrFail(exp.getType(), exp);
ret = exp.transformExpression(this);
}
if (ret!=null && ret!=exp) ret.setSourcePosition(exp);
return ret;
}
示例9: transformMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
protected Expression transformMethodCallExpression(MethodCallExpression mce) {
Expression args = transform(mce.getArguments());
Expression method = transform(mce.getMethod());
Expression object = transform(mce.getObjectExpression());
resolveGenericsTypes(mce.getGenericsTypes());
MethodCallExpression result = new MethodCallExpression(object, method, args);
result.setSafe(mce.isSafe());
result.setImplicitThis(mce.isImplicitThis());
result.setSpreadSafe(mce.isSpreadSafe());
result.setSourcePosition(mce);
result.setGenericsTypes(mce.getGenericsTypes());
result.setMethodTarget(mce.getMethodTarget());
return result;
}
示例10: checkSuperCallFromClosure
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
private void checkSuperCallFromClosure(Expression call, MethodNode directCallTarget) {
if (call instanceof MethodCallExpression && typeCheckingContext.getEnclosingClosure() != null) {
Expression objectExpression = ((MethodCallExpression)call).getObjectExpression();
if (objectExpression instanceof VariableExpression) {
VariableExpression var = (VariableExpression) objectExpression;
if (var.isSuperExpression()) {
ClassNode current = typeCheckingContext.getEnclosingClassNode();
LinkedList<MethodNode> list = current.getNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED);
if (list == null) {
list = new LinkedList<MethodNode>();
current.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, list);
}
list.add(directCallTarget);
call.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, current);
}
}
}
}
示例11: getTypeForSpreadExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
private ClassNode getTypeForSpreadExpression(ClassNode testClass, ClassNode objectExpressionType, PropertyExpression pexp) {
if (!pexp.isSpreadSafe()) return null;
MethodCallExpression mce = callX(varX("_", testClass), "iterator", ArgumentListExpression.EMPTY_ARGUMENTS);
mce.setImplicitThis(false);
mce.visit(this);
ClassNode callType = getType(mce);
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
GenericsType[] types = callType.getGenericsTypes();
ClassNode contentType = OBJECT_TYPE;
if (types!=null && types.length==1) contentType = types[0].getType();
PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
AtomicReference<ClassNode> result = new AtomicReference<ClassNode>();
if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {
ClassNode intf = LIST_TYPE.getPlainNodeReference();
intf.setGenericsTypes(new GenericsType[] { new GenericsType(getWrapper(result.get()))});
return intf;
}
return null;
}
示例12: inferComponentType
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
protected ClassNode inferComponentType(final ClassNode containerType, final ClassNode indexType) {
final ClassNode componentType = containerType.getComponentType();
if (componentType == null) {
// GROOVY-5521
// try to identify a getAt method
typeCheckingContext.pushErrorCollector();
MethodCallExpression vcall = callX(varX("_hash_", containerType), "getAt", varX("_index_", indexType));
try {
visitMethodCallExpression(vcall);
} finally {
typeCheckingContext.popErrorCollector();
}
return getType(vcall);
} else {
return componentType;
}
}
示例13: findMethodOrFail
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入依赖的package包/类
protected MethodNode findMethodOrFail(
Expression expr,
ClassNode receiver, String name, ClassNode... args) {
List<MethodNode> methods = findMethod(receiver, name, args);
if (methods.isEmpty() && (expr instanceof BinaryExpression)) {
BinaryExpression be = (BinaryExpression) expr;
MethodCallExpression call = callX(be.getLeftExpression(), name, be.getRightExpression());
methods = extension.handleMissingMethod(receiver, name, args(be.getLeftExpression()), args, call);
}
if (methods.isEmpty()) {
addNoMatchingMethodError(receiver, name, args, expr);
} else {
if (areCategoryMethodCalls(methods, name, args)) {
addCategoryMethodCallError(expr);
}
methods = disambiguateMethods(methods, receiver, args, expr);
if (methods.size() == 1) {
return methods.get(0);
} else {
addAmbiguousErrorMessage(methods, name, args, expr);
}
}
return null;
}
示例14: 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;
}
示例15: 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);
}