Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2011-04-22 10:36:41 -0400
committerRyan D. Brooks2011-04-22 10:36:41 -0400
commit87a439a142dad13c554519329ebec4da3b406f42 (patch)
tree74b3ef0e7657dd940d9105303952f3da6b07747d /plugins
parent9859206e571a21bfe880253e9c53aeb7e5dd54c6 (diff)
downloadorg.eclipse.osee-87a439a142dad13c554519329ebec4da3b406f42.tar.gz
org.eclipse.osee-87a439a142dad13c554519329ebec4da3b406f42.tar.xz
org.eclipse.osee-87a439a142dad13c554519329ebec4da3b406f42.zip
feature: Improve Osee Dsl validation to correctly validate type names and duplicate guids
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.ats/support/OseeTypes_ATS.osee2
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeDslJavaValidator.java65
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeNamesAreUniqueValidator.java61
3 files changed, 127 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.ats/support/OseeTypes_ATS.osee b/plugins/org.eclipse.osee.ats/support/OseeTypes_ATS.osee
index 16ee9140a0..877c319041 100644
--- a/plugins/org.eclipse.osee.ats/support/OseeTypes_ATS.osee
+++ b/plugins/org.eclipse.osee.ats/support/OseeTypes_ATS.osee
@@ -23,7 +23,7 @@ artifactType "ats.Review" extends "ats.State Machine" {
attribute "ats.Review Blocks"
}
-artifactType "PeerToPeer Review" extends "ats.Review" {
+artifactType "ats.Review Review" extends "ats.Review" {
guid "AAMFDhh_300dpgmNtRAA"
attribute "ats.Location"
attribute "ats.Review Defect"
diff --git a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeDslJavaValidator.java b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeDslJavaValidator.java
index 74d5bbc0e2..c6b9820bc6 100644
--- a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeDslJavaValidator.java
+++ b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeDslJavaValidator.java
@@ -14,23 +14,30 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessContext;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactInstanceRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AttributeTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.HierarchyRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslPackage;
import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactRef;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.util.OseeDslSwitch;
import org.eclipse.xtext.validation.Check;
+import org.eclipse.xtext.validation.ComposedChecks;
/**
* @author Roberto E. Escobar
+ * @author Donald G. Dunne
*/
+//Override the checks in AbstractAtsDslJavaValidator to provide own Name validator
+@ComposedChecks(validators = {org.eclipse.xtext.validation.ImportUriValidator.class, OseeNamesAreUniqueValidator.class})
public class OseeDslJavaValidator extends AbstractOseeDslJavaValidator {
public static final String NON_UNIQUE_HIERARCHY = "non_unique_hierarchy";
@@ -40,6 +47,64 @@ public class OseeDslJavaValidator extends AbstractOseeDslJavaValidator {
public static final String NON_UNIQUE_RELATION_TYPE_RESTRICTION = "non_unique_relation_type_restriction";
@Check
+ public void checkTypeNameValidity(OseeDsl oseeDsl) {
+ Set<String> typeNames = new HashSet<String>(50);
+ Map<String, String> guidToTypeName = new HashMap<String, String>(500);
+ for (XAttributeType attrType : oseeDsl.getAttributeTypes()) {
+ if (typeNames.contains(attrType.getName())) {
+ String message = String.format("Duplicate attribute type name [%s]", attrType.getName());
+ error(message, attrType, OseeDslPackage.XATTRIBUTE_TYPE__NAME);
+ } else {
+ typeNames.add(attrType.getName());
+ }
+ if (guidToTypeName.containsKey(attrType.getTypeGuid())) {
+ String message =
+ String.format("Duplicate guid [%s] for attribute types [%s] and [%s]", attrType.getTypeGuid(),
+ attrType.getName(), guidToTypeName.get(attrType.getTypeGuid()));
+ error(message, attrType, OseeDslPackage.XATTRIBUTE_TYPE__TYPE_GUID);
+ } else {
+ guidToTypeName.put(attrType.getTypeGuid(), attrType.getName());
+ }
+ }
+ typeNames.clear();
+ guidToTypeName.clear();
+ for (XArtifactType artType : oseeDsl.getArtifactTypes()) {
+ if (typeNames.contains(artType.getName())) {
+ String message = String.format("Duplicate artifact type name [%s]", artType.getName());
+ error(message, artType, OseeDslPackage.XARTIFACT_TYPE__NAME);
+ } else {
+ typeNames.add(artType.getName());
+ }
+ if (guidToTypeName.containsKey(artType.getTypeGuid())) {
+ String message =
+ String.format("Duplicate guid [%s] for artifact types [%s] and [%s]", artType.getTypeGuid(),
+ artType.getName(), guidToTypeName.get(artType.getTypeGuid()));
+ error(message, artType, OseeDslPackage.XARTIFACT_TYPE__TYPE_GUID);
+ } else {
+ guidToTypeName.put(artType.getTypeGuid(), artType.getName());
+ }
+ }
+ typeNames.clear();
+ guidToTypeName.clear();
+ for (XRelationType relType : oseeDsl.getRelationTypes()) {
+ if (typeNames.contains(relType.getName())) {
+ String message = String.format("Duplicate relation type name [%s]", relType.getName());
+ error(message, relType, OseeDslPackage.XRELATION_TYPE__NAME);
+ } else {
+ typeNames.add(relType.getName());
+ }
+ if (guidToTypeName.containsKey(relType.getTypeGuid())) {
+ String message =
+ String.format("Duplicate guid [%s] for relation types [%s] and [%s]", relType.getTypeGuid(),
+ relType.getName(), guidToTypeName.get(relType.getTypeGuid()));
+ error(message, relType, OseeDslPackage.XRELATION_TYPE__TYPE_GUID);
+ } else {
+ guidToTypeName.put(relType.getTypeGuid(), relType.getName());
+ }
+ }
+ }
+
+ @Check
public void checkAccessContextRulesUnique(AccessContext accessContext) {
checkObjectRestrictions(accessContext, accessContext.getAccessRules());
checkHierarchyUnique(accessContext, accessContext.getHierarchyRestrictions());
diff --git a/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeNamesAreUniqueValidator.java b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeNamesAreUniqueValidator.java
new file mode 100644
index 0000000000..af73d30816
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl/src/org/eclipse/osee/framework/core/dsl/validation/OseeNamesAreUniqueValidator.java
@@ -0,0 +1,61 @@
+/*
+ * Created on Feb 2, 2011
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.dsl.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.util.CancelIndicator;
+import org.eclipse.xtext.validation.NamesAreUniqueValidator;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * Osee specific name validator that ignores types names cause they conflict between types.<br>
+ * <br>
+ * Types instead will be checked via OseeDslJavaValidator
+ *
+ * @author Donald G. Dunne
+ */
+public class OseeNamesAreUniqueValidator extends NamesAreUniqueValidator {
+ OseeNamesAreUniqueValidationHelper oseeHelper;
+
+ public OseeNamesAreUniqueValidator() {
+ super();
+ oseeHelper = new OseeNamesAreUniqueValidationHelper();
+ }
+
+ public class OseeNamesAreUniqueValidationHelper extends org.eclipse.xtext.validation.NamesAreUniqueValidationHelper {
+
+ @Override
+ public void checkUniqueNames(Iterable<IEObjectDescription> descriptions, ValidationMessageAcceptor acceptor) {
+ super.checkUniqueNames(descriptions, acceptor);
+ }
+
+ @Override
+ public void checkUniqueNames(Iterable<IEObjectDescription> descriptions, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor) {
+ List<IEObjectDescription> validDescriptions = new ArrayList<IEObjectDescription>();
+ for (IEObjectDescription description : descriptions) {
+ if (!(description.getEObjectOrProxy() instanceof XArtifactType) && !(description.getEObjectOrProxy() instanceof XAttributeType) && !(description.getEObjectOrProxy() instanceof XRelationType)) {
+ validDescriptions.add(description);
+ }
+ }
+ super.checkUniqueNames(validDescriptions, cancelIndicator, acceptor);
+ }
+ }
+
+ @Override
+ public void checkUniqueNamesInResourceOf(EObject eObject) {
+ if (!(getHelper() instanceof OseeNamesAreUniqueValidationHelper)) {
+ setHelper(oseeHelper);
+ }
+ super.checkUniqueNamesInResourceOf(eObject);
+ }
+
+}

Back to the top