本文整理汇总了Java中org.codehaus.groovy.classgen.GeneratorContext类的典型用法代码示例。如果您正苦于以下问题:Java GeneratorContext类的具体用法?Java GeneratorContext怎么用?Java GeneratorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeneratorContext类属于org.codehaus.groovy.classgen包,在下文中一共展示了GeneratorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)
throws CompilationFailedException {
ImportCustomizer importCustomizer = new SmartImportCustomizer(source, context,
classNode);
ClassNode mainClassNode = MainClass.get(source.getAST().getClasses());
// Additional auto configuration
for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) {
if (autoConfiguration.matches(classNode)) {
if (GroovyCompiler.this.configuration.isGuessImports()) {
autoConfiguration.applyImports(importCustomizer);
importCustomizer.call(source, context, classNode);
}
if (classNode.equals(mainClassNode)) {
autoConfiguration.applyToMainClass(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
autoConfiguration.apply(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
}
importCustomizer.call(source, context, classNode);
}
示例2: getStubOutputItems
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@NotNull
static List<OutputItem> getStubOutputItems(CompilationUnit compilationUnit, final File stubDirectory) {
final List<OutputItem> compiledFiles = new ArrayList<OutputItem>();
compilationUnit.applyToPrimaryClassNodes(new CompilationUnit.PrimaryClassNodeOperation() {
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
final String topLevel = classNode.getName();
String fileName = source.getName();
if (fileName.startsWith("file:")) {
try {
fileName = new URL(fileName).getFile();
}
catch (MalformedURLException ignored) {
}
}
OutputItem item = new OutputItem(stubDirectory, topLevel.replace('.', '/') + ".java", fileName);
if (new File(item.getOutputPath()).exists()) {
compiledFiles.add(item);
}
}
});
return compiledFiles;
}
示例3: getClassNode
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
/**
* Convenience routine to get the named ClassNode.
*/
public ClassNode getClassNode(final String name) {
final ClassNode[] result = new ClassNode[]{null};
PrimaryClassNodeOperation handler = new PrimaryClassNodeOperation() {
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) {
if (classNode.getName().equals(name)) {
result[0] = classNode;
}
}
};
try {
applyToPrimaryClassNodes(handler);
} catch (CompilationFailedException e) {
if (debug) e.printStackTrace();
}
return result[0];
}
示例4: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
final ModuleNode ast = source.getAST();
for (Import anImport : imports) {
switch (anImport.type) {
case regular:
ast.addImport(anImport.alias, anImport.classNode);
break;
case staticImport:
ast.addStaticImport(anImport.classNode, anImport.field, anImport.alias);
break;
case staticStar:
ast.addStaticStarImport(anImport.alias, anImport.classNode);
break;
case star:
ast.addStarImport(anImport.star);
break;
}
}
}
示例5: registerASTTransformations
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的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());
}
示例6: apply
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration,
GeneratorContext generatorContext, SourceUnit source, ClassNode classNode)
throws CompilationFailedException {
if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) {
AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith"));
runWith.addMember("value",
new ClassExpression(ClassHelper.make("SpringRunner")));
classNode.addAnnotation(runWith);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:SpringTestCompilerAutoConfiguration.java
示例7: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.codehaus.groovy.control.CompilationUnit.PrimaryClassNodeOperation#call(org.codehaus.groovy.control.SourceUnit, org.codehaus.groovy.classgen.GeneratorContext, org.codehaus.groovy.ast.ClassNode)
*/
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
// Disable global transformations
classNode.addAnnotation(new AnnotationNode(ClassHelper.make(GroovyASTTransformation.class)));
for(ImportNode im: source.getAST().getImports()) {
for(AnnotationNode an: im.getAnnotations()) {
log.info("AnnotationNode: [{}]", an.getClassNode().getName());
}
}
}
示例8: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.codehaus.groovy.control.CompilationUnit.PrimaryClassNodeOperation#call(org.codehaus.groovy.control.SourceUnit, org.codehaus.groovy.classgen.GeneratorContext, org.codehaus.groovy.ast.ClassNode)
*/
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
classNode.setName(source.getName());
final Class<?>[] ifaces = ManagedScript.class.getInterfaces();
for(Class<?> iface: ifaces) {
classNode.addInterface(new ClassNode(iface));
}
}
示例9: apply
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration,
GeneratorContext generatorContext, SourceUnit source, ClassNode classNode)
throws CompilationFailedException {
if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) {
AnnotationNode runwith = new AnnotationNode(ClassHelper.make("RunWith"));
runwith.addMember("value",
new ClassExpression(ClassHelper.make("SpringJUnit4ClassRunner")));
classNode.addAnnotation(runwith);
}
}
示例10: MarkupTemplateEngine
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的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: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
if (classNode.isScriptBody()) {
classNode.setSuperClass(ClassHelper.make(config.getBaseTemplateClass()));
createConstructor(classNode);
transformRunMethod(classNode, source);
VariableScopeVisitor visitor = new VariableScopeVisitor(source);
visitor.visitClass(classNode);
}
}
示例12: call
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
String fileName = source.getName();
ReaderSource reader = source.getSource();
if (reader instanceof FileReaderSource) {
FileReaderSource file = (FileReaderSource) reader;
fileName = file.getFile().getName();
}
if (acceptSource(source) && acceptClass(classNode) && accept(fileName)) {
delegate.call(source, context, classNode);
}
}
示例13: addDynamicOuterClassAccessorsCallback
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的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);
}
}
});
}
}
示例14: getScriptClassDummy
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
public ClassNode getScriptClassDummy() {
if (scriptDummy!=null) {
setScriptBaseClassFromConfig(scriptDummy);
return scriptDummy;
}
String name = getPackageName();
if (name == null) {
name = "";
}
// now let's use the file name to determine the class name
if (getDescription() == null) {
throw new RuntimeException("Cannot generate main(String[]) class for statements when we have no file description");
}
name += GeneratorContext.encodeAsValidClassName(extractClassFromFileDescription());
ClassNode classNode;
if (isPackageInfo()) {
classNode = new ClassNode(name, ACC_ABSTRACT | ACC_INTERFACE, ClassHelper.OBJECT_TYPE);
} else {
classNode = new ClassNode(name, ACC_PUBLIC, ClassHelper.SCRIPT_TYPE);
setScriptBaseClassFromConfig(classNode);
classNode.setScript(true);
classNode.setScriptBody(true);
}
scriptDummy = classNode;
return classNode;
}
示例15: init
import org.codehaus.groovy.classgen.GeneratorContext; //导入依赖的package包/类
@Override
public void init(final AsmClassGenerator asmClassGenerator, final GeneratorContext gcon, final ClassVisitor cv, final ClassNode cn) {
super.init(asmClassGenerator, gcon, cv, cn);
this.callSiteWriter = new StaticTypesCallSiteWriter(this);
this.statementWriter = new StaticTypesStatementWriter(this);
this.typeChooser = new StaticTypesTypeChooser();
this.invocationWriter = new StaticInvocationWriter(this);
this.closureWriter = new StaticTypesClosureWriter(this);
this.unaryExpressionHelper = new StaticTypesUnaryExpressionHelper(this);
CompilerConfiguration config = cn.getCompileUnit().getConfig();
this.binaryExprHelper = config.isIndyEnabled()
? new IndyStaticTypesMultiTypeDispatcher(this)
: new StaticTypesBinaryExpressionMultiTypeDispatcher(this);
}