forked from ftsrg/gamma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Added initial validation and scope extensions
- Loading branch information
1 parent
8dc352a
commit d27707b
Showing
6 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ity.model/src/hu/bme/mit/gamma/activity/derivedfeatures/ActivityModelDerivedFeatures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package hu.bme.mit.gamma.activity.derivedfeatures; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
|
||
import hu.bme.mit.gamma.action.derivedfeatures.ActionModelDerivedFeatures; | ||
import hu.bme.mit.gamma.activity.model.ActivityDeclaration; | ||
import hu.bme.mit.gamma.activity.model.ActivityDeclarationReference; | ||
import hu.bme.mit.gamma.activity.model.ActivityDefinition; | ||
import hu.bme.mit.gamma.activity.model.InlineActivityDeclaration; | ||
import hu.bme.mit.gamma.activity.model.NamedActivityDeclarationReference; | ||
import hu.bme.mit.gamma.activity.model.OutsidePinReference; | ||
|
||
public class ActivityModelDerivedFeatures extends ActionModelDerivedFeatures { | ||
|
||
public static ActivityDeclaration getContainingActivityDeclaration(EObject element) { | ||
if (element instanceof ActivityDeclaration) { | ||
return (ActivityDeclaration)element; | ||
} | ||
|
||
return getContainingActivityDeclaration(element.eContainer()); | ||
} | ||
|
||
public static ActivityDefinition getContainingActivityDefinition(EObject element) { | ||
if (element instanceof ActivityDefinition) { | ||
return (ActivityDefinition)element; | ||
} | ||
|
||
return getContainingActivityDefinition(element.eContainer()); | ||
} | ||
|
||
public static ActivityDeclaration getReferencedActivityDeclaration(OutsidePinReference reference) { | ||
ActivityDeclarationReference declReference = reference.getActionNode().getActivityDeclarationReference(); | ||
|
||
if (declReference instanceof InlineActivityDeclaration) { | ||
return (InlineActivityDeclaration)declReference; | ||
} | ||
if (declReference instanceof NamedActivityDeclarationReference) { | ||
return ((NamedActivityDeclarationReference)declReference).getNamedActivityDeclaration(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...activity.model/src/hu/bme/mit/gamma/activity/util/ActivityExpressionTypeDeterminator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hu.bme.mit.gamma.activity.util; | ||
|
||
import hu.bme.mit.gamma.activity.model.InputPinReference; | ||
import hu.bme.mit.gamma.activity.model.OutputPinReference; | ||
import hu.bme.mit.gamma.activity.model.Pin; | ||
import hu.bme.mit.gamma.activity.model.PinReference; | ||
import hu.bme.mit.gamma.expression.model.Expression; | ||
import hu.bme.mit.gamma.expression.util.ExpressionType; | ||
import hu.bme.mit.gamma.expression.util.ExpressionTypeDeterminator; | ||
|
||
public class ActivityExpressionTypeDeterminator extends ExpressionTypeDeterminator { | ||
// Singleton | ||
public static final ActivityExpressionTypeDeterminator INSTANCE = new ActivityExpressionTypeDeterminator(); | ||
protected ActivityExpressionTypeDeterminator() {} | ||
// | ||
|
||
@Override | ||
public ExpressionType getType(Expression expression) { | ||
if (expression instanceof PinReference) { | ||
return getType((PinReference)expression); | ||
} | ||
|
||
return super.getType(expression); | ||
} | ||
|
||
public ExpressionType getType(PinReference reference) { | ||
Pin pin; | ||
|
||
if (reference instanceof InputPinReference) { | ||
pin = ((InputPinReference)reference).getInputPin(); | ||
} else { | ||
pin = ((OutputPinReference)reference).getOutputPin(); | ||
} | ||
|
||
return transform(pin.getType()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...e.mit.gamma.activity.model/src/hu/bme/mit/gamma/activity/util/ActivityModelValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package hu.bme.mit.gamma.activity.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import hu.bme.mit.gamma.action.util.ActionModelValidator; | ||
import hu.bme.mit.gamma.activity.model.ActivityDeclaration; | ||
import hu.bme.mit.gamma.activity.model.ActivityDefinition; | ||
import hu.bme.mit.gamma.activity.model.ActivityNode; | ||
import hu.bme.mit.gamma.activity.model.ActivityPackage; | ||
import hu.bme.mit.gamma.activity.model.NamedActivityDeclaration; | ||
import hu.bme.mit.gamma.activity.model.Pin; | ||
import hu.bme.mit.gamma.expression.model.ExpressionModelPackage; | ||
import hu.bme.mit.gamma.expression.model.NamedElement; | ||
|
||
public class ActivityModelValidator extends ActionModelValidator { | ||
// Singleton | ||
public static final ActivityModelValidator INSTANCE = new ActivityModelValidator(); | ||
protected ActivityModelValidator() { | ||
super.typeDeterminator = ActivityExpressionTypeDeterminator.INSTANCE; // PinReference | ||
} | ||
// | ||
|
||
@Override | ||
public Collection<ValidationResultMessage> checkNameUniqueness(NamedElement element) { | ||
String name = element.getName(); | ||
|
||
if (element instanceof ActivityNode) { | ||
ActivityDefinition activityDefinition = ecoreUtil.getContainerOfType(element, ActivityDefinition.class); | ||
|
||
return checkDirectNames(activityDefinition.getActivityNodes(), name); | ||
} | ||
if (element instanceof Pin) { | ||
ActivityDeclaration activityDeclaration = ecoreUtil.getContainerOfType(element, ActivityDeclaration.class); | ||
|
||
return checkDirectNames(activityDeclaration.getPins(), name); | ||
} | ||
if (element instanceof NamedActivityDeclaration) { | ||
ActivityPackage activityPackage = ecoreUtil.getContainerOfType(element, ActivityPackage.class); | ||
|
||
return checkDirectNames(activityPackage.getNamedActivityDeclarations(), name); | ||
} | ||
|
||
return super.checkNameUniqueness(element); | ||
} | ||
|
||
public <T> Collection<ValidationResultMessage> checkDirectNames(Collection<T> elements, String name) { | ||
int nameCount = 0; | ||
|
||
Collection<ValidationResultMessage> validationResultMessages = new ArrayList<ValidationResultMessage>(); | ||
|
||
for (T element : elements) { | ||
if (element instanceof NamedElement) { | ||
if (name.equals(((NamedElement)element).getName())) { | ||
++nameCount; | ||
} | ||
if (nameCount > 1) { | ||
validationResultMessages.add(new ValidationResultMessage(ValidationResult.ERROR, | ||
"In a Gamma model, these identifiers must be unique in the same context.", | ||
new ReferenceInfo(ExpressionModelPackage.Literals.NAMED_ELEMENT__NAME, null))); | ||
} | ||
} | ||
} | ||
return validationResultMessages; | ||
} | ||
|
||
} |