return generatedPkgName + "." + generatedClassName;
}
public void generateMethod(SourceWriter sw, JMethod method, TreeLogger logger)
throws UnableToCompleteException {
Selector selectorAnnotation = method.getAnnotation(Selector.class);
if (selectorAnnotation == null) {
return;
}
JParameter[] params = method.getParameters();
String retType = method.getReturnType()
.getParameterizedQualifiedSourceName();
sw.print("public final " + retType + " " + method.getName());
boolean hasContext = false;
if (params.length == 0) {
sw.print("()");
} else if (params.length == 1) {
JClassType type = params[0].getType().isClassOrInterface();
if (type != null && type.isAssignableTo(nodeType)) {
sw.print("(Node root)");
hasContext = true;
}
}
sw.println(" {");
sw.indent();
Selector sel = method.getAnnotation(Selector.class);
if (sel != null && sel.value().matches("^#\\w+$")) {
// short circuit #foo
sw.println("return "
+ wrap(method, "JsNodeArray.create(((Document)root).getElementById(\""
+ sel.value().substring(1) + "\"))") + ";");
} else if (sel != null && sel.value().matches("^\\w+$")) {
// short circuit FOO
sw.println("return "
+ wrap(method,
"JsNodeArray.create(((Element)root).getElementsByTagName(\""
+ sel.value() + "\"))") + ";");
} else if (sel != null && sel.value().matches("^\\.\\w+$")
&& hasGetElementsByClassName()) {
// short circuit .foo for browsers with native getElementsByClassName
sw.println("return "
+ wrap(method, "JsNodeArray.create(getElementsByClassName(\""
+ sel.value().substring(1) + "\", root))") + ";");
} else {
generateMethodBody(sw, method, logger, hasContext);
}
sw.outdent();
sw.println("}");