Skip to content

fix descriptions of targetOwner and originOwner predicates in JavaAccess#1603

Open
StefanGraeber wants to merge 1 commit intoTNG:mainfrom
StefanGraeber:fix-access-owner-predicate-descriptions
Open

fix descriptions of targetOwner and originOwner predicates in JavaAccess#1603
StefanGraeber wants to merge 1 commit intoTNG:mainfrom
StefanGraeber:fix-access-owner-predicate-descriptions

Conversation

@StefanGraeber
Copy link
Copy Markdown
Contributor

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.

@StefanGraeber StefanGraeber force-pushed the fix-access-owner-predicate-descriptions branch 3 times, most recently from 960e3d6 to ffe067a Compare April 13, 2026 07:09
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>
@StefanGraeber StefanGraeber force-pushed the fix-access-owner-predicate-descriptions branch from ffe067a to 759c85a Compare April 24, 2026 12:39
@StefanGraeber StefanGraeber requested a review from hankem May 6, 2026 15:35
Copy link
Copy Markdown
Member

@hankem hankem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

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));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants