blob: a54aefd7ef90e7707f75c5424950b009b2d524f0 [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 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.chart.validation;
import com.google.common.base.Objects;
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.ChartDSLPackage;
import org.eclipse.osbp.xtext.chart.ChartPackage;
import org.eclipse.osbp.xtext.chart.validation.AbstractChartDSLValidator;
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 checkDuplicateChartNames(final Chart chart) {
EObject eObj = chart.eContainer();
while ((!(eObj instanceof ChartPackage))) {
EObject _eContainer = eObj.eContainer();
eObj = _eContainer;
}
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
ChartPackage chartPackage = ((ChartPackage) eObj);
EList<Chart> _charts = chartPackage.getCharts();
String _name = chart.getName();
Chart _findDuplicateChartNames = this.findDuplicateChartNames(_charts, _name);
boolean _notEquals_1 = (!Objects.equal(_findDuplicateChartNames, null));
if (_notEquals_1) {
String _name_1 = chart.getName();
String _concat = "Duplicate chart name \'".concat(_name_1);
String _concat_1 = _concat.concat("\'!");
this.error(_concat_1, 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) {
boolean _and = false;
String _name = chart.getName();
boolean _add = tempSet.add(_name);
boolean _not = (!_add);
if (!_not) {
_and = false;
} else {
String _name_1 = chart.getName();
boolean _equals = _name_1.equals(chartName);
_and = _equals;
}
if (_and) {
return chart;
}
}
return null;
}
}