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(); }
/** * If an editor is connected then creates a new instance of the Velocity parser and initializes it * with data specified in Velocity preferences. */ public static void createVelocityParser() { if (fgRefCount > 0) { fgVelocityParser = new VelocityParser(); try { fgVelocityParser.init(); } catch (Exception e) { VelocityPlugin.log(e); } } }
public int openCompareDialog() { VelocityPlugin plugin = VelocityPlugin.getDefault(); // CompareUI.openCompareEditor(this); if (plugin != null) return plugin.openCompareDialog(this, error); return 0; }