本文整理汇总了Java中org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java ClassHelper.OBJECT_TYPE属性的具体用法?Java ClassHelper.OBJECT_TYPE怎么用?Java ClassHelper.OBJECT_TYPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.codehaus.groovy.ast.ClassHelper
的用法示例。
在下文中一共展示了ClassHelper.OBJECT_TYPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClassMember
private Variable findClassMember(ClassNode cn, String name) {
if (cn == null) return null;
if (cn.isScript()) {
return new DynamicVariable(name, false);
}
for (FieldNode fn : cn.getFields()) {
if (fn.getName().equals(name)) return fn;
}
for (MethodNode mn : cn.getMethods()) {
String pName = getPropertyName(mn);
if (pName != null && pName.equals(name))
return new PropertyNode(pName, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
}
for (PropertyNode pn : cn.getProperties()) {
if (pn.getName().equals(name)) return pn;
}
Variable ret = findClassMember(cn.getSuperClass(), name);
if (ret != null) return ret;
return findClassMember(cn.getOuterClass(), name);
}
示例2: printDefaultValue
private void printDefaultValue(PrintWriter out, ClassNode type) {
if (type.redirect() != ClassHelper.OBJECT_TYPE && type.redirect() != ClassHelper.boolean_TYPE) {
out.print("(");
printType(out, type);
out.print(")");
}
if (ClassHelper.isPrimitiveType(type)) {
if (type == ClassHelper.boolean_TYPE) {
out.print("false");
} else {
out.print("0");
}
} else {
out.print("null");
}
}
示例3: serialize
private Expression serialize(Expression e) {
if (e instanceof AnnotationConstantExpression) {
AnnotationConstantExpression ace = (AnnotationConstantExpression) e;
return serialize((AnnotationNode) ace.getValue());
} else if (e instanceof ListExpression) {
boolean annotationConstant = false;
ListExpression le = (ListExpression) e;
List<Expression> list = le.getExpressions();
List<Expression> newList = new ArrayList<Expression>(list.size());
for (Expression exp: list) {
annotationConstant = annotationConstant || exp instanceof AnnotationConstantExpression;
newList.add(serialize(exp));
}
ClassNode type = ClassHelper.OBJECT_TYPE;
if (annotationConstant) type = type.makeArray();
return new ArrayExpression(type, newList);
}
return e;
}
示例4: getMetaClassField
private static FieldNode getMetaClassField(ClassNode node) {
FieldNode ret = node.getDeclaredField("metaClass");
if (ret != null) {
ClassNode mcFieldType = ret.getType();
if (!mcFieldType.equals(ClassHelper.METACLASS_TYPE)) {
throw new RuntimeParserException("The class " + node.getName() +
" cannot declare field 'metaClass' of type " + mcFieldType.getName() + " as it needs to be of " +
"the type " + ClassHelper.METACLASS_TYPE.getName() + " for internal groovy purposes", ret);
}
return ret;
}
ClassNode current = node;
while (current != ClassHelper.OBJECT_TYPE) {
current = current.getSuperClass();
if (current == null) break;
ret = current.getDeclaredField("metaClass");
if (ret == null) continue;
if (isPrivate(ret.getModifiers())) continue;
return ret;
}
return null;
}
示例5: visitClosureExpression
public void visitClosureExpression(ClosureExpression expression) {
pushState();
expression.setVariableScope(currentScope);
if (expression.isParameterSpecified()) {
Parameter[] parameters = expression.getParameters();
for (Parameter parameter : parameters) {
parameter.setInStaticContext(currentScope.isInStaticContext());
if (parameter.hasInitialExpression()) {
parameter.getInitialExpression().visit(this);
}
declare(parameter, expression);
}
} else if (expression.getParameters() != null) {
Parameter var = new Parameter(ClassHelper.OBJECT_TYPE, "it");
var.setInStaticContext(currentScope.isInStaticContext());
currentScope.putDeclaredVariable(var);
}
super.visitClosureExpression(expression);
markClosureSharedVariables();
popState();
}
示例6: createRWClass
private void createRWClass() {
ClassNode parentRW = getRwClassOfDslParent();
rwClass = new InnerClassNode(
annotatedClass,
annotatedClass.getName() + RW_CLASS_SUFFIX,
0,
parentRW != null ? parentRW : ClassHelper.OBJECT_TYPE,
new ClassNode[] { make(Serializable.class)},
new MixinNode[0]);
// Need to explicitly add this field for non static inner classes (Groovy Bug?)
rwClass.addField(NAME_OF_MODEL_FIELD_IN_RW_CLASS, ACC_FINAL | ACC_PRIVATE | ACC_SYNTHETIC, newClass(annotatedClass), null);
annotatedClass.getModule().addClass(rwClass);
annotatedClass.addField(NAME_OF_RW_FIELD_IN_MODEL_CLASS, ACC_PRIVATE | ACC_SYNTHETIC | ACC_FINAL, rwClass, ctorX(rwClass, varX("this")));
annotatedClass.setNodeMetaData(RWCLASS_METADATA_KEY, rwClass);
createCoercionMethod();
}
示例7: newMethod
public MethodNode newMethod(final String name,
final Callable<ClassNode> returnType) {
MethodNode node = new MethodNode(name,
Opcodes.ACC_PUBLIC,
ClassHelper.OBJECT_TYPE,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
EmptyStatement.INSTANCE) {
@Override
public ClassNode getReturnType() {
try {
return returnType.call();
} catch (Exception e) {
return super.getReturnType();
}
}
};
generatedMethods.add(node);
return node;
}
示例8: doCast
public static void doCast(MethodVisitor mv, ClassNode type) {
if (type == ClassHelper.OBJECT_TYPE) return;
if (ClassHelper.isPrimitiveType(type) && type != ClassHelper.VOID_TYPE) {
unbox(mv, type);
} else {
mv.visitTypeInsn(
CHECKCAST,
type.isArray() ?
BytecodeHelper.getTypeDescription(type) :
BytecodeHelper.getClassInternalName(type.getName()));
}
}
示例9: pickGenericType
/**
* A helper method which will extract the n-th generic type from a class node.
* @param type the class node from which to pick a generic type
* @param gtIndex the index of the generic type to extract
* @return the n-th generic type, or {@link org.codehaus.groovy.ast.ClassHelper#OBJECT_TYPE} if it doesn't exist.
*/
public static ClassNode pickGenericType(ClassNode type, int gtIndex) {
final GenericsType[] genericsTypes = type.getGenericsTypes();
if (genericsTypes==null || genericsTypes.length<gtIndex) {
return ClassHelper.OBJECT_TYPE;
}
return genericsTypes[gtIndex].getType();
}
示例10: evaluateCompareExpression
protected void evaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression) {
Expression leftExp = expression.getLeftExpression();
TypeChooser typeChooser = controller.getTypeChooser();
ClassNode cn = controller.getClassNode();
ClassNode leftType = typeChooser.resolveType(leftExp,cn);
Expression rightExp = expression.getRightExpression();
ClassNode rightType = typeChooser.resolveType(rightExp,cn);
boolean done = false;
if ( ClassHelper.isPrimitiveType(leftType) &&
ClassHelper.isPrimitiveType(rightType))
{
BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(getController());
done = helper.doPrimitiveCompare(leftType, rightType, expression);
}
if (!done) {
AsmClassGenerator acg = controller.getAcg();
OperandStack operandStack = controller.getOperandStack();
leftExp.visit(acg);
operandStack.box();
rightExp.visit(acg);
operandStack.box();
compareMethod.call(controller.getMethodVisitor());
ClassNode resType = ClassHelper.boolean_TYPE;
if (compareMethod==findRegexMethod) {
resType = ClassHelper.OBJECT_TYPE;
}
operandStack.replace(resType,2);
}
}
示例11: addSimpleCloneHelperMethod
private static void addSimpleCloneHelperMethod(ClassNode cNode, List<FieldNode> fieldNodes, List<String> excludes) {
Parameter methodParam = new Parameter(GenericsUtils.nonGeneric(cNode), "other");
final Expression other = varX(methodParam);
boolean hasParent = cNode.getSuperClass() != ClassHelper.OBJECT_TYPE;
BlockStatement methodBody = new BlockStatement();
if (hasParent) {
methodBody.addStatement(stmt(callSuperX("cloneOrCopyMembers", args(other))));
}
for (FieldNode fieldNode : fieldNodes) {
String name = fieldNode.getName();
if (excludes != null && excludes.contains(name)) continue;
ClassNode fieldType = fieldNode.getType();
Expression direct = propX(varX("this"), name);
Expression to = propX(other, name);
Statement assignDirect = assignS(to, direct);
Statement assignCloned = assignS(to, castX(fieldType, callCloneDirectX(direct)));
Statement assignClonedDynamic = assignS(to, castX(fieldType, callCloneDynamicX(direct)));
if (isCloneableType(fieldType)) {
methodBody.addStatement(assignCloned);
} else if (!possiblyCloneable(fieldType)) {
methodBody.addStatement(assignDirect);
} else {
methodBody.addStatement(ifElseS(isInstanceOfX(direct, CLONEABLE_TYPE), assignClonedDynamic, assignDirect));
}
}
ClassNode[] exceptions = {make(CloneNotSupportedException.class)};
cNode.addMethod("cloneOrCopyMembers", ACC_PROTECTED, ClassHelper.VOID_TYPE, params(methodParam), exceptions, methodBody);
}
示例12: testDetectsFinalAndStaticMethodsInInterface
public void testDetectsFinalAndStaticMethodsInInterface() throws Exception {
ClassNode node = new ClassNode("zzz", ACC_ABSTRACT | ACC_INTERFACE, ClassHelper.OBJECT_TYPE);
node.addMethod(new MethodNode("xxx", ACC_PUBLIC | ACC_FINAL, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null));
node.addMethod(new MethodNode("yyy", ACC_PUBLIC | ACC_STATIC, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null));
addDummyConstructor(node);
verifier.visitClass(node);
checkErrorCount(2);
checkErrorMessage(EXPECTED_INTERFACE_FINAL_METHOD_ERROR_MESSAGE);
checkErrorMessage(EXPECTED_INTERFACE_STATIC_METHOD_ERROR_MESSAGE);
}
示例13: testDetectsIncorrectMemberVisibilityInInterface
public void testDetectsIncorrectMemberVisibilityInInterface() throws Exception {
ClassNode node = new ClassNode("zzz", ACC_ABSTRACT | ACC_INTERFACE, ClassHelper.OBJECT_TYPE);
node.addMethod(new MethodNode("prim", ACC_PRIVATE, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null));
node.addMethod(new MethodNode("prom", ACC_PROTECTED, ClassHelper.OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null));
node.addField("prif", ACC_PRIVATE, ClassHelper.OBJECT_TYPE, null);
node.addField("prof", ACC_PROTECTED, ClassHelper.OBJECT_TYPE, null);
addDummyConstructor(node);
verifier.visitClass(node);
checkErrorCount(4);
checkErrorMessage(EXPECTED_PROTECTED_FIELD_ERROR_MESSAGE);
checkErrorMessage(EXPECTED_PRIVATE_FIELD_ERROR_MESSAGE);
checkErrorMessage(EXPECTED_PROTECTED_METHOD_ERROR_MESSAGE);
checkErrorMessage(EXPECTED_PRIVATE_METHOD_ERROR_MESSAGE);
}
示例14: createSuperFallback
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;
}
示例15: testFields
public void testFields() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addField("x", ACC_PUBLIC, ClassHelper.OBJECT_TYPE, null);
classNode.addField("y", ACC_PUBLIC, ClassHelper.Integer_TYPE, null);
classNode.addField("z", ACC_PRIVATE, ClassHelper.STRING_TYPE, null);
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
assertField(fooClass, "x", Modifier.PUBLIC, ClassHelper.OBJECT_TYPE);
assertField(fooClass, "y", Modifier.PUBLIC, ClassHelper.Integer_TYPE);
assertField(fooClass, "z", Modifier.PRIVATE, ClassHelper.STRING_TYPE);
}