Search in sources :

Example 6 with PackageNode

use of org.codehaus.groovy.ast.PackageNode in project groovy by apache.

the class GeneralUtils method inSamePackage.

public static boolean inSamePackage(ClassNode first, ClassNode second) {
    PackageNode firstPackage = first.getPackage();
    PackageNode secondPackage = second.getPackage();
    return ((firstPackage == null && secondPackage == null) || firstPackage != null && secondPackage != null && firstPackage.getName().equals(secondPackage.getName()));
}
Also used : PackageNode(org.codehaus.groovy.ast.PackageNode)

Example 7 with PackageNode

use of org.codehaus.groovy.ast.PackageNode in project groovy-core by groovy.

the class ASTHelper method setPackage.

public PackageNode setPackage(String packageName, List<AnnotationNode> annotations) {
    this.packageName = packageName;
    if (packageName != null && packageName.length() > 0) {
        packageName += '.';
    }
    PackageNode packageNode = new PackageNode(packageName);
    packageNode.addAnnotations(annotations);
    output.setPackage(packageNode);
    return packageNode;
}
Also used : PackageNode(org.codehaus.groovy.ast.PackageNode)

Example 8 with PackageNode

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

the class GenericBomAstTransformationTests method transformationOfEmptyPackage.

@Test
public void transformationOfEmptyPackage() {
    this.moduleNode.setPackage(new PackageNode("foo"));
    this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
    assertThat(getValue().toString()).isEqualTo("[test:child:1.0.0]");
}
Also used : PackageNode(org.codehaus.groovy.ast.PackageNode) Test(org.junit.Test)

Example 9 with PackageNode

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

the class GenericBomAstTransformationTests method transformationOfClassWithExistingManagedDependencies.

@Test
public void transformationOfClassWithExistingManagedDependencies() {
    this.moduleNode.setPackage(new PackageNode("foo"));
    ClassNode cls = ClassHelper.make("MyClass");
    this.moduleNode.addClass(cls);
    AnnotationNode annotation = new AnnotationNode(ClassHelper.make(DependencyManagementBom.class));
    annotation.addMember("value", new ConstantExpression("test:parent:1.0.0"));
    cls.addAnnotation(annotation);
    this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
    assertThat(getValue().toString()).isEqualTo("[test:parent:1.0.0, test:child:1.0.0]");
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) PackageNode(org.codehaus.groovy.ast.PackageNode) DependencyManagementBom(org.springframework.boot.groovy.DependencyManagementBom) Test(org.junit.Test)

Example 10 with PackageNode

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

the class GenericBomAstTransformationTests method findAnnotation.

private AnnotationNode findAnnotation() {
    PackageNode packageNode = this.moduleNode.getPackage();
    ClassNode bom = ClassHelper.make(DependencyManagementBom.class);
    if (packageNode != null) {
        if (!packageNode.getAnnotations(bom).isEmpty()) {
            return packageNode.getAnnotations(bom).get(0);
        }
    }
    if (!this.moduleNode.getClasses().isEmpty()) {
        return this.moduleNode.getClasses().get(0).getAnnotations(bom).get(0);
    }
    throw new IllegalStateException("No package or class node found");
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) PackageNode(org.codehaus.groovy.ast.PackageNode)

Aggregations

PackageNode (org.codehaus.groovy.ast.PackageNode)14 ClassNode (org.codehaus.groovy.ast.ClassNode)8 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)6 MethodNode (org.codehaus.groovy.ast.MethodNode)4 Test (org.junit.Test)3 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 Constructor (java.lang.reflect.Constructor)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)2 FieldNode (org.codehaus.groovy.ast.FieldNode)2 ImportNode (org.codehaus.groovy.ast.ImportNode)2 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)2 InterfaceHelperClassNode (org.codehaus.groovy.ast.InterfaceHelperClassNode)2 Parameter (org.codehaus.groovy.ast.Parameter)2 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)2 MopWriter (org.codehaus.groovy.classgen.asm.MopWriter)2 WriterController (org.codehaus.groovy.classgen.asm.WriterController)2 WriterControllerFactory (org.codehaus.groovy.classgen.asm.WriterControllerFactory)2 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)2