*/
package com.google.gwt.query.client.builders;
-import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
- * A tag interface that is used in the generation of jsni bundles.
- *
+ * A tag interface that is used in the generation of jsni bundles.
+ *
* A jsni-bundle is a class with jsni methods whose content is taken from
* external handwritten javascript files.
- *
+ *
* The goals of using this technique are:
* - Use pure javascript files so as we can use IDEs for editing, formating etc,
* instead of dealing with code in comment blocks.
* </pre>
*/
public interface JsniBundle {
-
+
/**
* Annotation to mark inclusion of third-party libraries.
- *
+ *
* The content is wrapped with an inner javascript function to set
* the context to the document window instead of the iframe where GWT
- * code is run.
+ * code is run.
*/
@Target({METHOD})
@Retention(RetentionPolicy.RUNTIME)
* Fragment of code to include after the external javascript has been
* written.
*/
- String postpend() default "\n}.apply($wnd, [$wnd, $doc, $wnd.console]));";
+ String postpend() default "\n}.apply($wnd, [$wnd, $doc, $wnd.console]));";
+
+ /**
+ * Regular expression to run over the javascript code to import.
+ *
+ * You should add pairs of values with the same syntax than String.replaceAll.
+ */
+ String[] replace() default {};
}
-
+
/**
* Annotation to mark inclusion of jsni code writen in external js files.
- *
+ *
* The content is not wrapped by default, so the developer has the responsibility
* to return the suitable value and to handle correctly parameters.
*/
* Fragment of code to include after the external javascript has been
* written.
*/
- String postpend() default "";
+ String postpend() default "";
+
+ /**
+ * Regular expression to run over the javascript code to import.
+ *
+ * You should add pairs of values with the same syntax than String.replaceAll.
+ */
+ String[] replace() default {};
}
}
for (JMethod method : clazz.getMethods()) {
LibrarySource librarySource = method.getAnnotation(LibrarySource.class);
String value, prepend, postpend;
+ String replace[];
if (librarySource != null) {
value = librarySource.value();
prepend = librarySource.prepend();
postpend = librarySource.postpend();
+ replace = librarySource.replace();
} else {
MethodSource methodSource = method.getAnnotation(MethodSource.class);
if (methodSource != null) {
value = methodSource.value();
prepend = methodSource.prepend();
postpend = methodSource.postpend();
+ replace = methodSource.replace();
} else {
continue;
}
// breaking java syntax.
String jsni = parseJavascriptSource(content);
+ for (int i = 0; i < replace.length - 1; i += 2) {
+ jsni = jsni.replaceAll(replace[i], replace[i+1]);
+ }
+
pw.println(method.toString().replace("abstract", "native") + "/*-{");
pw.println(prepend);
pw.println(jsni);