| /** |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.entitymock.validation; |
| |
| import java.util.HashSet; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.osbp.xtext.entitymock.EntityMock; |
| import org.eclipse.osbp.xtext.entitymock.EntityMockDSLPackage; |
| import org.eclipse.osbp.xtext.entitymock.EntityMockPackage; |
| import org.eclipse.osbp.xtext.entitymock.validation.AbstractEntityMockDSLValidator; |
| import org.eclipse.xtext.validation.Check; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| |
| /** |
| * Custom validation rules. |
| * |
| * see http://www.eclipse.org/Xtext/documentation.html#validation |
| */ |
| @SuppressWarnings("all") |
| public class EntityMockDSLValidator extends AbstractEntityMockDSLValidator { |
| @Check |
| public void checkDuplicateElementId(final EntityMock mock) { |
| EObject eObj = mock.eContainer(); |
| while ((!(eObj instanceof EntityMockPackage))) { |
| eObj = eObj.eContainer(); |
| } |
| if ((eObj != null)) { |
| EntityMockPackage mockPackage = ((EntityMockPackage) eObj); |
| EntityMock _findDuplicateChartNames = this.findDuplicateChartNames(mockPackage.getMocks(), mock.getName()); |
| boolean _tripleNotEquals = (_findDuplicateChartNames != null); |
| if (_tripleNotEquals) { |
| this.error("Duplicate name \'".concat(mock.getName()).concat("\'!"), EntityMockDSLPackage.Literals.ENTITY_MOCK__NAME); |
| } |
| } |
| } |
| |
| private EntityMock findDuplicateChartNames(final EList<EntityMock> mocks, final String mockName) { |
| HashSet<String> tempSet = CollectionLiterals.<String>newHashSet(); |
| for (final EntityMock mock : mocks) { |
| if (((!tempSet.add(mock.getName())) && mock.getName().equals(mockName))) { |
| return mock; |
| } |
| } |
| return null; |
| } |
| } |