aboutsummaryrefslogtreecommitdiffstats
path: root/Application/hu.bme.mit.inf.dslreasoner.application/xtend-gen/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.java
blob: dbe4b17ba5cefbe88259362795d080a1d001801b (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
168
169
170
171
172
173
174
175
<<<<<<< HEAD
package hu.bme.mit.inf.dslreasoner.application.validation;

import com.google.common.collect.Iterables;
import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor;
import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.viatra.query.patternlanguage.emf.vql.Pattern;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.Pair;

@SuppressWarnings("all")
public class QueryAndMetamodelValidator {
  public LinkedList<String> validateQueryAndMetamodel(final EcoreMetamodelDescriptor metamodel, final Pair<ViatraQuerySetDescriptor, Set<Pattern>> viatra) {
    final Set<Pattern> patterns = viatra.getValue();
    List<EClass> _classes = metamodel.getClasses();
    List<EEnum> _enums = metamodel.getEnums();
    Iterable<EClassifier> _plus = Iterables.<EClassifier>concat(_classes, _enums);
    List<EEnumLiteral> _literals = metamodel.getLiterals();
    Iterable<ENamedElement> _plus_1 = Iterables.<ENamedElement>concat(_plus, _literals);
    List<EAttribute> _attributes = metamodel.getAttributes();
    Iterable<ENamedElement> _plus_2 = Iterables.<ENamedElement>concat(_plus_1, _attributes);
    List<EReference> _references = metamodel.getReferences();
    final Set<ENamedElement> elementsInMetamodel = IterableExtensions.<ENamedElement>toSet(Iterables.<ENamedElement>concat(_plus_2, _references));
    final LinkedList<String> errors = new LinkedList<String>();
    for (final Pattern pattern : patterns) {
      {
        final Iterable<ENamedElement> elements = this.getReferredNamedElements(pattern);
        for (final ENamedElement element : elements) {
          boolean _contains = elementsInMetamodel.contains(element);
          boolean _not = (!_contains);
          if (_not) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Pattern \"");
            String _name = pattern.getName();
            _builder.append(_name);
            _builder.append("\" refers to an element \"");
            _builder.append(element);
            _builder.append("\" that is not included to the selected metamodel!");
            errors.add(_builder.toString());
          }
        }
      }
    }
    return errors;
  }
  
  public Iterable<ENamedElement> getReferredNamedElements(final Pattern pattern) {
    final List<EObject> elements = IteratorExtensions.<EObject>toList(pattern.eAllContents());
    final Function1<EObject, Iterable<ENamedElement>> _function = (EObject element) -> {
      final EList<EReference> references = element.eClass().getEAllReferences();
      final Function1<EReference, Iterable<ENamedElement>> _function_1 = (EReference r) -> {
        boolean _isMany = r.isMany();
        if (_isMany) {
          Object _eGet = element.eGet(r);
          return Iterables.<ENamedElement>filter(((List<?>) _eGet), ENamedElement.class);
        } else {
          final Object value = element.eGet(r);
          if ((value instanceof ENamedElement)) {
            return Collections.<ENamedElement>unmodifiableList(CollectionLiterals.<ENamedElement>newArrayList(((ENamedElement)value)));
          } else {
            return Collections.<ENamedElement>unmodifiableList(CollectionLiterals.<ENamedElement>newArrayList());
          }
        }
      };
      return Iterables.<ENamedElement>filter((Iterables.<ENamedElement>concat(ListExtensions.<EReference, Iterable<ENamedElement>>map(references, _function_1))), ENamedElement.class);
    };
    return Iterables.<ENamedElement>concat(ListExtensions.<EObject, Iterable<ENamedElement>>map(elements, _function));
  }
}
=======
package hu.bme.mit.inf.dslreasoner.application.validation;

import com.google.common.collect.Iterables;
import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor;
import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.viatra.query.patternlanguage.emf.vql.Pattern;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.Pair;

@SuppressWarnings("all")
public class QueryAndMetamodelValidator {
  public LinkedList<String> validateQueryAndMetamodel(final EcoreMetamodelDescriptor metamodel, final Pair<ViatraQuerySetDescriptor, Set<Pattern>> viatra) {
    final Set<Pattern> patterns = viatra.getValue();
    List<EClass> _classes = metamodel.getClasses();
    List<EEnum> _enums = metamodel.getEnums();
    Iterable<EClassifier> _plus = Iterables.<EClassifier>concat(_classes, _enums);
    List<EEnumLiteral> _literals = metamodel.getLiterals();
    Iterable<ENamedElement> _plus_1 = Iterables.<ENamedElement>concat(_plus, _literals);
    List<EAttribute> _attributes = metamodel.getAttributes();
    Iterable<ENamedElement> _plus_2 = Iterables.<ENamedElement>concat(_plus_1, _attributes);
    List<EReference> _references = metamodel.getReferences();
    final Set<ENamedElement> elementsInMetamodel = IterableExtensions.<ENamedElement>toSet(Iterables.<ENamedElement>concat(_plus_2, _references));
    final LinkedList<String> errors = new LinkedList<String>();
    for (final Pattern pattern : patterns) {
      {
        final Iterable<ENamedElement> elements = this.getReferredNamedElements(pattern);
        for (final ENamedElement element : elements) {
          boolean _contains = elementsInMetamodel.contains(element);
          boolean _not = (!_contains);
          if (_not) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Pattern \"");
            String _name = pattern.getName();
            _builder.append(_name);
            _builder.append("\" refers to an element \"");
            _builder.append(element);
            _builder.append("\" that is not included to the selected metamodel!");
            errors.add(_builder.toString());
          }
        }
      }
    }
    return errors;
  }
  
  public Iterable<ENamedElement> getReferredNamedElements(final Pattern pattern) {
    final List<EObject> elements = IteratorExtensions.<EObject>toList(pattern.eAllContents());
    final Function1<EObject, Iterable<ENamedElement>> _function = (EObject element) -> {
      final EList<EReference> references = element.eClass().getEAllReferences();
      final Function1<EReference, Iterable<ENamedElement>> _function_1 = (EReference r) -> {
        boolean _isMany = r.isMany();
        if (_isMany) {
          Object _eGet = element.eGet(r);
          return Iterables.<ENamedElement>filter(((List<?>) _eGet), ENamedElement.class);
        } else {
          final Object value = element.eGet(r);
          if ((value instanceof ENamedElement)) {
            return Collections.<ENamedElement>unmodifiableList(CollectionLiterals.<ENamedElement>newArrayList(((ENamedElement)value)));
          } else {
            return Collections.<ENamedElement>unmodifiableList(CollectionLiterals.<ENamedElement>newArrayList());
          }
        }
      };
      return Iterables.<ENamedElement>filter((Iterables.<ENamedElement>concat(ListExtensions.<EReference, Iterable<ENamedElement>>map(references, _function_1))), ENamedElement.class);
    };
    return Iterables.<ENamedElement>concat(ListExtensions.<EObject, Iterable<ENamedElement>>map(elements, _function));
  }
}
>>>>>>> 8ecc73c4... VAMPIRE: Rebase on Master