本文整理汇总了Java中org.codehaus.groovy.control.CompilationUnit类的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit类的具体用法?Java CompilationUnit怎么用?Java CompilationUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnit类属于org.codehaus.groovy.control包,在下文中一共展示了CompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCompilationUnit
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
@Override
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) {
CompilationUnit compilationUnit = super.createCompilationUnit(config, source);
if ("/groovy/script".equals(source.getLocation().getPath())) {
return compilationUnit;
}
for (File file : FileUtils.listFiles(new File(FileUtils.getTempDirectory(), Configuration.GROOVY), new String[]{"groovy"}, true)) {
String srcPath = source.getLocation().getPath();
String flnPath = null;
try {
flnPath = file.getCanonicalPath();
} catch (IOException e) {
flnPath = file.getAbsolutePath();
}
if (!srcPath.equals(flnPath)) {
compilationUnit.addSource(file);
}
}
return compilationUnit;
}
示例2: createCollector
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
@Override
public ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
InnerLoader loader = AccessController
.doPrivileged(new PrivilegedAction<InnerLoader>() {
@Override
public InnerLoader run() {
return new InnerLoader(ExtendedGroovyClassLoader.this) {
// Don't return URLs from the inner loader so that Tomcat only
// searches the parent. Fixes 'TLD skipped' issues
@Override
public URL[] getURLs() {
return NO_URLS;
}
};
}
});
return new ExtendedClassCollector(loader, unit, su);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ExtendedGroovyClassLoader.java
示例3: patchCompilationUnit
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
public void patchCompilationUnit(CompilationUnit compilationUnit, GroovyResourceLoader resourceLoader, File[] srcFiles) {
File baseDir = guessBaseDir(srcFiles);
if (baseDir == null) {
return;
}
GriffonCompilerContext.basedir = baseDir.getPath();
GriffonCompilerContext.projectName = "IntelliJIDEARulezzzzz";
GriffonCompilerContext.setup();
if (!GriffonCompilerContext.getConfigOption(CommandLineConstants.KEY_DISABLE_AUTO_IMPORTS)) {
DefaultImportCompilerCustomizer customizer = new DefaultImportCompilerCustomizer();
customizer.collectDefaultImportsPerArtifact();
compilationUnit.addPhaseOperation(customizer, customizer.getPhase().getPhaseNumber());
}
}
示例4: makeCompileUnit
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
protected CompilationUnit makeCompileUnit(GroovyClassLoader loader) {
Map<String, Object> options = configuration.getJointCompilationOptions();
if (options != null) {
if (keepStubs) {
options.put("keepStubs", Boolean.TRUE);
}
if (stubDir != null) {
options.put("stubDir", stubDir);
} else {
try {
File tempStubDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
temporaryFiles.add(tempStubDir);
options.put("stubDir", tempStubDir);
} catch (IOException ioe) {
throw new BuildException(ioe);
}
}
return new JavaAwareCompilationUnit(configuration, loader);
} else {
return new CompilationUnit(configuration, null, loader);
}
}
示例5: doExtendTraits
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
/**
* Given a class node, if this class node implements a trait, then generate all the appropriate
* code which delegates calls to the trait. It is safe to call this method on a class node which
* does not implement a trait.
* @param cNode a class node
* @param unit the source unit
*/
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
if (cNode.isInterface()) return;
boolean isItselfTrait = Traits.isTrait(cNode);
SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
if (isItselfTrait) {
checkTraitAllowed(cNode, unit);
return;
}
if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) {
List<ClassNode> traits = findTraits(cNode);
for (ClassNode trait : traits) {
TraitHelpersTuple helpers = Traits.findHelpers(trait);
applyTrait(trait, cNode, helpers);
superCallTransformer.visitClass(cNode);
if (unit!=null) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader());
collector.visitClass(cNode);
}
}
}
}
示例6: registerASTTransformations
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
private void registerASTTransformations(final ClassNode helper) {
ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(
unit, compilationUnit.getTransformLoader()
);
collector.visitClass(helper);
// Perform an additional phase which has to be done *after* type checking
compilationUnit.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() {
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
if (classNode==helper) {
PostTypeCheckingExpressionReplacer replacer = new PostTypeCheckingExpressionReplacer(source);
replacer.visitClass(helper);
}
}
}, CompilePhase.INSTRUCTION_SELECTION.getPhaseNumber());
}
示例7: resolveClassNode
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
ClassNode dummyClass = new ClassNode("dummy",0, ClassHelper.OBJECT_TYPE);
dummyClass.setModule(new ModuleNode(sourceUnit));
dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
MethodNode dummyMN = new MethodNode(
"dummy",
0,
parsedNode,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
EmptyStatement.INSTANCE
);
dummyMN.setGenericsTypes(mn.getGenericsTypes());
dummyClass.addMethod(dummyMN);
ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
@Override
public void addError(final String msg, final ASTNode expr) {
sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
}
};
visitor.startResolving(dummyClass, sourceUnit);
return dummyMN.getReturnType();
}
示例8: GradleResolveVisitor
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
public GradleResolveVisitor(CompilationUnit cu, String[] exportedPackages, Map<String, List<String>> simpleNameToFQN) {
super(cu);
compilationUnit = cu;
this.classNodeResolver = new ClassNodeResolver();
this.simpleNameToFQN = simpleNameToFQN;
this.gradlePublicPackages = exportedPackages;
}
示例9: register
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
public void register(CompilationUnit compilationUnit) {
new FilteringScriptTransformer(filter).register(compilationUnit);
new TaskDefinitionScriptTransformer().register(compilationUnit);
new FixMainScriptTransformer().register(compilationUnit);
new StatementLabelsScriptTransformer().register(compilationUnit);
new ModelBlockTransformer(scriptSource.getDisplayName(), scriptSource.getResource().getLocation().getURI()).register(compilationUnit);
imperativeStatementDetectingTransformer.register(compilationUnit);
}
示例10: getPhaseOperations
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private LinkedList[] getPhaseOperations(CompilationUnit compilationUnit) {
try {
Field field = CompilationUnit.class.getDeclaredField("phaseOperations");
field.setAccessible(true);
LinkedList[] phaseOperations = (LinkedList[]) field.get(compilationUnit);
return phaseOperations;
}
catch (Exception ex) {
throw new IllegalStateException(
"Phase operations not available from compilation unit");
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:GroovyCompiler.java
示例11: processConversionOperations
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private void processConversionOperations(LinkedList conversionOperations) {
int index = getIndexOfASTTransformationVisitor(conversionOperations);
conversionOperations.add(index, new CompilationUnit.SourceUnitOperation() {
@Override
public void call(SourceUnit source) throws CompilationFailedException {
ASTNode[] nodes = new ASTNode[] { source.getAST() };
for (ASTTransformation transformation : GroovyCompiler.this.transformations) {
transformation.visit(nodes, source);
}
}
});
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:GroovyCompiler.java
示例12: execute
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
public long execute() throws Exception {
ClassLoader cl = new URLClassLoader(classpath, ClassLoader.getSystemClassLoader().getParent());
GroovyClassLoader gcl = new GroovyClassLoader(cl);
CompilationUnit cu = new CompilationUnit(new CompilerConfiguration(), null, gcl, new GroovyClassLoader(this.getClass().getClassLoader()));
for (File source : sources) {
cu.addSource(source);
}
long sd = System.nanoTime();
cu.compile(CompilePhase.CLASS_GENERATION.getPhaseNumber());
long dur = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sd);
return dur;
}
示例13: GroovyTypeCheckingExtensionSupport
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
/**
* Builds a type checking extension relying on a Groovy script (type checking DSL).
*
* @param typeCheckingVisitor the type checking visitor
* @param scriptPath the path to the type checking script (in classpath)
* @param compilationUnit
*/
public GroovyTypeCheckingExtensionSupport(
final StaticTypeCheckingVisitor typeCheckingVisitor,
final String scriptPath, final CompilationUnit compilationUnit) {
super(typeCheckingVisitor);
this.scriptPath = scriptPath;
this.compilationUnit = compilationUnit;
}
示例14: addDynamicOuterClassAccessorsCallback
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
private void addDynamicOuterClassAccessorsCallback(final ClassNode outer) {
if (outer != null && !isStaticallyCompiled(outer)
&& outer.getNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK) == null) {
outer.putNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK, new CompilationUnit.PrimaryClassNodeOperation() {
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
if (classNode == outer) {
addPrivateBridgeMethods(classNode);
addPrivateFieldsAccessors(classNode);
}
}
});
}
}
示例15: adjustSuperClass
import org.codehaus.groovy.control.CompilationUnit; //导入依赖的package包/类
private Class adjustSuperClass(Class superClass, final Class[] interfaces) {
boolean isSuperClassAnInterface = superClass.isInterface();
if (!isSuperClassAnInterface) {
return superClass;
}
Class result = Object.class;
Set<ClassNode> traits = new LinkedHashSet<ClassNode>();
// check if it's a trait
collectTraits(superClass, traits);
if (interfaces != null) {
for (Class anInterface : interfaces) {
collectTraits(anInterface, traits);
}
}
if (!traits.isEmpty()) {
String name = superClass.getName() + "$TraitAdapter";
ClassNode cn = new ClassNode(name, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE, traits.toArray(new ClassNode[traits.size()]), null);
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")
List<GroovyClass> classes = (List<GroovyClass>) cu.getClasses();
for (GroovyClass groovyClass : classes) {
if (groovyClass.getName().equals(name)) {
return loader.defineClass(name, groovyClass.getBytes());
}
}
}
return result;
}