use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class ExpandoMetaClass method findMixinMethod.
public MetaMethod findMixinMethod(String methodName, Class[] arguments) {
for (MixinInMetaClass mixin : mixinClasses) {
final CachedClass mixinClass = mixin.getMixinClass();
MetaClass metaClass = mixinClass.classInfo.getMetaClassForClass();
if (metaClass == null) {
metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(mixinClass.getTheClass());
}
MetaMethod metaMethod = metaClass.pickMethod(methodName, arguments);
if (metaMethod == null && metaClass instanceof MetaClassImpl) {
MetaClassImpl mc = (MetaClassImpl) metaClass;
for (CachedClass cl = mc.getTheCachedClass().getCachedSuperClass(); cl != null; cl = cl.getCachedSuperClass()) {
metaMethod = mc.getMethodWithoutCaching(cl.getTheClass(), methodName, arguments, false);
if (metaMethod != null)
break;
}
}
if (metaMethod != null) {
MetaMethod method = new MixinInstanceMetaMethod(metaMethod, mixin);
if (method.getParameterTypes().length == 1 && !method.getParameterTypes()[0].isPrimitive) {
MetaMethod noParam = pickMethod(methodName, EMPTY_CLASS_ARRAY);
// if the current call itself is with empty arg class array, no need to recurse with 'new Class[0]'
if (noParam == null && arguments.length != 0) {
try {
findMixinMethod(methodName, EMPTY_CLASS_ARRAY);
} catch (MethodSelectionException msex) {
/*
* Here we just additionally tried to find another no-arg mixin method of the same name and register that as well, if found.
* Safe to ignore a MethodSelectionException in this additional exercise. (GROOVY-4999)
*/
}
}
}
registerInstanceMethod(method);
return method;
}
}
return null;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaMethod method getMopName.
public String getMopName() {
if (mopName == null) {
String name = getName();
CachedClass declaringClass = getDeclaringClass();
if (Modifier.isPrivate(getModifiers()))
mopName = new StringBuffer().append("this$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
else
mopName = new StringBuffer().append("super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
}
return mopName;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method setupProperties.
/**
* This will build up the property map (Map of MetaProperty objects, keyed on
* property name).
*
* @param propertyDescriptors
*/
@SuppressWarnings("unchecked")
private void setupProperties(PropertyDescriptor[] propertyDescriptors) {
if (theCachedClass.isInterface) {
LinkedList<CachedClass> superClasses = new LinkedList<CachedClass>();
superClasses.add(ReflectionCache.OBJECT_CLASS);
Set interfaces = theCachedClass.getInterfaces();
LinkedList<CachedClass> superInterfaces = new LinkedList<CachedClass>(interfaces);
// ambiguous fields (class implementing two interfaces using the same field)
if (superInterfaces.size() > 1) {
Collections.sort(superInterfaces, CACHED_CLASS_NAME_COMPARATOR);
}
SingleKeyHashMap iPropertyIndex = classPropertyIndex.getNotNull(theCachedClass);
for (CachedClass iclass : superInterfaces) {
SingleKeyHashMap sPropertyIndex = classPropertyIndex.getNotNull(iclass);
copyNonPrivateFields(sPropertyIndex, iPropertyIndex);
addFields(iclass, iPropertyIndex);
}
addFields(theCachedClass, iPropertyIndex);
applyPropertyDescriptors(propertyDescriptors);
applyStrayPropertyMethods(superClasses, classPropertyIndex, true);
makeStaticPropertyIndex();
} else {
LinkedList<CachedClass> superClasses = getSuperClasses();
LinkedList<CachedClass> interfaces = new LinkedList<CachedClass>(theCachedClass.getInterfaces());
// ambiguous fields (class implementing two interfaces using the same field)
if (interfaces.size() > 1) {
Collections.sort(interfaces, CACHED_CLASS_NAME_COMPARATOR);
}
// if this an Array, then add the special read-only "length" property
if (theCachedClass.isArray) {
SingleKeyHashMap map = new SingleKeyHashMap();
map.put("length", arrayLengthProperty);
classPropertyIndex.put(theCachedClass, map);
}
inheritStaticInterfaceFields(superClasses, new LinkedHashSet(interfaces));
inheritFields(superClasses);
applyPropertyDescriptors(propertyDescriptors);
applyStrayPropertyMethods(superClasses, classPropertyIndex, true);
applyStrayPropertyMethods(superClasses, classPropertyIndexForSuper, false);
copyClassPropertyIndexForSuper(classPropertyIndexForSuper);
makeStaticPropertyIndex();
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method connectMultimethods.
private void connectMultimethods(List<CachedClass> superClasses, CachedClass firstGroovyClass) {
superClasses = DefaultGroovyMethods.reverse(superClasses);
MetaMethodIndex.Header last = null;
for (final CachedClass c : superClasses) {
MetaMethodIndex.Header methodIndex = metaMethodIndex.getHeader(c.getTheClass());
// It saves us a lot of space and some noticeable time
if (last != null)
metaMethodIndex.copyNonPrivateNonNewMetaMethods(last, methodIndex);
last = methodIndex;
if (c == firstGroovyClass)
break;
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
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