本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.visit方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.visit方法的具体用法?Java MethodCallExpression.visit怎么用?Java MethodCallExpression.visit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.visit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: evaluateArrayAssignmentWithOperator
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
protected void evaluateArrayAssignmentWithOperator(String method, BinaryExpression expression, BinaryExpression leftBinExpr) {
CompileStack compileStack = getController().getCompileStack();
AsmClassGenerator acg = getController().getAcg();
OperandStack os = getController().getOperandStack();
// e.g. x[a] += b
// to avoid loading x and a twice we transform the expression to use
// ExpressionAsVariableSlot
// -> subscript=a, receiver=x, receiver[subscript]+b, =, receiver[subscript]
// -> subscript=a, receiver=x, receiver#getAt(subscript)#plus(b), =, receiver#putAt(subscript)
// -> subscript=a, receiver=x, receiver#putAt(subscript, receiver#getAt(subscript)#plus(b))
// the result of x[a] += b is x[a]+b, thus:
// -> subscript=a, receiver=x, receiver#putAt(subscript, ret=receiver#getAt(subscript)#plus(b)), ret
ExpressionAsVariableSlot subscript = new ExpressionAsVariableSlot(controller, leftBinExpr.getRightExpression(), "subscript");
ExpressionAsVariableSlot receiver = new ExpressionAsVariableSlot(controller, leftBinExpr.getLeftExpression(), "receiver");
MethodCallExpression getAt = new MethodCallExpression(receiver, "getAt", new ArgumentListExpression(subscript));
MethodCallExpression operation = new MethodCallExpression(getAt, method, expression.getRightExpression());
ExpressionAsVariableSlot ret = new ExpressionAsVariableSlot(controller, operation, "ret");
MethodCallExpression putAt = new MethodCallExpression(receiver, "putAt", new ArgumentListExpression(subscript, ret));
putAt.visit(acg);
os.pop();
os.load(ret.getType(), ret.getIndex());
compileStack.removeVar(ret.getIndex());
compileStack.removeVar(subscript.getIndex());
compileStack.removeVar(receiver.getIndex());
}
示例3: 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());
}
示例4: 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);
}
示例5: assignToArray
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
protected void assignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader, boolean safe) {
ClassNode current = getController().getClassNode();
ClassNode arrayType = getController().getTypeChooser().resolveType(receiver, current);
ClassNode arrayComponentType = arrayType.getComponentType();
int operationType = getOperandType(arrayComponentType);
BinaryExpressionWriter bew = binExpWriter[operationType];
if (bew.arraySet(true) && arrayType.isArray() && !safe) {
super.assignToArray(parent, receiver, index, rhsValueLoader, safe);
} else {
/******
/ This code path is needed because ACG creates array access expressions
*******/
WriterController controller = getController();
StaticTypeCheckingVisitor visitor = new StaticCompilationVisitor(controller.getSourceUnit(), controller.getClassNode());
// let's replace this assignment to a subscript operator with a
// method call
// e.g. x[5] = 10
// -> (x, [], 5), =, 10
// -> methodCall(x, "putAt", [5, 10])
ArgumentListExpression ae = new ArgumentListExpression(index, rhsValueLoader);
if (rhsValueLoader instanceof VariableSlotLoader && parent instanceof BinaryExpression) {
// GROOVY-6061
rhsValueLoader.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE,
controller.getTypeChooser().resolveType(parent, controller.getClassNode()));
}
MethodCallExpression mce = new MethodCallExpression(
receiver,
"putAt",
ae
);
mce.setSafe(safe);
mce.setSourcePosition(parent);
visitor.visitMethodCallExpression(mce);
OperandStack operandStack = controller.getOperandStack();
int height = operandStack.getStackLength();
mce.visit(controller.getAcg());
operandStack.pop();
operandStack.remove(operandStack.getStackLength()-height);
// return value of assignment
rhsValueLoader.visit(controller.getAcg());
}
}
示例6: 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);
}
示例7: writeForInLoop
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
protected void writeForInLoop(ForStatement loop) {
controller.getAcg().onLineNumber(loop,"visitForLoop");
writeStatementLabel(loop);
CompileStack compileStack = controller.getCompileStack();
MethodVisitor mv = controller.getMethodVisitor();
OperandStack operandStack = controller.getOperandStack();
compileStack.pushLoop(loop.getVariableScope(), loop.getStatementLabels());
// Declare the loop counter.
BytecodeVariable variable = compileStack.defineVariable(loop.getVariable(), false);
// Then get the iterator and generate the loop control
MethodCallExpression iterator = new MethodCallExpression(loop.getCollectionExpression(), "iterator", new ArgumentListExpression());
iterator.visit(controller.getAcg());
operandStack.doGroovyCast(ClassHelper.Iterator_TYPE);
final 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);
compileStack.pop();
}