Skip to content

Commit 7dd818d

Browse files
committed
next step
1 parent 6b8ced2 commit 7dd818d

File tree

6 files changed

+103
-137
lines changed

6 files changed

+103
-137
lines changed

src/main/java/groovy/lang/MetaClassImpl.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private void fillMethodIndex() {
380380

381381
inheritInterfaceNewMetaMethods(interfaces);
382382

383-
if (isGroovyObject) {
383+
if (isGroovyObject()) {
384384
metaMethodIndex.copyMethodsToSuper(); // methods --> methodsForSuper
385385
connectMultimethods(superClasses, firstGroovySuper);
386386
removeMultimethodsOverloadedWithPrivateMethods();
@@ -662,7 +662,7 @@ private CachedClass calcFirstGroovySuperClass(final List<CachedClass> superClass
662662
}
663663

664664
if (firstGroovy == null) {
665-
return isGroovyObject ? theCachedClass.getCachedSuperClass() : theCachedClass;
665+
return isGroovyObject() ? theCachedClass.getCachedSuperClass() : theCachedClass;
666666
}
667667
// Closure for closures and GroovyObjectSupport for extenders (including Closure)
668668
if (firstGroovy.getTheClass() == GroovyObjectSupport.class) {
@@ -1490,13 +1490,15 @@ public Object invokeStaticMethod(final Object object, final String methodName, f
14901490
try {
14911491
return invokeStaticMissingMethod(theClass, methodName, nonNullArguments);
14921492
} catch (MissingMethodException missing) {
1493-
Class<?> outerClass = theClass.getEnclosingClass();
1494-
if (outerClass != null) {
1495-
try {
1493+
if (isGroovyObject()) { // GROOVY-11823, et al.
1494+
var outerClass = theClass.getEnclosingClass();
1495+
if (outerClass != null && object instanceof Class) {
14961496
MetaClass omc = registry.getMetaClass(outerClass);
1497-
return omc.invokeStaticMethod(outerClass, methodName, arguments);
1498-
} catch (MissingMethodException mme) {
1499-
missing.addSuppressed(mme);
1497+
try {
1498+
return omc.invokeStaticMethod(outerClass, methodName, arguments);
1499+
} catch (MissingMethodException mme) {
1500+
missing.addSuppressed(mme);
1501+
}
15001502
}
15011503
}
15021504
throw missing;
@@ -1928,13 +1930,15 @@ private Object getClassProperty(final Class<?> sender, final Class<?> receiver,
19281930
// try $static_propertyMissing / throw MissingPropertyException
19291931
return invokeStaticMissingProperty(receiver, name, null, true);
19301932
} catch (MissingPropertyException missing) {
1931-
Class<?> outerClass = theClass.getEnclosingClass();
1932-
if (outerClass != null && sender.isNestmateOf(outerClass)) {
1933-
try {
1934-
MetaClass omc = registry.getMetaClass(outerClass);
1935-
return omc.getProperty(sender, outerClass, name, false, false);
1936-
} catch (MissingPropertyException mpe) {
1937-
missing.addSuppressed(mpe);
1933+
if (isGroovyObject()) { // GROOVY-11823, et al.
1934+
var outerClass = theClass.getEnclosingClass();
1935+
if (outerClass != null && sender.isNestmateOf(outerClass)) {
1936+
try {
1937+
MetaClass omc = registry.getMetaClass(outerClass);
1938+
return omc.getProperty(sender, outerClass, name, false, false);
1939+
} catch (MissingPropertyException mpe) {
1940+
missing.addSuppressed(mpe);
1941+
}
19381942
}
19391943
}
19401944
throw missing;
@@ -2082,7 +2086,7 @@ public Object getProperty(final Object receiver) {
20822086
} catch (NoSuchFieldException e) {
20832087
}
20842088
}
2085-
return omc.getProperty(outerClass, outer, name, false, false);
2089+
return omc.getProperty(outerClass, outer, getName(), false, false);
20862090
} catch (MissingPropertyException suppressed) {
20872091
mpe.addSuppressed(suppressed);
20882092
} catch (Throwable t) {
@@ -2837,14 +2841,16 @@ public void setProperty(final Class sender, final Object object, final String na
28372841
try {
28382842
invokeStaticMissingProperty(object, name, newValue, false);
28392843
} catch (MissingPropertyException missing) {
2840-
Class<?> outerClass = theClass.getEnclosingClass();
2841-
if (outerClass != null && sender.isNestmateOf(outerClass)) {
2842-
try {
2843-
MetaClass omc = registry.getMetaClass(outerClass);
2844-
omc.setProperty(sender, outerClass, name, newValue, false, false);
2845-
return;
2846-
} catch (MissingPropertyException mpe) {
2847-
missing.addSuppressed(mpe);
2844+
if (isGroovyObject()) { // GROOVY-11823, et al.
2845+
var outerClass = theClass.getEnclosingClass();
2846+
if (outerClass != null && sender.isNestmateOf(outerClass)) {
2847+
try {
2848+
MetaClass omc = registry.getMetaClass(outerClass);
2849+
omc.setProperty(sender, outerClass, name, newValue, false, false);
2850+
return;
2851+
} catch (MissingPropertyException mpe) {
2852+
missing.addSuppressed(mpe);
2853+
}
28482854
}
28492855
}
28502856
throw missing;

src/main/java/org/codehaus/groovy/classgen/EnumCompletionVisitor.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import static org.codehaus.groovy.transform.sc.StaticCompilationVisitor.isStaticallyCompiled;
5454
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
5555
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
56-
import static org.objectweb.asm.Opcodes.ACC_STATIC;
5756
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
5857

5958
/**
@@ -222,19 +221,6 @@ private void addOuterClassDispatch(final InnerClassNode innerClass, final ClassN
222221
}
223222
);
224223

225-
visitor.addMissingHandler(
226-
innerClass,
227-
"$static_methodMissing",
228-
ACC_PUBLIC | ACC_STATIC,
229-
OBJECT_TYPE,
230-
params(param(STRING_TYPE, "name"), param(OBJECT_TYPE, "args")),
231-
(methodBody, parameters) -> {
232-
InnerClassVisitorHelper.setMethodDispatcherCode(methodBody, classX(outerClass), parameters);
233-
}
234-
);
235-
236-
//
237-
238224
visitor.addMissingHandler(
239225
innerClass,
240226
"propertyMissing",
@@ -246,19 +232,6 @@ private void addOuterClassDispatch(final InnerClassNode innerClass, final ClassN
246232
}
247233
);
248234

249-
visitor.addMissingHandler(
250-
innerClass,
251-
"$static_propertyMissing",
252-
ACC_PUBLIC | ACC_STATIC,
253-
OBJECT_TYPE,
254-
params(param(STRING_TYPE, "name")),
255-
(methodBody, parameters) -> {
256-
InnerClassVisitorHelper.setPropertyGetterDispatcher(methodBody, classX(outerClass), parameters);
257-
}
258-
);
259-
260-
//
261-
262235
visitor.addMissingHandler(
263236
innerClass,
264237
"propertyMissing",
@@ -269,16 +242,5 @@ private void addOuterClassDispatch(final InnerClassNode innerClass, final ClassN
269242
InnerClassVisitorHelper.setPropertySetterDispatcher(methodBody, classX(outerClass), parameters);
270243
}
271244
);
272-
273-
visitor.addMissingHandler(
274-
innerClass,
275-
"$static_propertyMissing",
276-
ACC_PUBLIC | ACC_STATIC,
277-
VOID_TYPE,
278-
params(param(STRING_TYPE, "name"), param(OBJECT_TYPE, "value")),
279-
(methodBody, parameters) -> {
280-
InnerClassVisitorHelper.setPropertySetterDispatcher(methodBody, classX(outerClass), parameters);
281-
}
282-
);
283245
}
284246
}

src/main/java/org/codehaus/groovy/classgen/InnerClassCompletionVisitor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static org.codehaus.groovy.ast.ClassHelper.VOID_TYPE;
5555
import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
5656
import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
57+
import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX;
5758
import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
5859
import static org.codehaus.groovy.ast.tools.GeneralUtils.castX;
5960
import static org.codehaus.groovy.ast.tools.GeneralUtils.catchS;
@@ -64,7 +65,6 @@
6465
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
6566
import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
6667
import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
67-
import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
6868
import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
6969
import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
7070
import static org.codehaus.groovy.ast.tools.GeneralUtils.tryCatchS;
@@ -319,14 +319,12 @@ public void visit(final MethodVisitor mv) {
319319
Parameter catchParam = param(OBJECT_TYPE, "notFound"); // dummy type
320320
ClassNode exceptionT;
321321
Expression newException;
322-
Expression selfType = varX("this");
323-
if ((modifiers & ACC_STATIC) == 0) selfType = callX(selfType, "getClass");
324322
if (methodName.endsWith("methodMissing")) {
325323
exceptionT = ClassHelper.make(groovy.lang.MissingMethodException.class);
326-
newException = ctorX(exceptionT, args(propX(varX(catchParam),"method"), selfType, propX(varX(catchParam),"arguments")));
324+
newException = ctorX(exceptionT, args(callX(varX(catchParam),"getMethod"), callThisX("getClass"), callX(varX(catchParam),"getArguments")));
327325
} else {
328326
exceptionT = ClassHelper.make(groovy.lang.MissingPropertyException.class);
329-
newException = ctorX(exceptionT, args(propX(varX(catchParam), "property"), selfType, propX(varX(catchParam), "cause")));
327+
newException = ctorX(exceptionT, args(callX(varX(catchParam),"getProperty"), callThisX("getClass"), callX(varX(catchParam),"getCause")));
330328
}
331329
catchParam.setType(exceptionT);
332330
catchParam.setOriginType(exceptionT);

src/test/groovy/bugs/Groovy7938Bug.groovy

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/test/groovy/gls/enums/EnumTest.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,23 @@ class EnumTest extends CompilableTestSupport {
338338
'''
339339
}
340340

341+
void testInnerEnumInitWithUnqualifiedOuterClassValue() {
342+
assertScript '''
343+
class C {
344+
private static int ONE() { 1 }
345+
enum E {
346+
FOO(1 + ONE())
347+
final value
348+
E(value) {
349+
this.value = value
350+
}
351+
}
352+
}
353+
354+
assert C.E.FOO.value == 2
355+
'''
356+
}
357+
341358
// GROOVY-3693
342359
void testStaticFieldInitValuesInAStaticBlock() {
343360
// trigger enum class load to test it - asserts are present in the enum

src/test/groovy/gls/innerClass/InnerClassTest.groovy

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,59 @@ final class InnerClassTest {
12441244
'''
12451245
}
12461246

1247+
// GROOVY-7938
1248+
@Test
1249+
void testUsageOfOuterMethod9() {
1250+
assertScript '''
1251+
class Outer {
1252+
Integer barCount = 0
1253+
static Integer fooCount = 0
1254+
void incBar() { barCount++ }
1255+
static void incFoo() { fooCount++ }
1256+
Inner innerFactory() { new Inner() }
1257+
1258+
static class Nested {
1259+
static void nestedIncFoo() { incFoo() }
1260+
static class NestedNested {
1261+
static void nestedNestedIncFoo() { incFoo() }
1262+
}
1263+
}
1264+
class Inner {
1265+
void innerIncFoo() { incFoo() }
1266+
static void staticInnerIncFoo() { incFoo() }
1267+
InnerInner innerInnerFactory() { new InnerInner() }
1268+
1269+
class InnerInner {
1270+
void innerInnerIncFoo() { incFoo() }
1271+
static void staticInnerInnerIncFoo() { incFoo() }
1272+
}
1273+
}
1274+
}
1275+
1276+
Outer.incFoo()
1277+
Outer.Nested.nestedIncFoo()
1278+
Outer.Nested.NestedNested.nestedNestedIncFoo()
1279+
assert Outer.fooCount == 3
1280+
1281+
new Outer().with {
1282+
incBar()
1283+
incFoo()
1284+
innerFactory().with {
1285+
incBar()
1286+
innerIncFoo()
1287+
staticInnerIncFoo()
1288+
innerInnerFactory().with {
1289+
incBar()
1290+
innerInnerIncFoo()
1291+
staticInnerInnerIncFoo()
1292+
}
1293+
}
1294+
assert barCount == 3
1295+
assert fooCount == 8
1296+
}
1297+
'''
1298+
}
1299+
12471300
@Test
12481301
void testUsageOfOuterMethodOverridden() {
12491302
assertScript '''

0 commit comments

Comments
 (0)