use of com.googlecode.gwt.test.patchers.PatchMethod in project gwt-test-utils by gwt-test-utils.
the class GwtDotCreateProviderPatcher method bind.
@PatchMethod
static <T> ScopedBindingBuilder bind(LinkedBindingBuilder<T> builder) {
if (!(builder instanceof AbstractBindingBuilder)) {
throw new GwtTestGinException("Not managed " + LinkedBindingBuilder.class.getSimpleName() + " implementation : " + builder.getClass().getName());
}
Binding<T> binding = GwtReflectionUtils.<Binding<T>>getPrivateFieldValue(builder, "binding");
Type type = binding.getKey().getTypeLiteral().getType();
if (!(type instanceof Class)) {
throw new GwtTestGinException("Not managed binded type : " + type);
}
Constructor<T> atInjectConstructor = getAtInjectConstructor((Class<T>) type);
if (atInjectConstructor != null) {
return builder.toConstructor(atInjectConstructor);
}
GwtDotCreateProvider<T> gwtDotCreateProvider = GwtReflectionUtils.instantiateClass(GwtDotCreateProvider.class);
GwtReflectionUtils.setPrivateFieldValue(gwtDotCreateProvider, BINDED_CLASS_FIELD, type);
return builder.toProvider(gwtDotCreateProvider);
}
use of com.googlecode.gwt.test.patchers.PatchMethod in project gwt-test-utils by gwt-test-utils.
the class HTMLTablePatcher method getEventTargetCell.
@PatchMethod
static Element getEventTargetCell(HTMLTable table, Event event) {
Object bodyElem = GwtReflectionUtils.getPrivateFieldValue(table, "bodyElem");
Element td = DOM.eventGetTarget(event);
for (; td != null; td = DOM.getParent(td)) {
// If it's a TD, it might be the one we're looking for.
if (DOM.getElementProperty(td, "tagName").equalsIgnoreCase("td")) {
// Make sure it's directly a part of this table before returning
// it.
Element tr = DOM.getParent(td);
Object body = DOM.getParent(tr);
if (body == bodyElem) {
return td;
}
}
// If we run into this table's body, we're out of options.
if (td == bodyElem) {
return null;
}
}
return null;
}
use of com.googlecode.gwt.test.patchers.PatchMethod in project gwt-test-utils by gwt-test-utils.
the class JSONParserPatcher method evaluate.
@PatchMethod
static JSONValue evaluate(String json, boolean strict) {
JsonParser jp = null;
try {
JsonFactory f = new JsonFactory();
if (!strict) {
f.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
f.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
f.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
f.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true);
}
jp = f.createJsonParser(json);
// will return JsonToken.START_OBJECT (verify?)
jp.nextToken();
JSONObject jsonObject = extractJSONObject(json, jp);
return jsonObject;
} catch (Exception e) {
if (e instanceof GwtTestException) {
throw (GwtTestException) e;
}
throw new GwtTestJSONException("Error while parsing JSON string '" + json + "'", e);
} finally {
if (jp != null) {
try {
// ensure resources get cleaned up timely and properly
jp.close();
} catch (IOException e) {
// should never happen
}
}
}
}
use of com.googlecode.gwt.test.patchers.PatchMethod in project gwt-test-utils by gwt-test-utils.
the class FramePatcher method setUrl.
@PatchMethod
static void setUrl(Frame frame, String url) {
IFrameElement e = frame.getElement().cast();
e.setSrc(url);
}
use of com.googlecode.gwt.test.patchers.PatchMethod 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;
}
Aggregations