use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class GwtTranslator method applyJavaClassModifiers.
private void applyJavaClassModifiers(CtClass ctClass) {
try {
// Apply internal modifiers
serializableModifier.modify(ctClass);
hasHTMLModifier.modify(ctClass);
hasNameModifier.modify(ctClass);
classVisibilityModifier.modify(ctClass);
} catch (Exception e) {
if (GwtTestException.class.isInstance(e)) {
throw (GwtTestException) e;
}
throw new GwtTestPatchException(e);
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getOverrideMethod.
private <T extends Annotation> CtMethod getOverrideMethod(List<CtMethod> methods, Class<T> annotationClass) {
CtMethod overrideInitMethod = null;
for (CtMethod method : methods) {
T annotation = getMethodAnnotation(method, annotationClass);
if (isOverride(annotation)) {
if (overrideInitMethod != null) {
throw new GwtTestPatchException("There are more than one @" + annotationClass.getSimpleName() + " with 'override=true' for the same target : '" + method.getLongName() + "' and '" + overrideInitMethod.getLongName() + "'");
} else {
overrideInitMethod = method;
}
}
}
if (overrideInitMethod == null) {
StringBuilder sb = new StringBuilder();
sb.append(methods.size()).append(" @");
sb.append(annotationClass.getSimpleName());
sb.append(" methods detected for the same target, but no one is set to override the other. You must use 'override=true' on the one which should be applied : ");
for (CtMethod method : methods) {
sb.append("'").append(method.getLongName()).append("'");
sb.append(" or ");
}
throw new GwtTestPatchException(sb.substring(0, sb.length() - 4));
}
return overrideInitMethod;
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getPatchMethods.
private Set<CtMethod> getPatchMethods(Set<CtClass> patchClasses) {
Set<CtMethod> result = new HashSet<CtMethod>();
// add all @PatchMethod found in a temporary map
Map<String, List<CtMethod>> temp = new HashMap<String, List<CtMethod>>();
for (CtClass patchClass : patchClasses) {
for (CtMethod ctMethod : patchClass.getDeclaredMethods()) {
if (ctMethod.hasAnnotation(PatchMethod.class)) {
if (!Modifier.isStatic(ctMethod.getModifiers())) {
throw new GwtTestPatchException("@" + PatchMethod.class.getName() + " has to be static : '" + ctMethod.getLongName() + "'");
}
String nameAndSignature = ctMethod.getName() + Descriptor.toString(ctMethod.getSignature());
List<CtMethod> correspondingMethods = temp.get(nameAndSignature);
if (correspondingMethods == null) {
correspondingMethods = new ArrayList<CtMethod>();
temp.put(nameAndSignature, correspondingMethods);
}
correspondingMethods.add(ctMethod);
}
}
}
// override=true
for (Map.Entry<String, List<CtMethod>> entry : temp.entrySet()) {
CtMethod methodToUse = getMethodToUse(entry.getValue(), PatchMethod.class);
methodToUse.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
result.add(methodToUse);
}
return result;
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class ClassesScanner method scanPackages.
public void scanPackages(ClassVisitor classVisitor, Set<String> rootPackages) {
for (String rootPackage : rootPackages) {
String path = rootPackage.replaceAll("\\.", "/");
logger.debug("Scan package " + rootPackage);
if (rootPackage.endsWith(".")) {
rootPackage = rootPackage.substring(0, rootPackage.length() - 1);
}
try {
Enumeration<URL> l = Thread.currentThread().getContextClassLoader().getResources(path);
while (l.hasMoreElements()) {
URL url = l.nextElement();
String u = url.toExternalForm();
if (u.startsWith("file:")) {
String directoryName = u.substring("file:".length());
directoryName = URLDecoder.decode(directoryName, "UTF-8");
scanClassesFromDirectory(new File(directoryName), rootPackage, classVisitor);
} else if (u.startsWith("jar:file:")) {
scanClassesFromJarFile(u.substring("jar:file:".length()), path, classVisitor);
} else {
throw new IllegalArgumentException("Not managed class container " + u);
}
}
} catch (Exception e) {
throw new GwtTestPatchException("Error while scanning package '" + rootPackage + "'", e);
}
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class GwtClassLoader method findClass.
@Override
protected Class<?> findClass(String className) throws ClassNotFoundException {
byte[] classfile = findClassBytes(className);
int i = className.lastIndexOf('.');
if (i != -1) {
String pname = className.substring(0, i);
if (getPackage(pname) == null) {
try {
definePackage(pname, null, null, null, null, null, null, null);
} catch (IllegalArgumentException e) {
// ignore. maybe the package object for the same
// name has been created just right away.
}
}
}
try {
if (domain == null) {
return defineClass(className, classfile, 0, classfile.length);
} else {
return defineClass(className, classfile, 0, classfile.length, domain);
}
} catch (Throwable t) {
throw new GwtTestPatchException("Error while defining " + className + " from modified bytecode", t);
}
}
Aggregations