From b58db2f76a10bae96a7b54cb105ce1d052d0cf7f Mon Sep 17 00:00:00 2001 From: Rodolfo Totaro Date: Sat, 14 Jan 2017 13:28:18 +0100 Subject: [PATCH] #190 In progress TqCL - syntax (insert) and library services --- .../commands/validation/TqclValidator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java index c78db9ce..2c14c821 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.triquetrum.commands.api.TqCLServices; import org.eclipse.triquetrum.commands.api.services.EntityDescriptor; @@ -29,6 +30,7 @@ import org.eclipse.triquetrum.commands.tqcl.Library; import org.eclipse.triquetrum.commands.tqcl.Parameter; import org.eclipse.triquetrum.commands.tqcl.TqclPackage; +import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.validation.Check; /** @@ -44,6 +46,8 @@ public class TqclValidator extends AbstractTqclValidator { public static final String INVALID_LIBRARY = "invalidLibrary"; public static final String INVALID_PARAMETER = "invalidParameter"; + + public static final String DUPLICATED_ENTITY_NAME = "invalidParameter"; @Check public void checkLibrary(Library library) { @@ -72,6 +76,27 @@ public void checkEntityInLibrary(Insert insert) { String message = MessageFormat.format("Entity class {0} not found in imported library", entityClass); error(message, TqclPackage.Literals.INSERT__ENTITY_CLASS, INVALID_ENTITY_CLASS); } + @Check + public void checkNameUnique(Insert insert) + { + String name = insert.getName(); + EObject rootContainer = EcoreUtil2.getRootContainer(insert); + TreeIterator eAllContents = rootContainer.eAllContents(); + while (eAllContents.hasNext()) { + EObject eObject = (EObject) eAllContents.next(); + if (eObject instanceof Insert) { + Insert otherInsert = (Insert) eObject; + if(otherInsert!=insert) + { + if(otherInsert.getName().equals(name)) + { + error("Duplicated entity name", TqclPackage.Literals.INSERT__NAME,DUPLICATED_ENTITY_NAME); + } + } + + } + } + } private String cleanEntityClassName(String entityClass) { return entityClass.substring(1, entityClass.lastIndexOf('>'));