aboutsummaryrefslogtreecommitdiffstats
path: root/Application/hu.bme.mit.inf.dslreasoner.application/xtend-gen/hu/bme/mit/inf/dslreasoner/application/validation/MetamodelValidator.java
blob: 44d860227a1179a0b480c4cb73a1bed278e91682 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package hu.bme.mit.inf.dslreasoner.application.validation;

import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;

@SuppressWarnings("all")
public class MetamodelValidator {
  public LinkedList<String> validateMetamodel(final EcoreMetamodelDescriptor descriptor) {
    final LinkedList<String> errors = new LinkedList<String>();
    List<EClass> _classes = descriptor.getClasses();
    this.allSupertypesAreIncluded(_classes, errors);
    List<EEnum> _enums = descriptor.getEnums();
    List<EEnumLiteral> _literals = descriptor.getLiterals();
    this.allEnumTypesareIncluded(_enums, _literals, errors);
    List<EClass> _classes_1 = descriptor.getClasses();
    List<EReference> _references = descriptor.getReferences();
    this.referenceEndpointsAreIncluded(_classes_1, _references, errors);
    List<EClass> _classes_2 = descriptor.getClasses();
    List<EAttribute> _attributes = descriptor.getAttributes();
    this.attributeSourcePontIsIncluded(_classes_2, _attributes, errors);
    List<EAttribute> _attributes_1 = descriptor.getAttributes();
    this.attributeTargetIsSupported(_attributes_1, errors);
    return errors;
  }
  
  private boolean supportedEDataType(final EDataType dataType) {
    @Extension
    final EcorePackage l = EcorePackage.eINSTANCE;
    EDataType _eInt = l.getEInt();
    EDataType _eBoolean = l.getEBoolean();
    EDataType _eString = l.getEString();
    EDataType _eDouble = l.getEDouble();
    EDataType _eFloat = l.getEFloat();
    return Collections.<EDataType>unmodifiableList(CollectionLiterals.<EDataType>newArrayList(_eInt, _eBoolean, _eString, _eDouble, _eFloat)).contains(dataType);
  }
  
  public void allSupertypesAreIncluded(final List<EClass> classes, final List<String> errors) {
    for (final EClass c : classes) {
      EList<EClass> _eSuperTypes = c.getESuperTypes();
      for (final EClass s : _eSuperTypes) {
        boolean _contains = classes.contains(s);
        boolean _not = (!_contains);
        if (_not) {
          StringConcatenation _builder = new StringConcatenation();
          _builder.append("Metamodel contains \"");
          String _name = c.getName();
          _builder.append(_name, "");
          _builder.append("\" but not contains its supertype \"");
          String _name_1 = s.getName();
          _builder.append(_name_1, "");
          _builder.append("\"!");
          errors.add(_builder.toString());
        }
      }
    }
  }
  
  public void allEnumTypesareIncluded(final List<EEnum> enums, final List<EEnumLiteral> literals, final List<String> errors) {
    for (final EEnumLiteral l : literals) {
      EEnum _eEnum = l.getEEnum();
      boolean _contains = enums.contains(_eEnum);
      boolean _not = (!_contains);
      if (_not) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Metamodel contains literal \"");
        String _name = l.getName();
        _builder.append(_name, "");
        _builder.append("\" but does not contains enum \"");
        EEnum _eEnum_1 = l.getEEnum();
        String _name_1 = _eEnum_1.getName();
        _builder.append(_name_1, "");
        _builder.append("\"!");
        errors.add(_builder.toString());
      }
    }
  }
  
  public void referenceEndpointsAreIncluded(final List<EClass> classes, final List<EReference> references, final List<String> errors) {
    for (final EReference reference : references) {
      {
        final EClass src = reference.getEContainingClass();
        boolean _contains = classes.contains(src);
        boolean _not = (!_contains);
        if (_not) {
          StringConcatenation _builder = new StringConcatenation();
          _builder.append("Metamodel contains reference \"");
          String _name = reference.getName();
          _builder.append(_name, "");
          _builder.append("\" but does not contains its source type \"");
          String _name_1 = src.getName();
          _builder.append(_name_1, "");
          _builder.append("\"!");
          errors.add(_builder.toString());
        }
        final EClass trg = reference.getEReferenceType();
        boolean _contains_1 = classes.contains(trg);
        boolean _not_1 = (!_contains_1);
        if (_not_1) {
          StringConcatenation _builder_1 = new StringConcatenation();
          _builder_1.append("Metamodel contains reference \"");
          String _name_2 = reference.getName();
          _builder_1.append(_name_2, "");
          _builder_1.append("\" but does not contains its target type \"");
          String _name_3 = trg.getName();
          _builder_1.append(_name_3, "");
          _builder_1.append("\"!");
          errors.add(_builder_1.toString());
        }
      }
    }
  }
  
  public void attributeSourcePontIsIncluded(final List<EClass> classes, final List<EAttribute> attributes, final List<String> errors) {
    for (final EAttribute attribute : attributes) {
      {
        final Class<?> src = attribute.getContainerClass();
        boolean _contains = classes.contains(src);
        boolean _not = (!_contains);
        if (_not) {
          StringConcatenation _builder = new StringConcatenation();
          _builder.append("Metamodel contains attribute \"");
          String _name = attribute.getName();
          _builder.append(_name, "");
          _builder.append("\" but does not contains its source type \"");
          String _name_1 = src.getName();
          _builder.append(_name_1, "");
          _builder.append("\"!");
          errors.add(_builder.toString());
        }
      }
    }
  }
  
  public void attributeTargetIsSupported(final List<EAttribute> attributes, final List<String> errors) {
    for (final EAttribute attribute : attributes) {
      {
        final EDataType trg = attribute.getEAttributeType();
        boolean _supportedEDataType = this.supportedEDataType(trg);
        boolean _not = (!_supportedEDataType);
        if (_not) {
          StringConcatenation _builder = new StringConcatenation();
          _builder.append("Metamodels contains attribute \"");
          String _name = attribute.getName();
          _builder.append(_name, "");
          _builder.append("\" with unsupported type \"");
          String _name_1 = trg.getName();
          _builder.append(_name_1, "");
          _builder.append("\"!");
          errors.add(_builder.toString());
        }
      }
    }
  }
}