Refine search
private static void addUnsupportedError(ASTNode node, SourceUnit unit) { unit.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage( new SyntaxException("The @Category transformation does not support instance "+ (node instanceof FieldNode?"fields":"properties") + " but found ["+getName(node)+"]", node.getLineNumber(), node.getColumnNumber() ), unit )); }
List<Message> errors = (List<Message>) collector.getErrors(); if (errors.size() > 0) { Message firstMessage = errors.get(0); @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) SyntaxException syntaxException = ((SyntaxErrorMessage) firstMessage).getCause(); Position errorPosition = new Position(syntaxException.getLine(), syntaxException.getStartColumn());
/** * Writes out a nicely formatted summary of the syntax error. */ public void write(PrintWriter output, Janitor janitor) { String name = source.getName(); int line = getCause().getStartLine(); int column = getCause().getStartColumn(); String sample = source.getSample(line, column, janitor); output.print(name + ": " + line + ": " + getCause().getMessage()); if (sample != null) { output.println(); output.print(sample); output.println(); } }
public void testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated() { SyntaxException syntaxException = new SyntaxException(someString(), -1, -1); assertEquals("source locator", null, syntaxException.getSourceLocator()); String sourceUnitName = someString(); SourceUnit sourceUnit = SourceUnit.create(sourceUnitName, someString()); new SyntaxErrorMessage(syntaxException, sourceUnit); assertEquals("source locator", sourceUnitName, syntaxException.getSourceLocator()); }
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); } }
private void throwSuperError(final ASTNode node) { unit.addError(new SyntaxException("Call to super is not allowed in a trait", node.getLineNumber(), node.getColumnNumber())); }
private Set<PublishDiagnosticsParams> parseErrors(ErrorCollector collector) { Map<URI, List<Diagnostic>> diagnosticsByFile = Maps.newHashMap(); for (int i = 0; i < collector.getWarningCount(); i++) { WarningMessage message = collector.getWarning(i); String message1 = message.getMessage() == null ? "" diagnosticsByFile.computeIfAbsent(workspaceRoot.toUri(), (ignored) -> Lists.newArrayList()).add(diag); for (int i = 0; i < collector.getErrorCount(); i++) { Message message = collector.getError(i); URI uri; Ranges.createZeroBasedRange(cause.getStartLine(), cause.getStartColumn(), cause.getEndLine(), cause.getEndColumn()); uri = Paths.get(cause.getSourceLocator()).toUri(); diagnostic = new Diagnostic( range, cause.getMessage(), DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER); } else { StringWriter data = new StringWriter();
List errors = errorCollector.getErrors(); if (errors != null) { for (Object object : errors) { SyntaxException ex = ((SyntaxErrorMessage)object).getCause(); String sourceLocator = ex.getSourceLocator(); String name = null; if (moduleNode != null) { int startLine = ex.getStartLine(); int startColumn = ex.getStartColumn(); int line = ex.getLine(); int endColumn = ex.getEndColumn(); endOffset = ASTUtils.getOffset(context.document, line > 0 ? line : 1, endColumn > 0 ? endColumn : 1); notifyError(context, null, Severity.ERROR, ex.getMessage(), null, startOffset, endOffset, sanitizing);
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"); } }
if (errorCollector.hasErrors()) { Message message = errorCollector.getLastError(); if (message instanceof SyntaxErrorMessage) { SyntaxException se = ((SyntaxErrorMessage)message).getCause(); int line = se.getStartLine(); int col = se.getStartColumn(); offset = ASTUtils.getOffset(context.document, line, col); errorMessage = se.getMessage(); localizedMessage = se.getLocalizedMessage();
/** * Convenience routine, primarily for use by the InteractiveShell, * that returns true if parse() failed with an unexpected EOF. */ public boolean failedWithUnexpectedEOF() { // Implementation note - there are several ways for the Groovy compiler // to report an unexpected EOF. Perhaps this implementation misses some. // If you find another way, please add it. if (getErrorCollector().hasErrors()) { Message last = (Message) getErrorCollector().getLastError(); Throwable cause = null; if (last instanceof SyntaxErrorMessage) { cause = ((SyntaxErrorMessage) last).getCause().getCause(); } if (cause != null) { if (cause instanceof NoViableAltException) { return isEofToken(((NoViableAltException) cause).token); } else if (cause instanceof NoViableAltForCharException) { char badChar = ((NoViableAltForCharException) cause).foundChar; return badChar == CharScanner.EOF_CHAR; } else if (cause instanceof MismatchedCharException) { char badChar = (char) ((MismatchedCharException) cause).foundChar; return badChar == CharScanner.EOF_CHAR; } else if (cause instanceof MismatchedTokenException) { return isEofToken(((MismatchedTokenException) cause).token); } } } return false; }
compilationUnit.compile(); } catch (MultipleCompilationErrorsException e) { if (e.getErrorCollector().getErrorCount() == 0 ) { throw new GTCompilationException("Error compiling groovy", e); Message errorMessage = e.getErrorCollector().getError(0); if ( errorMessage instanceof SyntaxErrorMessage) { SyntaxException se = ((SyntaxErrorMessage)errorMessage).getCause(); throw new GTCompilationExceptionWithSourceInfo(se.getOriginalMessage(), templateLocation, lineMapper.translateLineNo(se.getLine()));
} catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source ); getErrorCollector().failIfErrors();
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; }
if (e.getErrorCollector().getLastError() != null) { Message errorMsg = e.getErrorCollector().getLastError(); if (errorMsg instanceof SyntaxErrorMessage) { SyntaxErrorMessage errorMessage = (SyntaxErrorMessage) e.getErrorCollector().getLastError(); SyntaxException syntaxException = errorMessage.getCause(); Integer line = this.linesMatrix.get(syntaxException.getLine()); if (line == null) { line = 0; String message = syntaxException.getMessage(); if (message.indexOf("@") > 0) { message = message.substring(0, message.lastIndexOf("@"));
public static String getSyntaxErrorReport(MultipleCompilationErrorsException e, String configName) { StringBuilder b = new StringBuilder(); b.append("Config name: "); b.append(configName); b.append("\n"); b.append("Errors:\n"); for (Object o : e.getErrorCollector().getErrors()) { if (o instanceof SyntaxErrorMessage) { b.append(" - "); b.append(((SyntaxErrorMessage) o).getCause().getMessage()); b.append("\n"); } } return b.toString(); }
source.getErrorCollector().addError( new SyntaxErrorMessage(new SyntaxException("@Category can only be added to a ClassNode but got: " + (nodes.length==2?nodes[1]:"nothing"), nodes[0].getLineNumber(), nodes[0].getColumnNumber()), source));
/** * @return the end of the line on which the error occurs */ public int getStartLine() { return getLine(); }
/** * <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; } }
SyntaxException se = new SyntaxException(e.getMessage(), e, e.getLine(), e.getColumn()); se.setFatal(true); sourceUnit.addError(se); SyntaxException se = new SyntaxException(e.getMessage(), e, e.getLine(), e.getColumn()); se.setFatal(true); sourceUnit.addError(se);