protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); sw.println("return " + wrap(method, "impl.select(\"" + selector + "\", root)") + ";"); } }
@Override protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); if (selector.matches("#[\\w\\-]+")) { sw.println("return " + wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";"); } else if (selector.matches("\\.[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) { super.generateMethodBody(sw, method, treeLogger, hasContext); } else { sw.println("return " + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";"); } }
protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); String xselector = css2Xpath(selector); // Validate the generated xpath selector. try { validateXpath(xselector); } catch (XPathExpressionException e1) { System.err.println("Invalid XPath generated selector, please revise it: " + xselector); if (!selector.equals(xselector)) { System.err .println("If your css2 selector syntax is correct, open an issue in the gwtquery project. cssselector:" + selector + " xpath: " + xselector); } throw new UnableToCompleteException(); } sw.println("return " + wrap(method, "xpathEvaluate(\"" + xselector + "\", root)") + ";"); }
@Override protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); if (selector.matches("#[\\w\\-]+")) { sw.println("return " + wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";"); } else if (selector.matches("\\.[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) { super.generateMethodBody(sw, method, treeLogger, hasContext); } else { sw.println("return " + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";"); } }
@Override protected void generateMethodBody(SourceWriter sw, JMethod method, TreeLogger treeLogger, boolean hasContext) throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); if (selector.matches("#[\\w\\-]+")) { sw.println("return " + wrap(method, "veryQuickId(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.equals("*") || selector.matches("[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByTagName(\"" + selector + "\", root)") + ";"); } else if (selector.matches("\\.[\\w\\-]+")) { sw.println("return " + wrap(method, "elementsByClassName(\"" + selector.substring(1) + "\", root)") + ";"); } else if (selector.contains("!=")) { sw.println("return " + wrap(method, "querySelectorAll(\"" + selector.replaceAll("(\\[\\w+)!(=[^\\]]+\\])", ":not($1$2)") + "\", root)") + ";"); } else if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) { super.generateMethodBody(sw, method, treeLogger, hasContext); } else { sw.println("return " + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";"); } }
throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value(); String[] cssRules = selector.replaceAll("\\s*(,)\\s*", "$1").split(","); String currentRule;
Selector sel = method.getAnnotation(Selector.class); if (sel != null && sel.value().matches("^#\\w+$")) { + sel.value().substring(1) + "\"))") + ";"); } else if (sel != null && sel.value().matches("^\\w+$")) { + sel.value() + "\"))") + ";"); } else if (sel != null && sel.value().matches("^\\.\\w+$") && hasGetElementsByClassName()) { + sel.value().substring(1) + "\", root))") + ";"); } else { generateMethodBody(sw, method, logger, hasContext);
throws UnableToCompleteException { String selector = method.getAnnotation(Selector.class).value();
private void genGetAllMethod(SourceWriter sw, JMethod[] methods, TreeLogger treeLogger) { sw.println("public DeferredSelector[] getAllSelectors() {return ds;}"); sw.println("private final DeferredSelector[] ds = new DeferredSelector[] {"); sw.indent(); for (JMethod m : methods) { Selector selectorAnnotation = m.getAnnotation(Selector.class); if (selectorAnnotation == null) { continue; } String selector = selectorAnnotation.value(); sw.println("new DeferredSelector() {"); sw.indent(); sw .println("public String getSelector() { return \"" + selector + "\"; }"); sw .println("public NodeList<Element> runSelector(Node ctx) { return " + (m.getName() + (m.getParameters().length == 0 ? "()" : "(ctx)")) + ("NodeList".equals(m.getReturnType().getSimpleSourceName()) ? "" : ".get()") + ";}" ); sw.outdent(); sw.println("},"); } sw.outdent(); sw.println("};"); } }