@Override public String finish() { String template = readResource("web/ast.html"); String cssContent = readResource("web/ast.css"); String scriptContent = readResource("web/ast.js"); String jQuery = readResource("web/jquery.js"); return template .replace("{{@title}}", "AST nodes") .replace("{{@file}}", "source file name goes here") .replace("{{@jQuery}}", jQuery) .replace("{{@script}}", scriptContent) .replace("{{@css}}", cssContent) .replace("{{@body}}", sb.toString()) .replace("{{@errors}}", printErrors()) .replace("{{@rawSource}}", escapeHtml(rawSource)) .replace("{{@timeTaken}}", "" + timeTaken); }
@Override public void buildBlock(Node node) { generateOpenTag(node, "div"); }
@Override public void addError(int errorStart, int errorEnd, String errorMessage) { errors.add(String.format("<div class=\"parseError\">%s</div>", escapeHtml(errorMessage))); }
private void generateOpenTag(Node node, String tagName) { Set<String> classes = Sets.newHashSet(); AtomicReference<String> kind = new AtomicReference<String>(); findHtmlClassSignificantNodes(classes, kind, node == null ? null : node.getClass()); String description = node instanceof DescribedNode ? ((DescribedNode)node).getDescription() : null; sb.append("<").append(tagName); if (!classes.isEmpty()) { sb.append(" class=\""); Joiner.on(' ').appendTo(sb, classes); sb.append("\""); } if (nextElementName != null) { sb.append(" relation=\"").append(escapeHtml(nextElementName)).append("\""); nextElementName = null; } if (kind.get() != null) { sb.append(" kind=\"").append(escapeHtml(kind.get())).append("\""); } if (description != null) { sb.append(" description=\"").append(escapeHtml(description)).append("\""); } sb.append(">"); }
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new HtmlFormatter(source.getRawInput()); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
private static void findHtmlClassSignificantNodes(Set<String> names, AtomicReference<String> kind, Class<?> c) { if (c == null) return; if (java.lang.reflect.Modifier.isPublic(c.getModifiers())) { Matcher m = HTML_CLASS_SIGNIFICANT_NODE.matcher(c.getName()); if (m.matches()) { names.add(c.getSimpleName()); if (kind.get() == null) kind.set(c.getSimpleName()); } } findHtmlClassSignificantNodes(names, kind, c.getSuperclass()); for (Class<?> i : c.getInterfaces()) findHtmlClassSignificantNodes(names, kind, i); }
@Override public void addError(int errorStart, int errorEnd, String errorMessage) { errors.add(String.format("<div class=\"parseError\">%s</div>", escapeHtml(errorMessage))); }
private void generateOpenTag(Node node, String tagName) { Set<String> classes = Sets.newHashSet(); AtomicReference<String> kind = new AtomicReference<String>(); findHtmlClassSignificantNodes(classes, kind, node == null ? null : node.getClass()); String description = node instanceof DescribedNode ? ((DescribedNode)node).getDescription() : null; sb.append("<").append(tagName); if (!classes.isEmpty()) { sb.append(" class=\""); Joiner.on(' ').appendTo(sb, classes); sb.append("\""); } if (nextElementName != null) { sb.append(" relation=\"").append(escapeHtml(nextElementName)).append("\""); nextElementName = null; } if (kind.get() != null) { sb.append(" kind=\"").append(escapeHtml(kind.get())).append("\""); } if (description != null) { sb.append(" description=\"").append(escapeHtml(description)).append("\""); } sb.append(">"); }
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new HtmlFormatter(source.getRawInput()); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
private static void findHtmlClassSignificantNodes(Set<String> names, AtomicReference<String> kind, Class<?> c) { if (c == null) return; if (java.lang.reflect.Modifier.isPublic(c.getModifiers())) { Matcher m = HTML_CLASS_SIGNIFICANT_NODE.matcher(c.getName()); if (m.matches()) { names.add(c.getSimpleName()); if (kind.get() == null) kind.set(c.getSimpleName()); } } findHtmlClassSignificantNodes(names, kind, c.getSuperclass()); for (Class<?> i : c.getInterfaces()) findHtmlClassSignificantNodes(names, kind, i); }
@Override public String finish() { String template = readResource("web/ast.html"); String cssContent = readResource("web/ast.css"); String scriptContent = readResource("web/ast.js"); String jQuery = readResource("web/jquery.js"); return template .replace("{{@title}}", "AST nodes") .replace("{{@file}}", "source file name goes here") .replace("{{@jQuery}}", jQuery) .replace("{{@script}}", scriptContent) .replace("{{@css}}", cssContent) .replace("{{@body}}", sb.toString()) .replace("{{@errors}}", printErrors()) .replace("{{@rawSource}}", escapeHtml(rawSource)) .replace("{{@timeTaken}}", "" + timeTaken); }
@Override public void operator(String text) { sb.append("<span class=\"operator\">").append(escapeHtml(text)).append("</span>"); }
private void generateOpenTag(Node node, String tagName) { Set<String> classes = Sets.newHashSet(); AtomicReference<String> kind = new AtomicReference<String>(); findHtmlClassSignificantNodes(classes, kind, node == null ? null : node.getClass()); String description = node instanceof DescribedNode ? ((DescribedNode)node).getDescription() : null; sb.append("<").append(tagName); if (!classes.isEmpty()) { sb.append(" class=\""); Joiner.on(' ').appendTo(sb, classes); sb.append("\""); } if (nextElementName != null) { sb.append(" relation=\"").append(escapeHtml(nextElementName)).append("\""); nextElementName = null; } if (kind.get() != null) { sb.append(" kind=\"").append(escapeHtml(kind.get())).append("\""); } if (description != null) { sb.append(" description=\"").append(escapeHtml(description)).append("\""); } sb.append(">"); }
@Override public void buildInline(Node node) { generateOpenTag(node, "span"); }
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new HtmlFormatter(source.getRawInput()); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
private static void findHtmlClassSignificantNodes(Set<String> names, AtomicReference<String> kind, Class<?> c) { if (c == null) return; if (java.lang.reflect.Modifier.isPublic(c.getModifiers())) { Matcher m = HTML_CLASS_SIGNIFICANT_NODE.matcher(c.getName()); if (m.matches()) { names.add(c.getSimpleName()); if (kind.get() == null) kind.set(c.getSimpleName()); } } findHtmlClassSignificantNodes(names, kind, c.getSuperclass()); for (Class<?> i : c.getInterfaces()) findHtmlClassSignificantNodes(names, kind, i); }
@Override public String finish() { String template = readResource("web/ast.html"); String cssContent = readResource("web/ast.css"); String scriptContent = readResource("web/ast.js"); String jQuery = readResource("web/jquery.js"); return template .replace("{{@title}}", "AST nodes") .replace("{{@file}}", "source file name goes here") .replace("{{@jQuery}}", jQuery) .replace("{{@script}}", scriptContent) .replace("{{@css}}", cssContent) .replace("{{@body}}", sb.toString()) .replace("{{@errors}}", printErrors()) .replace("{{@rawSource}}", escapeHtml(rawSource)) .replace("{{@timeTaken}}", "" + timeTaken); }
@Override public void addError(int errorStart, int errorEnd, String errorMessage) { errors.add(String.format("<div class=\"parseError\">%s</div>", escapeHtml(errorMessage))); }
@Override public void buildBlock(Node node) { generateOpenTag(node, "div"); }
@Override public void keyword(String text) { sb.append("<span class=\"keyword\">").append(escapeHtml(text)).append("</span>"); }