Skip to content

Commit 40c8b7c

Browse files
committed
Stop using package protected code
See gh-28799
1 parent 5c2870e commit 40c8b7c

File tree

3 files changed

+61
-53
lines changed

3 files changed

+61
-53
lines changed

spring-core/src/main/java/org/springframework/aot/hint/ReflectionHintsPredicates.java

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* match the expected behavior for reflection.
3737
*
3838
* @author Brian Clozel
39+
* @author Stephane Nicoll
3940
* @since 6.0
4041
*/
4142
public class ReflectionHintsPredicates {
@@ -248,15 +249,17 @@ public boolean test(RuntimeHints runtimeHints) {
248249
abstract Predicate<RuntimeHints> exactMatch();
249250

250251
/**
251-
* Indicate whether the first {@code ExecutableHint} covers the reflection needs for the other one.
252-
* For that, both hints must apply to the same member (same type, name and parameters)
253-
* and the configured {@code ExecutableMode} of the first must cover the second.
252+
* Indicate whether the specified {@code ExecutableHint} covers the
253+
* reflection needs of the specified executable definition.
254+
* @return {@code true} if the member matches (same type, name and parameters),
255+
* and the configured {@code ExecutableMode} is compatibe
254256
*/
255-
static boolean includes(ExecutableHint hint, ExecutableHint other) {
256-
return hint.getName().equals(other.getName())
257-
&& hint.getParameterTypes().equals(other.getParameterTypes())
257+
static boolean includes(ExecutableHint hint, String name,
258+
List<TypeReference> parameterTypes, List<ExecutableMode> executableModes) {
259+
return hint.getName().equals(name)
260+
&& hint.getParameterTypes().equals(parameterTypes)
258261
&& (hint.getModes().contains(ExecutableMode.INVOKE)
259-
|| !other.getModes().contains(ExecutableMode.INVOKE));
262+
|| !executableModes.contains(ExecutableMode.INVOKE));
260263
}
261264
}
262265

@@ -269,31 +272,32 @@ public static class ConstructorHintPredicate extends ExecutableHintPredicate<Con
269272
@Override
270273
MemberCategory[] getPublicMemberCategories() {
271274
if (this.executableMode == ExecutableMode.INTROSPECT) {
272-
return new MemberCategory[] {MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS,
273-
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS};
275+
return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS,
276+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS };
274277
}
275-
return new MemberCategory[] {MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS};
278+
return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS };
276279
}
277280

278281
@Override
279282
MemberCategory[] getDeclaredMemberCategories() {
280283
if (this.executableMode == ExecutableMode.INTROSPECT) {
281-
return new MemberCategory[] {MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS,
282-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS};
284+
return new MemberCategory[] { MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS,
285+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS };
283286
}
284-
return new MemberCategory[] {MemberCategory.INVOKE_DECLARED_CONSTRUCTORS};
287+
return new MemberCategory[] { MemberCategory.INVOKE_DECLARED_CONSTRUCTORS };
285288
}
286289

287290
@Override
288291
Predicate<RuntimeHints> exactMatch() {
289292
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
290293
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).constructors().anyMatch(executableHint -> {
291-
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes()).map(TypeReference::of).toList();
292-
ExecutableHint syntheticHint = ExecutableHint.ofConstructor(parameters)
293-
.setModes(this.executableMode).build();
294-
return includes(executableHint, syntheticHint);
295-
});
294+
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
295+
.map(TypeReference::of).toList();
296+
return includes(executableHint, "<init>",
297+
parameters, List.of(this.executableMode));
298+
});
296299
}
300+
297301
}
298302

299303
public static class MethodHintPredicate extends ExecutableHintPredicate<Method> {
@@ -306,32 +310,33 @@ public static class MethodHintPredicate extends ExecutableHintPredicate<Method>
306310
@Override
307311
MemberCategory[] getPublicMemberCategories() {
308312
if (this.executableMode == ExecutableMode.INTROSPECT) {
309-
return new MemberCategory[] {MemberCategory.INTROSPECT_PUBLIC_METHODS,
310-
MemberCategory.INVOKE_PUBLIC_METHODS};
313+
return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_METHODS,
314+
MemberCategory.INVOKE_PUBLIC_METHODS };
311315
}
312-
return new MemberCategory[] {MemberCategory.INVOKE_PUBLIC_METHODS};
316+
return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_METHODS };
313317
}
314318

315319
@Override
316320
MemberCategory[] getDeclaredMemberCategories() {
317321

318322
if (this.executableMode == ExecutableMode.INTROSPECT) {
319-
return new MemberCategory[] {MemberCategory.INTROSPECT_DECLARED_METHODS,
320-
MemberCategory.INVOKE_DECLARED_METHODS};
323+
return new MemberCategory[] { MemberCategory.INTROSPECT_DECLARED_METHODS,
324+
MemberCategory.INVOKE_DECLARED_METHODS };
321325
}
322-
return new MemberCategory[] {MemberCategory.INVOKE_DECLARED_METHODS};
326+
return new MemberCategory[] { MemberCategory.INVOKE_DECLARED_METHODS };
323327
}
324328

