1 | package de.ugoe.cs.swe.bnftools.validation;
|
---|
2 |
|
---|
3 | import java.util.Map;
|
---|
4 |
|
---|
5 | import org.eclipse.emf.ecore.EClass;
|
---|
6 | import org.eclipse.emf.ecore.EObject;
|
---|
7 | import org.eclipse.xtext.resource.IEObjectDescription;
|
---|
8 | import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper;
|
---|
9 | import org.eclipse.xtext.validation.ValidationMessageAcceptor;
|
---|
10 |
|
---|
11 | import com.google.common.collect.Maps;
|
---|
12 |
|
---|
13 | import de.ugoe.cs.swe.bnftools.ebnf.ExtRule;
|
---|
14 | import de.ugoe.cs.swe.bnftools.ebnf.MergeRule;
|
---|
15 |
|
---|
16 | public class EbnfNamesAreUniqueValidationHelper extends
|
---|
17 | NamesAreUniqueValidationHelper {
|
---|
18 |
|
---|
19 | protected void checkDescriptionForDuplicatedName(
|
---|
20 | IEObjectDescription description,
|
---|
21 | Map<EClass, Map<String, IEObjectDescription>> clusterTypeToName,
|
---|
22 | ValidationMessageAcceptor acceptor) {
|
---|
23 |
|
---|
24 | EObject object = description.getEObjectOrProxy();
|
---|
25 | EClass eClass = object.eClass();
|
---|
26 | String qualifiedName = description.getName();
|
---|
27 | EClass clusterType = getAssociatedClusterType(eClass);
|
---|
28 |
|
---|
29 | if (object instanceof ExtRule)
|
---|
30 | return;
|
---|
31 | if(object instanceof MergeRule)
|
---|
32 | return;
|
---|
33 | Map<String, IEObjectDescription> nameToDescription = clusterTypeToName.get(clusterType);
|
---|
34 |
|
---|
35 | if (nameToDescription == null) {
|
---|
36 | nameToDescription = Maps.newHashMap();
|
---|
37 | nameToDescription.put(qualifiedName, description);
|
---|
38 |
|
---|
39 | clusterTypeToName.put(clusterType, nameToDescription);
|
---|
40 | } else {
|
---|
41 | if (nameToDescription.containsKey(qualifiedName)) {
|
---|
42 | IEObjectDescription prevDescription = nameToDescription.get(qualifiedName);
|
---|
43 | if (prevDescription != null) {
|
---|
44 | createDuplicateNameError(prevDescription, clusterType, acceptor);
|
---|
45 | nameToDescription.put(qualifiedName, null);
|
---|
46 | }
|
---|
47 | createDuplicateNameError(description, clusterType, acceptor);
|
---|
48 | } else {
|
---|
49 | nameToDescription.put(qualifiedName, description);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|