本文整理匯總了Java中org.codehaus.groovy.ast.expr.CastExpression.isCoerce方法的典型用法代碼示例。如果您正苦於以下問題:Java CastExpression.isCoerce方法的具體用法?Java CastExpression.isCoerce怎麽用?Java CastExpression.isCoerce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.groovy.ast.expr.CastExpression
的用法示例。
在下文中一共展示了CastExpression.isCoerce方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
}
示例3: 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());
}