本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.isImplicitThis方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.isImplicitThis方法的具体用法?Java MethodCallExpression.isImplicitThis怎么用?Java MethodCallExpression.isImplicitThis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.isImplicitThis方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void visitMethodCallExpression(MethodCallExpression call) {
if (call.isImplicitThis() && call.getMethod() instanceof ConstantExpression) {
ConstantExpression methodNameConstant = (ConstantExpression) call.getMethod();
Object value = methodNameConstant.getText();
if (!(value instanceof String)) {
throw new GroovyBugError("tried to make a method call with a non-String constant method name.");
}
String methodName = (String) value;
Variable v = checkVariableNameForDeclaration(methodName, call);
if (v != null && !(v instanceof DynamicVariable)) {
checkVariableContextAccess(v, call);
}
if (v instanceof VariableExpression || v instanceof Parameter) {
VariableExpression object = new VariableExpression(v);
object.setSourcePosition(methodNameConstant);
call.setObjectExpression(object);
ConstantExpression method = new ConstantExpression("call");
method.setSourcePosition(methodNameConstant); // important for GROOVY-4344
call.setImplicitThis(false);
call.setMethod(method);
}
}
super.visitMethodCallExpression(call);
}
示例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: isCallOnClosure
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static boolean isCallOnClosure(final MethodCallExpression expr) {
MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
return expr.isImplicitThis()
&& !"call".equals(expr.getMethodAsString())
&& (target == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS
|| target == StaticTypeCheckingVisitor.CLOSURE_CALL_NO_ARG
|| target == StaticTypeCheckingVisitor.CLOSURE_CALL_ONE_ARG);
}
示例5: transformMethodCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCall(final MethodCallExpression exp) {
String name = exp.getMethodAsString();
if (exp.isImplicitThis() && "include".equals(name)) {
return tryTransformInclude(exp);
} else if (exp.isImplicitThis() && name.startsWith(":")) {
List<Expression> args;
if (exp.getArguments() instanceof ArgumentListExpression) {
args = ((ArgumentListExpression) exp.getArguments()).getExpressions();
} else {
args = Collections.singletonList(exp.getArguments());
}
Expression newArguments = transform(new ArgumentListExpression(new ConstantExpression(name.substring(1)), new ArrayExpression(ClassHelper.OBJECT_TYPE, args)));
MethodCallExpression call = new MethodCallExpression(
new VariableExpression("this"),
"methodMissing",
newArguments
);
call.setImplicitThis(true);
call.setSafe(exp.isSafe());
call.setSpreadSafe(exp.isSpreadSafe());
call.setSourcePosition(exp);
return call;
} else if (name!=null && name.startsWith("$")) {
MethodCallExpression reformatted = new MethodCallExpression(
exp.getObjectExpression(),
name.substring(1),
exp.getArguments()
);
reformatted.setImplicitThis(exp.isImplicitThis());
reformatted.setSafe(exp.isSafe());
reformatted.setSpreadSafe(exp.isSpreadSafe());
reformatted.setSourcePosition(exp);
// wrap in a stringOf { ... } closure call
ClosureExpression clos = new ClosureExpression(Parameter.EMPTY_ARRAY, new ExpressionStatement(reformatted));
clos.setVariableScope(new VariableScope());
MethodCallExpression stringOf = new MethodCallExpression(new VariableExpression("this"),
"stringOf",
clos);
stringOf.setImplicitThis(true);
stringOf.setSourcePosition(reformatted);
return stringOf;
}
return super.transform(exp);
}
示例6: isStaticInvocation
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private boolean isStaticInvocation(MethodCallExpression call) {
if (!AsmClassGenerator.isThisExpression(call.getObjectExpression())) return false;
if (controller.isStaticMethod()) return true;
return controller.isStaticContext() && !call.isImplicitThis();
}
示例7: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void visitMethodCallExpression(MethodCallExpression methodCall) {
if (defaultScriptMethods.contains(methodCall.getMethodAsString())) {
visited = true;
isImplicitThis = methodCall.isImplicitThis();
}
}