本文整理汇总了Java中org.codehaus.groovy.control.customizers.CompilationCustomizer类的典型用法代码示例。如果您正苦于以下问题:Java CompilationCustomizer类的具体用法?Java CompilationCustomizer怎么用?Java CompilationCustomizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationCustomizer类属于org.codehaus.groovy.control.customizers包,在下文中一共展示了CompilationCustomizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postCompleteNode
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) {
if (node instanceof Map) {
Map map = (Map) node;
ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter(
map,
map.containsKey("superClass")?(Class)map.get("superClass"):CompilationCustomizer.class,
map.containsKey("interfaces")?(Class[])map.get("interfaces"):null,
this.getClass().getClassLoader(),
false,
null
);
Object phase = map.get("phase");
if (!(phase instanceof CompilePhase)) {
phase = CompilePhase.valueOf(phase.toString());
}
return adapter.proxy(map, phase);
}
return node;
}
示例2: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final org.codehaus.groovy.control.customizers.ImportCustomizer ic = new org.codehaus.groovy.control.customizers.ImportCustomizer();
// there's something weird in groovy about doing specific imports instead of wildcard imports. with wildcard
// imports groovy seems to allow methods to be overloaded with enums such that things like Column.values and
// __.values() can be resolved by the compiler. if they are both directly in the imports then one or the other
// can't be found. the temporary fix is to hardcode a wildcard import __ and then filter out the core imports
// from the incoming customizer. ultimately, the fix should be to resolve the naming conflicts to ensure a
// unique space somehow.
ic.addStaticStars(__.class.getCanonicalName());
for (ImportCustomizer customizer : customizers) {
customizer.getClassImports().forEach(i -> ic.addImports(i.getCanonicalName()));
customizer.getMethodImports().stream()
.filter(m -> !m.getDeclaringClass().equals(__.class))
.forEach(m -> ic.addStaticImport(m.getDeclaringClass().getCanonicalName(), m.getName()));
customizer.getEnumImports().forEach(m -> ic.addStaticImport(m.getDeclaringClass().getCanonicalName(), m.name()));
}
return ic;
}
示例3: compile
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public Set<Class<?>> compile(ScriptArchive archive, JBossModuleClassLoader moduleClassLoader, Path compilationRootDir)
throws ScriptCompilationException, IOException {
List<CompilationCustomizer> customizers = new LinkedList<CompilationCustomizer>();
for (String klassName: this.customizerClassNames) {
CompilationCustomizer instance = this.getCustomizerInstanceFromString(klassName, moduleClassLoader);
if (instance != null ) {
customizers.add(instance);
}
}
CompilerConfiguration config = new CompilerConfiguration(CompilerConfiguration.DEFAULT);
config.addCompilationCustomizers(customizers.toArray(new CompilationCustomizer[0]));
new Groovy2CompilerHelper(compilationRootDir)
.addScriptArchive(archive)
.withParentClassloader(moduleClassLoader) // TODO: replace JBossModuleClassLoader with generic class loader
.withConfiguration(config)
.compile();
return Collections.emptySet();
}
示例4: testCompile
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Test
public void testCompile() throws Exception {
Groovy2Compiler compiler;
List<CompilationCustomizer> customizers;
Map<String, Object> compilerParams;
Path scriptRootPath = GroovyTestResourceUtil.findRootPathForScript(TestScript.HELLO_WORLD);
PathScriptArchive scriptArchive = new PathScriptArchive.Builder(scriptRootPath)
.setRecurseRoot(false)
.addFile(TestScript.HELLO_WORLD.getScriptPath())
.build();
compilerParams = new HashMap<String, Object>();
compilerParams.put(Groovy2Compiler.GROOVY2_COMPILER_PARAMS_CUSTOMIZERS, Arrays.asList(new Object[] {"testmodule.customizers.TestCompilationCustomizer"}));
compiler = new Groovy2Compiler(compilerParams);
compiler.compile(scriptArchive, null, scriptRootPath);
}
示例5: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final ImportCustomizer ic = new ImportCustomizer();
processImports(ic, imports);
processStaticImports(ic, staticImports);
processImports(ic, extraImports);
processStaticImports(ic, extraStaticImports);
return ic;
}
示例6: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
timedInterruptAnnotationParams.put("value", interruptionTimeout);
timedInterruptAnnotationParams.put("unit", GeneralUtils.propX(GeneralUtils.classX(TimeUnit.class), TimeUnit.MILLISECONDS.toString()));
timedInterruptAnnotationParams.put("checkOnMethodStart", false);
timedInterruptAnnotationParams.put("thrown", GeneralUtils.classX(TimedInterruptTimeoutException.class));
return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TimedInterrupt.class);
}
示例7: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> annotationParams = new HashMap<>();
if (extensions != null && !extensions.isEmpty()) {
if (extensions.contains(","))
annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
else
annotationParams.put("extensions", Collections.singletonList(extensions));
}
return new ASTTransformationCustomizer(annotationParams, TypeChecked.class);
}
示例8: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> annotationParams = new HashMap<>();
if (extensions != null && !extensions.isEmpty()) {
if (extensions.contains(","))
annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
else
annotationParams.put("extensions", Collections.singletonList(extensions));
}
return new ASTTransformationCustomizer(annotationParams, CompileStatic.class);
}
示例9: create
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final ImportCustomizer ic = new ImportCustomizer();
processImports(ic, extraImports);
processStaticImports(ic, extraStaticImports);
return ic;
}
示例10: MarkupTemplateEngine
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration tplConfig, final TemplateResolver resolver) {
compilerConfiguration = new CompilerConfiguration();
templateConfiguration = tplConfig;
compilerConfiguration.addCompilationCustomizers(new TemplateASTTransformer(tplConfig));
compilerConfiguration.addCompilationCustomizers(
new ASTTransformationCustomizer(Collections.singletonMap("extensions", "groovy.text.markup.MarkupTemplateTypeCheckingExtension"), CompileStatic.class));
if (templateConfiguration.isAutoNewLine()) {
compilerConfiguration.addCompilationCustomizers(
new CompilationCustomizer(CompilePhase.CONVERSION) {
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
new AutoNewLineTransformer(source).visitClass(classNode);
}
}
);
}
groovyClassLoader = AccessController.doPrivileged(new PrivilegedAction<TemplateGroovyClassLoader>() {
public TemplateGroovyClassLoader run() {
return new TemplateGroovyClassLoader(parentLoader, compilerConfiguration);
}
});
if (DEBUG_BYTECODE) {
compilerConfiguration.setBytecodePostprocessor(BytecodeDumper.STANDARD_ERR);
}
templateResolver = resolver == null ? new DefaultTemplateResolver() : resolver;
templateResolver.configure(groovyClassLoader, templateConfiguration);
}
示例11: setChild
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void setChild(final FactoryBuilderSupport builder, final Object parent, final Object child) {
if (parent instanceof Collection && child instanceof CompilationCustomizer) {
((Collection) parent).add(child);
}
}
示例12: postCompleteNode
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) {
if (node instanceof List) {
List col = (List) node;
return col.toArray(new CompilationCustomizer[col.size()]);
}
return node;
}
示例13: newInstance
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
public Object newInstance(final FactoryBuilderSupport builder, final Object name, final Object value, final Map attributes) throws InstantiationException, IllegalAccessException {
SourceOptions data = new SourceOptions();
if (value instanceof CompilationCustomizer) {
data.delegate = (CompilationCustomizer) value;
}
return data;
}
示例14: Workspace
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
public Workspace(WorkspaceService workspaceService, String name) {
this.workspaceService = workspaceService;
this.name = name;
File autorunDirectory = workspaceService.getAutorunDirectory();
autorunFile = new File(autorunDirectory, name+".groovy");
this.autorunDirectory = new File(autorunDirectory, name);
compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.setScriptBaseClass(CallerScript.class.getName());
List<CompilationCustomizer> compilationCustomizers = compilerConfiguration.getCompilationCustomizers();
compilerConfiguration.getClasspath().addAll(workspaceService.getClassPath());
String encoding = workspaceService.getVarScript().getConfig().getString("sources.encoding");
if (encoding != null) compilerConfiguration.setSourceEncoding(encoding);
compilationCustomizers.addAll(workspaceService.getCompilationCustomizers());
groovyClassLoader = new GroovyClassLoader(workspaceService.getGroovyClassLoader(), compilerConfiguration);
}
示例15: testCustomiizerParamsProcessing
import org.codehaus.groovy.control.customizers.CompilationCustomizer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testCustomiizerParamsProcessing() throws Exception {
Groovy2Compiler compiler;
List<CompilationCustomizer> customizers;
Map<String, Object> compilerParams;
Field f = Groovy2Compiler.class.getDeclaredField("customizerClassNames");
f.setAccessible(true);
// empty parameters map
compiler = new Groovy2Compiler(new HashMap<String, Object>());
customizers = (List<CompilationCustomizer>)f.get(compiler);
assertTrue(customizers.size() == 0, "no valid objects expected");
// null value customizers parameter
compilerParams = new HashMap<String, Object>();
compilerParams.put(Groovy2Compiler.GROOVY2_COMPILER_PARAMS_CUSTOMIZERS, null);
compiler = new Groovy2Compiler(compilerParams);
customizers = (List)f.get(compiler);
assertTrue(customizers.size() == 0, "no valid objects expected");
// list with valid customizer
compilerParams = new HashMap<String, Object>();
compilerParams.put(Groovy2Compiler.GROOVY2_COMPILER_PARAMS_CUSTOMIZERS, Arrays.asList(new String[] {"org.codehaus.groovy.control.customizers.ImportCustomizer"}));
compiler = new Groovy2Compiler(compilerParams);
customizers = (List)f.get(compiler);
assertTrue(customizers.size() == 1, "one valid object expected");
// list with invalid objects
compilerParams = new HashMap<String, Object>();
compilerParams.put(Groovy2Compiler.GROOVY2_COMPILER_PARAMS_CUSTOMIZERS, Arrays.asList(new Object[] {"org.codehaus.groovy.control.customizers.ImportCustomizer", "org.codehaus.groovy.control.customizers.ImportCustomizer", new HashMap<String, Object>(), null}));
compiler = new Groovy2Compiler(compilerParams);
customizers = (List)f.get(compiler);
assertTrue(customizers.size() == 2, "two valid objects expected");
}