-
Notifications
You must be signed in to change notification settings - Fork 35
Add SimplifiedPredicate #246
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
Changes from all commits
05680e2
d845fa3
23cb1b0
604bcef
1bc748a
dfb80ab
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package liquidjava.rj_language; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| import spoon.reflect.reference.CtTypeReference; | ||
|
|
||
| /** | ||
| * Represents a predicate simplified from another predicate. Stores the original predicate and any variables that must | ||
| * be reintroduced as binders when relating the simplified predicate back to its origin. | ||
| * <p> | ||
| * For example, simplifying {@code x == 1 && y > x} with binders {@code x: int, y: int} may produce {@code y > 1}. The | ||
| * origin {@code x == 1 && y > x} and binder {@code x: int} are kept so we can relate the simplified predicate back to | ||
| * the original. | ||
| */ | ||
| public class SimplifiedPredicate extends Predicate { | ||
|
|
||
| private final Predicate origin; | ||
| private final List<Binder> binders; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. say what you mean by binders |
||
|
|
||
| public SimplifiedPredicate(Predicate simplified, Predicate origin) { | ||
| this(simplified, origin, List.of()); | ||
| } | ||
|
|
||
| public SimplifiedPredicate(Predicate simplified, Predicate origin, List<Binder> binders) { | ||
| super(simplified.getExpression()); | ||
| this.origin = origin; | ||
| this.binders = new ArrayList<>(binders); | ||
| } | ||
|
|
||
| public Predicate getSimplifiedPredicate() { | ||
| return new Predicate(getExpression()); | ||
| } | ||
|
|
||
| public Predicate getOrigin() { | ||
| return origin; | ||
| } | ||
|
|
||
| public List<Binder> getBinders() { | ||
| return binders; | ||
| } | ||
|
|
||
| @Override | ||
| public SimplifiedPredicate clone() { | ||
| return new SimplifiedPredicate(new Predicate(getExpression().clone()), origin.clone(), binders); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(getExpression(), origin, binders); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| SimplifiedPredicate other = (SimplifiedPredicate) obj; | ||
| return getExpression().equals(other.getExpression()) && origin.equals(other.origin) | ||
| && binders.equals(other.binders); | ||
| } | ||
|
|
||
| /** | ||
| * Represents a variable that must be bound when relating the simplified predicate to its origin | ||
| */ | ||
| public static class Binder { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we nee dthis to be public? if yes create another file with it, but maybe we dont? not sure
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we need it to be public, and it is currently accessed as
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hum ok i see, we can work with that |
||
| private final String name; | ||
| private final String type; | ||
|
|
||
| public Binder(String name, String type) { | ||
| this.name = name; | ||
| this.type = type; | ||
| } | ||
|
|
||
| public Binder(String name, CtTypeReference<?> type) { | ||
| this(name, type.getQualifiedName()); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, type); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| Binder other = (Binder) obj; | ||
| return name.equals(other.name) && type.equals(other.type); | ||
| } | ||
| } | ||
| } | ||
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.
actually add some javadoc exlaining this class nature and what it represents with an example