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 )); }
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(); } }
/** * This method adds a SyntaxException to the error collector. The exception should specify the line and column * number of the error. This method should be reserved for real errors in the syntax of the SourceUnit. If * your error is not in syntax, and is a semantic error, or more general error, then use addException or use * the error collector directly by retrieving it with getErrorCollector(). * @param se * the exception, which should have line and column information * @throws CompilationFailedException * on error */ public void addError(SyntaxException se) throws CompilationFailedException { getErrorCollector().addError(se, this); }
/** * Adds a fatal exception to the message set and throws * the unit as a PhaseFailedException. */ public void addFatalError(Message message) throws CompilationFailedException { addError(message); failIfErrors(); }
/** * Adds an optionally-fatal error to the message set. * The message is not required to have a source line and column specified, but it is best practice to try * and include that information. * @param fatal * if true then then processing will stop */ public void addError(Message message, boolean fatal) throws CompilationFailedException { if (fatal) { addFatalError(message); } else { addError(message); } }
public ErrorCollector pushErrorCollector() { ErrorCollector current = getErrorCollector(); ErrorCollector collector = new ErrorCollector(current.getConfiguration()); errorCollectors.add(0, collector); return collector; }
/** * 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; }
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) { name = moduleNode.getContext().getName(); } else if (context.snapshot.getSource().getFileObject() != null) { name = context.snapshot.getSource().getFileObject().getNameExt(); int startLine = ex.getStartLine(); int startColumn = ex.getStartColumn(); int line = ex.getLine(); int endColumn = ex.getEndColumn();
public void error(String msg, Object... args) { sourceUnit.getErrorCollector().addErrorAndContinue( new SimpleMessage(String.format(msg, args), sourceUnit)); }
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; Diagnostic diagnostic; Ranges.createZeroBasedRange(cause.getStartLine(), cause.getStartColumn(), cause.getEndLine(), cause.getEndColumn()); uri = Paths.get(cause.getSourceLocator()).toUri();
/** * Resolve metadata and details of the annotation. * * @param unvisited the node to visit * @return the visited node */ private AnnotationNode visitAnnotation(AnnotationNode unvisited) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); AnnotationNode visited = visitor.visit(unvisited); this.source.getErrorCollector().addCollectorContents(errorCollector); return visited; }
private void checkVisitErrors(String name, int modifiers, boolean expectedToFail) { ClassNode node = new ClassNode(name, modifiers, ClassHelper.OBJECT_TYPE); verifier.visitClass(node); assertTrue(source.getErrorCollector().hasErrors() == expectedToFail); }
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(); if (fileName.equals(moduleNode.getContext().getName())) { module = moduleNode;
CompilationUnit cu = new CompilationUnit(loader); CompilerConfiguration config = new CompilerConfiguration(); SourceUnit su = new SourceUnit(name + "wrapper", "", config, loader, new ErrorCollector(config)); cu.addSource(su); cu.compile(Phases.CONVERSION); su.getAST().addClass(cn); cu.compile(Phases.CLASS_GENERATION); @SuppressWarnings("unchecked")
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(); }
protected void addError(String msg, ASTNode expr) { this.errorCollector.addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException(msg + " in @" + this.reportClass.getName() + '\n', expr.getLineNumber(), expr.getColumnNumber(), expr.getLastLineNumber(), expr.getLastColumnNumber()), this.source) ); }
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());
new SourceUnit(name, compiledSource, compilerConfiguration, tClassLoader, compilationUnit.getErrorCollector())); 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("@")); ExceptionMessage errorMessage = (ExceptionMessage) e.getErrorCollector().getLastError(); Exception exception = errorMessage.getCause(); Integer line = 0;
/** * Returns the specified error message, or null. */ public Message getError(int index) { if (index < getErrorCount()) { return (Message) this.errors.get(index); } return null; }