private void parse() { String name = fEditor.getEditorInput().getName(); Reader reader = new StringReader(fEditor.getDocument().get()); Template template = null; try { parseHtml(); if (fEditor.getEditorInput() instanceof IFileEditorInput) ((IFileEditorInput) fEditor.getEditorInput()) .getFile() .deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); RuntimeInstance runtime = VelocityEditorEnvironment.getParser(); SimpleNode root = runtime.parse(reader, name); // Create tree model NodeVisitor visitor = new NodeVisitor(name); root.jjtAccept(visitor, null); template = visitor.getTemplate(); fError = ""; } catch (ParseException e) { if (!name.matches(".*?\\.jsp.*")) { if (e.getMessage() != null) { fError = e.getMessage(); Token token = e.currentToken; if (token != null) { fEditor.addProblemMarker(e.getMessage(), token.next.beginLine, IMarker.SEVERITY_ERROR); } } else { fError = ""; } } } catch (Exception e) { fError = ""; VelocityPlugin.log(e); } finally { try { reader.close(); } catch (IOException e) { VelocityPlugin.log(e); } } // Replace saved template with the new parsed one synchronized (this) { if (template != null) { fTemplate = template; // Save last successful parse tree fLastTemplate = template; } else { fTemplate = null; } } // Update outline view and display error message in status line Display.getDefault() .syncExec( new Runnable() { public void run() { fEditor.updateOutlinePage(); fEditor.displayErrorMessage(fError); } }); reconcile(); }
@Override public SQLStatement processTemplate(String template, List<Object> positionalParameters) { SimpleNode parsedTemplate = parse(template); Map<String, Object> internalParameters = new HashMap<>(); PositionalParamMapper visitor = new PositionalParamMapper(positionalParameters, internalParameters); parsedTemplate.jjtAccept(visitor, null); visitor.onFinish(); return processTemplate(template, parsedTemplate, internalParameters); }