use of javassist.bytecode.AnnotationsAttribute in project powermock by powermock.
the class TestClassTransformer method removeTestMethodAnnotationFrom.
private void removeTestMethodAnnotationFrom(CtMethod m) throws ClassNotFoundException {
final AnnotationsAttribute attr = (AnnotationsAttribute) m.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation[] newAnnotations = new javassist.bytecode.annotation.Annotation[attr.numAnnotations() - 1];
int i = -1;
for (javassist.bytecode.annotation.Annotation a : attr.getAnnotations()) {
if (a.getTypeName().equals(testMethodAnnotationType.getName())) {
continue;
}
newAnnotations[++i] = a;
}
attr.setAnnotations(newAnnotations);
}
use of javassist.bytecode.AnnotationsAttribute in project play-cookbook by spinscale.
the class XmlEnhancer method enhanceThisClass.
@Override
public void enhanceThisClass(ApplicationClass applicationClass) throws Exception {
CtClass ctClass = makeClass(applicationClass);
if (!ctClass.subtypeOf(classPool.get("play.db.jpa.JPABase"))) {
return;
}
if (!hasAnnotation(ctClass, "javax.persistence.Entity")) {
return;
}
ConstPool constpool = ctClass.getClassFile().getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
if (!hasAnnotation(ctClass, "javax.xml.bind.annotation.XmlAccessorType")) {
Annotation annot = new Annotation("javax.xml.bind.annotation.XmlAccessorType", constpool);
EnumMemberValue enumValue = new EnumMemberValue(constpool);
enumValue.setType("javax.xml.bind.annotation.XmlAccessType");
enumValue.setValue("FIELD");
annot.addMemberValue("value", enumValue);
attr.addAnnotation(annot);
ctClass.getClassFile().addAttribute(attr);
}
if (!hasAnnotation(ctClass, "javax.xml.bind.annotation.XmlRootElement")) {
Annotation annot = new Annotation("javax.xml.bind.annotation.XmlRootElement", constpool);
String entityName = ctClass.getName();
String entity = entityName.substring(entityName.lastIndexOf('.') + 1).toLowerCase();
annot.addMemberValue("name", new StringMemberValue(entity, constpool));
attr.addAnnotation(annot);
ctClass.getClassFile().addAttribute(attr);
}
applicationClass.enhancedByteCode = ctClass.toBytecode();
ctClass.defrost();
}
use of javassist.bytecode.AnnotationsAttribute in project gwt-test-utils by gwt-test-utils.
the class JavassistUtils method getInvisibleAnnotationStringValue.
/**
* 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;
}
use of javassist.bytecode.AnnotationsAttribute in project gwt-test-utils by gwt-test-utils.
the class JavassistUtils method getInvisibleAnnotationStringValue.
/**
* 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;
}
use of javassist.bytecode.AnnotationsAttribute in project hibernate-orm by hibernate.
the class ClassFileArchiveEntryHandler method toClassDescriptor.
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) {
ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;
;
final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag);
if (visibleAnnotations != null) {
if (visibleAnnotations.getAnnotation(Entity.class.getName()) != null || visibleAnnotations.getAnnotation(MappedSuperclass.class.getName()) != null || visibleAnnotations.getAnnotation(Embeddable.class.getName()) != null) {
categorization = ClassDescriptor.Categorization.MODEL;
} else if (visibleAnnotations.getAnnotation(Converter.class.getName()) != null) {
categorization = ClassDescriptor.Categorization.CONVERTER;
}
}
return new ClassDescriptorImpl(classFile.getName(), categorization, entry.getStreamAccess());
}
Aggregations