Skip to content

Commit

Permalink
classgen: upper before outer
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 22, 2024
1 parent 461b871 commit 6553534
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.InnerClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.PropertyNode;
Expand Down Expand Up @@ -455,7 +454,7 @@ private boolean makeGetPropertyWithGetter(final Expression receiver, final Class
getterName = "is" + capitalize(propertyName);
getterNode = receiverType.getGetterMethod(getterName);
}
if (getterNode != null && receiver instanceof ClassExpression && !CLASS_Type.equals(receiverType) && !getterNode.isStatic()) {
if (getterNode != null && !getterNode.isStatic() && receiver instanceof ClassExpression && !CLASS_Type.equals(receiverType)) {
return false;
}

Expand All @@ -464,10 +463,7 @@ private boolean makeGetPropertyWithGetter(final Expression receiver, final Class
// generated by the compiler yet (generated by the Verifier)
PropertyNode propertyNode = receiverType.getProperty(propertyName);
if (getterNode == null && propertyNode != null) {
String prefix = "get";
if (boolean_TYPE.equals(propertyNode.getOriginType())) {
prefix = "is";
}
String prefix = boolean_TYPE.equals(propertyNode.getOriginType()) ? "is" : "get";
getterName = prefix + capitalize(propertyName);
getterNode = new MethodNode(
getterName,
Expand All @@ -488,22 +484,27 @@ private boolean makeGetPropertyWithGetter(final Expression receiver, final Class
return true;
}

if (receiverType instanceof InnerClassNode && !receiverType.isStaticClass()) {
if (makeGetPropertyWithGetter(receiver, receiverType.getOuterClass(), propertyName, safe, implicitThis)) {
return true;
}
}

// GROOVY-7149: check direct interfaces
for (ClassNode node : receiverType.getInterfaces()) {
if (makeGetPropertyWithGetter(receiver, node, propertyName, safe, implicitThis)) {
for (ClassNode traitClass : receiverType.getInterfaces()) {
if (makeGetPropertyWithGetter(receiver, traitClass, propertyName, safe, implicitThis)) {
return true;
}
}
// go upper level
// check super class
ClassNode superClass = receiverType.getSuperClass();
if (superClass != null) {
return makeGetPropertyWithGetter(receiver, superClass, propertyName, safe, implicitThis);
if (makeGetPropertyWithGetter(receiver, superClass, propertyName, safe, implicitThis)) {
return true;
}
}
// check outer class
ClassNode outerClass = receiverType.getOuterClass();
if (implicitThis && outerClass != null
&& !outerClass.implementsInterface(MAP_TYPE)
&& (receiverType.getModifiers() & ACC_STATIC) == 0) {
if (makeGetPropertyWithGetter(receiver, outerClass, propertyName, safe, implicitThis)) {
return true;
}
}

return false;
Expand Down

0 comments on commit 6553534

Please sign in to comment.