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()));
}
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;
}
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]");
}
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]");
}
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");
}
Aggregations