/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }
private String buildErrorMessage(int count) { StringBuilder sb = new StringBuilder(); sb.append("Expected ").append(count); sb.append(" error messages but found "); sb.append(source.getErrorCollector().getErrorCount()).append(":\n"); sb.append(flattenErrorMessage()); return sb.toString(); }
private String flattenErrorMessage() { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter, true); for (int i = source.getErrorCollector().getErrorCount() - 1; i >= 0; i--) { source.getErrorCollector().getError(i).write(writer); } writer.close(); return stringWriter.toString(); } }
private void checkErrorCount(int count) { assertEquals(buildErrorMessage(count), count, source.getErrorCollector().getErrorCount()); }
((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) { final String errorMessage = String.format("The Gremlin statement that was submitted exceeds the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", trimMessage(msg)); logger.warn(errorMessage);
/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }
/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }
/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }
/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }
try { new GroovyShell().parse(groovyCode); } catch(MultipleCompilationErrorsException cfe) { ErrorCollector errorCollector = cfe.getErrorCollector(); System.out.println("Errors: "+errorCollector.getErrorCount()); }
public static ScriptError fromGroovyException(MultipleCompilationErrorsException e) { ErrorCollector errorCollector = e.getErrorCollector(); if (errorCollector.getErrorCount() > 0) { Message error = errorCollector.getError(0); if (error instanceof SyntaxErrorMessage) { SyntaxException cause = ((SyntaxErrorMessage) error).getCause(); return new ScriptError(cause.getMessage(), cause.getStartLine(), cause.getStartColumn(), cause.getEndLine(), cause.getEndColumn()); } else { throw new AssertionError("SyntaxErrorMessage is expected"); } } else { throw new AssertionError("At least one error is expected"); } }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e;
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
/** * Attempts to parse the specified code with the specified tolerance. * Updates the <code>parser</code> and <code>error</code> members * appropriately. Returns true if the text parsed, false otherwise. * The attempts to identify and suppress errors resulting from the * unfinished source text. */ private boolean parse(final String code, final int tolerance) { assert code != null; boolean parsed = false; parser = null; error = null; // Create the parser and attempt to parse the text as a top-level statement. try { parser = SourceUnit.create("groovysh-script", code, tolerance); parser.parse(); parsed = true; } // We report errors other than unexpected EOF to the user. catch (CompilationFailedException e) { if (parser.getErrorCollector().getErrorCount() > 1 || !parser.failedWithUnexpectedEOF()) { error = e; } } catch (Exception e) { error = e; } return parsed; }
private void assertImproperOverride(String methodStub) { try { sandboxedSh.evaluate(SCRIPT_HARNESS.replace("METHOD", methodStub)); fail("Should have failed"); } catch (MultipleCompilationErrorsException e) { assertThat(e.getErrorCollector().getErrorCount(), equalTo(1)); assertThat(e.getMessage(), anyOf( containsString("cannot override finalize in java.lang.Object"), containsString("incompatible with void in java.lang.Object"))); } }
private void assertForbidden(String methodStub, boolean isDangerous) { String script = SCRIPT_HARNESS.replace("METHOD", methodStub); try { sandboxedSh.evaluate(script); fail("Should have failed"); } catch (MultipleCompilationErrorsException e) { assertThat(e.getErrorCollector().getErrorCount(), equalTo(1)); Exception innerE = e.getErrorCollector().getException(0); assertThat(innerE, instanceOf(SecurityException.class)); assertThat(innerE.getMessage(), containsString("Object.finalize()")); } Object actual = unsandboxedSh.evaluate(script); assertThat(actual, equalTo((Object)isDangerous)); }
compilationUnit.compile(); } catch (MultipleCompilationErrorsException e) { if (e.getErrorCollector().getErrorCount() == 0 ) { throw new GTCompilationException("Error compiling groovy", e);
for (int i = 0; i < collector.getErrorCount(); ++i) { result.registerError(convertMessage(collector.getError(i)));