This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new ec5d81bc11 Trivial refactor: eliminate duplicated code
ec5d81bc11 is described below
commit ec5d81bc11b64ab6ed7832a8f676e3604ae06909
Author: Daniel Sun <[email protected]>
AuthorDate: Sun Jun 1 02:25:12 2025 +0900
Trivial refactor: eliminate duplicated code
(cherry picked from commit f42b327929620d0e1e4f01f535c72ade57516246)
---
.../transform/AbstractASTTransformation.java | 62 +++++++++++-----------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
index 3e56632cf7..b7c57072ea 100644
--- a/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
@@ -279,57 +279,57 @@ public abstract class AbstractASTTransformation
implements ASTTransformation, Er
}
public static boolean shouldSkipOnDescriptorUndefinedAware(boolean
checkReturn, Map genericsSpec, MethodNode mNode,
- List<ClassNode>
excludeTypes, List<ClassNode> includeTypes) {
+ List<ClassNode>
excludeTypes, List<ClassNode> includeTypes) {
String descriptor = mNode.getTypeDescriptor();
String descriptorNoReturn =
MethodNodeUtils.methodDescriptorWithoutReturnType(mNode);
- if (excludeTypes != null) {
- for (ClassNode cn : excludeTypes) {
- List<ClassNode> remaining = new LinkedList<>();
- remaining.add(cn);
- Map updatedGenericsSpec = new HashMap(genericsSpec);
- while (!remaining.isEmpty()) {
- ClassNode next = remaining.remove(0);
- if (!isObjectType(next)) {
- updatedGenericsSpec =
GenericsUtils.createGenericsSpec(next, updatedGenericsSpec);
- for (MethodNode mn : next.getMethods()) {
- MethodNode correctedMethodNode =
GenericsUtils.correctToGenericsSpec(updatedGenericsSpec, mn);
- if (checkReturn) {
- String md =
correctedMethodNode.getTypeDescriptor();
- if (md.equals(descriptor)) return true;
- } else {
- String md =
MethodNodeUtils.methodDescriptorWithoutReturnType(correctedMethodNode);
- if (md.equals(descriptorNoReturn)) return true;
- }
- }
- remaining.addAll(Arrays.asList(next.getInterfaces()));
- }
- }
- }
+
+ // Check excludes first - if any match is found, we should skip
+ if (excludeTypes != null && hasMatchingMethodDescriptor(checkReturn,
genericsSpec, descriptor, descriptorNoReturn, excludeTypes)) {
+ return true;
}
- if (includeTypes == null) return false;
- for (ClassNode cn : includeTypes) {
+
+ // Then check includes - if any defined but none match, we should skip
+ if (includeTypes != null && !hasMatchingMethodDescriptor(checkReturn,
genericsSpec, descriptor, descriptorNoReturn, includeTypes)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private static boolean hasMatchingMethodDescriptor(boolean checkReturn,
Map genericsSpec, String descriptor,
+ String
descriptorNoReturn, List<ClassNode> types) {
+ for (ClassNode cn : types) {
List<ClassNode> remaining = new LinkedList<>();
remaining.add(cn);
Map updatedGenericsSpec = new HashMap(genericsSpec);
+
while (!remaining.isEmpty()) {
ClassNode next = remaining.remove(0);
if (!isObjectType(next)) {
updatedGenericsSpec =
GenericsUtils.createGenericsSpec(next, updatedGenericsSpec);
for (MethodNode mn : next.getMethods()) {
MethodNode correctedMethodNode =
GenericsUtils.correctToGenericsSpec(updatedGenericsSpec, mn);
+ String md;
+ String compareTo;
+
if (checkReturn) {
- String md =
correctedMethodNode.getTypeDescriptor();
- if (md.equals(descriptor)) return false;
+ md = correctedMethodNode.getTypeDescriptor();
+ compareTo = descriptor;
} else {
- String md =
MethodNodeUtils.methodDescriptorWithoutReturnType(correctedMethodNode);
- if (md.equals(descriptorNoReturn)) return false;
+ md =
MethodNodeUtils.methodDescriptorWithoutReturnType(correctedMethodNode);
+ compareTo = descriptorNoReturn;
+ }
+
+ if (md.equals(compareTo)) {
+ return true; // Found a match
}
}
remaining.addAll(Arrays.asList(next.getInterfaces()));
}
}
}
- return true;
+
+ return false; // No match found
}
protected boolean checkIncludeExcludeUndefinedAware(AnnotationNode node,
List<String> excludes, List<String> includes, String typeName) {