fix descriptions of targetOwner and originOwner predicates in JavaAccess#1603
Open
StefanGraeber wants to merge 1 commit intoTNG:mainfrom
Open
fix descriptions of targetOwner and originOwner predicates in JavaAccess#1603StefanGraeber wants to merge 1 commit intoTNG:mainfrom
StefanGraeber wants to merge 1 commit intoTNG:mainfrom
Conversation
960e3d6 to
ffe067a
Compare
targetOwner and originOwner() were producing the same message as target() and origin() e.g. "access target where target is annotated with..." instead of "access target where target owner is annotated with..." The existing test is also updated to assert that the correct element is passed to the given predicate, for which new testUtils are introduced. Signed-off-by: Stefan Gräber <stefan.graeber@tngtech.com>
ffe067a to
759c85a
Compare
hankem
approved these changes
May 10, 2026
Comment on lines
+109
to
+144
| public static <T> DescribedPredicate<T> predicateWithDescription(String description) { | ||
| return DescribedPredicate.<T>alwaysTrue().as(description); | ||
| } | ||
|
|
||
| public static <T> CapturingDescribedPredicate<T> alwaysFalseCapturingPredicateWithDescription(String description) { | ||
| return new CapturingDescribedPredicate<T>(false, description); | ||
| } | ||
|
|
||
| public static <T> CapturingDescribedPredicate<T> alwaysTrueCapturingPredicateWithDescription(String description) { | ||
| return new CapturingDescribedPredicate<T>(true, description); | ||
| } | ||
|
|
||
| public static class CapturingDescribedPredicate<T> extends DescribedPredicate<T> { | ||
|
|
||
| private final List<T> capturedValues; | ||
| private final Predicate<T> check; | ||
|
|
||
| public CapturingDescribedPredicate(boolean result, String description, Object... params) { | ||
| this(o -> result, description, params); | ||
| } | ||
|
|
||
| public CapturingDescribedPredicate(Predicate<T> check, String description, Object... params) { | ||
| super(description, params); | ||
| this.check = check; | ||
| this.capturedValues = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean test(T t) { | ||
| this.capturedValues.add(t); | ||
| return check.test(t); | ||
| } | ||
|
|
||
| public List<T> getCapturedValues() { | ||
| return Collections.unmodifiableList(new ArrayList<>(capturedValues)); | ||
| } |
Member
There was a problem hiding this comment.
I wouldn't introduce unused methods, but keep it simple:
Suggested change
| public static <T> DescribedPredicate<T> predicateWithDescription(String description) { | |
| return DescribedPredicate.<T>alwaysTrue().as(description); | |
| } | |
| public static <T> CapturingDescribedPredicate<T> alwaysFalseCapturingPredicateWithDescription(String description) { | |
| return new CapturingDescribedPredicate<T>(false, description); | |
| } | |
| public static <T> CapturingDescribedPredicate<T> alwaysTrueCapturingPredicateWithDescription(String description) { | |
| return new CapturingDescribedPredicate<T>(true, description); | |
| } | |
| public static class CapturingDescribedPredicate<T> extends DescribedPredicate<T> { | |
| private final List<T> capturedValues; | |
| private final Predicate<T> check; | |
| public CapturingDescribedPredicate(boolean result, String description, Object... params) { | |
| this(o -> result, description, params); | |
| } | |
| public CapturingDescribedPredicate(Predicate<T> check, String description, Object... params) { | |
| super(description, params); | |
| this.check = check; | |
| this.capturedValues = new ArrayList<>(); | |
| } | |
| @Override | |
| public boolean test(T t) { | |
| this.capturedValues.add(t); | |
| return check.test(t); | |
| } | |
| public List<T> getCapturedValues() { | |
| return Collections.unmodifiableList(new ArrayList<>(capturedValues)); | |
| } | |
| public static <T> CapturingDescribedPredicate<T> alwaysTrueCapturingPredicateWithDescription(String description) { | |
| return new CapturingDescribedPredicate<T>(true, description); | |
| } | |
| public static class CapturingDescribedPredicate<T> extends DescribedPredicate<T> { | |
| private final List<T> capturedValues = new ArrayList<>(); | |
| private final Predicate<T> check; | |
| CapturingDescribedPredicate(boolean result, String description) { | |
| super(description); | |
| this.check = o -> result; | |
| } | |
| @Override | |
| public boolean test(T t) { | |
| this.capturedValues.add(t); | |
| return check.test(t); | |
| } |
(Note that this also removes the need to import java.util.Collections;.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
targetOwner and originOwner() were producing the same message as target() and origin() e.g. "access target where target is annotated with..." instead of "access target where target owner is annotated with..." The existing test is also updated to assert that the correct element is passed to the given predicate, for which new testUtils are introduced.