use of javassist.bytecode.annotation.StringMemberValue 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.annotation.StringMemberValue in project gwt-test-utils by gwt-test-utils.
the class ConfigurationLoader method visitPatchClasses.
private void visitPatchClasses() {
final Map<String, Set<CtClass>> patchClassMap = new HashMap<String, Set<CtClass>>();
ClassVisitor patchClassVisitor = new ClassVisitor() {
public void visit(CtClass ctClass) {
try {
if (ctClass.hasAnnotation(PatchClass.class)) {
Annotation annotation = JavassistUtils.getAnnotation(ctClass, PatchClass.class);
String classToPatchName = PatchClass.class.getName();
ClassMemberValue value = (ClassMemberValue) annotation.getMemberValue("value");
if (value != null) {
classToPatchName = value.getValue();
}
if (classToPatchName.equals(PatchClass.class.getName())) {
StringMemberValue target = (StringMemberValue) annotation.getMemberValue("target");
classToPatchName = (target != null) ? target.getValue() : "";
}
if (!"".equals(classToPatchName)) {
addPatchClass(classToPatchName, ctClass);
}
}
} catch (ClassNotFoundException e) {
// should never happen
throw new GwtTestPatchException(e);
}
}
private void addPatchClass(String targetName, CtClass patchClass) {
Set<CtClass> patchClasses = patchClassMap.get(targetName);
if (patchClasses == null) {
patchClasses = new HashSet<CtClass>();
patchClassMap.put(targetName, patchClasses);
}
patchClasses.add(patchClass);
LOGGER.debug("Add patch for class '" + targetName + "' : '" + patchClass.getName() + "'");
}
};
ClassesScanner.getInstance().scanPackages(patchClassVisitor, scanPackages);
// create all patchers
patcherFactory = new PatcherFactory(patchClassMap);
}
use of javassist.bytecode.annotation.StringMemberValue in project gwt-test-utils by gwt-test-utils.
the class RemoteServiceCreateHandler method getRemoveServiceRelativePath.
private String getRemoveServiceRelativePath(Class<?> clazz) {
CtClass ctClass = GwtClassPool.getCtClass((clazz));
Object[] annotations = ctClass.getAvailableAnnotations();
for (Object o : annotations) {
if (Proxy.isProxyClass(o.getClass())) {
AnnotationImpl annotation = (AnnotationImpl) Proxy.getInvocationHandler(o);
if (annotation.getTypeName().equals(RemoteServiceRelativePath.class.getName())) {
return ((StringMemberValue) annotation.getAnnotation().getMemberValue("value")).getValue();
}
}
}
throw new GwtTestRpcException("Cannot find the '@" + RemoteServiceRelativePath.class.getSimpleName() + "' annotation on RemoteService interface '" + clazz.getName() + "'");
}
Aggregations