Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pnml-relast
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
pnml
pnml-relast
Commits
dcc473be
Commit
dcc473be
authored
4 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
add some constraint checking
parent
f014f7df
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/jastadd/Constraints.jrag
+91
-0
91 additions, 0 deletions
src/main/jastadd/Constraints.jrag
with
91 additions
and
0 deletions
src/main/jastadd/Constraints.jrag
0 → 100644
+
91
−
0
View file @
dcc473be
aspect Constraints {
coll Set<ConstraintViolation> PetriNet.constraintViolations() [new java.util.HashSet()] root PetriNet;
}
aspect ConstraintViolations {
abstract class ConstraintViolation {
public String toString() {
return "Constraint " + getTitle() + " violated in object " + id() + ": " + getMessage();
}
protected ASTNode location;
public String id() {
if (location instanceof PnObject) return ((PnObject) location).getId();
if (location instanceof PetriNet) return ((PetriNet) location).getId();
return location.toString();
}
protected String title;
protected String description;
protected String message;
public String getTitle() { return title; }
public String getDescription() { return description; }
public String getMessage() { return message; }
}
class CheckIdsConstraint extends ConstraintViolation {
public CheckIdsConstraint(ASTNode location) {
this.location = location;
this.title = "CheckIds";
this.description = "Checks id attribute existence";
this.message = "A node of type '" + location.getClass().getSimpleName() + "' must have an id attribute.";
}
}
class CheckIdUniquenessConstraint extends ConstraintViolation {
public CheckIdUniquenessConstraint(ASTNode location) {
this.location = location;
this.title = "CheckIdUniquess";
this.description = "Checks id attribute uniqueness";
this.message = "The id attribute value " + id() + " of the node of type '" + location.getClass().getSimpleName() + "' is not unique.";
}
}
PetriNet contributes new CheckIdsConstraint(this)
when checkIdsConstraintViolated()
to PetriNet.constraintViolations();
PnObject contributes new CheckIdsConstraint(this)
when checkIdsConstraintViolated()
to PetriNet.constraintViolations();
}
aspect CoreModelConstraints {
syn boolean PetriNet.checkIdsConstraintViolated() = getId() == null || getId().equals("");
syn boolean PnObject.checkIdsConstraintViolated() = getId() == null || getId().equals("");
coll List<String> PetriNet.ids() [new ArrayList()] root PetriNet;
PnObject contributes getId() to PetriNet.ids();
syn Map<String, Long> PetriNet.idCount() =
ids().stream().collect(Collectors.groupingBy(java.util.function.Function.identity(), Collectors.counting()));
syn boolean PetriNet.uniqueId(String id) = idCount().get(id) <= 1;
syn boolean PnObject.uniqueId(String id) = petriNet().idCount().get(id) <= 1;
syn Optional<CheckIdUniquenessConstraint> PetriNet.checkIdUniqueness() {
if(uniqueId(getId())) return Optional.empty();
else return Optional.of(new CheckIdUniquenessConstraint(this));
}
syn Optional<CheckIdUniquenessConstraint> PnObject.checkIdUniqueness() {
if(petriNet().uniqueId(getId())) return Optional.empty();
else return Optional.of(new CheckIdUniquenessConstraint(this));
}
PetriNet contributes checkIdUniqueness().get()
when checkIdUniqueness().isPresent()
to PetriNet.constraintViolations();
PnObject contributes checkIdUniqueness().get()
when checkIdUniqueness().isPresent()
to PetriNet.constraintViolations();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment