This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new f1da776 GROOVY-10434: ClassNode isRecord() refactoring: additional
clarification when information will be available
f1da776 is described below
commit f1da776d95156c9467b0a2a697bcb84392839436
Author: Paul King <[email protected]>
AuthorDate: Tue Jan 25 20:15:45 2022 +1000
GROOVY-10434: ClassNode isRecord() refactoring: additional clarification
when information will be available
---
src/main/java/org/codehaus/groovy/ast/ClassNode.java | 14 +++++++++-----
.../groovy/transform/RecordTypeASTTransformation.java | 12 ++++++++++++
.../codehaus/groovy/transform/SealedASTTransformation.java | 6 +++---
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index caeceb8..9d39dc3 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -55,6 +55,7 @@ import static org.codehaus.groovy.ast.ClassHelper.SEALED_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.isObjectType;
import static org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean;
import static org.codehaus.groovy.ast.ClassHelper.isPrimitiveVoid;
+import static
org.codehaus.groovy.transform.RecordTypeASTTransformation.recordNative;
import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
import static org.objectweb.asm.Opcodes.ACC_ANNOTATION;
import static org.objectweb.asm.Opcodes.ACC_ENUM;
@@ -1369,23 +1370,24 @@ public class ClassNode extends AnnotatedNode {
/**
* Checks if the {@link ClassNode} instance represents a native {@code
record}.
- * Check instead for the {@code RecordType} annotation if looking for
records and record-like classes.
+ * Check instead for the {@code RecordBase} annotation if looking for
records and
+ * record-like classes currently being compiled.
*
* @return {@code true} if the instance represents a native {@code record}
- *
* @since 4.0.0
*/
+ @Incubating
public boolean isRecord() {
- return getUnresolvedSuperClass() != null &&
"java.lang.Record".equals(getUnresolvedSuperClass().getName());
+ return recordNative(this);
}
/**
* Gets the record components of record type.
*
* @return {@code RecordComponentNode} instances
- *
* @since 4.0.0
*/
+ @Incubating
public List<RecordComponentNode> getRecordComponents() {
if (redirect != null)
return redirect.getRecordComponents();
@@ -1398,6 +1400,7 @@ public class ClassNode extends AnnotatedNode {
*
* @since 4.0.0
*/
+ @Incubating
public void setRecordComponents(List<RecordComponentNode>
recordComponents) {
if (redirect != null) {
redirect.setRecordComponents(recordComponents);
@@ -1411,7 +1414,8 @@ public class ClassNode extends AnnotatedNode {
}
/**
- * @return true for native and emulated (annotation based) sealed classes
+ * @return {@code true} for native and emulated (annotation based) sealed
classes
+ * @since 4.0.0
*/
@Incubating
public boolean isSealed() {
diff --git
a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
index d47ed5b..e1bf231 100644
---
a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
+++
b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
@@ -26,6 +26,7 @@ import groovy.transform.RecordOptions;
import groovy.transform.RecordTypeMode;
import groovy.transform.options.PropertyHandler;
import org.apache.groovy.ast.tools.MethodNodeUtils;
+import org.apache.groovy.lang.annotation.Incubating;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
@@ -254,6 +255,17 @@ public class RecordTypeASTTransformation extends
AbstractASTTransformation imple
}
}
+ /**
+ * Indicates that the given classnode is a native JVM record class.
+ * For classes being compiled, this will only be valid after the
+ * {@code RecordTypeASTTransformation} transform has been invoked.
+ */
+ @Incubating
+ public static boolean recordNative(ClassNode node) {
+ return node.getUnresolvedSuperClass() != null &&
+
"java.lang.Record".equals(node.getUnresolvedSuperClass().getName());
+ }
+
private void createComponents(ClassNode cNode, List<PropertyNode> pList) {
if (pList.size() > 16) { // Groovy currently only goes to Tuple16
addError("Record has too many components for a components()
method", cNode);
diff --git
a/src/main/java/org/codehaus/groovy/transform/SealedASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/SealedASTTransformation.java
index 5f38c68..9037670 100644
--- a/src/main/java/org/codehaus/groovy/transform/SealedASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/SealedASTTransformation.java
@@ -115,9 +115,9 @@ public class SealedASTTransformation extends
AbstractASTTransformation {
}
/**
- * Reports true if the {@code Sealed} annotation should be included in the
bytecode for
- * a sealed or emulated-sealed class.
- * Will only ever return true after the SealedASTTransformation visit
method has completed.
+ * Reports true if the {@code Sealed} annotation should not be
+ * included in the bytecode for a sealed or emulated-sealed class.
+ * Will only ever return true after the {@code SealedASTTransformation}
transform has been invoked.
*
* @return true if a {@code Sealed} annotation is not required for this
node
*/