-
Notifications
You must be signed in to change notification settings - Fork 1.9k
GROOVY-11928: Make MetaClassImpl.getProperties() respect @Internal #2467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -252,10 +252,26 @@ public static List<String> tokenize(String rawExcludes) { | |||||
| return rawExcludes == null ? new ArrayList<>() : StringGroovyMethods.tokenize(rawExcludes, ", "); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @see org.apache.groovy.ast.tools.AnnotatedNodeUtils#markAsInternal(AnnotatedNode) | ||||||
| * @since 6.0.0 | ||||||
| */ | ||||||
| public static void markAsInternal(AnnotatedNode node) { | ||||||
| AnnotatedNodeUtils.markAsInternal(node); | ||||||
| } | ||||||
|
|
||||||
| public static boolean deemedInternalName(String name) { | ||||||
| return name.contains("$"); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @see org.apache.groovy.ast.tools.AnnotatedNodeUtils#deemedInternal(AnnotatedNode) | ||||||
| * @since 6.0.0 | ||||||
| */ | ||||||
| public static boolean deemedInternal(AnnotatedNode node) { | ||||||
| return AnnotatedNodeUtils.deemedInternal(node); | ||||||
| } | ||||||
|
|
||||||
| public static boolean shouldSkipUndefinedAware(String name, List<String> excludes, List<String> includes) { | ||||||
| return shouldSkipUndefinedAware(name, excludes, includes, false); | ||||||
| } | ||||||
|
|
@@ -266,6 +282,18 @@ public static boolean shouldSkipUndefinedAware(String name, List<String> exclude | |||||
| (includes != null && !includes.contains(name)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Variant that checks both the name and {@link groovy.transform.Internal @Internal} annotation. | ||||||
| * | ||||||
| * @since 6.0.0 | ||||||
| */ | ||||||
| public static boolean shouldSkipUndefinedAware(AnnotatedNode node, List<String> excludes, List<String> includes, boolean allNames) { | ||||||
| String name = nodeName(node); | ||||||
| return (excludes != null && excludes.contains(name)) || | ||||||
| (!allNames && deemedInternal(node)) || | ||||||
| (includes != null && !includes.contains(name)); | ||||||
| } | ||||||
|
|
||||||
| public static boolean shouldSkip(String name, List<String> excludes, List<String> includes) { | ||||||
| return shouldSkip(name, excludes, includes, false); | ||||||
| } | ||||||
|
|
@@ -276,6 +304,25 @@ public static boolean shouldSkip(String name, List<String> excludes, List<String | |||||
| (includes != null && !includes.isEmpty() && !includes.contains(name)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Variant that checks both the name and {@link groovy.transform.Internal @Internal} annotation. | ||||||
| * | ||||||
| * @since 6.0.0 | ||||||
| */ | ||||||
| public static boolean shouldSkip(AnnotatedNode node, List<String> excludes, List<String> includes, boolean allNames) { | ||||||
| String name = nodeName(node); | ||||||
| return (excludes != null && excludes.contains(name)) || | ||||||
| (!allNames && deemedInternal(node)) || | ||||||
| (includes != null && !includes.isEmpty() && !includes.contains(name)); | ||||||
| } | ||||||
|
|
||||||
| private static String nodeName(AnnotatedNode node) { | ||||||
| if (node instanceof FieldNode fn) return fn.getName(); | ||||||
| if (node instanceof PropertyNode pn) return pn.getName(); | ||||||
| if (node instanceof MethodNode mn) return mn.getName(); | ||||||
| return ""; | ||||||
|
||||||
| return ""; | |
| throw new IllegalArgumentException("Unsupported AnnotatedNode type: " + (node == null ? "null" : node.getClass().getName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cf.getCachedField().isAnnotationPresent(Internal.class)forcesCachedField#getCachedField()which callsReflectionUtils.makeAccessibleInPrivilegedAction(field)(side-effect + overhead) even though we only need to read the annotation. Consider adding/using an annotation accessor onCachedFieldthat does not callmakeAccessible, and use that here to avoid unnecessary accessibility changes during property enumeration.