/** * Convenience wrapper for addError(). */ public void addError(String text, CSTNode context, SourceUnit source) throws CompilationFailedException { addError(new LocatedMessage(text, context, source)); }
/** * 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(); }
/** * 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 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); } }
/** * Convenience wrapper for addError(). */ public void addError(SyntaxException error, SourceUnit source) throws CompilationFailedException { addError(Message.create(error, source), error.isFatal()); }
private void verifyClass(AnnotationNode annotation, Class klass) { if (!ASTTransformation.class.isAssignableFrom(klass)) { source.getErrorCollector().addError(new SimpleMessage("Not an ASTTransformation: " + klass.getName() + " declared by " + annotation.getClassNode().getName(), source)); } }
private List<String> getTransformClassNames(AnnotationNode annotation, Annotation transformClassAnnotation) { List<String> result = new ArrayList<String>(); try { Method valueMethod = transformClassAnnotation.getClass().getMethod("value"); String[] names = (String[]) valueMethod.invoke(transformClassAnnotation); result.addAll(Arrays.asList(names)); Method classesMethod = transformClassAnnotation.getClass().getMethod("classes"); Class[] classes = (Class[]) classesMethod.invoke(transformClassAnnotation); for (Class klass : classes) { result.add(klass.getName()); } if (names.length > 0 && classes.length > 0) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " should specify transforms only by class names or by classes and not by both", source)); } } catch (Exception e) { source.addException(e); } return result; } }
public void call(GroovyClass gclass) throws CompilationFailedException { String name = gclass.getName().replace('.', File.separatorChar) + ".class"; File path = new File(configuration.getTargetDirectory(), name); // // Ensure the path is ready for the file // File directory = path.getParentFile(); if (directory != null && !directory.exists()) { directory.mkdirs(); } // // Create the file and write out the data // byte[] bytes = gclass.getBytes(); try (FileOutputStream stream = new FileOutputStream(path)) { stream.write(bytes, 0, bytes.length); } catch (IOException e) { getErrorCollector().addError(Message.create(e.getMessage(), CompilationUnit.this)); } } };
private void convertUncaughtExceptionToCompilationError(final Throwable e) { // check the exception for a nested compilation exception ErrorCollector nestedCollector = null; for (Throwable next = e.getCause(); next != e && next != null; next = next.getCause()) { if (!(next instanceof MultipleCompilationErrorsException)) continue; MultipleCompilationErrorsException mcee = (MultipleCompilationErrorsException) next; nestedCollector = mcee.collector; break; } if (nestedCollector != null) { getErrorCollector().addCollectorContents(nestedCollector); } else { Exception err = e instanceof Exception?((Exception)e):new RuntimeException(e); getErrorCollector().addError(new ExceptionMessage(err, configuration.getDebug(), this)); } }
public void addException(Exception cause, SourceUnit source) throws CompilationFailedException { addError(new ExceptionMessage(cause,configuration.getDebug(),source)); failIfErrors(); }
transformInstances.put(transformClass, transformClass.newInstance()); } catch (InstantiationException | IllegalAccessException e) { source.getErrorCollector().addError( new SimpleMessage( "Could not instantiate Transformation Processor " + transformClass
private void verifyCompilePhase(AnnotationNode annotation, Class<?> klass) { GroovyASTTransformation transformationClass = klass.getAnnotation(GroovyASTTransformation.class); if (transformationClass != null) { CompilePhase specifiedCompilePhase = transformationClass.phase(); if (specifiedCompilePhase.getPhaseNumber() < CompilePhase.SEMANTIC_ANALYSIS.getPhaseNumber()) { source.getErrorCollector().addError( new SimpleMessage( annotation.getClassNode().getName() + " is defined to be run in compile phase " + specifiedCompilePhase + ". Local AST transformations must run in " + CompilePhase.SEMANTIC_ANALYSIS + " or later!", source)); } } else { source.getErrorCollector().addError( new SimpleMessage("AST transformation implementation classes must be annotated with " + GroovyASTTransformation.class.getName() + ". " + klass.getName() + " lacks this annotation.", source)); } }
className = svcIn.readLine(); } catch (IOException ioe) { compilationUnit.getErrorCollector().addError(new SimpleMessage( "IOException reading the service definition at " + service.toExternalForm() + " because of exception " + ioe.toString(), null)); className = svcIn.readLine(); } catch (IOException ioe) { compilationUnit.getErrorCollector().addError(new SimpleMessage( "IOException reading the service definition at " + service.toExternalForm() + " because of exception " + ioe.toString(), null)); compilationUnit.getErrorCollector().addError(new SimpleMessage( "IO Exception attempting to load global transforms:" + e.getMessage(), null));
compilationUnit.getErrorCollector().addError(new SimpleMessage( "Transform Class " + entry.getKey() + " specified at " + entry.getValue().toExternalForm() + " is not an ASTTransformation.", null)); compilationUnit.getErrorCollector().addError(new SimpleMessage( "Could not instantiate global transform class " + entry.getKey() + " specified at " + entry.getValue().toExternalForm() + " because of exception " + e.toString(), null));
private void addTransformsToClassNode(AnnotationNode annotation, Annotation transformClassAnnotation) { List<String> transformClassNames = getTransformClassNames(annotation, transformClassAnnotation); if (transformClassNames.isEmpty()) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " does not specify any transform class names/classes", source)); } for (String transformClass : transformClassNames) { Class klass = loadTransformClass(transformClass, annotation); if (klass != null) { verifyAndAddTransform(annotation, klass); } } }
getErrorCollector().addError(new SyntaxErrorMessage(e, this));
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));
} catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source
private void logTransformationError(ASTNode astNode, Exception e) { StringBuilder message = new StringBuilder("Fatal error occurred applying query transformations [ " + e.getMessage() + "] to source [" + sourceUnit.getName() + "]. Please report an issue."); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); message.append(System.getProperty("line.separator")); message.append(sw.toString()); sourceUnit.getErrorCollector().addError(new LocatedMessage(message.toString(), Token.newString(astNode.getText(), astNode.getLineNumber(), astNode.getColumnNumber()), sourceUnit)); }
/** * Convenience wrapper for addError(). */ public void addError(SyntaxException error, SourceUnit source) throws CompilationFailedException { addError(Message.create(error, source), error.isFatal()); }