use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class CallSiteGenerator method compilePojoMethod.
public static Constructor compilePojoMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genPojoMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class CallSiteGenerator method compileStaticMethod.
public static Constructor compileStaticMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genStaticMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method addNewInstanceMethod.
/**
*Adds an instance method to this metaclass.
*
* @param method The method to be added
*/
public void addNewInstanceMethod(Method method) {
final CachedMethod cachedMethod = CachedMethod.find(method);
NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
final CachedClass declaringClass = newMethod.getDeclaringClass();
addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
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 by apache.
the class MetaClassImpl method calcFirstGroovySuperClass.
private CachedClass calcFirstGroovySuperClass(Collection superClasses) {
if (theCachedClass.isInterface)
return ReflectionCache.OBJECT_CLASS;
CachedClass firstGroovy = null;
Iterator iter = superClasses.iterator();
for (; iter.hasNext(); ) {
CachedClass c = (CachedClass) iter.next();
if (GroovyObject.class.isAssignableFrom(c.getTheClass())) {
firstGroovy = c;
break;
}
}
if (firstGroovy == null)
firstGroovy = theCachedClass;
else {
if (firstGroovy.getTheClass() == GroovyObjectSupport.class && iter.hasNext()) {
firstGroovy = (CachedClass) iter.next();
if (firstGroovy.getTheClass() == Closure.class && iter.hasNext()) {
firstGroovy = (CachedClass) iter.next();
}
}
}
return GroovyObject.class.isAssignableFrom(firstGroovy.getTheClass()) ? firstGroovy.getCachedSuperClass() : firstGroovy;
}
Aggregations