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);
}
Aggregations