blackdrag commented on code in PR #3293:
URL: https://github.com/apache/groovy/pull/3293#discussion_r4594248823


##########
src/main/java/org/codehaus/groovy/control/ResolveVisitor.java:
##########
@@ -474,6 +483,102 @@ private void resolveOrFail(final ClassNode type, final 
String msg, final ASTNode
         addError("unable to resolve class " + type.toString(false) + msg, 
node);
     }
 
+    /**
+     * JLS 6.5.5.1, 8.1.3, 8.5: within {@code Outer<T>}, the simple name 
{@code Inner}
+     * of an inner class is the type {@code Outer<T>.Inner}, and within a 
subclass that
+     * extends {@code Outer<String>} it is {@code Outer<String>.Inner}. 
Neither is the
+     * raw type {@code Outer.Inner}. Records the enclosing type for such a 
name. A name
+     * used where the type variables are out of scope, as in a static method, 
stays raw.
+     */
+    private void setOuterClassTypeOfSimpleName(ClassNode type) {
+        while (type.isArray()) type = type.getComponentType();
+        if (!type.isRedirectNode() || type.isGenericsPlaceHolder() || 
type.getOuterClassType() != null) return;
+        String name = type.getUnresolvedName();
+        if (name.indexOf('.') != -1 || name.indexOf('$') != -1) return; // 
Outer.Inner is the raw type

Review Comment:
   are you aware that `I$O` is a legal class name, even for a top level class?



##########
src/main/java/org/codehaus/groovy/control/ResolveVisitor.java:
##########
@@ -474,6 +483,102 @@ private void resolveOrFail(final ClassNode type, final 
String msg, final ASTNode
         addError("unable to resolve class " + type.toString(false) + msg, 
node);
     }
 
+    /**
+     * JLS 6.5.5.1, 8.1.3, 8.5: within {@code Outer<T>}, the simple name 
{@code Inner}
+     * of an inner class is the type {@code Outer<T>.Inner}, and within a 
subclass that
+     * extends {@code Outer<String>} it is {@code Outer<String>.Inner}. 
Neither is the
+     * raw type {@code Outer.Inner}. Records the enclosing type for such a 
name. A name
+     * used where the type variables are out of scope, as in a static method, 
stays raw.
+     */
+    private void setOuterClassTypeOfSimpleName(ClassNode type) {
+        while (type.isArray()) type = type.getComponentType();
+        if (!type.isRedirectNode() || type.isGenericsPlaceHolder() || 
type.getOuterClassType() != null) return;
+        String name = type.getUnresolvedName();
+        if (name.indexOf('.') != -1 || name.indexOf('$') != -1) return; // 
Outer.Inner is the raw type
+        ClassNode inner = type.redirect(), outer = inner.getOuterClass();
+        if (outer == null || isStaticMember(inner)) return;
+        if (type.getGenericsTypes() == null && inner.getGenericsTypes() != 
null) return; // raw type
+
+        for (ClassNode cn = currentClass; cn != null; cn = cn.getOuterClass()) 
{
+            boolean declares = cn.equals(outer);
+            if (declares || inherits(cn, outer)) {
+                ClassNode outerType = typeOfThis(cn);
+                if (outerType != null && !declares) {
+                    outerType = GenericsUtils.parameterizeType(outerType, 
outer);
+                }
+                if (outerType != null && (outerType.getOuterClassType() != null
+                        || (outerType.isRedirectNode() && 
outerType.getGenericsTypes() != null))) {
+                    type.setOuterClassType(outerType);
+                }
+                return;
+            }
+            if (isRecord(cn)) return; // the type variables of its enclosing 
classes are out of scope
+        }
+    }
+
+    private static boolean isStaticMember(final ClassNode cn) {
+        return isStaticMemberType(cn) || isRecord(cn);
+    }
+
+    /**
+     * A nested record is implicitly static (JLS 8.10), which its declaration 
does not
+     * show until {@code RecordTypeASTTransformation} has run.
+     */
+    private static boolean isRecord(final ClassNode cn) {
+        for (AnnotationNode annotation : cn.getAnnotations()) {
+            String name = annotation.getClassNode().getName();
+            if (name.endsWith("RecordType") || name.endsWith("RecordBase")) 
return true;

Review Comment:
   So I cannot have "@ARecordType class Foo{}"?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to