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)); } }
/** * Adds a source file to the unit. */ public SourceUnit addSource(URL url) { return addSource(new SourceUnit(url, configuration, classLoader, getErrorCollector())); }
/** * Adds a source file to the unit. */ public SourceUnit addSource(File file) { return addSource(new SourceUnit(file, configuration, classLoader, getErrorCollector())); }
public SourceUnit addSource(String name, String scriptText) { return addSource(new SourceUnit(name, scriptText, configuration, classLoader, getErrorCollector())); }
private static void addJavacError(String header, CompilationUnit cu, StringBuilderWriter msg) { if (msg != null) { header = header + "\n" + msg.getBuilder().toString(); } else { header = header + "\nThis javac version does not support compile(String[],PrintWriter), " + "so no further details of the error are available. The message error text " + "should be found on System.err.\n"; } cu.getErrorCollector().addFatalError(new SimpleMessage(header, cu)); }
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)); } } };
/** * Adds a InputStream source to the unit. */ public SourceUnit addSource(String name, InputStream stream) { ReaderSource source = new InputStreamReaderSource(stream, configuration); return addSource(new SourceUnit(name, source, configuration, classLoader, getErrorCollector())); }
getErrorCollector().addErrorAndContinue( new SimpleMessage(message.toString(), CompilationUnit.this) );
compilationUnit.getErrorCollector().addWarning(new WarningMessage( WarningMessage.POSSIBLE_ERRORS, "Transform Class " + entry.getKey() + " is specified as a global transform in " + entry.getValue().toExternalForm() 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));
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)); try { if (!service.toURI().equals(transformNames.get(className).toURI())) { compilationUnit.getErrorCollector().addWarning( WarningMessage.POSSIBLE_ERRORS, "The global transform for class " + className + " is defined in both " compilationUnit.getErrorCollector().addWarning( WarningMessage.POSSIBLE_ERRORS, "Failed to parse URL as URI because of exception " + e.toString(), 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));
/** * Compiles a string of code. */ public void compile( String name, String code ) throws CompilationFailedException { CompilationUnit unit = new CompilationUnit( configuration ); unit.addSource( new SourceUnit(name, code, configuration, unit.getClassLoader(), unit.getErrorCollector()) ); unit.compile(); }
cu.getErrorCollector().addFatalError(new ExceptionMessage((Exception) ite.getCause(), true, cu)); } catch (Exception e) { cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
/** * A loop driver for applying operations to all SourceUnits. * Automatically skips units that have already been processed * through the current phase. */ public void applyToSourceUnits(SourceUnitOperation body) throws CompilationFailedException { for (String name : names) { SourceUnit source = sources.get(name); if ((source.phase < phase) || (source.phase == phase && !source.phaseComplete)) { try { body.call(source); } catch (CompilationFailedException e) { throw e; } catch (Exception e) { GroovyBugError gbe = new GroovyBugError(e); changeBugText(gbe, source); throw gbe; } catch (GroovyBugError e) { changeBugText(e, source); throw e; } } } getErrorCollector().failIfErrors(); }
public void applyToGeneratedGroovyClasses(GroovyClassOperation body) throws CompilationFailedException { if (this.phase != Phases.OUTPUT && !(this.phase == Phases.CLASS_GENERATION && this.phaseComplete)) { throw new GroovyBugError("CompilationUnit not ready for output(). Current phase=" + getPhaseDescription()); } for (GroovyClass gclass : this.generatedClasses) { // // Get the class and calculate its filesystem name // try { body.call(gclass); } catch (CompilationFailedException e) { // fall through, getErrorReporter().failIfErrors() will trigger } catch (NullPointerException npe) { throw npe; } catch (GroovyBugError e) { changeBugText(e, null); throw e; } catch (Exception e) { throw new GroovyBugError(e); } } getErrorCollector().failIfErrors(); }
getErrorCollector().failIfErrors();
} catch (GroovyRuntimeException rpe) { ASTNode node = rpe.getNode(); getErrorCollector().addError( new SyntaxException(rpe.getMessage(), node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source getErrorCollector().failIfErrors();
private void addJavacError(String header, CompilationUnit cu, StringWriter msg) { if (msg != null) { header = header + "\n" + msg.getBuffer().toString(); } else { header = header + "\nThis javac version does not support compile(String[],PrintWriter), " + "so no further details of the error are available. The message error text " + "should be found on System.err.\n"; } cu.getErrorCollector().addFatalError(new SimpleMessage(header, cu)); }
/** * Adds a source file to the unit. */ public SourceUnit addSource(File file) { return addSource(new SourceUnit(file, configuration, classLoader, getErrorCollector())); }
/** * Adds a source file to the unit. */ public SourceUnit addSource(URL url) { return addSource(new SourceUnit(url, configuration, classLoader, getErrorCollector())); }
/** * Adds a source file to the unit. */ public SourceUnit addSource(URL url) { return addSource(new SourceUnit(url, configuration, classLoader, getErrorCollector())); }