Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL - syntax (insert) and library s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
rtotaro committed Jan 14, 2017
1 parent f35f258 commit b58db2f
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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<EObject> 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('>'));
Expand Down

0 comments on commit b58db2f

Please sign in to comment.