@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) SyntaxException syntaxException = ((SyntaxErrorMessage) firstMessage).getCause(); Position errorPosition = new Position(syntaxException.getLine(), syntaxException.getStartColumn());
/** * @return the end of the line on which the error occurs */ public int getStartLine() { return getLine(); }
/** * @return the end of the line on which the error occurs */ public int getStartLine() { return getLine(); }
/** * @return the end of the line on which the error occurs */ public int getStartLine() { return getLine(); }
/** * @return the end of the line on which the error occurs */ public int getStartLine() { return getLine(); }
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) { // Fix the source file name displayed in the error messages for (Object message : e.getErrorCollector().getErrors()) { if (message instanceof SyntaxErrorMessage) { try { SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message; Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source"); sourceField.setAccessible(true); SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage); Field nameField = SourceUnit.class.getDeclaredField("name"); nameField.setAccessible(true); nameField.set(sourceUnit, source.getDisplayName()); } catch (Exception failure) { throw UncheckedException.throwAsUncheckedException(failure); } } } SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0); Integer lineNumber = syntaxError == null ? null : syntaxError.getLine(); throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber); }
public Object eval(String script, ScriptContext ctx) throws ScriptException { try { return eval(getScriptClass(script), ctx); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } }
/** * <p>Converts the given Groovy compiler message into a compilation message that * our compilation API consists of.</p> * * @param message the Groovy compiler message you want to convert * @return the final converted compilation message */ protected CompilationMessage convertMessage(Message message) { if (message instanceof SimpleMessage) { SimpleMessage simpleMessage = (SimpleMessage) message; return new CompilationMessage(-1, simpleMessage.getMessage()); } else if (message instanceof SyntaxErrorMessage) { SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message; return new CompilationMessage( syntaxErrorMessage.getCause().getLine(), syntaxErrorMessage.getCause().getMessage()); } else { if (_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "This compiler came across an unknown message kind ['{0}']. It will be ignored.", message); } return null; } }
public Object eval(String script, ScriptContext ctx) throws ScriptException { try { Class clazz = getScriptClass(script); if(clazz == null) throw new ScriptException("Script class is null"); return eval(clazz, ctx); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (Exception e) { if (DEBUG) e.printStackTrace(); throw new ScriptException(e); } }
public CompiledScript compile(String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (IOException e) { throw new ScriptException(e); } catch (CompilationFailedException ee) { throw new ScriptException(ee); } } public CompiledScript compile(Reader reader) throws ScriptException {
public Object eval(String script, ScriptContext ctx) throws ScriptException { try { String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE); ReferenceBundle bundle = ReferenceBundle.getHardBundle(); if (val!=null && val.length()>0) { if (val.equalsIgnoreCase("soft")) { bundle = ReferenceBundle.getSoftBundle(); } else if (val.equalsIgnoreCase("weak")) { bundle = ReferenceBundle.getWeakBundle(); } else if (val.equalsIgnoreCase("phantom")) { bundle = ReferenceBundle.getPhantomBundle(); } } globalClosures.setBundle(bundle); } catch (ClassCastException cce) { /*ignore.*/ } try { Class clazz = getScriptClass(script); if (clazz == null) throw new ScriptException("Script class is null"); return eval(clazz, ctx); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (Exception e) { if (debug) e.printStackTrace(); throw new ScriptException(e); } }
public static List<CheckStatus> toCheckStatus(CompilationFailedException x) { List<CheckStatus> errors = new ArrayList<CheckStatus>(); if (x instanceof MultipleCompilationErrorsException) { for (Object o : ((MultipleCompilationErrorsException) x).getErrorCollector().getErrors()) { if (o instanceof SyntaxErrorMessage) { SyntaxException cause = ((SyntaxErrorMessage) o).getCause(); CheckStatus st = new CheckStatus(cause.getOriginalMessage(), FAIL_KEY); st.setLine(cause.getLine()); st.setColumn(cause.getStartColumn()); errors.add(st); } } } if (errors.isEmpty()) { // Fallback to simple message CheckStatus st = new CheckStatus(x.getMessage(), FAIL_KEY); st.setLine(1); st.setColumn(0); errors.add(st); } return errors; }
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) SyntaxException syntaxException = ((SyntaxErrorMessage) firstMessage).getCause(); Position errorPosition = new Position(syntaxException.getLine(), syntaxException.getStartColumn());
public Object eval(String script, ScriptContext ctx) throws ScriptException { try { String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE); ReferenceBundle bundle = ReferenceBundle.getHardBundle(); if (val != null && val.length() > 0) { if (val.equalsIgnoreCase("soft")) { bundle = ReferenceBundle.getSoftBundle(); } else if (val.equalsIgnoreCase("weak")) { bundle = ReferenceBundle.getWeakBundle(); } else if (val.equalsIgnoreCase("phantom")) { bundle = ReferenceBundle.getPhantomBundle(); } } globalClosures.setBundle(bundle); } catch (ClassCastException cce) { /*ignore.*/ } try { Class clazz = getScriptClass(script); if (clazz == null) throw new ScriptException("Script class is null"); return eval(clazz, ctx); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (Exception e) { if (debug) e.printStackTrace(); throw new ScriptException(e); } } public Bindings createBindings() {
public CompiledScript compile(String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (IOException e) { throw new ScriptException(e); } catch (CompilationFailedException ee) { throw new ScriptException(ee); } }
@Override public Object eval(final String script, final ScriptContext context) throws ScriptException { try { final String val = (String) context.getAttribute(KEY_REFERENCE_TYPE, ScriptContext.ENGINE_SCOPE); ReferenceBundle bundle = ReferenceBundle.getHardBundle(); if (val != null && val.length() > 0) { if (val.equalsIgnoreCase(REFERENCE_TYPE_SOFT)) { bundle = ReferenceBundle.getSoftBundle(); } else if (val.equalsIgnoreCase(REFERENCE_TYPE_WEAK)) { bundle = ReferenceBundle.getWeakBundle(); } else if (val.equalsIgnoreCase(REFERENCE_TYPE_PHANTOM)) { bundle = ReferenceBundle.getPhantomBundle(); } } globalClosures.setBundle(bundle); } catch (ClassCastException cce) { /*ignore.*/ } try { final Class clazz = getScriptClass(script); if (null == clazz) throw new ScriptException("Script class is null"); return eval(clazz, context); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (Exception e) { throw new ScriptException(e); } }
public CompiledScript compile(String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (IOException e) { throw new ScriptException(e); } catch (CompilationFailedException ee) { throw new ScriptException(ee); } }
public CompiledScript compile(String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (IOException e) { throw new ScriptException(e); } catch (CompilationFailedException ee) { throw new ScriptException(ee); } }
@Override public CompiledScript compile(final String scriptSource) throws ScriptException { try { return new GroovyCompiledScript(this, getScriptClass(scriptSource)); } catch (SyntaxException e) { throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine()); } catch (IOException e) { throw new ScriptException(e); } catch (CompilationFailedException ee) { throw new ScriptException(ee); } }
if ( errorMessage instanceof SyntaxErrorMessage) { SyntaxException se = ((SyntaxErrorMessage)errorMessage).getCause(); throw new GTCompilationExceptionWithSourceInfo(se.getOriginalMessage(), templateLocation, lineMapper.translateLineNo(se.getLine()));