blob: f18f023e4092349ba55738d27dedb92cb3071221 [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 java.util.HashSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.xtext.chart.Chart;
import org.eclipse.osbp.xtext.chart.ChartAxis;
import org.eclipse.osbp.xtext.chart.ChartDSLPackage;
import org.eclipse.osbp.xtext.chart.ChartPackage;
import org.eclipse.osbp.xtext.chart.validation.AbstractChartDSLValidator;
import org.eclipse.osbp.xtext.datamartdsl.AxisEnum;
import org.eclipse.osbp.xtext.datamartdsl.DatamartAxis;
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 ChartDSLValidator extends AbstractChartDSLValidator {
@Check
public void checkAxis(final ChartAxis chartAxis) {
DatamartAxis axis = chartAxis.getAxis();
AxisEnum axisName = axis.getName();
if (((axis.eContainer() == null) && (axisName.getLiteral() == "default"))) {
this.error("Datamart has no attribute definitions anymore. This axis is not available.", ChartDSLPackage.Literals.CHART_AXIS__AXIS);
}
}
@Check
public void checkDuplicateChartNames(final Chart chart) {
EObject eObj = chart.eContainer();
while ((!(eObj instanceof ChartPackage))) {
eObj = eObj.eContainer();
}
if ((eObj != null)) {
ChartPackage chartPackage = ((ChartPackage) eObj);
Chart _findDuplicateChartNames = this.findDuplicateChartNames(chartPackage.getCharts(), chart.getName());
boolean _tripleNotEquals = (_findDuplicateChartNames != null);
if (_tripleNotEquals) {
this.error("Duplicate chart name \'".concat(chart.getName()).concat("\'!"), ChartDSLPackage.Literals.CHART_BASE__NAME);
}
}
}
private Chart findDuplicateChartNames(final EList<Chart> charts, final String chartName) {
HashSet<String> tempSet = CollectionLiterals.<String>newHashSet();
for (final Chart chart : charts) {
if (((!tempSet.add(chart.getName())) && chart.getName().equals(chartName))) {
return chart;
}
}
return null;
}
}