use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getInitMethod.
private CtMethod getInitMethod(Set<CtClass> patchClasses) {
List<CtMethod> initMethods = new ArrayList<CtMethod>();
for (CtClass patchClass : patchClasses) {
for (CtMethod ctMethod : patchClass.getDeclaredMethods()) {
if (ctMethod.hasAnnotation(InitMethod.class)) {
if (!Modifier.isStatic(ctMethod.getModifiers())) {
throw new GwtTestPatchException("@" + InitMethod.class.getSimpleName() + " has to be static : '" + ctMethod.getLongName() + "'");
}
try {
if (ctMethod.getParameterTypes().length != 1 || ctMethod.getParameterTypes()[0] != GwtClassPool.getCtClass(CtClass.class)) {
throw new GwtTestPatchException("@" + InitMethod.class.getName() + " method must have one and only one parameter of type '" + CtClass.class.getName() + "'");
}
} catch (NotFoundException e) {
// should never happen
throw new GwtTestPatchException(e);
}
initMethods.add(ctMethod);
}
}
}
CtMethod initMethod = getMethodToUse(initMethods, InitMethod.class);
if (initMethod != null) {
initMethod.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
}
return initMethod;
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException 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 com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class GwtHtmlParser method parseInternal.
private NodeList<Node> parseInternal(String html) {
if (html == null || html.trim().length() == 0) {
return JsoUtils.newNodeList(Collections.<Node>emptyList());
}
try {
XMLReader xmlReader = getXMLReader();
GwtHtmlContentHandler contentHandler = new GwtHtmlContentHandler();
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(new InputSource(new StringReader(html)));
return contentHandler.getParsedNodes();
} catch (Exception e) {
throw new GwtTestPatchException("Error while parsing HTML '" + html + "'", e);
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestPatchException in project gwt-test-utils by gwt-test-utils.
the class SafeHtmlUtilsPatcher method fromSafeConstant.
@PatchMethod
public static SafeHtml fromSafeConstant(String s) {
// PatchMethod to avoid gwt-dev dependency.. See SafeHtmlHostedModeUtils
Class<?> clazz;
try {
clazz = Class.forName("com.google.gwt.safehtml.shared.SafeHtmlString");
Constructor<?> cons = clazz.getDeclaredConstructor(String.class);
return (SafeHtml) GwtReflectionUtils.instantiateClass(cons, s);
} catch (Exception e) {
throw new GwtTestPatchException("Error while instanciate a SafeHtmlString instance", e);
}
}
Aggregations