diff options
Diffstat (limited to 'subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java index 9486dc2a..a9efc4bb 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java +++ b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java | |||
@@ -7,33 +7,12 @@ package tools.refinery.language.utils; | |||
7 | 7 | ||
8 | import org.eclipse.emf.common.util.URI; | 8 | import org.eclipse.emf.common.util.URI; |
9 | import org.eclipse.emf.ecore.EObject; | 9 | import org.eclipse.emf.ecore.EObject; |
10 | 10 | import tools.refinery.language.model.problem.*; | |
11 | import tools.refinery.language.model.problem.ImplicitVariable; | ||
12 | import tools.refinery.language.model.problem.Node; | ||
13 | import tools.refinery.language.model.problem.ProblemPackage; | ||
14 | import tools.refinery.language.model.problem.Variable; | ||
15 | 11 | ||
16 | public final class ProblemUtil { | 12 | public final class ProblemUtil { |
17 | public static final String BUILTIN_LIBRARY_NAME = "builtin"; | 13 | public static final String BUILTIN_LIBRARY_NAME = "builtin"; |
18 | |||
19 | public static final URI BUILTIN_LIBRARY_URI = getLibraryUri(BUILTIN_LIBRARY_NAME); | 14 | public static final URI BUILTIN_LIBRARY_URI = getLibraryUri(BUILTIN_LIBRARY_NAME); |
20 | 15 | ||
21 | public static final String NODE_CLASS_NAME = "node"; | ||
22 | |||
23 | public static final String DOMAIN_CLASS_NAME = "domain"; | ||
24 | |||
25 | public static final String DATA_CLASS_NAME = "data"; | ||
26 | |||
27 | public static final String INT_CLASS_NAME = "int"; | ||
28 | |||
29 | public static final String REAL_CLASS_NAME = "real"; | ||
30 | |||
31 | public static final String STRING_CLASS_NAME = "string"; | ||
32 | |||
33 | public static final String EQUALS_RELATION_NAME = "equals"; | ||
34 | |||
35 | public static final String EXISTS_PREDICATE_NAME = "exists"; | ||
36 | |||
37 | private ProblemUtil() { | 16 | private ProblemUtil() { |
38 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | 17 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); |
39 | } | 18 | } |
@@ -70,6 +49,10 @@ public final class ProblemUtil { | |||
70 | } | 49 | } |
71 | } | 50 | } |
72 | 51 | ||
52 | public static boolean isError(EObject eObject) { | ||
53 | return eObject instanceof PredicateDefinition predicateDefinition && predicateDefinition.isError(); | ||
54 | } | ||
55 | |||
73 | public static boolean isIndividualNode(Node node) { | 56 | public static boolean isIndividualNode(Node node) { |
74 | var containingFeature = node.eContainingFeature(); | 57 | var containingFeature = node.eContainingFeature(); |
75 | return containingFeature == ProblemPackage.Literals.INDIVIDUAL_DECLARATION__NODES | 58 | return containingFeature == ProblemPackage.Literals.INDIVIDUAL_DECLARATION__NODES |
@@ -80,6 +63,26 @@ public final class ProblemUtil { | |||
80 | return node.eContainingFeature() == ProblemPackage.Literals.CLASS_DECLARATION__NEW_NODE; | 63 | return node.eContainingFeature() == ProblemPackage.Literals.CLASS_DECLARATION__NEW_NODE; |
81 | } | 64 | } |
82 | 65 | ||
66 | public static boolean isInvalidMultiplicityConstraint(PredicateDefinition predicateDefinition) { | ||
67 | return predicateDefinition.eContainingFeature() == | ||
68 | ProblemPackage.Literals.REFERENCE_DECLARATION__INVALID_MULTIPLICITY; | ||
69 | } | ||
70 | |||
71 | public static boolean hasMultiplicityConstraint(ReferenceDeclaration referenceDeclaration) { | ||
72 | var opposite = referenceDeclaration.getOpposite(); | ||
73 | if (opposite != null && opposite.getKind() == ReferenceKind.CONTAINMENT) { | ||
74 | return false; | ||
75 | } | ||
76 | var multiplicity = referenceDeclaration.getMultiplicity(); | ||
77 | if (multiplicity instanceof UnboundedMultiplicity) { | ||
78 | return false; | ||
79 | } | ||
80 | if (multiplicity instanceof RangeMultiplicity rangeMultiplicity) { | ||
81 | return rangeMultiplicity.getLowerBound() > 0 || rangeMultiplicity.getUpperBound() >= 0; | ||
82 | } | ||
83 | return true; | ||
84 | } | ||
85 | |||
83 | private static URI getLibraryUri(String libraryName) { | 86 | private static URI getLibraryUri(String libraryName) { |
84 | return URI.createURI(ProblemUtil.class.getClassLoader() | 87 | return URI.createURI(ProblemUtil.class.getClassLoader() |
85 | .getResource("tools/refinery/language/%s.problem".formatted(libraryName)).toString()); | 88 | .getResource("tools/refinery/language/%s.problem".formatted(libraryName)).toString()); |