Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

Copy link
Copy Markdown
Collaborator

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


private final Predicate origin;
private final List<Binder> binders;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 SimplifiedPredicate.Binder which I think makes more sense since we don't want to use Binder in any other context, so I think it should stay nested. What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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);
}
}
}
Loading