| /** |
| * 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))) { |
| eObj = eObj.eContainer(); |
| } |
| boolean _notEquals = (!Objects.equal(eObj, null)); |
| if (_notEquals) { |
| ChartPackage chartPackage = ((ChartPackage) eObj); |
| Chart _findDuplicateChartNames = this.findDuplicateChartNames(chartPackage.getCharts(), chart.getName()); |
| boolean _notEquals_1 = (!Objects.equal(_findDuplicateChartNames, null)); |
| if (_notEquals_1) { |
| 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; |
| } |
| } |