/**
* generated by Xtext
*/
package org.example.entities.validation;
import com.google.common.base.Objects;
import java.util.HashSet;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.validation.Check;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.example.entities.entities.Attribute;
import org.example.entities.entities.EntitiesPackage;
import org.example.entities.entities.Entity;
import org.example.entities.validation.AbstractEntitiesValidator;
/**
* Custom validation rules.
*
* see http://www.eclipse.org/Xtext/documentation.html#validation
*/
@SuppressWarnings("all")
public class EntitiesValidator extends AbstractEntitiesValidator {
public final static String HIERARCHY_CYCLE = "org.example.entities.HierarchyCycle";
public final static String INVALID_ENTITY_NAME = "org.example.entities.InvalidEntityName";
public final static String INVALID_ATTRIBUTE_NAME = "org.example.entities.InvalidAttributeName";
@Check
public void checkNoCycleInEntityHierarchy(final Entity entity) {
Entity _superType = entity.getSuperType();
boolean _equals = Objects.equal(_superType, null);
if (_equals) {
return;
}
final HashSet<Entity> visitedEntities = CollectionLiterals.<Entity>newHashSet();
visitedEntities.add(entity);
Entity current = entity.getSuperType();
while ((!Objects.equal(current, null))) {
{
boolean _contains = visitedEntities.contains(current);
if (_contains) {
String _name = current.getName();
String _plus = ("cycle in hierarchy of entity \'" + _name);
String _plus_1 = (_plus + "\'");
EReference _entity_SuperType = EntitiesPackage.eINSTANCE.getEntity_SuperType();
Entity _superType_1 = current.getSuperType();
String _name_1 = _superType_1.getName();
this.error(_plus_1, _entity_SuperType,
EntitiesValidator.HIERARCHY_CYCLE, _name_1);
return;
}
visitedEntities.add(current);
Entity _superType_2 = current.getSuperType();
current = _superType_2;
}
}
}
@Check
public void checkEntityNameStartsWithCapital(final Entity entity) {
String _name = entity.getName();
char _charAt = _name.charAt(0);
boolean _isLowerCase = Character.isLowerCase(_charAt);
if (_isLowerCase) {
EAttribute _entity_Name = EntitiesPackage.eINSTANCE.getEntity_Name();
String _name_1 = entity.getName();
this.warning("Entity name should start with a capital", _entity_Name,
EntitiesValidator.INVALID_ENTITY_NAME, _name_1);
}
}
@Check
public void checkAttributeNameStartsWithLowercase(final Attribute attr) {
String _name = attr.getName();
char _charAt = _name.charAt(0);
boolean _isUpperCase = Character.isUpperCase(_charAt);
if (_isUpperCase) {
EAttribute _attribute_Name = EntitiesPackage.eINSTANCE.getAttribute_Name();
String _name_1 = attr.getName();
this.warning("Attribute name should start with a lowercase", _attribute_Name,
EntitiesValidator.INVALID_ATTRIBUTE_NAME, _name_1);
}
}
}