Skip to content

Commit

Permalink
GROOVY-8587: remove standard MOP methods from trait helper inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 8, 2023
1 parent 90eedda commit cef3a2c
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 299 deletions.
Expand Up @@ -68,6 +68,7 @@
import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.tryCatchS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
import static org.codehaus.groovy.transform.trait.Traits.isTrait;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
Expand Down Expand Up @@ -101,24 +102,29 @@ protected SourceUnit getSourceUnit() {
public void visitClass(final ClassNode node) {
classNode = node;
thisField = null;
InnerClassNode innerClass = null;
if (!node.isEnum() && !node.isInterface() && node instanceof InnerClassNode) {
innerClass = (InnerClassNode) node;
thisField = innerClass.getField("this$0");
if (innerClass.getVariableScope() == null && innerClass.getDeclaredConstructors().isEmpty()) {

if (node.isEnum() || node.isInterface() || isTrait(node.getOuterClass())) return;

// if the class has an inner class, add methods to support private member access
if (node.getInnerClasses().hasNext()) {
addDispatcherMethods(node);
}

if (node instanceof InnerClassNode) {
thisField = node.getField("this$0");
InnerClassNode innerClass = (InnerClassNode) node;
if (innerClass.getVariableScope() == null && node.getDeclaredConstructors().isEmpty()) {
// add empty default constructor
addGeneratedConstructor(innerClass, ACC_PUBLIC, Parameter.EMPTY_ARRAY, null, null);
}
}
if (node.isEnum() || node.isInterface()) return;
// use Iterator.hasNext() to check for available inner classes
if (node.getInnerClasses().hasNext()) addDispatcherMethods(node);
if (innerClass == null) return;
super.visitClass(node);
boolean innerPojo = hasAnnotation(innerClass, ClassHelper.make(POJO.class))
&& hasAnnotation(innerClass, ClassHelper.make(CompileStatic.class));
if (!innerPojo) {
addMopMethods(innerClass);

super.visitClass(node);

boolean innerPojo = hasAnnotation(node, ClassHelper.make(POJO.class))
&& hasAnnotation(node, ClassHelper.make(CompileStatic.class));
if (!innerPojo) {
addMopMethods(innerClass);
}
}
}

Expand Down

0 comments on commit cef3a2c

Please sign in to comment.