blob: 2f985e8c972654f75b7ee159af6cd61dd36b1f6d [file] [log] [blame]
/**
*
* 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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* 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 org.eclipse.emf.common.util.EList
import org.eclipse.osbp.xtext.entitymock.EntityMock
import org.eclipse.osbp.xtext.entitymock.EntityMockDSLPackage
import org.eclipse.osbp.xtext.entitymock.EntityMockPackage
import org.eclipse.xtext.validation.Check
/**
* Custom validation rules.
*
* see http://www.eclipse.org/Xtext/documentation.html#validation
*/
class EntityMockDSLValidator extends AbstractEntityMockDSLValidator {
@Check
def void checkDuplicateElementId(EntityMock mock){
var eObj = mock.eContainer()
while (!(eObj instanceof EntityMockPackage)) {
eObj = eObj.eContainer
}
if (eObj!==null){
var mockPackage = eObj as EntityMockPackage;
if (findDuplicateChartNames(mockPackage.mocks, mock.getName()) !== null){
error("Duplicate name '".concat(mock.getName()).concat("'!"), EntityMockDSLPackage.Literals.ENTITY_MOCK__NAME)
}
}
}
def private EntityMock findDuplicateChartNames(
EList<EntityMock> mocks, String mockName) {
var tempSet = <String>newHashSet()
for (EntityMock mock : mocks){
if (!tempSet.add(mock.name) && (mock.name.equals(mockName))){
return mock
}
}
return null
}
}