Weaver() { try { _pool = ClassPool.getDefault(); _pool.insertClassPath(new ClassClassPath(Weaver.class)); _iced = _pool.get("water.Iced"); // Needs serialization _dtask= _pool.get("water.DTask");// Needs serialization and remote execution _enum = _pool.get("java.lang.Enum"); // Needs serialization _freezable = _pool.get("water.Freezable"); // Needs serialization // _apiSchema = _pool.get("water.api.rest.schemas.ApiSchema"); // _apiAdaptor = _pool.get("water.api.rest.ApiAdaptor"); // _apiHandler = _pool.get("water.api.rest.handlers.AbstractHandler"); //_versioned = _pool.get("water.api.rest.REST$Versioned"); _serBases = new CtClass[] { _iced, _dtask, _enum, _freezable }; for( CtClass c : _serBases ) c.freeze(); _fielddoc = _pool.get("water.api.DocGen$FieldDoc");// Is auto-documentation result _arg = _pool.get("water.api.RequestArguments$Argument"); // Needs auto-documentation } catch( NotFoundException e ) { throw new RuntimeException(e); } }
CtClass ycc = null; while( xcc.subtypeOf(_freezable) ) { ycc = xcc; xcc = xcc.getSuperclass(); } if( !ycc.isFrozen() ) ycc.freeze(); // Freeze the alternative base return cc == ycc ? cc : javassistLoadClass(cc); // And weave the subclass
private synchronized CtClass javassistLoadClass( CtClass cc ) throws NotFoundException, CannotCompileException, BadBytecode { if( cc.isFrozen() ) return cc; // serialize parent javassistLoadClass(cc.getSuperclass()); // Serialize enums first, since we need the raw_enum function for this class for( CtField ctf : cc.getDeclaredFields() ) { CtClass base = ctf.getType(); while( base.isArray() ) base = base.getComponentType(); if( base.subclassOf(_enum) && base != cc ) javassistLoadClass(base); } CtClass ccr = addSerializationMethods(cc); ccr.freeze(); return ccr; }
@SuppressWarnings("unchecked") private Class<? extends NativeStruct> generate(final String className, final Class<?> definitionClass, final Struct struct) throws NotFoundException, CannotCompileException { CtClass definition = classes.get(definitionClass.getName()); definition.freeze(); CtClass nativeStruct = classes.get(NativeStruct.class.getName()); nativeStruct.freeze(); CtClass generated = classes.makeClass(className, nativeStruct); generated.addInterface(definition); long offset = 0; for(Field field : struct.value()) { generateFieldAccessors(generated, struct, field, offset, definition); offset += byteLength(struct, field); } generateGetSize(generated, struct, offset); return generated.toClass(definitionClass.getClassLoader(), definitionClass.getProtectionDomain()); }
classRef.freeze();
classRef.freeze();
proxyclazz.getClassFile().addAttribute(attr); ret = proxyclazz.toClass(classloader, type.getProtectionDomain()); proxyclazz.freeze();
/** * Retrieve the String value of an annotation which is not available at runtime. * * @param method The annotated method * @param annotation The annotation which is not visible at runtime * @param name The name of the String property of the annotation to retrieve * @return The String value of the annotation or null if the annotation or its property is not * present */ public static String getInvisibleAnnotationStringValue(Method method, Class<? extends Annotation> annotation, String name) { CtClass ctClass = GwtClassPool.getCtClass(method.getDeclaringClass()); ctClass.defrost(); AnnotationsAttribute attr = (AnnotationsAttribute) ctClass.getClassFile().getMethod( method.getName()).getAttribute(AnnotationsAttribute.visibleTag); if (attr == null) { attr = (AnnotationsAttribute) ctClass.getClassFile().getMethod(method.getName()).getAttribute( AnnotationsAttribute.invisibleTag); } if (attr == null) { return null; } javassist.bytecode.annotation.Annotation an = attr.getAnnotation(annotation.getName()); ctClass.freeze(); return an != null ? ((StringMemberValue) an.getMemberValue(name)).getValue() : null; }
/** * Retrieve the String value of an annotation which is not available at runtime. * * @param method The annotated method * @param annotation The annotation which is not visible at runtime * @param name The name of the String property of the annotation to retrieve * @return The String value of the annotation or null if the annotation or its property is not * present */ public static String getInvisibleAnnotationStringValue(Method method, Class<? extends Annotation> annotation, String name) { CtClass ctClass = GwtClassPool.getCtClass(method.getDeclaringClass()); ctClass.defrost(); AnnotationsAttribute attr = (AnnotationsAttribute) ctClass.getClassFile().getMethod( method.getName()).getAttribute(AnnotationsAttribute.visibleTag); if (attr == null) { attr = (AnnotationsAttribute) ctClass.getClassFile().getMethod(method.getName()).getAttribute( AnnotationsAttribute.invisibleTag); } if (attr == null) { return null; } javassist.bytecode.annotation.Annotation an = attr.getAnnotation(annotation.getName()); ctClass.freeze(); return an != null ? ((StringMemberValue) an.getMemberValue(name)).getValue() : null; }
/** * Retrieve the String value of an annotation which is not available at runtime. * * @param clazz The annotated class * @param annotation The annotation which is not visible at runtime * @param name The name of the String property of the annotation to retrieve * @return The String value of the annotation or null if the annotation or its property is not * present */ public static String getInvisibleAnnotationStringValue(Class<?> clazz, Class<? extends Annotation> annotation, String name) { CtClass ctClass = GwtClassPool.getCtClass(clazz); ctClass.defrost(); AnnotationsAttribute attr = (AnnotationsAttribute) ctClass.getClassFile().getAttribute( AnnotationsAttribute.visibleTag); if (attr == null) { attr = (AnnotationsAttribute) ctClass.getClassFile().getAttribute( AnnotationsAttribute.invisibleTag); } if (attr == null) { return null; } javassist.bytecode.annotation.Annotation an = attr.getAnnotation(annotation.getName()); ctClass.freeze(); return an != null ? ((StringMemberValue) an.getMemberValue(name)).getValue() : null; }
/** * Retrieve the String value of an annotation which is not available at runtime. * * @param clazz The annotated class * @param annotation The annotation which is not visible at runtime * @param name The name of the String property of the annotation to retrieve * @return The String value of the annotation or null if the annotation or its property is not * present */ public static String getInvisibleAnnotationStringValue(Class<?> clazz, Class<? extends Annotation> annotation, String name) { CtClass ctClass = GwtClassPool.getCtClass(clazz); ctClass.defrost(); AnnotationsAttribute attr = (AnnotationsAttribute) ctClass.getClassFile().getAttribute( AnnotationsAttribute.visibleTag); if (attr == null) { attr = (AnnotationsAttribute) ctClass.getClassFile().getAttribute( AnnotationsAttribute.invisibleTag); } if (attr == null) { return null; } javassist.bytecode.annotation.Annotation an = attr.getAnnotation(annotation.getName()); ctClass.freeze(); return an != null ? ((StringMemberValue) an.getMemberValue(name)).getValue() : null; }
proxyclazz.freeze();