blob: 83464dca1d288fd1ef54f121e29e63829ca31ac9 [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.chart.validation
import org.eclipse.osbp.xtext.chart.Chart
import org.eclipse.osbp.xtext.chart.ChartPackage
import org.eclipse.osbp.xtext.chart.ChartDSLPackage
import org.eclipse.emf.common.util.EList
import org.eclipse.xtext.validation.Check
//import org.eclipse.xtext.validation.Check
/**
* Custom validation rules.
*
* see http://www.eclipse.org/Xtext/documentation.html#validation
*/
class ChartDSLValidator extends AbstractChartDSLValidator {
// public static val INVALID_NAME = 'invalidName'
//
// @Check
// def checkGreetingStartsWithCapital(Greeting greeting) {
// if (!Character.isUpperCase(greeting.name.charAt(0))) {
// warning('Name should start with a capital',
// MyDslPackage.Literals.GREETING__NAME,
// INVALID_NAME)
// }
// }
@Check
def void checkDuplicateChartNames(Chart chart){
var eObj = chart.eContainer()
while (!(eObj instanceof ChartPackage)) {
eObj = eObj.eContainer
}
if (eObj!=null){
var chartPackage = eObj as ChartPackage;
if (findDuplicateChartNames(chartPackage.charts, chart.getName()) != null){
error("Duplicate chart name '".concat(chart.getName()).concat("'!"), ChartDSLPackage.Literals.CHART_BASE__NAME)
}
}
}
def private Chart findDuplicateChartNames(
EList<Chart> charts, String chartName) {
var tempSet = <String>newHashSet()
for (Chart chart : charts){
if (!tempSet.add(chart.name) && (chart.name.equals(chartName))){
return chart
}
}
return null
}
}