use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method getMetaProperty.
private MetaProperty getMetaProperty(String name, boolean useStatic) {
CachedClass clazz = theCachedClass;
SingleKeyHashMap propertyMap;
if (useStatic) {
propertyMap = staticPropertyIndex;
} else {
propertyMap = classPropertyIndex.getNullable(clazz);
}
if (propertyMap == null) {
return null;
}
return (MetaProperty) propertyMap.get(name);
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method getMatchKindForCategory.
/**
* return false: add method
* null: ignore method
* true: replace
*/
private Boolean getMatchKindForCategory(MetaMethod aMethod, MetaMethod categoryMethod) {
CachedClass[] params1 = aMethod.getParameterTypes();
CachedClass[] params2 = categoryMethod.getParameterTypes();
if (params1.length != params2.length)
return Boolean.FALSE;
for (int i = 0; i < params1.length; i++) {
if (params1[i] != params2[i])
return Boolean.FALSE;
}
Class aMethodClass = aMethod.getDeclaringClass().getTheClass();
Class categoryMethodClass = categoryMethod.getDeclaringClass().getTheClass();
if (aMethodClass == categoryMethodClass)
return Boolean.TRUE;
boolean match = aMethodClass.isAssignableFrom(categoryMethodClass);
if (match)
return Boolean.TRUE;
return null;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method addMetaMethod.
// Implementation methods
//-------------------------------------------------------------------------
/**
* adds a MetaMethod to this class. WARNING: this method will not
* do the neccessary steps for multimethod logic and using this
* method doesn't mean, that a method added here is replacing another
* method from a parent class completely. These steps are usually done
* by initialize, which means if you need these steps, you have to add
* the method before running initialize the first time.
*
* @param method the MetaMethod
* @see #initialize()
*/
public void addMetaMethod(MetaMethod method) {
if (isInitialized()) {
throw new RuntimeException("Already initialized, cannot add new method: " + method);
}
final CachedClass declaringClass = method.getDeclaringClass();
addMetaMethodToIndex(method, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class DgmConverter method createDoMethodInvokeMethod.
private static void createDoMethodInvokeMethod(CachedMethod method, ClassWriter cw, String className, Class returnType, String methodDescriptor) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "doMethodInvoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", null, null);
mv.visitCode();
if (method.getParamsCount() == 2 && method.getParameterTypes()[0].isNumber && method.getParameterTypes()[1].isNumber) {
mv.visitVarInsn(ALOAD, 1);
BytecodeHelper.doCast(mv, method.getParameterTypes()[0].getTheClass());
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, className, "getParameterTypes", "()[Lorg/codehaus/groovy/reflection/CachedClass;", false);
mv.visitInsn(ICONST_0);
mv.visitInsn(AALOAD);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ICONST_0);
mv.visitInsn(AALOAD);
mv.visitMethodInsn(INVOKEVIRTUAL, "org/codehaus/groovy/reflection/CachedClass", "coerceArgument", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
// cast argument to parameter class, inclusive unboxing
// for methods with primitive types
Class type = method.getParameterTypes()[1].getTheClass();
BytecodeHelper.doCast(mv, type);
} else {
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, className, "coerceArgumentsToClasses", "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 1);
BytecodeHelper.doCast(mv, method.getParameterTypes()[0].getTheClass());
loadParameters(method, 2, mv);
}
mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(method.getDeclaringClass().getTheClass()), method.getName(), methodDescriptor, false);
BytecodeHelper.box(mv, returnType);
if (method.getReturnType() == void.class) {
mv.visitInsn(ACONST_NULL);
}
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class DgmConverter method loadParameters.
protected static void loadParameters(CachedMethod method, int argumentIndex, MethodVisitor mv) {
CachedClass[] parameters = method.getParameterTypes();
int size = parameters.length - 1;
for (int i = 0; i < size; i++) {
// unpack argument from Object[]
mv.visitVarInsn(ALOAD, argumentIndex);
BytecodeHelper.pushConstant(mv, i);
mv.visitInsn(AALOAD);
// cast argument to parameter class, inclusive unboxing
// for methods with primitive types
Class type = parameters[i + 1].getTheClass();
BytecodeHelper.doCast(mv, type);
}
}
Aggregations