javassist
javassist copied to clipboard
Annotation processing while creating a new class using javassist
I have been trying to use javassist to create some classes dynamically and I want to add some annotations to them, which is supposed to create separate helper classes when compiling the annotated class. I was able to create the new class with annotations with javassist and I was able to save it as a file, but the issue is that the annotation is not processed and the helper classes are not created. I tried decompiling the class generated by javassist and recompiling the same java file using intellij and it seems to generate the helper classes properly.
It would be great if someone can confirm if javassist does support annotation processing while doing compilation and if there is a workaround for doing this for a class created using javassist.
Suggest give some examples or unit tests. And your environment, javassist version.
CtField field = new CtField(classPool.get(typeClazz.getName()), productField.getKey(),
productSpuClass);
field.setModifiers(AccessFlag.PUBLIC);
ConstPool constPool = field.getFieldInfo().getConstPool();
List<Annotation> list = createAnnotations(field, productSpuClass, productField);
AnnotationsAttribute fieldAttr =
new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
fieldAttr.setAnnotations(list.toArray(new Annotation[list.size()]));
field.getFieldInfo().addAttribute(fieldAttr);
Annotation can be successfully created on the window platform, but Annotation cannot be created successfully on linux docker