diff options
Diffstat (limited to 'subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java index 738a0896..59e26561 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java +++ b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemDesugarer.java | |||
@@ -6,7 +6,6 @@ | |||
6 | package tools.refinery.language.utils; | 6 | package tools.refinery.language.utils; |
7 | 7 | ||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import com.google.inject.Provider; | ||
10 | import com.google.inject.Singleton; | 9 | import com.google.inject.Singleton; |
11 | import org.eclipse.emf.ecore.EObject; | 10 | import org.eclipse.emf.ecore.EObject; |
12 | import org.eclipse.emf.ecore.resource.Resource; | 11 | import org.eclipse.emf.ecore.resource.Resource; |
@@ -21,9 +20,6 @@ public class ProblemDesugarer { | |||
21 | @Inject | 20 | @Inject |
22 | private IResourceScopeCache cache = IResourceScopeCache.NullImpl.INSTANCE; | 21 | private IResourceScopeCache cache = IResourceScopeCache.NullImpl.INSTANCE; |
23 | 22 | ||
24 | @Inject | ||
25 | private Provider<SymbolCollector> symbolCollectorProvider; | ||
26 | |||
27 | public Optional<Problem> getBuiltinProblem(EObject context) { | 23 | public Optional<Problem> getBuiltinProblem(EObject context) { |
28 | return Optional.ofNullable(context).map(EObject::eResource).flatMap(resource -> | 24 | return Optional.ofNullable(context).map(EObject::eResource).flatMap(resource -> |
29 | cache.get("builtinProblem", resource, () -> doGetBuiltinProblem(resource))); | 25 | cache.get("builtinProblem", resource, () -> doGetBuiltinProblem(resource))); |
@@ -43,12 +39,12 @@ public class ProblemDesugarer { | |||
43 | 39 | ||
44 | private BuiltinSymbols doGetBuiltinSymbols(Problem builtin) { | 40 | private BuiltinSymbols doGetBuiltinSymbols(Problem builtin) { |
45 | var node = doGetDeclaration(builtin, ClassDeclaration.class, "node"); | 41 | var node = doGetDeclaration(builtin, ClassDeclaration.class, "node"); |
46 | var equals = doGetEqualsReference(node); | 42 | var equals = doGetDeclaration(builtin, PredicateDefinition.class, "equals"); |
47 | var exists = doGetDeclaration(builtin, PredicateDefinition.class, "exists"); | 43 | var exists = doGetDeclaration(builtin, PredicateDefinition.class, "exists"); |
48 | var contained = doGetDeclaration(builtin, PredicateDefinition.class, "contained"); | 44 | var contained = doGetDeclaration(builtin, ClassDeclaration.class, "contained"); |
49 | var contains = doGetDeclaration(builtin, PredicateDefinition.class, "contains"); | 45 | var contains = doGetDeclaration(builtin, PredicateDefinition.class, "contains"); |
50 | var root = doGetDeclaration(builtin, PredicateDefinition.class, "root"); | 46 | var invalidContainer = doGetDeclaration(builtin, PredicateDefinition.class, "invalidContainer"); |
51 | return new BuiltinSymbols(builtin, node, equals, exists, contained, contains, root); | 47 | return new BuiltinSymbols(builtin, node, equals, exists, contained, contains, invalidContainer); |
52 | } | 48 | } |
53 | 49 | ||
54 | private <T extends Statement & NamedElement> T doGetDeclaration(Problem builtin, Class<T> type, String name) { | 50 | private <T extends Statement & NamedElement> T doGetDeclaration(Problem builtin, Class<T> type, String name) { |
@@ -57,13 +53,6 @@ public class ProblemDesugarer { | |||
57 | .orElseThrow(() -> new IllegalArgumentException("Built-in declaration " + name + " was not found")); | 53 | .orElseThrow(() -> new IllegalArgumentException("Built-in declaration " + name + " was not found")); |
58 | } | 54 | } |
59 | 55 | ||
60 | private ReferenceDeclaration doGetEqualsReference(ClassDeclaration nodeClassDeclaration) { | ||
61 | return (ReferenceDeclaration) nodeClassDeclaration.getFeatureDeclarations().stream() | ||
62 | .filter(reference -> reference instanceof ReferenceDeclaration && | ||
63 | "equals".equals(reference.getName())).findFirst() | ||
64 | .orElseThrow(() -> new IllegalArgumentException("Reference " + "equals" + " not found")); | ||
65 | } | ||
66 | |||
67 | public Collection<ClassDeclaration> getSuperclassesAndSelf(ClassDeclaration classDeclaration) { | 56 | public Collection<ClassDeclaration> getSuperclassesAndSelf(ClassDeclaration classDeclaration) { |
68 | return cache.get(Tuples.create(classDeclaration, "superclassesAndSelf"), classDeclaration.eResource(), | 57 | return cache.get(Tuples.create(classDeclaration, "superclassesAndSelf"), classDeclaration.eResource(), |
69 | () -> doGetSuperclassesAndSelf(classDeclaration)); | 58 | () -> doGetSuperclassesAndSelf(classDeclaration)); |
@@ -109,9 +98,4 @@ public class ProblemDesugarer { | |||
109 | public boolean isContainmentReference(ReferenceDeclaration referenceDeclaration) { | 98 | public boolean isContainmentReference(ReferenceDeclaration referenceDeclaration) { |
110 | return referenceDeclaration.getKind() == ReferenceKind.CONTAINMENT; | 99 | return referenceDeclaration.getKind() == ReferenceKind.CONTAINMENT; |
111 | } | 100 | } |
112 | |||
113 | public CollectedSymbols collectSymbols(Problem problem) { | ||
114 | return cache.get(Tuples.create(problem, "collectedSymbols"), problem.eResource(), | ||
115 | () -> symbolCollectorProvider.get().collectSymbols(problem)); | ||
116 | } | ||
117 | } | 101 | } |