本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.setMethodTarget方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.setMethodTarget方法的具体用法?Java MethodCallExpression.setMethodTarget怎么用?Java MethodCallExpression.setMethodTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.setMethodTarget方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: convertInOperatorToTernary
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression convertInOperatorToTernary(final BinaryExpression bin, final Expression rightExpression, final Expression leftExpression) {
MethodCallExpression call = new MethodCallExpression(
rightExpression,
"isCase",
leftExpression
);
call.setMethodTarget((MethodNode) bin.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET));
call.setSourcePosition(bin);
call.copyNodeMetaData(bin);
TernaryExpression tExp = new TernaryExpression(
new BooleanExpression(
new BinaryExpression(rightExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null))
),
new BinaryExpression(leftExpression, Token.newSymbol("==", -1, -1), new ConstantExpression(null)),
call
);
return staticCompilationTransformer.transform(tExp);
}
示例3: 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;
}
示例4: transformStaticMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
Expression transformStaticMethodCallExpression(final StaticMethodCallExpression orig) {
MethodNode target = (MethodNode) orig.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
if (target != null) {
MethodCallExpression call = new MethodCallExpression(
new ClassExpression(orig.getOwnerType()),
orig.getMethod(),
orig.getArguments()
);
call.setMethodTarget(target);
call.setSourcePosition(orig);
call.copyNodeMetaData(orig);
return transformer.transform(call);
}
return transformer.superTransform(orig);
}
示例5: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
super.visitMethodCallExpression(call);
MethodNode target = (MethodNode) call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
if (target!=null) {
call.setMethodTarget(target);
memorizeInitialExpressions(target);
}
if (call.getMethodTarget()==null && call.getLineNumber()>0) {
addError("Target method for method call expression hasn't been set", call);
}
}
示例6: makeDirectCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
protected boolean makeDirectCall(final Expression origin, final Expression receiver, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean implicitThis, final boolean containsSpreadExpression) {
if (origin instanceof MethodCallExpression &&
receiver instanceof VariableExpression &&
((VariableExpression) receiver).isSuperExpression()) {
ClassNode superClass = receiver.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
if (superClass!=null && !controller.getCompileStack().isLHS()) {
// GROOVY-7300
MethodCallExpression mce = (MethodCallExpression) origin;
MethodNode node = superClass.getDeclaredMethod(mce.getMethodAsString(), Parameter.EMPTY_ARRAY);
mce.setMethodTarget(node);
}
}
return super.makeDirectCall(origin, receiver, message, arguments, adapter, implicitThis, containsSpreadExpression);
}
示例7: makeDynamicGetProperty
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private void makeDynamicGetProperty(final Expression receiver, final String methodName, final boolean safe) {
MethodNode target = safe?INVOKERHELPER_GETPROPERTYSAFE_METHOD:INVOKERHELPER_GETPROPERTY_METHOD;
MethodCallExpression mce = new MethodCallExpression(
new ClassExpression(INVOKERHELPER_TYPE),
target.getName(),
new ArgumentListExpression(receiver, new ConstantExpression(methodName))
);
mce.setSafe(false);
mce.setImplicitThis(false);
mce.setMethodTarget(target);
mce.visit(controller.getAcg());
}
示例8: createDirectCallMethod
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static void createDirectCallMethod(final ClassNode closureClass, final MethodNode doCallMethod) {
// in case there is no "call" method on the closure, we can create a "fast invocation" paths
// to avoid going through ClosureMetaClass by call(Object...) method
// we can't have a specialized version of call(Object...) because the dispatch logic in ClosureMetaClass
// is too complex!
// call(Object)
Parameter args = new Parameter(ClassHelper.OBJECT_TYPE, "args");
MethodCallExpression doCall1arg = new MethodCallExpression(
new VariableExpression("this", closureClass),
"doCall",
new ArgumentListExpression(new VariableExpression(args))
);
doCall1arg.setImplicitThis(true);
doCall1arg.setMethodTarget(doCallMethod);
closureClass.addMethod(
new MethodNode("call",
Opcodes.ACC_PUBLIC,
ClassHelper.OBJECT_TYPE,
new Parameter[]{args},
ClassNode.EMPTY_ARRAY,
new ReturnStatement(doCall1arg)));
// call()
MethodCallExpression doCallNoArgs = new MethodCallExpression(new VariableExpression("this", closureClass), "doCall", new ArgumentListExpression(new ConstantExpression(null)));
doCallNoArgs.setImplicitThis(true);
doCallNoArgs.setMethodTarget(doCallMethod);
closureClass.addMethod(
new MethodNode("call",
Opcodes.ACC_PUBLIC,
ClassHelper.OBJECT_TYPE,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
new ReturnStatement(doCallNoArgs)));
}
示例9: visitMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
super.visitMethodCallExpression(call);
MethodNode mn = call.getMethodTarget();
if (mn == null) {
call.setMethodTarget(doCallMethod);
}
}
示例10: transformBinaryExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformBinaryExpression(final BinaryExpression exp) {
Expression trn = super.transform(exp);
if (trn instanceof BinaryExpression) {
BinaryExpression bin = (BinaryExpression) trn;
Expression leftExpression = bin.getLeftExpression();
if (bin.getOperation().getType() == Types.EQUAL && leftExpression instanceof PropertyExpression) {
ClassNode traitReceiver = null;
PropertyExpression leftPropertyExpression = (PropertyExpression) leftExpression;
if (isTraitSuperPropertyExpression(leftPropertyExpression.getObjectExpression())) {
PropertyExpression pexp = (PropertyExpression) leftPropertyExpression.getObjectExpression();
traitReceiver = pexp.getObjectExpression().getType();
}
if (traitReceiver!=null) {
// A.super.foo = ...
TraitHelpersTuple helpers = Traits.findHelpers(traitReceiver);
ClassNode helper = helpers.getHelper();
String setterName = MetaProperty.getSetterName(leftPropertyExpression.getPropertyAsString());
List<MethodNode> methods = helper.getMethods(setterName);
for (MethodNode method : methods) {
Parameter[] parameters = method.getParameters();
if (parameters.length==2 && parameters[0].getType().equals(traitReceiver)) {
ArgumentListExpression args = new ArgumentListExpression(
new VariableExpression("this"),
transform(exp.getRightExpression())
);
MethodCallExpression setterCall = new MethodCallExpression(
new ClassExpression(helper),
setterName,
args
);
setterCall.setMethodTarget(method);
setterCall.setImplicitThis(false);
return setterCall;
}
}
return bin;
}
}
}
return trn;
}
示例11: writePostOrPrefixMethod
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
protected void writePostOrPrefixMethod(int op, String method, Expression expression, Expression orig) {
MethodNode mn = orig.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
WriterController controller = getController();
OperandStack operandStack = controller.getOperandStack();
if (mn!=null) {
operandStack.pop();
MethodCallExpression call = new MethodCallExpression(
expression,
method,
ArgumentListExpression.EMPTY_ARGUMENTS
);
call.setMethodTarget(mn);
call.visit(controller.getAcg());
return;
}
ClassNode top = operandStack.getTopOperand();
if (ClassHelper.isPrimitiveType(top) && (ClassHelper.isNumberType(top)||char_TYPE.equals(top))) {
MethodVisitor mv = controller.getMethodVisitor();
if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
mv.visitInsn(ICONST_1);
} else if (long_TYPE.equals(top)) {
mv.visitInsn(LCONST_1);
} else if (float_TYPE.equals(top)) {
mv.visitInsn(FCONST_1);
} else if (double_TYPE.equals(top)) {
mv.visitInsn(DCONST_1);
}
if ("next".equals(method)) {
if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
mv.visitInsn(IADD);
} else if (long_TYPE.equals(top)) {
mv.visitInsn(LADD);
} else if (float_TYPE.equals(top)) {
mv.visitInsn(FADD);
} else if (double_TYPE.equals(top)) {
mv.visitInsn(DADD);
}
} else {
if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
mv.visitInsn(ISUB);
} else if (long_TYPE.equals(top)) {
mv.visitInsn(LSUB);
} else if (float_TYPE.equals(top)) {
mv.visitInsn(FSUB);
} else if (double_TYPE.equals(top)) {
mv.visitInsn(DSUB);
}
}
return;
}
super.writePostOrPrefixMethod(op, method, expression, orig);
}
示例12: transformSpreadOnLHS
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private void transformSpreadOnLHS(BinaryExpression origin) {
PropertyExpression spreadExpression = (PropertyExpression) origin.getLeftExpression();
Expression value = origin.getRightExpression();
WriterController controller = getController();
MethodVisitor mv = controller.getMethodVisitor();
CompileStack compileStack = controller.getCompileStack();
TypeChooser typeChooser = controller.getTypeChooser();
OperandStack operandStack = controller.getOperandStack();
ClassNode classNode = controller.getClassNode();
int counter = labelCounter.incrementAndGet();
Expression receiver = spreadExpression.getObjectExpression();
// create an empty arraylist
VariableExpression result = new VariableExpression(
this.getClass().getSimpleName()+"$spreadresult" + counter,
ARRAYLIST_CLASSNODE
);
ConstructorCallExpression cce = new ConstructorCallExpression(ARRAYLIST_CLASSNODE, ArgumentListExpression.EMPTY_ARGUMENTS);
cce.setNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, ARRAYLIST_CONSTRUCTOR);
DeclarationExpression declr = new DeclarationExpression(
result,
Token.newSymbol("=", spreadExpression.getLineNumber(), spreadExpression.getColumnNumber()),
cce
);
declr.visit(controller.getAcg());
// if (receiver != null)
receiver.visit(controller.getAcg());
Label ifnull = compileStack.createLocalLabel("ifnull_" + counter);
mv.visitJumpInsn(IFNULL, ifnull);
operandStack.remove(1); // receiver consumed by if()
Label nonull = compileStack.createLocalLabel("nonull_" + counter);
mv.visitLabel(nonull);
ClassNode componentType = StaticTypeCheckingVisitor.inferLoopElementType(typeChooser.resolveType(receiver, classNode));
Parameter iterator = new Parameter(componentType, "for$it$" + counter);
VariableExpression iteratorAsVar = new VariableExpression(iterator);
PropertyExpression pexp = spreadExpression instanceof AttributeExpression ?
new AttributeExpression(iteratorAsVar, spreadExpression.getProperty(), true):
new PropertyExpression(iteratorAsVar, spreadExpression.getProperty(), true);
pexp.setImplicitThis(spreadExpression.isImplicitThis());
pexp.setSourcePosition(spreadExpression);
BinaryExpression assignment = new BinaryExpression(
pexp,
origin.getOperation(),
value
);
MethodCallExpression add = new MethodCallExpression(
result,
"add",
assignment
);
add.setMethodTarget(ARRAYLIST_ADD_METHOD);
// for (e in receiver) { result.add(e?.method(arguments) }
ForStatement stmt = new ForStatement(
iterator,
receiver,
new ExpressionStatement(add)
);
stmt.visit(controller.getAcg());
// else { empty list }
mv.visitLabel(ifnull);
// end of if/else
// return result list
result.visit(controller.getAcg());
}
示例13: writeIteratorBasedForEachLoop
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private void writeIteratorBasedForEachLoop(
CompileStack compileStack,
OperandStack operandStack,
MethodVisitor mv,
ForStatement loop,
Expression collectionExpression,
ClassNode collectionType,
Parameter loopVariable) {
// Declare the loop counter.
BytecodeVariable variable = compileStack.defineVariable(loopVariable, false);
if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(collectionType, ITERABLE_CLASSNODE)) {
MethodCallExpression iterator = new MethodCallExpression(collectionExpression, "iterator", new ArgumentListExpression());
iterator.setMethodTarget(collectionType.getMethod("iterator", Parameter.EMPTY_ARRAY));
iterator.setImplicitThis(false);
iterator.visit(controller.getAcg());
} else {
collectionExpression.visit(controller.getAcg());
mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/DefaultGroovyMethods", "iterator", "(Ljava/lang/Object;)Ljava/util/Iterator;", false);
operandStack.replace(ClassHelper.Iterator_TYPE);
}
// Then get the iterator and generate the loop control
int iteratorIdx = compileStack.defineTemporaryVariable("iterator", ClassHelper.Iterator_TYPE, true);
Label continueLabel = compileStack.getContinueLabel();
Label breakLabel = compileStack.getBreakLabel();
mv.visitLabel(continueLabel);
mv.visitVarInsn(ALOAD, iteratorIdx);
writeIteratorHasNext(mv);
// note: ifeq tests for ==0, a boolean is 0 if it is false
mv.visitJumpInsn(IFEQ, breakLabel);
mv.visitVarInsn(ALOAD, iteratorIdx);
writeIteratorNext(mv);
operandStack.push(ClassHelper.OBJECT_TYPE);
operandStack.storeVar(variable);
// Generate the loop body
loop.getLoopBlock().visit(controller.getAcg());
mv.visitJumpInsn(GOTO, continueLabel);
mv.visitLabel(breakLabel);
compileStack.removeVar(iteratorIdx);
}