Search in sources :

Example 6 with ClassInjector

use of grails.compiler.ast.ClassInjector in project grails-core by grails.

the class GrailsAwareInjectionOperation method call.

@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
    URL url = null;
    final String filename = source.getName();
    Resource resource = new FileSystemResource(filename);
    if (resource.exists()) {
        try {
            url = resource.getURL();
        } catch (IOException e) {
        // ignore
        }
    }
    ClassInjector[] classInjectors1 = getLocalClassInjectors();
    if (classInjectors1 == null || classInjectors1.length == 0) {
        classInjectors1 = getClassInjectors();
    }
    for (ClassInjector classInjector : classInjectors1) {
        if (classInjector.shouldInject(url)) {
            classInjector.performInjection(source, context, classNode);
        }
    }
}
Also used : FileSystemResource(org.grails.io.support.FileSystemResource) Resource(org.grails.io.support.Resource) FileSystemResource(org.grails.io.support.FileSystemResource) IOException(java.io.IOException) URL(java.net.URL) GlobalClassInjector(grails.compiler.ast.GlobalClassInjector) ClassInjector(grails.compiler.ast.ClassInjector)

Example 7 with ClassInjector

use of grails.compiler.ast.ClassInjector in project grails-core by grails.

the class ArtefactTypeAstTransformation method performInjection.

public static void performInjection(SourceUnit sourceUnit, ClassNode cNode, Collection<ClassInjector> injectors) {
    try {
        for (ClassInjector injector : injectors) {
            if (!GrailsASTUtils.isApplied(cNode, injector.getClass())) {
                GrailsASTUtils.markApplied(cNode, injector.getClass());
                injector.performInjectionOnAnnotatedClass(sourceUnit, cNode);
            }
        }
    } catch (RuntimeException e) {
        try {
            GrailsConsole.getInstance().error("Error occurred calling AST injector: " + e.getMessage(), e);
        } catch (Throwable t) {
        // ignore it
        }
        throw e;
    }
}
Also used : GrailsArtefactClassInjector(grails.compiler.ast.GrailsArtefactClassInjector) GlobalClassInjector(grails.compiler.ast.GlobalClassInjector) ClassInjector(grails.compiler.ast.ClassInjector) AllArtefactClassInjector(grails.compiler.ast.AllArtefactClassInjector)

Example 8 with ClassInjector

use of grails.compiler.ast.ClassInjector in project grails-core by grails.

the class ArtefactTypeAstTransformation method performInjectionOnArtefactType.

public void performInjectionOnArtefactType(SourceUnit sourceUnit, ClassNode cNode, String artefactType) {
    List<ClassInjector> injectors = findInjectors(artefactType, GrailsAwareInjectionOperation.getClassInjectors());
    for (ClassInjector injector : injectors) {
        if (injector instanceof CompilationUnitAware) {
            ((CompilationUnitAware) injector).setCompilationUnit(this.compilationUnit);
        }
    }
    performInjection(sourceUnit, cNode, injectors);
}
Also used : CompilationUnitAware(groovy.transform.CompilationUnitAware) GrailsArtefactClassInjector(grails.compiler.ast.GrailsArtefactClassInjector) GlobalClassInjector(grails.compiler.ast.GlobalClassInjector) ClassInjector(grails.compiler.ast.ClassInjector) AllArtefactClassInjector(grails.compiler.ast.AllArtefactClassInjector)

Aggregations

ClassInjector (grails.compiler.ast.ClassInjector)8 GlobalClassInjector (grails.compiler.ast.GlobalClassInjector)4 AllArtefactClassInjector (grails.compiler.ast.AllArtefactClassInjector)3 GrailsArtefactClassInjector (grails.compiler.ast.GrailsArtefactClassInjector)2 IOException (java.io.IOException)2 FileSystemResource (org.grails.io.support.FileSystemResource)2 Resource (org.grails.io.support.Resource)2 AnnotatedClassInjector (grails.compiler.ast.AnnotatedClassInjector)1 GrailsDomainClassInjector (grails.compiler.ast.GrailsDomainClassInjector)1 GroovyPageInjector (grails.compiler.ast.GroovyPageInjector)1 CompilationUnitAware (groovy.transform.CompilationUnitAware)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 AbstractGrailsArtefactTransformer (org.grails.compiler.injection.AbstractGrailsArtefactTransformer)1 PathMatchingResourcePatternResolver (org.grails.io.support.PathMatchingResourcePatternResolver)1 AnnotationVisitor (org.springframework.asm.AnnotationVisitor)1 ClassReader (org.springframework.asm.ClassReader)1 ClassVisitor (org.springframework.asm.ClassVisitor)1