本文整理匯總了Java中org.codehaus.groovy.ast.expr.CastExpression類的典型用法代碼示例。如果您正苦於以下問題:Java CastExpression類的具體用法?Java CastExpression怎麽用?Java CastExpression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CastExpression類屬於org.codehaus.groovy.ast.expr包,在下文中一共展示了CastExpression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitCastExpression
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
public void visitCastExpression(CastExpression castExpression) {
ClassNode type = castExpression.getType();
Expression subExpression = castExpression.getExpression();
subExpression.visit(this);
if (ClassHelper.OBJECT_TYPE.equals(type)) return;
if (castExpression.isCoerce()) {
controller.getOperandStack().doAsType(type);
} else {
if (isNullConstant(subExpression) && !ClassHelper.isPrimitiveType(type)) {
controller.getOperandStack().replace(type);
} else {
ClassNode subExprType = controller.getTypeChooser().resolveType(subExpression, controller.getClassNode());
if (castExpression.isStrict() ||
(!ClassHelper.isPrimitiveType(type) && WideningCategories.implementsInterfaceOrSubclassOf(subExprType, type))) {
BytecodeHelper.doCast(controller.getMethodVisitor(), type);
controller.getOperandStack().replace(type);
} else {
controller.getOperandStack().doGroovyCast(type);
}
}
}
}
示例2: visitTupleExpression
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
void visitTupleExpression(TupleExpression expression, boolean useWrapper) {
MethodVisitor mv = controller.getMethodVisitor();
int size = expression.getExpressions().size();
BytecodeHelper.pushConstant(mv, size);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
for (int i = 0; i < size; i++) {
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
Expression argument = expression.getExpression(i);
argument.visit(this);
controller.getOperandStack().box();
if (useWrapper && argument instanceof CastExpression) loadWrapper(argument);
mv.visitInsn(AASTORE);
controller.getOperandStack().remove(1);
}
}
示例3: makeInvokeMethodCall
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
private void makeInvokeMethodCall(MethodCallExpression call, boolean useSuper, MethodCallerMultiAdapter adapter) {
// receiver
// we operate on GroovyObject if possible
Expression objectExpression = call.getObjectExpression();
// message name
Expression messageName = new CastExpression(ClassHelper.STRING_TYPE, call.getMethod());
if (useSuper) {
ClassNode classNode = controller.isInClosure() ? controller.getOutermostClass() : controller.getClassNode(); // GROOVY-4035
ClassNode superClass = classNode.getSuperClass();
makeCall(call, new ClassExpression(superClass),
objectExpression, messageName,
call.getArguments(), adapter,
call.isSafe(), call.isSpreadSafe(),
false
);
} else {
makeCall(call, objectExpression, messageName,
call.getArguments(), adapter,
call.isSafe(), call.isSpreadSafe(),
call.isImplicitThis()
);
}
}
示例4: getMethodName
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
protected String getMethodName(Expression message) {
String methodName = null;
if (message instanceof CastExpression) {
CastExpression msg = (CastExpression) message;
if (msg.getType() == ClassHelper.STRING_TYPE) {
final Expression methodExpr = msg.getExpression();
if (methodExpr instanceof ConstantExpression)
methodName = methodExpr.getText();
}
}
if (methodName == null && message instanceof ConstantExpression) {
ConstantExpression constantExpression = (ConstantExpression) message;
methodName = constantExpression.getText();
}
return methodName;
}
示例5: visitCastExpression
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public void visitCastExpression(final CastExpression exp) {
if (exp.isCoerce()) {
makeNode("sandboxCast", new Runnable() {
@Override
public void run() {
loc(exp);
visit(exp.getExpression());
literal(exp.getType());
literal(exp.isIgnoringAutoboxing());
literal(exp.isStrict());
}
});
} else {
super.visitCastExpression(exp);
}
}
示例6: visitCastExprAlt
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public CastExpression visitCastExprAlt(CastExprAltContext ctx) {
return configureAST(
new CastExpression(
this.visitCastParExpression(ctx.castParExpression()),
(Expression) this.visit(ctx.expression())
),
ctx
);
}
示例7: visitRelationalExprAlt
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public Expression visitRelationalExprAlt(RelationalExprAltContext ctx) {
switch (ctx.op.getType()) {
case AS:
return configureAST(
CastExpression.asExpression(this.visitType(ctx.type()), (Expression) this.visit(ctx.left)),
ctx);
case INSTANCEOF:
case NOT_INSTANCEOF:
ctx.type().putNodeMetaData(IS_INSIDE_INSTANCEOF_EXPR, true);
return configureAST(
new BinaryExpression((Expression) this.visit(ctx.left),
this.createGroovyToken(ctx.op),
configureAST(new ClassExpression(this.visitType(ctx.type())), ctx.type())),
ctx);
case LE:
case GE:
case GT:
case LT:
case IN:
case NOT_IN: {
if (ctx.op.getType() == IN || ctx.op.getType() == NOT_IN ) {
return this.createBinaryExpression(ctx.left, ctx.op, ctx.right, ctx);
}
return configureAST(
this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
ctx);
}
default:
throw createParsingFailedException("Unsupported relational expression: " + ctx.getText(), ctx);
}
}
示例8: visitCastExpression
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public void visitCastExpression(final CastExpression expression) {
super.visitCastExpression(expression);
if (!expression.isCoerce()) {
ClassNode targetType = expression.getType();
Expression source = expression.getExpression();
ClassNode expressionType = getType(source);
if (!checkCast(targetType, source) && !isDelegateOrOwnerInClosure(source)) {
addStaticTypeError("Inconvertible types: cannot cast " + expressionType.toString(false) + " to " + targetType.toString(false), expression);
}
}
storeType(expression, expression.getType());
}
示例9: transform
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public Expression transform(Expression expr) {
if (expr instanceof StaticMethodCallExpression) {
return staticMethodCallExpressionTransformer.transformStaticMethodCallExpression((StaticMethodCallExpression) expr);
}
if (expr instanceof BinaryExpression) {
return binaryExpressionTransformer.transformBinaryExpression((BinaryExpression)expr);
}
if (expr instanceof MethodCallExpression) {
return methodCallExpressionTransformer.transformMethodCallExpression((MethodCallExpression) expr);
}
if (expr instanceof ClosureExpression) {
return closureExpressionTransformer.transformClosureExpression((ClosureExpression) expr);
}
if (expr instanceof ConstructorCallExpression) {
return constructorCallTransformer.transformConstructorCall((ConstructorCallExpression) expr);
}
if (expr instanceof BooleanExpression) {
return booleanExpressionTransformer.transformBooleanExpression((BooleanExpression)expr);
}
if (expr instanceof VariableExpression) {
return variableExpressionTransformer.transformVariableExpression((VariableExpression)expr);
}
if (expr instanceof RangeExpression) {
return rangeExpressionTransformer.transformRangeExpression(((RangeExpression)expr));
}
if (expr instanceof ListExpression) {
return listExpressionTransformer.transformListExpression((ListExpression) expr);
}
if (expr instanceof CastExpression) {
return castExpressionTransformer.transformCastExpression(((CastExpression)expr));
}
return super.transform(expr);
}
示例10: createSuperFallback
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
private static Statement createSuperFallback(MethodNode forwarderMethod, ClassNode returnType) {
ArgumentListExpression args = new ArgumentListExpression();
Parameter[] forwarderMethodParameters = forwarderMethod.getParameters();
for (final Parameter forwarderMethodParameter : forwarderMethodParameters) {
args.addExpression(new VariableExpression(forwarderMethodParameter));
}
BinaryExpression instanceOfExpr = new BinaryExpression(new VariableExpression("this"), Token.newSymbol(Types.KEYWORD_INSTANCEOF, -1, -1), new ClassExpression(Traits.GENERATED_PROXY_CLASSNODE));
MethodCallExpression superCall = new MethodCallExpression(
new VariableExpression("super"),
forwarderMethod.getName(),
args
);
superCall.setImplicitThis(false);
CastExpression proxyReceiver = new CastExpression(Traits.GENERATED_PROXY_CLASSNODE, new VariableExpression("this"));
MethodCallExpression getProxy = new MethodCallExpression(proxyReceiver, "getProxyTarget", ArgumentListExpression.EMPTY_ARGUMENTS);
getProxy.setImplicitThis(true);
StaticMethodCallExpression proxyCall = new StaticMethodCallExpression(
ClassHelper.make(InvokerHelper.class),
"invokeMethod",
new ArgumentListExpression(getProxy, new ConstantExpression(forwarderMethod.getName()), new ArrayExpression(ClassHelper.OBJECT_TYPE, args.getExpressions()))
);
IfStatement stmt = new IfStatement(
new BooleanExpression(instanceOfExpr),
new ExpressionStatement(new CastExpression(returnType,proxyCall)),
new ExpressionStatement(superCall)
);
return stmt;
}
示例11: asExpression
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
protected Expression asExpression(AST node) {
AST leftNode = node.getFirstChild();
Expression leftExpression = expression(leftNode);
AST rightNode = leftNode.getNextSibling();
ClassNode type = makeTypeWithArguments(rightNode);
return CastExpression.asExpression(type, leftExpression);
}
示例12: makeIndyCall
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
private void makeIndyCall(MethodCallerMultiAdapter adapter, Expression receiver, boolean implicitThis, boolean safe, String methodName, Expression arguments) {
OperandStack operandStack = controller.getOperandStack();
StringBuilder sig = new StringBuilder(prepareIndyCall(receiver, implicitThis));
// load arguments
int numberOfArguments = 1;
ArgumentListExpression ae = makeArgumentList(arguments);
boolean containsSpreadExpression = AsmClassGenerator.containsSpreadExpression(arguments);
if (containsSpreadExpression) {
controller.getAcg().despreadList(ae.getExpressions(), true);
sig.append(getTypeDescription(Object[].class));
} else {
for (Expression arg : ae.getExpressions()) {
arg.visit(controller.getAcg());
if (arg instanceof CastExpression) {
operandStack.box();
controller.getAcg().loadWrapper(arg);
sig.append(getTypeDescription(Wrapper.class));
} else {
sig.append(getTypeDescription(operandStack.getTopOperand()));
}
numberOfArguments++;
}
}
sig.append(")Ljava/lang/Object;");
String callSiteName = METHOD.getCallSiteName();
if (adapter==null) callSiteName = INIT.getCallSiteName();
int flags = getMethodCallFlags(adapter, safe, containsSpreadExpression);
finishIndyCall(BSM, callSiteName, sig.toString(), numberOfArguments, methodName, flags);
}
示例13: fallbackAttributeOrPropertySite
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
public void fallbackAttributeOrPropertySite(PropertyExpression expression, Expression objectExpression, String name, MethodCallerMultiAdapter adapter) {
if (controller.getCompileStack().isLHS()) controller.getOperandStack().box();
controller.getInvocationWriter().makeCall(
expression,
objectExpression, // receiver
new CastExpression(ClassHelper.STRING_TYPE, expression.getProperty()), // messageName
MethodCallExpression.NO_ARGUMENTS, adapter,
expression.isSafe(), expression.isSpreadSafe(), expression.isImplicitThis()
);
}
示例14: pushDynamicName
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
public void pushDynamicName(Expression name) {
if (name instanceof ConstantExpression) {
ConstantExpression ce = (ConstantExpression) name;
Object value = ce.getValue();
if (value instanceof String) {
pushConstant(ce);
return;
}
}
new CastExpression(ClassHelper.STRING_TYPE, name).visit(controller.getAcg());
}
示例15: transform
import org.codehaus.groovy.ast.expr.CastExpression; //導入依賴的package包/類
@Override
public Expression transform(Expression expr) {
if (expr instanceof PropertyExpression) {
PropertyExpression objectPropExpr = (PropertyExpression) expr;
if (objectPropExpr.isDynamic()) {
String name = objectPropExpr.getText();
int idx = name.indexOf(".groovy.");
if (idx != -1 && shouldTransformClass(name)) {
return rewrite(objectPropExpr);
}
}
} else if (expr instanceof VariableExpression) {
VariableExpression variableExpression = (VariableExpression) expr;
variableExpression.setType(handleType(variableExpression.getType()));
ClassNode originType = handleType(variableExpression.getOriginType());
if (originType != variableExpression.getOriginType()) {
return new VariableExpression(variableExpression.getName(), rewriteType(variableExpression.getOriginType()));
}
} else if (expr instanceof ClassExpression) {
ClassExpression classExpression = (ClassExpression) expr;
classExpression.setType(handleType(classExpression.getType()));
} else if (expr instanceof ClosureExpression) {
ClosureExpression closureExpr = (ClosureExpression) expr;
Parameter[] parameters = closureExpr.getParameters();
if (parameters != null) {
for (Parameter param : parameters) {
handleParam(param);
}
}
} else if (expr instanceof CastExpression) {
CastExpression castExpr = (CastExpression) expr;
castExpr.setType(handleType(castExpr.getType()));
}
return expr.transformExpression(this);
}