Search in sources :

Example 16 with ModuleNode

use of org.codehaus.groovy.ast.ModuleNode in project spring-boot by spring-projects.

the class AnnotatedNodeASTTransformation method visit.

@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
    this.sourceUnit = source;
    List<AnnotationNode> annotationNodes = new ArrayList<>();
    ClassVisitor classVisitor = new ClassVisitor(source, annotationNodes);
    for (ASTNode node : nodes) {
        if (node instanceof ModuleNode) {
            ModuleNode module = (ModuleNode) node;
            visitAnnotatedNode(module.getPackage(), annotationNodes);
            for (ImportNode importNode : module.getImports()) {
                visitAnnotatedNode(importNode, annotationNodes);
            }
            for (ImportNode importNode : module.getStarImports()) {
                visitAnnotatedNode(importNode, annotationNodes);
            }
            for (Map.Entry<String, ImportNode> entry : module.getStaticImports().entrySet()) {
                visitAnnotatedNode(entry.getValue(), annotationNodes);
            }
            for (Map.Entry<String, ImportNode> entry : module.getStaticStarImports().entrySet()) {
                visitAnnotatedNode(entry.getValue(), annotationNodes);
            }
            for (ClassNode classNode : module.getClasses()) {
                visitAnnotatedNode(classNode, annotationNodes);
                classNode.visitContents(classVisitor);
            }
        }
    }
    processAnnotationNodes(annotationNodes);
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ArrayList(java.util.ArrayList) ASTNode(org.codehaus.groovy.ast.ASTNode) ImportNode(org.codehaus.groovy.ast.ImportNode) Map(java.util.Map) ModuleNode(org.codehaus.groovy.ast.ModuleNode)

Example 17 with ModuleNode

use of org.codehaus.groovy.ast.ModuleNode in project intellij-community by JetBrains.

the class GroovyCompilerWrapper method getCompiledFiles.

private List<OutputItem> getCompiledFiles(CompilationUnit compilationUnit) throws IOException {
    File targetDirectory = compilationUnit.getConfiguration().getTargetDirectory();
    if (forStubs) {
        return getStubOutputItems(compilationUnit, targetDirectory);
    }
    final SortedSet<String> allClasses = new TreeSet<String>();
    //noinspection unchecked
    List<GroovyClass> listOfClasses = compilationUnit.getClasses();
    for (GroovyClass listOfClass : listOfClasses) {
        allClasses.add(listOfClass.getName());
    }
    List<OutputItem> compiledFiles = new ArrayList<OutputItem>();
    for (Iterator iterator = compilationUnit.iterator(); iterator.hasNext(); ) {
        SourceUnit sourceUnit = (SourceUnit) iterator.next();
        String fileName = sourceUnit.getName();
        //for debug purposes
        //System.out.println("source: " + fileName);
        //System.out.print("classes:");
        final ModuleNode ast = sourceUnit.getAST();
        final List<ClassNode> topLevelClasses = ast.getClasses();
        for (ClassNode classNode : topLevelClasses) {
            final String topLevel = classNode.getName();
            final String nested = topLevel + "$";
            final SortedSet<String> tail = allClasses.tailSet(topLevel);
            for (Iterator<String> tailItr = tail.iterator(); tailItr.hasNext(); ) {
                String className = tailItr.next();
                if (className.equals(topLevel) || className.startsWith(nested)) {
                    tailItr.remove();
                    compiledFiles.add(new OutputItem(targetDirectory, className.replace('.', '/') + ".class", fileName));
                } else {
                    break;
                }
            }
        }
    }
    return compiledFiles;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) GroovyClass(org.codehaus.groovy.tools.GroovyClass) File(java.io.File) ModuleNode(org.codehaus.groovy.ast.ModuleNode)

Aggregations

ModuleNode (org.codehaus.groovy.ast.ModuleNode)17 ClassNode (org.codehaus.groovy.ast.ClassNode)9 ImportNode (org.codehaus.groovy.ast.ImportNode)6 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)5 Expression (org.codehaus.groovy.ast.expr.Expression)5 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)5 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)5 ASTNode (org.codehaus.groovy.ast.ASTNode)4 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)4 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)4 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)4 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)4 File (java.io.File)3 MethodNode (org.codehaus.groovy.ast.MethodNode)3 AnnotationConstantExpression (org.codehaus.groovy.ast.expr.AnnotationConstantExpression)3 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)3 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)3 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)3 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)3 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)3