325329
@Override
326330
Predicate<RuntimeHints> exactMatch() {
327331
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
328332
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).methods().anyMatch(executableHint -> {
329-
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes()).map(TypeReference::of).toList();
330-
ExecutableHint syntheticHint = ExecutableHint.ofMethod(this.executable.getName(), parameters)
331-
.setModes(this.executableMode).build();
332-
return includes(executableHint, syntheticHint);
333+
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
334+
.map(TypeReference::of).toList();
335+
return includes(executableHint, this.executable.getName(),
336+
parameters, List.of(this.executableMode));
333337
});
334338
}
339+
335340
}
336341

337342
public static class FieldHintPredicate implements Predicate<RuntimeHints> {

spring-core/src/main/java/org/springframework/aot/hint/ResourceHintsPredicates.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.aot.hint;
1818

19+
import java.util.ArrayList;
20+
import java.util.List;
1921
import java.util.function.Predicate;
2022
import java.util.regex.Pattern;
2123

@@ -27,6 +29,7 @@
2729
* match the expected behavior for resources.
2830
*
2931
* @author Brian Clozel
32+
* @author Stephane Nicoll
3033
* @since 6.0
3134
*/
3235
public class ResourceHintsPredicates {
@@ -78,16 +81,31 @@ private String resolveAbsoluteResourceName(TypeReference type, String resourceNa
7881
* @return the {@link RuntimeHints} predicate
7982
*/
8083
public Predicate<RuntimeHints> forResource(String resourceName) {
81-
return hints -> hints.resources().resourcePatterns().reduce(ResourcePatternHints::merge)
82-
.map(hint -> {
83-
boolean isExcluded = hint.getExcludes().stream()
84-
.anyMatch(excluded -> CACHED_RESOURCE_PATTERNS.get(excluded).matcher(resourceName).matches());
85-
if (isExcluded) {
86-
return false;
87-
}
88-
return hint.getIncludes().stream()
89-
.anyMatch(included -> CACHED_RESOURCE_PATTERNS.get(included).matcher(resourceName).matches());
90-
}).orElse(false);
84+
return hints -> {
85+
AggregatedResourcePatternHints aggregatedResourcePatternHints = AggregatedResourcePatternHints.of(
86+
hints.resources());
87+
boolean isExcluded = aggregatedResourcePatternHints.excludes().stream().anyMatch(excluded ->
88+
CACHED_RESOURCE_PATTERNS.get(excluded).matcher(resourceName).matches());
89+
if (isExcluded) {
90+
return false;
91+
}
92+
return aggregatedResourcePatternHints.includes().stream().anyMatch(included ->
93+
CACHED_RESOURCE_PATTERNS.get(included).matcher(resourceName).matches());
94+
};
95+
}
96+
97+
private record AggregatedResourcePatternHints(List<ResourcePatternHint> includes, List<ResourcePatternHint> excludes) {
98+
99+
static AggregatedResourcePatternHints of(ResourceHints resourceHints) {
100+
List<ResourcePatternHint> includes = new ArrayList<>();
101+
List<ResourcePatternHint> excludes = new ArrayList<>();
102+
resourceHints.resourcePatterns().forEach(resourcePatternHint -> {
103+
includes.addAll(resourcePatternHint.getIncludes());
104+
excludes.addAll(resourcePatternHint.getExcludes());
105+
});
106+
return new AggregatedResourcePatternHints(includes, excludes);
107+
}
108+
91109
}
92110

93111
}

spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ private ResourcePatternHints(Builder builder) {
4545
this.excludes = new ArrayList<>(builder.excludes);
4646
}
4747

48-
private ResourcePatternHints(List<ResourcePatternHint> includes, List<ResourcePatternHint> excludes) {
49-
this.includes = includes;
50-
this.excludes = excludes;
51-
}
52-
5348
/**
5449
* Return the include patterns to use to identify the resources to match.
5550
* @return the include patterns
@@ -66,16 +61,6 @@ public List<ResourcePatternHint> getExcludes() {
6661
return this.excludes;
6762
}
6863

69-
ResourcePatternHints merge(ResourcePatternHints resourcePatternHints) {
70-
List<ResourcePatternHint> includes = new ArrayList<>();
71-
includes.addAll(this.includes);
72-
includes.addAll(resourcePatternHints.includes);
73-
List<ResourcePatternHint> excludes = new ArrayList<>();
74-
excludes.addAll(this.excludes);
75-
excludes.addAll(resourcePatternHints.excludes);
76-
return new ResourcePatternHints(includes, excludes);
77-
}
78-
7964

8065
/**
8166
* Builder for {@link ResourcePatternHints}.

0 commit comments

Comments
 (0)