Search in sources :

Example 26 with Annotation

use of javassist.bytecode.annotation.Annotation 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<>();
    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<>();
                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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) StringMemberValue(javassist.bytecode.annotation.StringMemberValue) ClassVisitor(com.googlecode.gwt.test.internal.ClassesScanner.ClassVisitor) Annotation(javassist.bytecode.annotation.Annotation) ClassMemberValue(javassist.bytecode.annotation.ClassMemberValue) GwtTestPatchException(com.googlecode.gwt.test.exceptions.GwtTestPatchException) CtClass(javassist.CtClass) PatchClass(com.googlecode.gwt.test.patchers.PatchClass)

Aggregations

Annotation (javassist.bytecode.annotation.Annotation)26 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)19 StringMemberValue (javassist.bytecode.annotation.StringMemberValue)12 ConstPool (javassist.bytecode.ConstPool)11 ClassFile (javassist.bytecode.ClassFile)9 ArrayList (java.util.ArrayList)7 CtClass (javassist.CtClass)7 ClassPool (javassist.ClassPool)6 CtMethod (javassist.CtMethod)5 AnnotationMemberValue (javassist.bytecode.annotation.AnnotationMemberValue)5 ArrayMemberValue (javassist.bytecode.annotation.ArrayMemberValue)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)4 MethodInfo (javassist.bytecode.MethodInfo)4 EnumMemberValue (javassist.bytecode.annotation.EnumMemberValue)4 MemberValue (javassist.bytecode.annotation.MemberValue)4 DataInputStream (java.io.DataInputStream)3 HashSet (java.util.HashSet)3 CtField (javassist.CtField)3 ClassMemberValue (javassist.bytecode.annotation.ClassMemberValue)3