Search in sources :

Example 1 with ClassMemberValue

use of javassist.bytecode.annotation.ClassMemberValue 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);
}
Also used : 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

GwtTestPatchException (com.googlecode.gwt.test.exceptions.GwtTestPatchException)1 ClassVisitor (com.googlecode.gwt.test.internal.ClassesScanner.ClassVisitor)1 PatchClass (com.googlecode.gwt.test.patchers.PatchClass)1 CtClass (javassist.CtClass)1 Annotation (javassist.bytecode.annotation.Annotation)1 ClassMemberValue (javassist.bytecode.annotation.ClassMemberValue)1 StringMemberValue (javassist.bytecode.annotation.StringMemberValue)1