| /** |
| * |
| * 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.menu.validation |
| |
| import java.util.Collection |
| import java.util.HashSet |
| import java.util.LinkedHashSet |
| import java.util.Set |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute |
| import org.eclipse.osbp.xtext.menu.MenuTree |
| import org.eclipse.osbp.xtext.reportdsl.DatamartTableAttribute |
| import org.eclipse.osbp.xtext.menu.MenuCategory |
| import org.eclipse.osbp.xtext.menu.MenuDslPackage |
| 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 MenuDslValidator extends AbstractMenuDslValidator { |
| |
| // 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) |
| // } |
| // } |
| |
| |
| def private Set<MenuTree> findDuplicates(Collection<MenuTree> list) { |
| var duplicates = new LinkedHashSet<MenuTree>(); |
| var uniques = new HashSet<String>(); |
| |
| for(MenuTree tree : list) { |
| if(!uniques.add(tree.name)) { |
| duplicates.add(tree); |
| } |
| } |
| return duplicates; |
| } |
| |
| @Check |
| def checkMenuTreeDuplicates(MenuCategory menu) { |
| var duplicates = menu.trees.findDuplicates |
| var idx = 0 |
| for (menuTree : menu.trees) { |
| if (duplicates.contains(menuTree)) { |
| error('Duplicated menu tree names are not allowed in a menu category definition', MenuDslPackage.Literals.MENU_CATEGORY__TREES, idx) |
| } |
| idx++ |
| } |
| } |
| } |