本文整理汇总了Java中org.codehaus.groovy.ast.expr.Expression.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.getType方法的具体用法?Java Expression.getType怎么用?Java Expression.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.Expression
的用法示例。
在下文中一共展示了Expression.getType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeBaseScriptTypeFromPackageOrImport
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
Expression value = node.getMember("value");
ClassNode scriptType;
if (value == null) {
scriptType = BASE_SCRIPT_TYPE;
} else {
if (!(value instanceof ClassExpression)) {
addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
return;
}
scriptType = value.getType();
}
List<ClassNode> classes = source.getAST().getClasses();
for (ClassNode classNode : classes) {
if (classNode.isScriptBody()) {
changeBaseScriptType(source, parent, classNode, scriptType, node);
}
}
}
示例2: getTargetListFromValue
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private List<AnnotationNode> getTargetListFromValue(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, SourceUnit source) {
Expression memberValue = collector.getMember("value");
if (memberValue == null) {
return Collections.emptyList();
}
if (!(memberValue instanceof ListExpression)) {
addError("Annotation collector expected a list of classes, but got a "+memberValue.getClass(), collector, source);
return Collections.emptyList();
}
ListExpression memberListExp = (ListExpression) memberValue;
List<Expression> memberList = memberListExp.getExpressions();
if (memberList.isEmpty()) {
return Collections.emptyList();
}
List<AnnotationNode> ret = new ArrayList<AnnotationNode>();
for (Expression e : memberList) {
AnnotationNode toAdd = new AnnotationNode(e.getType());
toAdd.setSourcePosition(aliasAnnotationUsage);
ret.add(toAdd);
}
return ret;
}
示例3: extractStaticReceiver
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
/**
* Given a method call, first checks that it's a static method call, and if it is, returns the
* class node for the receiver. For example, with the following code:
* <code></code>Person.findAll { ... }</code>, it would return the class node for <i>Person</i>.
* If it's not a static method call, returns null.
* @param call a method call
* @return null if it's not a static method call, or the class node for the receiver instead.
*/
public ClassNode extractStaticReceiver(MethodCall call) {
if (call instanceof StaticMethodCallExpression) {
return ((StaticMethodCallExpression) call).getOwnerType();
} else if (call instanceof MethodCallExpression) {
Expression objectExpr = ((MethodCallExpression) call).getObjectExpression();
if (objectExpr instanceof ClassExpression && ClassHelper.CLASS_Type.equals(objectExpr.getType())) {
GenericsType[] genericsTypes = objectExpr.getType().getGenericsTypes();
if (genericsTypes!=null && genericsTypes.length==1) {
return genericsTypes[0].getType();
}
}
if (objectExpr instanceof ClassExpression) {
return objectExpr.getType();
}
}
return null;
}
示例4: createConstructorStatementCollection
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static Statement createConstructorStatementCollection(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
ClassNode fieldType = fieldExpr.getType();
Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression)initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneCollectionExpr(initExpr, fieldType));
}
Expression collection = findArg(fNode.getName());
return ifElseS(
equalsNullX(collection),
assignInit,
ifElseS(
isInstanceOfX(collection, CLONEABLE_TYPE),
assignS(fieldExpr, cloneCollectionExpr(cloneArrayOrCloneableExpr(collection, fieldType), fieldType)),
assignS(fieldExpr, cloneCollectionExpr(collection, fieldType)))
);
}
示例5: resolveType
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public ClassNode resolveType(final Expression exp, final ClassNode current) {
if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
ClassNode type = null;
if (meta != null) type = meta.type;
if (type != null) return type;
if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.isClosureSharedVariable()) return ve.getType();
type = ve.getOriginType();
if (ve.getAccessedVariable() instanceof FieldNode) {
FieldNode fn = (FieldNode) ve.getAccessedVariable();
if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
}
} else if (exp instanceof Variable) {
Variable v = (Variable) exp;
type = v.getOriginType();
} else {
type = exp.getType();
}
return type.redirect();
}
示例6: getClassAnnotationParameter
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected static ClassNode getClassAnnotationParameter(AnnotationNode node, String parameterName, ClassNode defaultValue) {
Expression member = node.getMember(parameterName);
if (member != null) {
if (member instanceof ClassExpression) {
try {
return member.getType();
} catch (Exception e) {
internalError("Expecting class value for " + parameterName + " annotation parameter. Found " + member + "member");
}
} else {
internalError("Expecting class value for " + parameterName + " annotation parameter. Found " + member + "member");
}
}
return defaultValue;
}
示例7: getMemberClassValue
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public ClassNode getMemberClassValue(AnnotationNode node, String name, ClassNode defaultValue) {
final Expression member = node.getMember(name);
if (member != null) {
if (member instanceof ClassExpression) {
if (!isUndefined(member.getType())) return member.getType();
} else if (member instanceof VariableExpression) {
addError("Error expecting to find class value for '" + name + "' but found variable: " + member.getText() + ". Missing import?", node);
return null;
} else if (member instanceof ConstantExpression) {
addError("Error expecting to find class value for '" + name + "' but found constant: " + member.getText() + "!", node);
return null;
}
}
return defaultValue;
}
示例8: isTraitSuperPropertyExpression
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private boolean isTraitSuperPropertyExpression(Expression exp) {
if (exp instanceof PropertyExpression) {
PropertyExpression pexp = (PropertyExpression) exp;
Expression objectExpression = pexp.getObjectExpression();
if (objectExpression instanceof ClassExpression) {
ClassNode type = objectExpression.getType();
if (Traits.isTrait(type) && "super".equals(pexp.getPropertyAsString())) {
return true;
}
}
}
return false;
}
示例9: createConstructorStatementMapSpecial
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static Statement createConstructorStatementMapSpecial(FieldNode fNode) {
final Expression fieldExpr = varX(fNode);
final ClassNode fieldType = fieldExpr.getType();
final Expression initExpr = fNode.getInitialValueExpression();
final Statement assignInit;
if (initExpr == null || (initExpr instanceof ConstantExpression && ((ConstantExpression)initExpr).isNullExpression())) {
assignInit = assignS(fieldExpr, ConstantExpression.EMPTY_EXPRESSION);
} else {
assignInit = assignS(fieldExpr, cloneCollectionExpr(initExpr, fieldType));
}
Expression namedArgs = findArg(fNode.getName());
Expression baseArgs = varX("args");
return ifElseS(
equalsNullX(baseArgs),
assignInit,
ifElseS(
equalsNullX(namedArgs),
ifElseS(
isTrueX(callX(baseArgs, "containsKey", constX(fNode.getName()))),
assignS(fieldExpr, namedArgs),
assignS(fieldExpr, cloneCollectionExpr(baseArgs, fieldType))),
ifElseS(
isOneX(callX(baseArgs, "size")),
assignS(fieldExpr, cloneCollectionExpr(namedArgs, fieldType)),
assignS(fieldExpr, cloneCollectionExpr(baseArgs, fieldType)))
)
);
}
示例10: loadWrapper
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public void loadWrapper(Expression argument) {
MethodVisitor mv = controller.getMethodVisitor();
ClassNode goalClass = argument.getType();
visitClassExpression(new ClassExpression(goalClass));
if (goalClass.isDerivedFromGroovyObject()) {
createGroovyObjectWrapperMethod.call(mv);
} else {
createPojoWrapperMethod.call(mv);
}
controller.getOperandStack().remove(1);
}
示例11: getConstructorArgumentType
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) {
if (!(arg instanceof VariableExpression)) return arg.getType();
VariableExpression vexp = (VariableExpression) arg;
String name = vexp.getName();
for (Parameter param : node.getParameters()) {
if (param.getName().equals(name)) {
return param.getType();
}
}
return vexp.getType();
}
示例12: printField
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private void printField(PrintWriter out, FieldNode fieldNode, boolean isInterface) {
if ((fieldNode.getModifiers() & Opcodes.ACC_PRIVATE) != 0) return;
printAnnotations(out, fieldNode);
if (!isInterface) {
printModifiers(out, fieldNode.getModifiers());
}
ClassNode type = fieldNode.getType();
printType(out, type);
out.print(" ");
out.print(fieldNode.getName());
if (isInterface || (fieldNode.getModifiers() & Opcodes.ACC_FINAL) != 0) {
out.print(" = ");
Expression valueExpr = fieldNode.getInitialValueExpression();
if (valueExpr instanceof ConstantExpression) {
valueExpr = Verifier.transformToPrimitiveConstantIfPossible((ConstantExpression) valueExpr);
}
if (valueExpr instanceof ConstantExpression
&& fieldNode.isStatic() && fieldNode.isFinal()
&& ClassHelper.isStaticConstantInitializerType(valueExpr.getType())
&& valueExpr.getType().equals(fieldNode.getType())) {
// GROOVY-5150 : Initialize value with a dummy constant so that Java cross compiles correctly
if (ClassHelper.STRING_TYPE.equals(valueExpr.getType())) {
out.print(formatString(valueExpr.getText()));
} else if (ClassHelper.char_TYPE.equals(valueExpr.getType())) {
out.print("'"+valueExpr.getText()+"'");
} else {
ClassNode constantType = valueExpr.getType();
out.print('(');
printType(out, type);
out.print(") ");
out.print(valueExpr.getText());
if (ClassHelper.Long_TYPE.equals(ClassHelper.getWrapper(constantType))) out.print('L');
}
} else if (ClassHelper.isPrimitiveType(type)) {
String val = type == ClassHelper.boolean_TYPE ? "false" : "0";
out.print("new " + ClassHelper.getWrapper(type) + "((" + type + ")" + val + ")");
} else {
out.print("null");
}
}
out.println(";");
}