/** * Set one or more customizers to be applied to this evaluator's compiler configuration. * <p>Note that this modifies the shared compiler configuration held by this evaluator. * @since 4.3.3 * @see #setCompilerConfiguration */ public void setCompilationCustomizers(CompilationCustomizer... compilationCustomizers) { this.compilerConfiguration.addCompilationCustomizers(compilationCustomizers); }
/** * A convenience routine to create a standalone SourceUnit on a String * with defaults for almost everything that is configurable. */ public static SourceUnit create(String name, String source, int tolerance) { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setTolerance(tolerance); return new SourceUnit(name, source, configuration, null, new ErrorCollector(configuration)); }
/** * Enable compiler to report stack trace information if a problem occurs * during compilation. * * @param stacktrace set to true to enable stacktrace reporting */ public void setStacktrace(boolean stacktrace) { configuration.setDebug(stacktrace); }
/** * Create a new GroovyScriptFactory for the given script source, * specifying a strategy interface that can customize Groovy's compilation * process within the underlying GroovyClassLoader. * @param scriptSourceLocator a locator that points to the source of the script. * Interpreted by the post-processor that actually creates the script. * @param compilationCustomizers one or more customizers to be applied to the * GroovyClassLoader compiler configuration * @since 4.3.3 * @see CompilerConfiguration#addCompilationCustomizers * @see org.codehaus.groovy.control.customizers.ImportCustomizer */ public GroovyScriptFactory(String scriptSourceLocator, CompilationCustomizer... compilationCustomizers) { this(scriptSourceLocator); if (!ObjectUtils.isEmpty(compilationCustomizers)) { this.compilerConfiguration = new CompilerConfiguration(); this.compilerConfiguration.addCompilationCustomizers(compilationCustomizers); } }
/** * Initialize the ProcessingUnit to the empty state. */ public ProcessingUnit(CompilerConfiguration configuration, GroovyClassLoader classLoader, ErrorCollector er) { this.phase = Phases.INITIALIZATION; this.configuration = configuration; this.setClassLoader(classLoader); configure((configuration == null ? new CompilerConfiguration() : configuration)); if (er==null) er = new ErrorCollector(getConfiguration()); this.errorCollector = er; }
public MultipleCompilationErrorsException(ErrorCollector ec) { super(0, null); if (ec == null) { CompilerConfiguration config = super.getUnit() != null ? super.getUnit().getConfiguration() : new CompilerConfiguration(); collector = new ErrorCollector(config); } else { collector = ec; } }
public ModuleNode getAST(String source, int untilPhase) { SourceUnit unit = SourceUnit.create("Test", source); CompilationUnit compUnit = new CompilationUnit(); compUnit.addSource(unit); compUnit.compile(untilPhase); return unit.getAST(); }
/** * 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(); }
/** * Set a custom compiler configuration for this evaluator. * @since 4.3.3 * @see #setCompilationCustomizers */ public void setCompilerConfiguration(@Nullable CompilerConfiguration compilerConfiguration) { this.compilerConfiguration = (compilerConfiguration != null ? compilerConfiguration : new CompilerConfiguration()); }
/** * Adds a source file to the unit. */ public SourceUnit addSource(URL url) { return addSource(new SourceUnit(url, configuration, classLoader, getErrorCollector())); }
/** * 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); }
/** * This method adds an exception to the error collector. The Exception most likely has no line number attached to it. * For this reason you should use this method sparingly. Prefer using addError for syntax errors or add an error * to the {@link ErrorCollector} directly by retrieving it with getErrorCollector(). * @param e * the exception that occurred * @throws CompilationFailedException * on error */ public void addException(Exception e) throws CompilationFailedException { getErrorCollector().addException(e, this); }
/** * Check if the current runtime allows Annotation usage. * * @return true if running on a 1.5+ runtime */ protected boolean isAnnotationCompatible() { return CompilerConfiguration.isPostJDK5(this.source.getConfiguration().getTargetBytecode()); }
/** * Configures its debugging mode and classloader classpath from a given compiler configuration. * This cannot be done more than once due to limitations in {@link java.net.URLClassLoader URLClassLoader}. */ public void configure(CompilerConfiguration configuration) { super.configure(configuration); this.debug = configuration.getDebug(); if (!this.configured && this.classLoader instanceof GroovyClassLoader) { appendCompilerConfigurationClasspathToClassLoader(configuration, (GroovyClassLoader) this.classLoader); } this.configured = true; }
/** * Causes the current phase to fail by throwing a * CompilationFailedException. */ protected void failIfErrors() throws CompilationFailedException { if (hasErrors()) { throw new MultipleCompilationErrorsException(this); } }
public void close() { janitor.cleanup(); } }
/** * Returns the class loader for loading AST transformations. * @return - the transform class loader */ public GroovyClassLoader getTransformLoader() { return astTransformationsContext.getTransformLoader() == null ? getClassLoader() : astTransformationsContext.getTransformLoader(); }
/** * A convenience routine to create a standalone SourceUnit on a String * with defaults for almost everything that is configurable. */ public static SourceUnit create(String name, String source) { CompilerConfiguration configuration = new CompilerConfiguration(); configuration.setTolerance(1); return new SourceUnit(name, source, configuration, null, new ErrorCollector(configuration)); }
/** * Set a custom compiler configuration for this evaluator. * @since 4.3.3 * @see #setCompilationCustomizers */ public void setCompilerConfiguration(@Nullable CompilerConfiguration compilerConfiguration) { this.compilerConfiguration = (compilerConfiguration != null ? compilerConfiguration : new CompilerConfiguration()); }
/** * Set one or more customizers to be applied to this evaluator's compiler configuration. * <p>Note that this modifies the shared compiler configuration held by this evaluator. * @since 4.3.3 * @see #setCompilerConfiguration */ public void setCompilationCustomizers(CompilationCustomizer... compilationCustomizers) { this.compilerConfiguration.addCompilationCustomizers(compilationCustomizers); }