diff options
Diffstat (limited to 'subprojects/language-model/src')
7 files changed, 795 insertions, 0 deletions
diff --git a/subprojects/language-model/src/main/java/tools/refinery/language/model/GenerateProblemModel.mwe2 b/subprojects/language-model/src/main/java/tools/refinery/language/model/GenerateProblemModel.mwe2 new file mode 100644 index 00000000..15198d69 --- /dev/null +++ b/subprojects/language-model/src/main/java/tools/refinery/language/model/GenerateProblemModel.mwe2 | |||
@@ -0,0 +1,20 @@ | |||
1 | module tools.refinery.language.model.GenerateProblemModel | ||
2 | |||
3 | Workflow { | ||
4 | bean = org.eclipse.emf.mwe.utils.StandaloneSetup { | ||
5 | projectMapping = { | ||
6 | projectName = "tools.refinery.refinery-language-model" | ||
7 | path = "." | ||
8 | } | ||
9 | } | ||
10 | |||
11 | component = org.eclipse.emf.mwe.utils.DirectoryCleaner { | ||
12 | directory = "src/main/emf-gen" | ||
13 | } | ||
14 | |||
15 | component = org.eclipse.emf.mwe2.ecore.EcoreGenerator { | ||
16 | generateCustomClasses = false | ||
17 | genModel = "platform:/resource/tools.refinery.refinery-language-model/src/main/resources/model/problem.genmodel" | ||
18 | srcPath = "platform:/resource/tools.refinery.refinery-language-model/src/main/emf-gen" | ||
19 | } | ||
20 | } | ||
diff --git a/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java b/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java new file mode 100644 index 00000000..9383098b --- /dev/null +++ b/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java | |||
@@ -0,0 +1,34 @@ | |||
1 | package tools.refinery.language.model; | ||
2 | |||
3 | import org.eclipse.emf.ecore.EPackage; | ||
4 | import org.eclipse.emf.ecore.resource.Resource; | ||
5 | |||
6 | import tools.refinery.language.model.problem.ProblemPackage; | ||
7 | import tools.refinery.language.model.problem.impl.ProblemFactoryImpl; | ||
8 | |||
9 | public class ProblemEMFSetup { | ||
10 | public static final String XMI_RESOURCE_EXTENSION = "problem_xmi"; | ||
11 | |||
12 | private ProblemEMFSetup() { | ||
13 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
14 | } | ||
15 | |||
16 | // Here we can't rely on java.util.HashMap#putIfAbsent, because | ||
17 | // org.eclipse.emf.ecore.impl.EPackageRegistryImpl#containsKey is overridden | ||
18 | // without also overriding putIfAbsent. We must make sure to call the | ||
19 | // overridden containsKey implementation. | ||
20 | @SuppressWarnings("squid:S3824") | ||
21 | public static void doEMFRegistration() { | ||
22 | if (!EPackage.Registry.INSTANCE.containsKey(ProblemPackage.eNS_URI)) { | ||
23 | EPackage.Registry.INSTANCE.put(ProblemPackage.eNS_URI, ProblemPackage.eINSTANCE); | ||
24 | } | ||
25 | |||
26 | // This Resource.Factory is not actually used once | ||
27 | // tools.refinery.language.ProblemStandaloneSetup.createInjectorAndDoEMFRegistration() | ||
28 | // is called, because if will be replaced by | ||
29 | // tools.refinery.language.resource.ProblemXmiResourceFactory, which implements | ||
30 | // org.eclipse.xtext.resource.IResourceFactory as required by Xtext. | ||
31 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().putIfAbsent(XMI_RESOURCE_EXTENSION, | ||
32 | new ProblemFactoryImpl()); | ||
33 | } | ||
34 | } | ||
diff --git a/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemUtil.java b/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemUtil.java new file mode 100644 index 00000000..d8958381 --- /dev/null +++ b/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemUtil.java | |||
@@ -0,0 +1,121 @@ | |||
1 | package tools.refinery.language.model; | ||
2 | |||
3 | import java.util.ArrayDeque; | ||
4 | import java.util.Collection; | ||
5 | import java.util.Deque; | ||
6 | import java.util.HashSet; | ||
7 | import java.util.Optional; | ||
8 | import java.util.Set; | ||
9 | |||
10 | import org.eclipse.emf.common.util.URI; | ||
11 | import org.eclipse.emf.ecore.EObject; | ||
12 | import org.eclipse.emf.ecore.resource.Resource; | ||
13 | |||
14 | import tools.refinery.language.model.problem.ClassDeclaration; | ||
15 | import tools.refinery.language.model.problem.ImplicitVariable; | ||
16 | import tools.refinery.language.model.problem.Node; | ||
17 | import tools.refinery.language.model.problem.Problem; | ||
18 | import tools.refinery.language.model.problem.ProblemPackage; | ||
19 | import tools.refinery.language.model.problem.ReferenceDeclaration; | ||
20 | import tools.refinery.language.model.problem.Relation; | ||
21 | import tools.refinery.language.model.problem.Variable; | ||
22 | |||
23 | public final class ProblemUtil { | ||
24 | public static final String BUILTIN_LIBRARY_NAME = "builtin"; | ||
25 | |||
26 | public static final URI BUILTIN_LIBRARY_URI = getLibraryUri(BUILTIN_LIBRARY_NAME); | ||
27 | |||
28 | public static final String NODE_CLASS_NAME = "node"; | ||
29 | |||
30 | private ProblemUtil() { | ||
31 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
32 | } | ||
33 | |||
34 | public static boolean isSingletonVariable(Variable variable) { | ||
35 | return variable.eContainingFeature() == ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__SINGLETON_VARIABLE; | ||
36 | } | ||
37 | |||
38 | public static boolean isImplicitVariable(Variable variable) { | ||
39 | return variable instanceof ImplicitVariable; | ||
40 | } | ||
41 | |||
42 | public static boolean isImplicitNode(Node node) { | ||
43 | return node.eContainingFeature() == ProblemPackage.Literals.PROBLEM__NODES; | ||
44 | } | ||
45 | |||
46 | public static boolean isImplicit(EObject eObject) { | ||
47 | if (eObject instanceof Node node) { | ||
48 | return isImplicitNode(node); | ||
49 | } else if (eObject instanceof Variable variable) { | ||
50 | return isImplicitVariable(variable); | ||
51 | } else { | ||
52 | return false; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public static boolean isIndividualNode(Node node) { | ||
57 | var containingFeature = node.eContainingFeature(); | ||
58 | return containingFeature == ProblemPackage.Literals.INDIVIDUAL_DECLARATION__NODES | ||
59 | || containingFeature == ProblemPackage.Literals.ENUM_DECLARATION__LITERALS; | ||
60 | } | ||
61 | |||
62 | public static boolean isNewNode(Node node) { | ||
63 | return node.eContainingFeature() == ProblemPackage.Literals.CLASS_DECLARATION__NEW_NODE; | ||
64 | } | ||
65 | |||
66 | public static Optional<Problem> getBuiltInLibrary(EObject context) { | ||
67 | return Optional.ofNullable(context.eResource()).map(Resource::getResourceSet) | ||
68 | .map(resourceSet -> resourceSet.getResource(BUILTIN_LIBRARY_URI, true)).map(Resource::getContents) | ||
69 | .filter(contents -> !contents.isEmpty()).map(contents -> contents.get(0)) | ||
70 | .filter(Problem.class::isInstance).map(Problem.class::cast); | ||
71 | } | ||
72 | |||
73 | public static boolean isBuiltIn(EObject eObject) { | ||
74 | if (eObject != null) { | ||
75 | var eResource = eObject.eResource(); | ||
76 | if (eResource != null) { | ||
77 | return BUILTIN_LIBRARY_URI.equals(eResource.getURI()); | ||
78 | } | ||
79 | } | ||
80 | return false; | ||
81 | } | ||
82 | |||
83 | public static Optional<ClassDeclaration> getNodeClassDeclaration(EObject context) { | ||
84 | return getBuiltInLibrary(context).flatMap(problem -> problem.getStatements().stream() | ||
85 | .filter(ClassDeclaration.class::isInstance).map(ClassDeclaration.class::cast) | ||
86 | .filter(declaration -> NODE_CLASS_NAME.equals(declaration.getName())).findFirst()); | ||
87 | } | ||
88 | |||
89 | public static Collection<ClassDeclaration> getSuperclassesAndSelf(ClassDeclaration classDeclaration) { | ||
90 | Set<ClassDeclaration> found = new HashSet<>(); | ||
91 | getNodeClassDeclaration(classDeclaration).ifPresent(found::add); | ||
92 | Deque<ClassDeclaration> queue = new ArrayDeque<>(); | ||
93 | queue.addLast(classDeclaration); | ||
94 | while (!queue.isEmpty()) { | ||
95 | ClassDeclaration current = queue.removeFirst(); | ||
96 | if (!found.contains(current)) { | ||
97 | found.add(current); | ||
98 | for (Relation superType : current.getSuperTypes()) { | ||
99 | if (superType instanceof ClassDeclaration superDeclaration) { | ||
100 | queue.addLast(superDeclaration); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | return found; | ||
106 | } | ||
107 | |||
108 | public static Collection<ReferenceDeclaration> getAllReferenceDeclarations(ClassDeclaration classDeclaration) { | ||
109 | Set<ReferenceDeclaration> referenceDeclarations = new HashSet<>(); | ||
110 | for (ClassDeclaration superclass : getSuperclassesAndSelf(classDeclaration)) { | ||
111 | referenceDeclarations.addAll(superclass.getReferenceDeclarations()); | ||
112 | } | ||
113 | return referenceDeclarations; | ||
114 | } | ||
115 | |||
116 | private static URI getLibraryUri(String libraryName) { | ||
117 | return URI.createURI(ProblemUtil.class.getClassLoader() | ||
118 | .getResource("model/" + libraryName + "." + ProblemEMFSetup.XMI_RESOURCE_EXTENSION) | ||
119 | .toString()); | ||
120 | } | ||
121 | } | ||
diff --git a/subprojects/language-model/src/main/resources/model/builtin.problem_xmi b/subprojects/language-model/src/main/resources/model/builtin.problem_xmi new file mode 100644 index 00000000..9255ab66 --- /dev/null +++ b/subprojects/language-model/src/main/resources/model/builtin.problem_xmi | |||
@@ -0,0 +1,67 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <problem:Problem | ||
3 | xmi:version="2.0" | ||
4 | xmlns:xmi="http://www.omg.org/XMI" | ||
5 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
6 | xmlns:problem="https://refinery.tools/emf/2021/Problem" | ||
7 | xsi:schemaLocation="https://refinery.tools/emf/2021/Problem problem.ecore" | ||
8 | name="builtin"> | ||
9 | <statements | ||
10 | xsi:type="problem:ClassDeclaration" | ||
11 | name="node" | ||
12 | abstract="true"> | ||
13 | <referenceDeclarations | ||
14 | name="equals" | ||
15 | referenceType="//@statements.0" | ||
16 | opposite="//@statements.0/@referenceDeclarations.0"> | ||
17 | <multiplicity | ||
18 | xsi:type="problem:UnboundedMultiplicity"/> | ||
19 | </referenceDeclarations> | ||
20 | </statements> | ||
21 | <statements | ||
22 | xsi:type="problem:PredicateDefinition" | ||
23 | name="exists"> | ||
24 | <parameters | ||
25 | name="node" | ||
26 | parameterType="//@statements.0"/> | ||
27 | </statements> | ||
28 | <statements | ||
29 | xsi:type="problem:ClassDeclaration" | ||
30 | name="domain" | ||
31 | abstract="true" | ||
32 | superTypes="//@statements.0"/> | ||
33 | <statements | ||
34 | xsi:type="problem:ClassDeclaration" | ||
35 | name="data" | ||
36 | abstract="true" | ||
37 | superTypes="//@statements.0"/> | ||
38 | <statements | ||
39 | xsi:type="problem:EnumDeclaration" | ||
40 | name="bool"> | ||
41 | <literals | ||
42 | name="false"/> | ||
43 | <literals | ||
44 | name="true"/> | ||
45 | </statements> | ||
46 | <statements | ||
47 | xsi:type="problem:ClassDeclaration" | ||
48 | name="real" | ||
49 | superTypes="//@statements.3"> | ||
50 | <newNode | ||
51 | name="new"/> | ||
52 | </statements> | ||
53 | <statements | ||
54 | xsi:type="problem:ClassDeclaration" | ||
55 | name="int" | ||
56 | superTypes="//@statements.3"> | ||
57 | <newNode | ||
58 | name="new"/> | ||
59 | </statements> | ||
60 | <statements | ||
61 | xsi:type="problem:ClassDeclaration" | ||
62 | name="string" | ||
63 | superTypes="//@statements.3"> | ||
64 | <newNode | ||
65 | name="new"/> | ||
66 | </statements> | ||
67 | </problem:Problem> | ||
diff --git a/subprojects/language-model/src/main/resources/model/problem.ecore b/subprojects/language-model/src/main/resources/model/problem.ecore new file mode 100644 index 00000000..582f67c8 --- /dev/null +++ b/subprojects/language-model/src/main/resources/model/problem.ecore | |||
@@ -0,0 +1,191 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="problem" nsURI="https://refinery.tools/emf/2021/Problem" nsPrefix="problem"> | ||
4 | <eClassifiers xsi:type="ecore:EClass" name="Problem" eSuperTypes="#//NamedElement"> | ||
5 | <eStructuralFeatures xsi:type="ecore:EReference" name="nodes" upperBound="-1" | ||
6 | eType="#//Node" transient="true" containment="true"/> | ||
7 | <eStructuralFeatures xsi:type="ecore:EReference" name="statements" upperBound="-1" | ||
8 | eType="#//Statement" containment="true"/> | ||
9 | </eClassifiers> | ||
10 | <eClassifiers xsi:type="ecore:EClass" name="Relation" abstract="true" eSuperTypes="#//NamedElement"/> | ||
11 | <eClassifiers xsi:type="ecore:EClass" name="ClassDeclaration" eSuperTypes="#//Relation #//Statement"> | ||
12 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="abstract" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
13 | <eStructuralFeatures xsi:type="ecore:EReference" name="superTypes" upperBound="-1" | ||
14 | eType="#//Relation"/> | ||
15 | <eStructuralFeatures xsi:type="ecore:EReference" name="referenceDeclarations" | ||
16 | upperBound="-1" eType="#//ReferenceDeclaration" containment="true"/> | ||
17 | <eStructuralFeatures xsi:type="ecore:EReference" name="newNode" eType="#//Node" | ||
18 | transient="true" containment="true"/> | ||
19 | </eClassifiers> | ||
20 | <eClassifiers xsi:type="ecore:EClass" name="ReferenceDeclaration" eSuperTypes="#//Relation"> | ||
21 | <eStructuralFeatures xsi:type="ecore:EReference" name="referenceType" eType="#//Relation"/> | ||
22 | <eStructuralFeatures xsi:type="ecore:EReference" name="opposite" eType="#//ReferenceDeclaration"/> | ||
23 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="containment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
24 | <eStructuralFeatures xsi:type="ecore:EReference" name="multiplicity" eType="#//Multiplicity" | ||
25 | containment="true"/> | ||
26 | </eClassifiers> | ||
27 | <eClassifiers xsi:type="ecore:EClass" name="NamedElement" abstract="true"> | ||
28 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> | ||
29 | </eClassifiers> | ||
30 | <eClassifiers xsi:type="ecore:EClass" name="PredicateDefinition" eSuperTypes="#//Relation #//ParametricDefinition"> | ||
31 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="error" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
32 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="kind" eType="#//PredicateKind" | ||
33 | defaultValueLiteral="PARTIAL"/> | ||
34 | </eClassifiers> | ||
35 | <eClassifiers xsi:type="ecore:EClass" name="Parameter" eSuperTypes="#//Variable"> | ||
36 | <eStructuralFeatures xsi:type="ecore:EReference" name="parameterType" eType="#//Relation"/> | ||
37 | </eClassifiers> | ||
38 | <eClassifiers xsi:type="ecore:EClass" name="Variable" abstract="true" eSuperTypes="#//VariableOrNode"/> | ||
39 | <eClassifiers xsi:type="ecore:EClass" name="Conjunction" eSuperTypes="#//ExistentialQuantifier"> | ||
40 | <eStructuralFeatures xsi:type="ecore:EReference" name="literals" upperBound="-1" | ||
41 | eType="#//Literal" containment="true"/> | ||
42 | </eClassifiers> | ||
43 | <eClassifiers xsi:type="ecore:EClass" name="Literal" abstract="true"/> | ||
44 | <eClassifiers xsi:type="ecore:EClass" name="Atom" eSuperTypes="#//Literal"> | ||
45 | <eStructuralFeatures xsi:type="ecore:EReference" name="relation" eType="#//Relation"/> | ||
46 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="transitiveClosure" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
47 | <eStructuralFeatures xsi:type="ecore:EReference" name="arguments" upperBound="-1" | ||
48 | eType="#//Argument" containment="true"/> | ||
49 | </eClassifiers> | ||
50 | <eClassifiers xsi:type="ecore:EClass" name="ImplicitVariable" eSuperTypes="#//Variable"/> | ||
51 | <eClassifiers xsi:type="ecore:EClass" name="NegativeLiteral" eSuperTypes="#//ExistentialQuantifier #//CompoundLiteral"/> | ||
52 | <eClassifiers xsi:type="ecore:EClass" name="ExistentialQuantifier" abstract="true" | ||
53 | interface="true"> | ||
54 | <eStructuralFeatures xsi:type="ecore:EReference" name="implicitVariables" upperBound="-1" | ||
55 | eType="#//ImplicitVariable" transient="true" containment="true"/> | ||
56 | </eClassifiers> | ||
57 | <eClassifiers xsi:type="ecore:EClass" name="Assertion" eSuperTypes="#//Statement"> | ||
58 | <eStructuralFeatures xsi:type="ecore:EReference" name="relation" eType="#//Relation"/> | ||
59 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="#//LogicValue"/> | ||
60 | <eStructuralFeatures xsi:type="ecore:EReference" name="arguments" upperBound="-1" | ||
61 | eType="#//AssertionArgument" containment="true"/> | ||
62 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="default" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" | ||
63 | defaultValueLiteral="false"/> | ||
64 | </eClassifiers> | ||
65 | <eClassifiers xsi:type="ecore:EClass" name="Node" eSuperTypes="#//VariableOrNode"/> | ||
66 | <eClassifiers xsi:type="ecore:EEnum" name="LogicValue"> | ||
67 | <eLiterals name="TRUE" literal="TRUE"/> | ||
68 | <eLiterals name="FALSE" value="1"/> | ||
69 | <eLiterals name="UNKNOWN" value="2"/> | ||
70 | <eLiterals name="ERROR" value="3"/> | ||
71 | </eClassifiers> | ||
72 | <eClassifiers xsi:type="ecore:EClass" name="ScopeDeclaration" eSuperTypes="#//Statement"> | ||
73 | <eStructuralFeatures xsi:type="ecore:EReference" name="typeScopes" upperBound="-1" | ||
74 | eType="#//TypeScope" containment="true"/> | ||
75 | </eClassifiers> | ||
76 | <eClassifiers xsi:type="ecore:EClass" name="Statement" abstract="true" interface="true"/> | ||
77 | <eClassifiers xsi:type="ecore:EClass" name="TypeScope"> | ||
78 | <eStructuralFeatures xsi:type="ecore:EReference" name="targetType" eType="#//ClassDeclaration"/> | ||
79 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="increment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
80 | <eStructuralFeatures xsi:type="ecore:EReference" name="multiplicity" eType="#//Multiplicity" | ||
81 | containment="true"/> | ||
82 | </eClassifiers> | ||
83 | <eClassifiers xsi:type="ecore:EClass" name="Multiplicity" abstract="true"/> | ||
84 | <eClassifiers xsi:type="ecore:EClass" name="RangeMultiplicity" eSuperTypes="#//Multiplicity"> | ||
85 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="lowerBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt" | ||
86 | defaultValueLiteral="0"/> | ||
87 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="upperBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt" | ||
88 | defaultValueLiteral="-1"/> | ||
89 | </eClassifiers> | ||
90 | <eClassifiers xsi:type="ecore:EClass" name="ExactMultiplicity" eSuperTypes="#//Multiplicity"> | ||
91 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="exactValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt" | ||
92 | defaultValueLiteral="1"/> | ||
93 | </eClassifiers> | ||
94 | <eClassifiers xsi:type="ecore:EClass" name="UnboundedMultiplicity" eSuperTypes="#//Multiplicity"/> | ||
95 | <eClassifiers xsi:type="ecore:EClass" name="VariableOrNodeArgument" eSuperTypes="#//Argument"> | ||
96 | <eStructuralFeatures xsi:type="ecore:EReference" name="variableOrNode" eType="#//VariableOrNode"/> | ||
97 | <eStructuralFeatures xsi:type="ecore:EReference" name="singletonVariable" eType="#//ImplicitVariable" | ||
98 | transient="true" containment="true"/> | ||
99 | </eClassifiers> | ||
100 | <eClassifiers xsi:type="ecore:EClass" name="EnumDeclaration" eSuperTypes="#//Relation #//Statement"> | ||
101 | <eStructuralFeatures xsi:type="ecore:EReference" name="literals" upperBound="-1" | ||
102 | eType="#//Node" containment="true"/> | ||
103 | </eClassifiers> | ||
104 | <eClassifiers xsi:type="ecore:EClass" name="VariableOrNode" abstract="true" eSuperTypes="#//NamedElement"/> | ||
105 | <eClassifiers xsi:type="ecore:EClass" name="Constant" abstract="true"/> | ||
106 | <eClassifiers xsi:type="ecore:EClass" name="IntConstant" eSuperTypes="#//Constant"> | ||
107 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="intValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt" | ||
108 | defaultValueLiteral="0"/> | ||
109 | </eClassifiers> | ||
110 | <eClassifiers xsi:type="ecore:EClass" name="RealConstant" eSuperTypes="#//Constant"> | ||
111 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="realValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble" | ||
112 | defaultValueLiteral="0.0"/> | ||
113 | </eClassifiers> | ||
114 | <eClassifiers xsi:type="ecore:EClass" name="StringConstant" eSuperTypes="#//Constant"> | ||
115 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="stringValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> | ||
116 | </eClassifiers> | ||
117 | <eClassifiers xsi:type="ecore:EClass" name="ConstantArgument" eSuperTypes="#//Argument"> | ||
118 | <eStructuralFeatures xsi:type="ecore:EReference" name="constant" eType="#//Constant" | ||
119 | containment="true"/> | ||
120 | </eClassifiers> | ||
121 | <eClassifiers xsi:type="ecore:EClass" name="Argument" abstract="true"/> | ||
122 | <eClassifiers xsi:type="ecore:EClass" name="NodeAssertionArgument" eSuperTypes="#//AssertionArgument"> | ||
123 | <eStructuralFeatures xsi:type="ecore:EReference" name="node" eType="#//Node"/> | ||
124 | </eClassifiers> | ||
125 | <eClassifiers xsi:type="ecore:EClass" name="AssertionArgument" abstract="true"/> | ||
126 | <eClassifiers xsi:type="ecore:EClass" name="ConstantAssertionArgument" eSuperTypes="#//AssertionArgument"> | ||
127 | <eStructuralFeatures xsi:type="ecore:EReference" name="constant" eType="#//Constant" | ||
128 | containment="true"/> | ||
129 | </eClassifiers> | ||
130 | <eClassifiers xsi:type="ecore:EClass" name="NodeValueAssertion" eSuperTypes="#//Statement"> | ||
131 | <eStructuralFeatures xsi:type="ecore:EReference" name="node" eType="#//Node"/> | ||
132 | <eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="#//Constant" | ||
133 | containment="true"/> | ||
134 | </eClassifiers> | ||
135 | <eClassifiers xsi:type="ecore:EClass" name="IndividualDeclaration" eSuperTypes="#//Statement"> | ||
136 | <eStructuralFeatures xsi:type="ecore:EReference" name="nodes" upperBound="-1" | ||
137 | eType="#//Node" containment="true"/> | ||
138 | </eClassifiers> | ||
139 | <eClassifiers xsi:type="ecore:EClass" name="WildcardAssertionArgument" eSuperTypes="#//AssertionArgument"/> | ||
140 | <eClassifiers xsi:type="ecore:EClass" name="ParametricDefinition" abstract="true" | ||
141 | interface="true" eSuperTypes="#//Statement"> | ||
142 | <eStructuralFeatures xsi:type="ecore:EReference" name="bodies" upperBound="-1" | ||
143 | eType="#//Conjunction" containment="true"/> | ||
144 | <eStructuralFeatures xsi:type="ecore:EReference" name="parameters" upperBound="-1" | ||
145 | eType="#//Parameter" containment="true"/> | ||
146 | </eClassifiers> | ||
147 | <eClassifiers xsi:type="ecore:EClass" name="RuleDefinition" eSuperTypes="#//ParametricDefinition #//NamedElement"> | ||
148 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="kind" eType="#//RuleKind" | ||
149 | defaultValueLiteral="DIRECT"/> | ||
150 | <eStructuralFeatures xsi:type="ecore:EReference" name="action" eType="#//Action" | ||
151 | containment="true"/> | ||
152 | </eClassifiers> | ||
153 | <eClassifiers xsi:type="ecore:EClass" name="Action"> | ||
154 | <eStructuralFeatures xsi:type="ecore:EReference" name="actionLiterals" upperBound="-1" | ||
155 | eType="#//ActionLiteral" containment="true"/> | ||
156 | </eClassifiers> | ||
157 | <eClassifiers xsi:type="ecore:EClass" name="ActionLiteral" abstract="true"/> | ||
158 | <eClassifiers xsi:type="ecore:EClass" name="ValueActionLiteral" eSuperTypes="#//ActionLiteral"> | ||
159 | <eStructuralFeatures xsi:type="ecore:EReference" name="atom" eType="#//Atom" containment="true"/> | ||
160 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="#//LogicValue" | ||
161 | defaultValueLiteral="TRUE"/> | ||
162 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="refinement" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" | ||
163 | defaultValueLiteral="FALSE"/> | ||
164 | </eClassifiers> | ||
165 | <eClassifiers xsi:type="ecore:EClass" name="DeleteActionLiteral" eSuperTypes="#//ActionLiteral"> | ||
166 | <eStructuralFeatures xsi:type="ecore:EReference" name="variableOrNode" eType="#//VariableOrNode"/> | ||
167 | </eClassifiers> | ||
168 | <eClassifiers xsi:type="ecore:EClass" name="NewActionLiteral" eSuperTypes="#//ActionLiteral"> | ||
169 | <eStructuralFeatures xsi:type="ecore:EReference" name="variable" eType="#//NewVariable" | ||
170 | containment="true"/> | ||
171 | </eClassifiers> | ||
172 | <eClassifiers xsi:type="ecore:EClass" name="NewVariable" eSuperTypes="#//Variable"/> | ||
173 | <eClassifiers xsi:type="ecore:EClass" name="CompoundLiteral" abstract="true" eSuperTypes="#//Literal"> | ||
174 | <eStructuralFeatures xsi:type="ecore:EReference" name="atom" eType="#//Atom" containment="true"/> | ||
175 | </eClassifiers> | ||
176 | <eClassifiers xsi:type="ecore:EClass" name="ValueLiteral" eSuperTypes="#//CompoundLiteral"> | ||
177 | <eStructuralFeatures xsi:type="ecore:EReference" name="values" upperBound="-1" | ||
178 | eType="#//LogicConstant" containment="true"/> | ||
179 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="refinement" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> | ||
180 | </eClassifiers> | ||
181 | <eClassifiers xsi:type="ecore:EClass" name="LogicConstant"> | ||
182 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="#//LogicValue"/> | ||
183 | </eClassifiers> | ||
184 | <eClassifiers xsi:type="ecore:EEnum" name="PredicateKind"> | ||
185 | <eLiterals name="PARTIAL"/> | ||
186 | <eLiterals name="DIRECT" value="1"/> | ||
187 | </eClassifiers> | ||
188 | <eClassifiers xsi:type="ecore:EEnum" name="RuleKind"> | ||
189 | <eLiterals name="DIRECT"/> | ||
190 | </eClassifiers> | ||
191 | </ecore:EPackage> | ||
diff --git a/subprojects/language-model/src/main/resources/model/problem.genmodel b/subprojects/language-model/src/main/resources/model/problem.genmodel new file mode 100644 index 00000000..9ba2274b --- /dev/null +++ b/subprojects/language-model/src/main/resources/model/problem.genmodel | |||
@@ -0,0 +1,165 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" | ||
4 | modelDirectory="/tools.refinery.refinery-language-model/src/main/emf-gen" | ||
5 | creationIcons="false" editDirectory="/language-edit/src/main/emf-gen" editorDirectory="/org.eclipse.viatra.solver.language.model.editor/src-gen" | ||
6 | modelPluginID="language-model" modelName="Problem" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container" | ||
7 | codeFormatting="true" importerID="org.eclipse.emf.importer.ecore" complianceLevel="5.0" | ||
8 | copyrightFields="false" operationReflection="true" importOrganizing="true"> | ||
9 | <foreignModel>problem.ecore</foreignModel> | ||
10 | <testsDirectory xsi:nil="true"/> | ||
11 | <genPackages prefix="Problem" basePackage="tools.refinery.language.model" resource="XMI" | ||
12 | disposableProviderFactory="true" fileExtensions="problem_xmi" ecorePackage="problem.ecore#/"> | ||
13 | <genEnums typeSafeEnumCompatible="false" ecoreEnum="problem.ecore#//LogicValue"> | ||
14 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//LogicValue/TRUE"/> | ||
15 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//LogicValue/FALSE"/> | ||
16 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//LogicValue/UNKNOWN"/> | ||
17 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//LogicValue/ERROR"/> | ||
18 | </genEnums> | ||
19 | <genEnums typeSafeEnumCompatible="false" ecoreEnum="problem.ecore#//PredicateKind"> | ||
20 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//PredicateKind/PARTIAL"/> | ||
21 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//PredicateKind/DIRECT"/> | ||
22 | </genEnums> | ||
23 | <genEnums typeSafeEnumCompatible="false" ecoreEnum="problem.ecore#//RuleKind"> | ||
24 | <genEnumLiterals ecoreEnumLiteral="problem.ecore#//RuleKind/DIRECT"/> | ||
25 | </genEnums> | ||
26 | <genClasses ecoreClass="problem.ecore#//Problem"> | ||
27 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//Problem/nodes"/> | ||
28 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//Problem/statements"/> | ||
29 | </genClasses> | ||
30 | <genClasses ecoreClass="problem.ecore#//Relation"/> | ||
31 | <genClasses ecoreClass="problem.ecore#//ClassDeclaration"> | ||
32 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ClassDeclaration/abstract"/> | ||
33 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//ClassDeclaration/superTypes"/> | ||
34 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ClassDeclaration/referenceDeclarations"/> | ||
35 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ClassDeclaration/newNode"/> | ||
36 | </genClasses> | ||
37 | <genClasses ecoreClass="problem.ecore#//ReferenceDeclaration"> | ||
38 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//ReferenceDeclaration/referenceType"/> | ||
39 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//ReferenceDeclaration/opposite"/> | ||
40 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ReferenceDeclaration/containment"/> | ||
41 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ReferenceDeclaration/multiplicity"/> | ||
42 | </genClasses> | ||
43 | <genClasses ecoreClass="problem.ecore#//NamedElement"> | ||
44 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//NamedElement/name"/> | ||
45 | </genClasses> | ||
46 | <genClasses ecoreClass="problem.ecore#//PredicateDefinition"> | ||
47 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//PredicateDefinition/error"/> | ||
48 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//PredicateDefinition/kind"/> | ||
49 | </genClasses> | ||
50 | <genClasses ecoreClass="problem.ecore#//Parameter"> | ||
51 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//Parameter/parameterType"/> | ||
52 | </genClasses> | ||
53 | <genClasses ecoreClass="problem.ecore#//Variable"/> | ||
54 | <genClasses ecoreClass="problem.ecore#//Conjunction"> | ||
55 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//Conjunction/literals"/> | ||
56 | </genClasses> | ||
57 | <genClasses ecoreClass="problem.ecore#//Literal"/> | ||
58 | <genClasses ecoreClass="problem.ecore#//Atom"> | ||
59 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//Atom/relation"/> | ||
60 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//Atom/transitiveClosure"/> | ||
61 | <genFeatures children="true" createChild="true" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//Atom/arguments"/> | ||
62 | </genClasses> | ||
63 | <genClasses ecoreClass="problem.ecore#//ImplicitVariable"/> | ||
64 | <genClasses ecoreClass="problem.ecore#//NegativeLiteral"/> | ||
65 | <genClasses ecoreClass="problem.ecore#//ExistentialQuantifier"> | ||
66 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ExistentialQuantifier/implicitVariables"/> | ||
67 | </genClasses> | ||
68 | <genClasses ecoreClass="problem.ecore#//Assertion"> | ||
69 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//Assertion/relation"/> | ||
70 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//Assertion/value"/> | ||
71 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//Assertion/arguments"/> | ||
72 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//Assertion/default"/> | ||
73 | </genClasses> | ||
74 | <genClasses ecoreClass="problem.ecore#//Node"/> | ||
75 | <genClasses ecoreClass="problem.ecore#//ScopeDeclaration"> | ||
76 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ScopeDeclaration/typeScopes"/> | ||
77 | </genClasses> | ||
78 | <genClasses ecoreClass="problem.ecore#//Statement"/> | ||
79 | <genClasses ecoreClass="problem.ecore#//TypeScope"> | ||
80 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//TypeScope/targetType"/> | ||
81 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//TypeScope/increment"/> | ||
82 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//TypeScope/multiplicity"/> | ||
83 | </genClasses> | ||
84 | <genClasses ecoreClass="problem.ecore#//Multiplicity"/> | ||
85 | <genClasses ecoreClass="problem.ecore#//RangeMultiplicity"> | ||
86 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//RangeMultiplicity/lowerBound"/> | ||
87 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//RangeMultiplicity/upperBound"/> | ||
88 | </genClasses> | ||
89 | <genClasses ecoreClass="problem.ecore#//ExactMultiplicity"> | ||
90 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ExactMultiplicity/exactValue"/> | ||
91 | </genClasses> | ||
92 | <genClasses ecoreClass="problem.ecore#//UnboundedMultiplicity"/> | ||
93 | <genClasses ecoreClass="problem.ecore#//VariableOrNodeArgument"> | ||
94 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//VariableOrNodeArgument/variableOrNode"/> | ||
95 | <genFeatures children="true" createChild="true" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//VariableOrNodeArgument/singletonVariable"/> | ||
96 | </genClasses> | ||
97 | <genClasses ecoreClass="problem.ecore#//EnumDeclaration"> | ||
98 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//EnumDeclaration/literals"/> | ||
99 | </genClasses> | ||
100 | <genClasses ecoreClass="problem.ecore#//VariableOrNode"/> | ||
101 | <genClasses ecoreClass="problem.ecore#//Constant"/> | ||
102 | <genClasses ecoreClass="problem.ecore#//IntConstant"> | ||
103 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//IntConstant/intValue"/> | ||
104 | </genClasses> | ||
105 | <genClasses ecoreClass="problem.ecore#//RealConstant"> | ||
106 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//RealConstant/realValue"/> | ||
107 | </genClasses> | ||
108 | <genClasses ecoreClass="problem.ecore#//StringConstant"> | ||
109 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//StringConstant/stringValue"/> | ||
110 | </genClasses> | ||
111 | <genClasses ecoreClass="problem.ecore#//ConstantArgument"> | ||
112 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ConstantArgument/constant"/> | ||
113 | </genClasses> | ||
114 | <genClasses ecoreClass="problem.ecore#//Argument"/> | ||
115 | <genClasses ecoreClass="problem.ecore#//NodeAssertionArgument"> | ||
116 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//NodeAssertionArgument/node"/> | ||
117 | </genClasses> | ||
118 | <genClasses ecoreClass="problem.ecore#//AssertionArgument"/> | ||
119 | <genClasses ecoreClass="problem.ecore#//ConstantAssertionArgument"> | ||
120 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ConstantAssertionArgument/constant"/> | ||
121 | </genClasses> | ||
122 | <genClasses ecoreClass="problem.ecore#//NodeValueAssertion"> | ||
123 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//NodeValueAssertion/node"/> | ||
124 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//NodeValueAssertion/value"/> | ||
125 | </genClasses> | ||
126 | <genClasses ecoreClass="problem.ecore#//IndividualDeclaration"> | ||
127 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//IndividualDeclaration/nodes"/> | ||
128 | </genClasses> | ||
129 | <genClasses ecoreClass="problem.ecore#//WildcardAssertionArgument"/> | ||
130 | <genClasses ecoreClass="problem.ecore#//ParametricDefinition"> | ||
131 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ParametricDefinition/bodies"/> | ||
132 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ParametricDefinition/parameters"/> | ||
133 | </genClasses> | ||
134 | <genClasses ecoreClass="problem.ecore#//RuleDefinition"> | ||
135 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//RuleDefinition/kind"/> | ||
136 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//RuleDefinition/action"/> | ||
137 | </genClasses> | ||
138 | <genClasses ecoreClass="problem.ecore#//Action"> | ||
139 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//Action/actionLiterals"/> | ||
140 | </genClasses> | ||
141 | <genClasses ecoreClass="problem.ecore#//ActionLiteral"/> | ||
142 | <genClasses ecoreClass="problem.ecore#//ValueActionLiteral"> | ||
143 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ValueActionLiteral/atom"/> | ||
144 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ValueActionLiteral/value"/> | ||
145 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ValueActionLiteral/refinement"/> | ||
146 | </genClasses> | ||
147 | <genClasses ecoreClass="problem.ecore#//DeleteActionLiteral"> | ||
148 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference problem.ecore#//DeleteActionLiteral/variableOrNode"/> | ||
149 | </genClasses> | ||
150 | <genClasses ecoreClass="problem.ecore#//NewActionLiteral"> | ||
151 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//NewActionLiteral/variable"/> | ||
152 | </genClasses> | ||
153 | <genClasses ecoreClass="problem.ecore#//NewVariable"/> | ||
154 | <genClasses ecoreClass="problem.ecore#//CompoundLiteral"> | ||
155 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//CompoundLiteral/atom"/> | ||
156 | </genClasses> | ||
157 | <genClasses ecoreClass="problem.ecore#//ValueLiteral"> | ||
158 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference problem.ecore#//ValueLiteral/values"/> | ||
159 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//ValueLiteral/refinement"/> | ||
160 | </genClasses> | ||
161 | <genClasses ecoreClass="problem.ecore#//LogicConstant"> | ||
162 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute problem.ecore#//LogicConstant/value"/> | ||
163 | </genClasses> | ||
164 | </genPackages> | ||
165 | </genmodel:GenModel> | ||
diff --git a/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java b/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java new file mode 100644 index 00000000..d0990dc0 --- /dev/null +++ b/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java | |||
@@ -0,0 +1,197 @@ | |||
1 | package tools.refinery.language.model.tests; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.stream.Stream; | ||
5 | |||
6 | import org.eclipse.emf.ecore.resource.Resource.Diagnostic; | ||
7 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
8 | |||
9 | import tools.refinery.language.model.ProblemUtil; | ||
10 | import tools.refinery.language.model.problem.ActionLiteral; | ||
11 | import tools.refinery.language.model.problem.Argument; | ||
12 | import tools.refinery.language.model.problem.Assertion; | ||
13 | import tools.refinery.language.model.problem.AssertionArgument; | ||
14 | import tools.refinery.language.model.problem.Atom; | ||
15 | import tools.refinery.language.model.problem.ClassDeclaration; | ||
16 | import tools.refinery.language.model.problem.Conjunction; | ||
17 | import tools.refinery.language.model.problem.DeleteActionLiteral; | ||
18 | import tools.refinery.language.model.problem.EnumDeclaration; | ||
19 | import tools.refinery.language.model.problem.IndividualDeclaration; | ||
20 | import tools.refinery.language.model.problem.Literal; | ||
21 | import tools.refinery.language.model.problem.NamedElement; | ||
22 | import tools.refinery.language.model.problem.NegativeLiteral; | ||
23 | import tools.refinery.language.model.problem.NewActionLiteral; | ||
24 | import tools.refinery.language.model.problem.Node; | ||
25 | import tools.refinery.language.model.problem.NodeAssertionArgument; | ||
26 | import tools.refinery.language.model.problem.NodeValueAssertion; | ||
27 | import tools.refinery.language.model.problem.Parameter; | ||
28 | import tools.refinery.language.model.problem.ParametricDefinition; | ||
29 | import tools.refinery.language.model.problem.PredicateDefinition; | ||
30 | import tools.refinery.language.model.problem.Problem; | ||
31 | import tools.refinery.language.model.problem.ReferenceDeclaration; | ||
32 | import tools.refinery.language.model.problem.Relation; | ||
33 | import tools.refinery.language.model.problem.RuleDefinition; | ||
34 | import tools.refinery.language.model.problem.Statement; | ||
35 | import tools.refinery.language.model.problem.ValueActionLiteral; | ||
36 | import tools.refinery.language.model.problem.ValueLiteral; | ||
37 | import tools.refinery.language.model.problem.Variable; | ||
38 | import tools.refinery.language.model.problem.VariableOrNode; | ||
39 | import tools.refinery.language.model.problem.VariableOrNodeArgument; | ||
40 | |||
41 | public class ProblemTestUtil { | ||
42 | public Problem builtin(Problem problem) { | ||
43 | return ProblemUtil.getBuiltInLibrary(problem).get(); | ||
44 | } | ||
45 | |||
46 | public List<Diagnostic> errors(Problem problem) { | ||
47 | EcoreUtil.resolveAll(problem); | ||
48 | return problem.eResource().getErrors(); | ||
49 | } | ||
50 | |||
51 | public List<String> nodeNames(Problem problem) { | ||
52 | return problem.getNodes().stream().map(node -> node.getName()).toList(); | ||
53 | } | ||
54 | |||
55 | public PredicateDefinition pred(Problem problem, String name) { | ||
56 | return namedStatementOfType(problem, PredicateDefinition.class, name); | ||
57 | } | ||
58 | |||
59 | public RuleDefinition rule(Problem problem, String name) { | ||
60 | return namedStatementOfType(problem, RuleDefinition.class, name); | ||
61 | } | ||
62 | |||
63 | public Parameter param(ParametricDefinition definition, int i) { | ||
64 | return definition.getParameters().get(i); | ||
65 | } | ||
66 | |||
67 | public Conjunction conj(ParametricDefinition definition, int i) { | ||
68 | return definition.getBodies().get(i); | ||
69 | } | ||
70 | |||
71 | public Literal lit(Conjunction conjunction, int i) { | ||
72 | return conjunction.getLiterals().get(i); | ||
73 | } | ||
74 | |||
75 | public ActionLiteral actionLit(RuleDefinition rule, int i) { | ||
76 | return rule.getAction().getActionLiterals().get(i); | ||
77 | } | ||
78 | |||
79 | public Atom valueAtom(Literal literal) { | ||
80 | return ((ValueLiteral) literal).getAtom(); | ||
81 | } | ||
82 | |||
83 | public Atom negated(Literal literal) { | ||
84 | return ((NegativeLiteral) literal).getAtom(); | ||
85 | } | ||
86 | |||
87 | public Relation relation(Literal literal) { | ||
88 | return ((Atom) literal).getRelation(); | ||
89 | } | ||
90 | |||
91 | public Argument arg(Atom atom, int i) { | ||
92 | return atom.getArguments().get(i); | ||
93 | } | ||
94 | |||
95 | public Argument arg(Literal literal, int i) { | ||
96 | return arg((Atom) literal, i); | ||
97 | } | ||
98 | |||
99 | public VariableOrNode variableOrNode(Argument argument) { | ||
100 | return ((VariableOrNodeArgument) argument).getVariableOrNode(); | ||
101 | } | ||
102 | |||
103 | public Variable variable(Argument argument) { | ||
104 | return (Variable) variableOrNode(argument); | ||
105 | } | ||
106 | |||
107 | public Variable variable(ValueActionLiteral valueActionLiteral, int i) { | ||
108 | return variable(arg(valueActionLiteral.getAtom(), i)); | ||
109 | } | ||
110 | |||
111 | public Variable variable(NewActionLiteral newActionLiteral) { | ||
112 | return newActionLiteral.getVariable(); | ||
113 | } | ||
114 | |||
115 | public VariableOrNode deleteVar(ActionLiteral actionLiteral) { | ||
116 | return ((DeleteActionLiteral) actionLiteral).getVariableOrNode(); | ||
117 | } | ||
118 | |||
119 | public VariableOrNode newVar(ActionLiteral actionLiteral) { | ||
120 | return ((NewActionLiteral) actionLiteral).getVariable(); | ||
121 | } | ||
122 | |||
123 | public Atom valueAtom(ActionLiteral actionLiteral) { | ||
124 | return ((ValueActionLiteral) actionLiteral).getAtom(); | ||
125 | } | ||
126 | |||
127 | public Variable variable(DeleteActionLiteral deleteActionLiteral) { | ||
128 | return (Variable) deleteActionLiteral.getVariableOrNode(); | ||
129 | } | ||
130 | |||
131 | public Node node(Argument argument) { | ||
132 | return (Node) variableOrNode(argument); | ||
133 | } | ||
134 | |||
135 | public Assertion assertion(Problem problem, int i) { | ||
136 | return nthStatementOfType(problem, Assertion.class, i); | ||
137 | } | ||
138 | |||
139 | public AssertionArgument arg(Assertion assertion, int i) { | ||
140 | return assertion.getArguments().get(i); | ||
141 | } | ||
142 | |||
143 | public Node node(AssertionArgument argument) { | ||
144 | return ((NodeAssertionArgument) argument).getNode(); | ||
145 | } | ||
146 | |||
147 | public Node node(Problem problem, String name) { | ||
148 | return named(problem.getNodes(), name); | ||
149 | } | ||
150 | |||
151 | public Node individualNode(Problem problem, String name) { | ||
152 | var uniqueNodes = statementsOfType(problem, IndividualDeclaration.class) | ||
153 | .flatMap(declaration -> declaration.getNodes().stream()); | ||
154 | return named(uniqueNodes, name); | ||
155 | } | ||
156 | |||
157 | public NodeValueAssertion nodeValueAssertion(Problem problem, int i) { | ||
158 | return nthStatementOfType(problem, NodeValueAssertion.class, i); | ||
159 | } | ||
160 | |||
161 | public ClassDeclaration findClass(Problem problem, String name) { | ||
162 | return namedStatementOfType(problem, ClassDeclaration.class, name); | ||
163 | } | ||
164 | |||
165 | public ReferenceDeclaration reference(ClassDeclaration declaration, String name) { | ||
166 | return named(declaration.getReferenceDeclarations(), name); | ||
167 | } | ||
168 | |||
169 | public EnumDeclaration findEnum(Problem problem, String name) { | ||
170 | return namedStatementOfType(problem, EnumDeclaration.class, name); | ||
171 | } | ||
172 | |||
173 | public Node literal(EnumDeclaration declaration, String name) { | ||
174 | return named(declaration.getLiterals(), name); | ||
175 | } | ||
176 | |||
177 | private <T extends NamedElement> T named(Stream<? extends T> stream, String name) { | ||
178 | return stream.filter(statement -> name.equals(statement.getName())).findAny().get(); | ||
179 | } | ||
180 | |||
181 | private <T extends NamedElement> T named(List<? extends T> list, String name) { | ||
182 | return named(list.stream(), name); | ||
183 | } | ||
184 | |||
185 | private <T extends Statement> Stream<T> statementsOfType(Problem problem, Class<? extends T> type) { | ||
186 | return problem.getStatements().stream().filter(type::isInstance).map(type::cast); | ||
187 | } | ||
188 | |||
189 | private <T extends Statement & NamedElement> T namedStatementOfType(Problem problem, Class<? extends T> type, | ||
190 | String name) { | ||
191 | return named(statementsOfType(problem, type), name); | ||
192 | } | ||
193 | |||
194 | private <T extends Statement> T nthStatementOfType(Problem problem, Class<? extends T> type, int n) { | ||
195 | return statementsOfType(problem, type).skip(n).findFirst().get(); | ||
196 | } | ||
197 | } | ||