Skip to content

Commit

Permalink
Merge pull request #41 from anemonekk/issue9
Browse files Browse the repository at this point in the history
Add validation for duplicate event labels
  • Loading branch information
schlichtig authored Dec 4, 2020
2 parents 57d2cee + 7011532 commit 5f6cd60
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtext.validation.Check;

import de.darmstadt.tu.crossing.crySL.Event;
import de.darmstadt.tu.crossing.crySL.ForbMethod;
import de.darmstadt.tu.crossing.crySL.RequiredBlock;
import de.darmstadt.tu.crossing.crySL.SuperType;
import de.darmstadt.tu.crossing.crySL.impl.ObjectImpl;

/**
* This class contains custom validation rules.
Expand All @@ -19,8 +23,32 @@ public class CrySLValidator extends AbstractCrySLValidator {

@Check
public void checkGreetingStartsWithCapital(ForbMethod greeting) {

}


}
/**
* Add error markers for duplicate event labels.
*
* @param s of type supertype being checked for duplicity
*/
@Check
public void checkDuplicateEventLabel(SuperType s) {

if(!(s instanceof ObjectImpl)) {
for(Event e : ((RequiredBlock) s.eContainer()).getReq_event()) {
for(Event ev : ((RequiredBlock) s.eContainer()).getReq_event()) {
if(e instanceof SuperType && ev instanceof SuperType) {
SuperType es = (SuperType) e;
SuperType evs = (SuperType) ev;
if(es != evs && es.getName().equals(evs.getName())) {
if(s.getName().contentEquals(es.getName())
&& s.getName().contentEquals(evs.getName())) {
error("Duplicate label", INVALID_NAME);
}
}
}
}
}
}
}
}

0 comments on commit 5f6cd60

Please sign in to comment.