diff options
author | 2021-10-05 00:36:47 +0200 | |
---|---|---|
committer | 2021-10-05 00:36:47 +0200 | |
commit | c3e27396c62f191b4343df151e5a86bfa63a32f3 (patch) | |
tree | 4f698c9ba0320a5c740c53877c3f75c00240dca4 /language/src/main/java/org/eclipse | |
parent | fix(web): improve accessibility (diff) | |
download | refinery-c3e27396c62f191b4343df151e5a86bfa63a32f3.tar.gz refinery-c3e27396c62f191b4343df151e5a86bfa63a32f3.tar.zst refinery-c3e27396c62f191b4343df151e5a86bfa63a32f3.zip |
chore: change package name
Diffstat (limited to 'language/src/main/java/org/eclipse')
18 files changed, 0 insertions, 1272 deletions
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/GenerateProblem.mwe2 b/language/src/main/java/org/eclipse/viatra/solver/language/GenerateProblem.mwe2 deleted file mode 100644 index 4dfbb242..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/GenerateProblem.mwe2 +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | module org.eclipse.viatra.solver.language.GenerateProblem | ||
2 | |||
3 | import org.eclipse.xtext.xtext.generator.* | ||
4 | import org.eclipse.xtext.xtext.generator.model.project.* | ||
5 | |||
6 | import org.eclipse.viatra.solver.language.mwe2.* | ||
7 | |||
8 | var rootPath = ".." | ||
9 | |||
10 | Workflow { | ||
11 | component = XtextGenerator { | ||
12 | configuration = { | ||
13 | project = StandardProjectConfig { | ||
14 | baseName = "language" | ||
15 | rootPath = rootPath | ||
16 | runtimeTest = { | ||
17 | enabled = true | ||
18 | srcGen = 'src/testFixtures/xtext-gen' | ||
19 | } | ||
20 | genericIde = { | ||
21 | name = "language-ide" | ||
22 | } | ||
23 | web = { | ||
24 | enabled = true | ||
25 | name = "language-web" | ||
26 | assets = "../language-web/build/generated/sources/xtext" | ||
27 | } | ||
28 | mavenLayout = true | ||
29 | } | ||
30 | code = { | ||
31 | encoding = "UTF-8" | ||
32 | lineDelimiter = "\n" | ||
33 | fileHeader = "/*\n * generated by Xtext \${version}\n */" | ||
34 | preferXtendStubs = false | ||
35 | } | ||
36 | } | ||
37 | |||
38 | language = StandardLanguage { | ||
39 | name = "org.eclipse.viatra.solver.language.Problem" | ||
40 | fileExtensions = "problem" | ||
41 | referencedResource = "platform:/resource/refinery-language-model/model/problem.genmodel" | ||
42 | serializer = { | ||
43 | generateStub = false | ||
44 | } | ||
45 | validator = { | ||
46 | generateDeprecationValidation = true | ||
47 | } | ||
48 | generator = { | ||
49 | generateStub = false | ||
50 | } | ||
51 | junitSupport = { | ||
52 | generateStub = false | ||
53 | skipXbaseTestingPackage = true | ||
54 | junitVersion = "5" | ||
55 | } | ||
56 | webSupport = ProblemWebIntegrationFragment { | ||
57 | highlightingPath = "js/mode-problem.js" | ||
58 | generateHtmlExample = false | ||
59 | generateJettyLauncher = false | ||
60 | generateServlet = false | ||
61 | generateWebXml = false | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext b/language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext deleted file mode 100644 index d4fa6f35..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | grammar org.eclipse.viatra.solver.language.Problem with org.eclipse.xtext.common.Terminals | ||
2 | |||
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore | ||
4 | import "http://www.eclipse.org/viatra/solver/language/model/Problem" | ||
5 | |||
6 | Problem: | ||
7 | ("problem" name=Identifier ".")? | ||
8 | statements+=Statement*; | ||
9 | |||
10 | Statement: | ||
11 | ClassDeclaration | EnumDeclaration | PredicateDefinition | Assertion | NodeValueAssertion | ScopeDeclaration | | ||
12 | UniqueDeclaration; | ||
13 | |||
14 | ClassDeclaration: | ||
15 | abstract?="abstract"? "class" | ||
16 | name=Identifier | ||
17 | ("extends" superTypes+=[Relation|QualifiedName] ("," superTypes+=[Relation|QualifiedName])*)? | ||
18 | ("{" (referenceDeclarations+=ReferenceDeclaration ";"?)* "}" | "."); | ||
19 | |||
20 | EnumDeclaration: | ||
21 | "enum" | ||
22 | name=Identifier | ||
23 | ("{" (literals+=EnumLiteral ("," literals+=EnumLiteral)* ("," | ";")?)? "}" | "."); | ||
24 | |||
25 | EnumLiteral returns Node: | ||
26 | name=Identifier; | ||
27 | |||
28 | ReferenceDeclaration: | ||
29 | (-> (containment?="contains" | "refers"))? | ||
30 | referenceType=[Relation|QualifiedName] | ||
31 | ("[" multiplicity=Multiplicity "]")? | ||
32 | name=Identifier | ||
33 | ("opposite" opposite=[ReferenceDeclaration|QualifiedName])?; | ||
34 | |||
35 | PredicateDefinition: | ||
36 | (error?="error" "pred"? | "pred") | ||
37 | name=Identifier | ||
38 | "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" | ||
39 | ("<->" bodies+=Conjunction (";" bodies+=Conjunction)*)? | ||
40 | "."; | ||
41 | |||
42 | Parameter: | ||
43 | parameterType=[Relation|QualifiedName]? name=Identifier; | ||
44 | |||
45 | Conjunction: | ||
46 | literals+=Literal ("," literals+=Literal)*; | ||
47 | |||
48 | Literal: | ||
49 | Atom | NegativeLiteral; | ||
50 | |||
51 | NegativeLiteral: | ||
52 | "!" atom=Atom; | ||
53 | |||
54 | Atom: | ||
55 | relation=[Relation|QualifiedName] | ||
56 | transitiveClosure?="+"? | ||
57 | "(" (arguments+=Argument ("," arguments+=Argument)*)? ")"; | ||
58 | |||
59 | Argument: | ||
60 | VariableOrNodeArgument | ConstantArgument; | ||
61 | |||
62 | VariableOrNodeArgument: | ||
63 | variableOrNode=[VariableOrNode|QualifiedName]; | ||
64 | |||
65 | ConstantArgument: | ||
66 | constant=Constant; | ||
67 | |||
68 | Assertion: | ||
69 | default?="default"? | ||
70 | (relation=[Relation|QualifiedName] | ||
71 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")" | ||
72 | ":" value=LogicValue | | ||
73 | value=ShortLogicValue? | ||
74 | relation=[Relation|QualifiedName] | ||
75 | "(" (arguments+=AssertionArgument ("," arguments+=AssertionArgument)*)? ")") | ||
76 | "."; | ||
77 | |||
78 | AssertionArgument: | ||
79 | NodeAssertionArgument | WildcardAssertionArgument | ConstantAssertionArgument; | ||
80 | |||
81 | NodeAssertionArgument: | ||
82 | node=[Node|QualifiedName]; | ||
83 | |||
84 | WildcardAssertionArgument: | ||
85 | {WildcardAssertionArgument} "*"; | ||
86 | |||
87 | ConstantAssertionArgument: | ||
88 | constant=Constant; | ||
89 | |||
90 | enum LogicValue: | ||
91 | TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error"; | ||
92 | |||
93 | enum ShortLogicValue returns LogicValue: | ||
94 | FALSE="!" | UNKNOWN="?"; | ||
95 | |||
96 | NodeValueAssertion: | ||
97 | node=[Node|QualifiedName] ":" value=Constant "."; | ||
98 | |||
99 | Constant: | ||
100 | RealConstant | IntConstant | StringConstant; | ||
101 | |||
102 | IntConstant: | ||
103 | intValue=Integer; | ||
104 | |||
105 | RealConstant: | ||
106 | realValue=Real; | ||
107 | |||
108 | StringConstant: | ||
109 | stringValue=STRING; | ||
110 | |||
111 | ScopeDeclaration: | ||
112 | "scope" typeScopes+=TypeScope ("," typeScopes+=TypeScope)* "."; | ||
113 | |||
114 | TypeScope: | ||
115 | targetType=[ClassDeclaration] | ||
116 | (increment?="+=" | "=") | ||
117 | multiplicity=DefiniteMultiplicity; | ||
118 | |||
119 | Multiplicity: | ||
120 | UnboundedMultiplicity | DefiniteMultiplicity; | ||
121 | |||
122 | DefiniteMultiplicity returns Multiplicity: | ||
123 | RangeMultiplicity | ExactMultiplicity; | ||
124 | |||
125 | UnboundedMultiplicity: | ||
126 | {UnboundedMultiplicity}; | ||
127 | |||
128 | RangeMultiplicity: | ||
129 | lowerBound=INT ".." upperBound=UpperBound; | ||
130 | |||
131 | ExactMultiplicity: | ||
132 | exactValue=INT; | ||
133 | |||
134 | UniqueDeclaration: | ||
135 | "unique" nodes+=EnumLiteral ("," nodes+=EnumLiteral)* "."; | ||
136 | |||
137 | UpperBound returns ecore::EInt: | ||
138 | INT | "*"; | ||
139 | |||
140 | QualifiedName hidden(): | ||
141 | Identifier ("::" Identifier)*; | ||
142 | |||
143 | Identifier: | ||
144 | ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | "pred" | "scope" | | ||
145 | "unique" | "default" | "problem" | "contains" | "refers"; | ||
146 | |||
147 | Integer returns ecore::EInt hidden(): | ||
148 | "-"? INT; | ||
149 | |||
150 | Real returns ecore::EDouble: | ||
151 | "-"? (EXPONENTIAL | INT "." (INT | EXPONENTIAL)); | ||
152 | |||
153 | @Override | ||
154 | terminal ID: | ||
155 | ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*; | ||
156 | |||
157 | terminal EXPONENTIAL: | ||
158 | INT ("e" | "E") ("+" | "-")? INT; | ||
159 | |||
160 | @Override | ||
161 | terminal SL_COMMENT: | ||
162 | ('%' | '//') !('\n' | '\r')* ('\r'? '\n')?; | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemRuntimeModule.java b/language/src/main/java/org/eclipse/viatra/solver/language/ProblemRuntimeModule.java deleted file mode 100644 index 9fec7d75..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemRuntimeModule.java +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language; | ||
5 | |||
6 | import org.eclipse.viatra.solver.language.conversion.ProblemValueConverterService; | ||
7 | import org.eclipse.viatra.solver.language.naming.ProblemQualifiedNameConverter; | ||
8 | import org.eclipse.viatra.solver.language.resource.ProblemDerivedStateComputer; | ||
9 | import org.eclipse.viatra.solver.language.resource.ProblemLocationInFileProvider; | ||
10 | import org.eclipse.viatra.solver.language.resource.ProblemResourceDescriptionStrategy; | ||
11 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; | ||
12 | import org.eclipse.viatra.solver.language.scoping.ProblemLocalScopeProvider; | ||
13 | import org.eclipse.xtext.conversion.IValueConverterService; | ||
14 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | ||
15 | import org.eclipse.xtext.resource.DerivedStateAwareResource; | ||
16 | import org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager; | ||
17 | import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy; | ||
18 | import org.eclipse.xtext.resource.IDerivedStateComputer; | ||
19 | import org.eclipse.xtext.resource.ILocationInFileProvider; | ||
20 | import org.eclipse.xtext.resource.IResourceDescription; | ||
21 | import org.eclipse.xtext.resource.XtextResource; | ||
22 | import org.eclipse.xtext.scoping.IGlobalScopeProvider; | ||
23 | import org.eclipse.xtext.scoping.IScopeProvider; | ||
24 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; | ||
25 | import org.eclipse.xtext.validation.IResourceValidator; | ||
26 | import org.eclipse.xtext.xbase.annotations.validation.DerivedStateAwareResourceValidator; | ||
27 | |||
28 | import com.google.inject.Binder; | ||
29 | import com.google.inject.name.Names; | ||
30 | |||
31 | /** | ||
32 | * Use this class to register components to be used at runtime / without the | ||
33 | * Equinox extension registry. | ||
34 | */ | ||
35 | public class ProblemRuntimeModule extends AbstractProblemRuntimeModule { | ||
36 | public Class<? extends IQualifiedNameConverter> bindIQualifiedNameConverter() { | ||
37 | return ProblemQualifiedNameConverter.class; | ||
38 | } | ||
39 | |||
40 | public Class<? extends IDefaultResourceDescriptionStrategy> bindIDefaultResourceDescriptionStrategy() { | ||
41 | return ProblemResourceDescriptionStrategy.class; | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public Class<? extends IValueConverterService> bindIValueConverterService() { | ||
46 | return ProblemValueConverterService.class; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() { | ||
51 | return ProblemGlobalScopeProvider.class; | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public void configureIScopeProviderDelegate(Binder binder) { | ||
56 | binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) | ||
57 | .to(ProblemLocalScopeProvider.class); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public Class<? extends XtextResource> bindXtextResource() { | ||
62 | return DerivedStateAwareResource.class; | ||
63 | } | ||
64 | |||
65 | // Method name follows Xtext convention. | ||
66 | @SuppressWarnings("squid:S100") | ||
67 | public Class<? extends IResourceDescription.Manager> bindIResourceDescription$Manager() { | ||
68 | return DerivedStateAwareResourceDescriptionManager.class; | ||
69 | } | ||
70 | |||
71 | public Class<? extends IResourceValidator> bindIResourceValidator() { | ||
72 | return DerivedStateAwareResourceValidator.class; | ||
73 | } | ||
74 | |||
75 | public Class<? extends IDerivedStateComputer> bindIDerivedStateComputer() { | ||
76 | return ProblemDerivedStateComputer.class; | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public Class<? extends ILocationInFileProvider> bindILocationInFileProvider() { | ||
81 | return ProblemLocationInFileProvider.class; | ||
82 | } | ||
83 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemStandaloneSetup.java b/language/src/main/java/org/eclipse/viatra/solver/language/ProblemStandaloneSetup.java deleted file mode 100644 index 11e5ad8a..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemStandaloneSetup.java +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language; | ||
5 | |||
6 | import org.eclipse.emf.ecore.EPackage; | ||
7 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
8 | |||
9 | import com.google.inject.Injector; | ||
10 | |||
11 | /** | ||
12 | * Initialization support for running Xtext languages without Equinox extension | ||
13 | * registry. | ||
14 | */ | ||
15 | public class ProblemStandaloneSetup extends ProblemStandaloneSetupGenerated { | ||
16 | |||
17 | public static void doSetup() { | ||
18 | new ProblemStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
19 | } | ||
20 | |||
21 | @Override | ||
22 | // Here we can't rely on java.util.HashMap#computeIfAbsent, because | ||
23 | // org.eclipse.emf.ecore.impl.EPackageRegistryImpl#containsKey is overridden | ||
24 | // without also overriding computeIfAbsent. We must make sure to call the | ||
25 | // overridden containsKey implementation. | ||
26 | @SuppressWarnings("squid:S3824") | ||
27 | public Injector createInjectorAndDoEMFRegistration() { | ||
28 | if (!EPackage.Registry.INSTANCE.containsKey(ProblemPackage.eNS_URI)) { | ||
29 | EPackage.Registry.INSTANCE.put(ProblemPackage.eNS_URI, ProblemPackage.eINSTANCE); | ||
30 | } | ||
31 | return super.createInjectorAndDoEMFRegistration(); | ||
32 | } | ||
33 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java b/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java deleted file mode 100644 index a2938274..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language; | ||
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.ecore.EObject; | ||
11 | import org.eclipse.emf.ecore.resource.Resource; | ||
12 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.Relation; | ||
18 | import org.eclipse.viatra.solver.language.model.problem.Variable; | ||
19 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; | ||
20 | |||
21 | import com.google.common.collect.ImmutableList; | ||
22 | |||
23 | public final class ProblemUtil { | ||
24 | private ProblemUtil() { | ||
25 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
26 | } | ||
27 | |||
28 | public static final String NODE_CLASS_NAME = "node"; | ||
29 | |||
30 | public static boolean isSingletonVariable(Variable variable) { | ||
31 | return variable.eContainingFeature() == ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__SINGLETON_VARIABLE; | ||
32 | } | ||
33 | |||
34 | public static boolean isUniqueNode(Node node) { | ||
35 | var containingFeature = node.eContainingFeature(); | ||
36 | return containingFeature == ProblemPackage.Literals.UNIQUE_DECLARATION__NODES | ||
37 | || containingFeature == ProblemPackage.Literals.ENUM_DECLARATION__LITERALS; | ||
38 | } | ||
39 | |||
40 | public static boolean isNewNode(Node node) { | ||
41 | return node.eContainingFeature() == ProblemPackage.Literals.CLASS_DECLARATION__NEW_NODE; | ||
42 | } | ||
43 | |||
44 | public static Optional<Problem> getBuiltInLibrary(EObject context) { | ||
45 | return Optional.ofNullable(context.eResource()).map(Resource::getResourceSet) | ||
46 | .map(resourceSet -> resourceSet.getResource(ProblemGlobalScopeProvider.BULTIN_LIBRARY_URI, true)) | ||
47 | .map(Resource::getContents).filter(contents -> !contents.isEmpty()).map(contents -> contents.get(0)) | ||
48 | .filter(Problem.class::isInstance).map(Problem.class::cast); | ||
49 | } | ||
50 | |||
51 | public static boolean isBuiltIn(EObject eObject) { | ||
52 | if (eObject != null) { | ||
53 | var eResource = eObject.eResource(); | ||
54 | if (eResource != null) { | ||
55 | return ProblemGlobalScopeProvider.BULTIN_LIBRARY_URI.equals(eResource.getURI()); | ||
56 | } | ||
57 | } | ||
58 | return false; | ||
59 | } | ||
60 | |||
61 | public static Optional<ClassDeclaration> getNodeClassDeclaration(EObject context) { | ||
62 | return getBuiltInLibrary(context).flatMap(problem -> problem.getStatements().stream() | ||
63 | .filter(ClassDeclaration.class::isInstance).map(ClassDeclaration.class::cast) | ||
64 | .filter(declaration -> NODE_CLASS_NAME.equals(declaration.getName())).findFirst()); | ||
65 | } | ||
66 | |||
67 | public static Collection<ClassDeclaration> getSuperclassesAndSelf(ClassDeclaration classDeclaration) { | ||
68 | Set<ClassDeclaration> found = new HashSet<>(); | ||
69 | getNodeClassDeclaration(classDeclaration).ifPresent(found::add); | ||
70 | Deque<ClassDeclaration> queue = new ArrayDeque<>(); | ||
71 | queue.addLast(classDeclaration); | ||
72 | while (!queue.isEmpty()) { | ||
73 | ClassDeclaration current = queue.removeFirst(); | ||
74 | if (!found.contains(current)) { | ||
75 | found.add(current); | ||
76 | for (Relation superType : current.getSuperTypes()) { | ||
77 | if (superType instanceof ClassDeclaration superDeclaration) { | ||
78 | queue.addLast(superDeclaration); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | return found; | ||
84 | } | ||
85 | |||
86 | public static Collection<ReferenceDeclaration> getAllReferenceDeclarations(ClassDeclaration classDeclaration) { | ||
87 | ImmutableList.Builder<ReferenceDeclaration> builder = ImmutableList.builder(); | ||
88 | for (ClassDeclaration superclass : getSuperclassesAndSelf(classDeclaration)) { | ||
89 | builder.addAll(superclass.getReferenceDeclarations()); | ||
90 | } | ||
91 | return builder.build(); | ||
92 | } | ||
93 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/conversion/ProblemValueConverterService.java b/language/src/main/java/org/eclipse/viatra/solver/language/conversion/ProblemValueConverterService.java deleted file mode 100644 index 1c665e6f..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/conversion/ProblemValueConverterService.java +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.conversion; | ||
2 | |||
3 | import org.eclipse.xtext.common.services.DefaultTerminalConverters; | ||
4 | import org.eclipse.xtext.conversion.IValueConverter; | ||
5 | import org.eclipse.xtext.conversion.ValueConverter; | ||
6 | |||
7 | import com.google.inject.Inject; | ||
8 | |||
9 | public class ProblemValueConverterService extends DefaultTerminalConverters { | ||
10 | @Inject | ||
11 | private UpperBoundValueConverter upperBoundValueConverter; | ||
12 | |||
13 | @ValueConverter(rule = "UpperBound") | ||
14 | // Method name follows Xtext convention. | ||
15 | @SuppressWarnings("squid:S100") | ||
16 | public IValueConverter<Integer> UpperBound() { | ||
17 | return upperBoundValueConverter; | ||
18 | } | ||
19 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/conversion/UpperBoundValueConverter.java b/language/src/main/java/org/eclipse/viatra/solver/language/conversion/UpperBoundValueConverter.java deleted file mode 100644 index 3111b69b..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/conversion/UpperBoundValueConverter.java +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.conversion; | ||
2 | |||
3 | import org.eclipse.xtext.conversion.ValueConverterException; | ||
4 | import org.eclipse.xtext.conversion.impl.AbstractValueConverter; | ||
5 | import org.eclipse.xtext.conversion.impl.INTValueConverter; | ||
6 | import org.eclipse.xtext.nodemodel.INode; | ||
7 | |||
8 | import com.google.inject.Inject; | ||
9 | import com.google.inject.Singleton; | ||
10 | |||
11 | @Singleton | ||
12 | public class UpperBoundValueConverter extends AbstractValueConverter<Integer> { | ||
13 | public static final String INFINITY = "*"; | ||
14 | |||
15 | @Inject | ||
16 | private INTValueConverter intValueConverter; | ||
17 | |||
18 | @Override | ||
19 | public Integer toValue(String string, INode node) throws ValueConverterException { | ||
20 | if (INFINITY.equals(string)) { | ||
21 | return -1; | ||
22 | } else { | ||
23 | return intValueConverter.toValue(string, node); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | @Override | ||
28 | public String toString(Integer value) throws ValueConverterException { | ||
29 | if (value < 0) { | ||
30 | return INFINITY; | ||
31 | } else { | ||
32 | return intValueConverter.toString(value); | ||
33 | } | ||
34 | } | ||
35 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/naming/NamingUtil.java b/language/src/main/java/org/eclipse/viatra/solver/language/naming/NamingUtil.java deleted file mode 100644 index edd455bb..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/naming/NamingUtil.java +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.naming; | ||
2 | |||
3 | import java.util.regex.Pattern; | ||
4 | |||
5 | public final class NamingUtil { | ||
6 | private static final String SINGLETON_VARIABLE_PREFIX = "_"; | ||
7 | |||
8 | private static final Pattern ID_REGEX = Pattern.compile("[_a-zA-Z][_0-9a-zA-Z]*"); | ||
9 | |||
10 | private NamingUtil() { | ||
11 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
12 | } | ||
13 | |||
14 | public static boolean isNullOrEmpty(String name) { | ||
15 | return name == null || name.isEmpty(); | ||
16 | } | ||
17 | |||
18 | public static boolean isSingletonVariableName(String name) { | ||
19 | return name != null && name.startsWith(SINGLETON_VARIABLE_PREFIX); | ||
20 | } | ||
21 | |||
22 | public static boolean isValidId(String name) { | ||
23 | return name != null && ID_REGEX.matcher(name).matches(); | ||
24 | } | ||
25 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/naming/ProblemQualifiedNameConverter.java b/language/src/main/java/org/eclipse/viatra/solver/language/naming/ProblemQualifiedNameConverter.java deleted file mode 100644 index e55e5dda..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/naming/ProblemQualifiedNameConverter.java +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.naming; | ||
2 | |||
3 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | ||
4 | |||
5 | import com.google.inject.Singleton; | ||
6 | |||
7 | @Singleton | ||
8 | public class ProblemQualifiedNameConverter extends IQualifiedNameConverter.DefaultImpl { | ||
9 | public static final String DELIMITER = "::"; | ||
10 | |||
11 | @Override | ||
12 | public String getDelimiter() { | ||
13 | return DELIMITER; | ||
14 | } | ||
15 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java deleted file mode 100644 index 2789f590..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/DerivedVariableComputer.java +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | ||
2 | |||
3 | import java.util.HashSet; | ||
4 | import java.util.List; | ||
5 | import java.util.Set; | ||
6 | |||
7 | import org.eclipse.viatra.solver.language.model.problem.Argument; | ||
8 | import org.eclipse.viatra.solver.language.model.problem.Atom; | ||
9 | import org.eclipse.viatra.solver.language.model.problem.Conjunction; | ||
10 | import org.eclipse.viatra.solver.language.model.problem.ExistentialQuantifier; | ||
11 | import org.eclipse.viatra.solver.language.model.problem.ImplicitVariable; | ||
12 | import org.eclipse.viatra.solver.language.model.problem.Literal; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.NegativeLiteral; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.Parameter; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.ProblemFactory; | ||
18 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
19 | import org.eclipse.viatra.solver.language.model.problem.Statement; | ||
20 | import org.eclipse.viatra.solver.language.model.problem.VariableOrNodeArgument; | ||
21 | import org.eclipse.viatra.solver.language.naming.NamingUtil; | ||
22 | import org.eclipse.xtext.linking.impl.LinkingHelper; | ||
23 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | ||
24 | import org.eclipse.xtext.nodemodel.INode; | ||
25 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
26 | import org.eclipse.xtext.scoping.IScope; | ||
27 | import org.eclipse.xtext.scoping.IScopeProvider; | ||
28 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; | ||
29 | |||
30 | import com.google.inject.Inject; | ||
31 | import com.google.inject.Singleton; | ||
32 | import com.google.inject.name.Named; | ||
33 | |||
34 | @Singleton | ||
35 | public class DerivedVariableComputer { | ||
36 | @Inject | ||
37 | private LinkingHelper linkingHelper; | ||
38 | |||
39 | @Inject | ||
40 | private IQualifiedNameConverter qualifiedNameConverter; | ||
41 | |||
42 | @Inject | ||
43 | @Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE) | ||
44 | private IScopeProvider scopeProvider; | ||
45 | |||
46 | public void installDerivedVariables(Problem problem, Set<String> nodeNames) { | ||
47 | for (Statement statement : problem.getStatements()) { | ||
48 | if (statement instanceof PredicateDefinition definition) { | ||
49 | installDerivedPredicateDefinitionState(definition, nodeNames); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | protected void installDerivedPredicateDefinitionState(PredicateDefinition definition, Set<String> nodeNames) { | ||
55 | Set<String> knownVariables = new HashSet<>(); | ||
56 | knownVariables.addAll(nodeNames); | ||
57 | for (Parameter parameter : definition.getParameters()) { | ||
58 | String name = parameter.getName(); | ||
59 | if (name != null) { | ||
60 | knownVariables.add(name); | ||
61 | } | ||
62 | } | ||
63 | for (Conjunction body : definition.getBodies()) { | ||
64 | installDeriveConjunctionState(body, knownVariables); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | protected void installDeriveConjunctionState(Conjunction conjunction, Set<String> knownVariables) { | ||
69 | Set<String> newVariables = new HashSet<>(); | ||
70 | for (Literal literal : conjunction.getLiterals()) { | ||
71 | if (literal instanceof Atom atom) { | ||
72 | createSigletonVariablesAndCollectVariables(atom, knownVariables, newVariables); | ||
73 | } | ||
74 | } | ||
75 | createVariables(conjunction, newVariables); | ||
76 | newVariables.addAll(knownVariables); | ||
77 | for (Literal literal : conjunction.getLiterals()) { | ||
78 | if (literal instanceof NegativeLiteral negativeLiteral) { | ||
79 | installDeriveNegativeLiteralState(negativeLiteral, newVariables); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | protected void installDeriveNegativeLiteralState(NegativeLiteral negativeLiteral, Set<String> knownVariables) { | ||
85 | Set<String> newVariables = new HashSet<>(); | ||
86 | createSigletonVariablesAndCollectVariables(negativeLiteral.getAtom(), knownVariables, newVariables); | ||
87 | createVariables(negativeLiteral, newVariables); | ||
88 | } | ||
89 | |||
90 | protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, | ||
91 | Set<String> newVariables) { | ||
92 | for (Argument argument : atom.getArguments()) { | ||
93 | if (argument instanceof VariableOrNodeArgument variableOrNodeArgument) { | ||
94 | IScope scope = scopeProvider.getScope(variableOrNodeArgument, | ||
95 | ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE); | ||
96 | List<INode> nodes = NodeModelUtils.findNodesForFeature(variableOrNodeArgument, | ||
97 | ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE); | ||
98 | for (INode node : nodes) { | ||
99 | var variableName = linkingHelper.getCrossRefNodeAsString(node, true); | ||
100 | var created = tryCreateVariableForArgument(variableOrNodeArgument, variableName, scope, | ||
101 | knownVariables, newVariables); | ||
102 | if (created) { | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | protected boolean tryCreateVariableForArgument(VariableOrNodeArgument variableOrNodeArgument, String variableName, | ||
111 | IScope scope, Set<String> knownVariables, Set<String> newVariables) { | ||
112 | if (!NamingUtil.isValidId(variableName)) { | ||
113 | return false; | ||
114 | } | ||
115 | var qualifiedName = qualifiedNameConverter.toQualifiedName(variableName); | ||
116 | if (scope.getSingleElement(qualifiedName) != null) { | ||
117 | return false; | ||
118 | } | ||
119 | if (NamingUtil.isSingletonVariableName(variableName)) { | ||
120 | createSingletonVariable(variableOrNodeArgument, variableName); | ||
121 | return true; | ||
122 | } | ||
123 | if (!knownVariables.contains(variableName)) { | ||
124 | newVariables.add(variableName); | ||
125 | return true; | ||
126 | } | ||
127 | return false; | ||
128 | } | ||
129 | |||
130 | protected void createVariables(ExistentialQuantifier quantifier, Set<String> newVariables) { | ||
131 | for (String variableName : newVariables) { | ||
132 | createVariable(quantifier, variableName); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | protected void createVariable(ExistentialQuantifier quantifier, String variableName) { | ||
137 | if (NamingUtil.isValidId(variableName)) { | ||
138 | ImplicitVariable variable = createNamedVariable(variableName); | ||
139 | quantifier.getImplicitVariables().add(variable); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | protected void createSingletonVariable(VariableOrNodeArgument argument, String variableName) { | ||
144 | if (NamingUtil.isValidId(variableName)) { | ||
145 | ImplicitVariable variable = createNamedVariable(variableName); | ||
146 | argument.setSingletonVariable(variable); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | protected ImplicitVariable createNamedVariable(String variableName) { | ||
151 | var variable = ProblemFactory.eINSTANCE.createImplicitVariable(); | ||
152 | variable.setName(variableName); | ||
153 | return variable; | ||
154 | } | ||
155 | |||
156 | public void discardDerivedVariables(Problem problem) { | ||
157 | for (Statement statement : problem.getStatements()) { | ||
158 | if (statement instanceof PredicateDefinition predicateDefinition) { | ||
159 | discardPredicateDefinitionState(predicateDefinition); | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | protected void discardPredicateDefinitionState(PredicateDefinition definition) { | ||
165 | for (Conjunction body : definition.getBodies()) { | ||
166 | body.getImplicitVariables().clear(); | ||
167 | for (Literal literal : body.getLiterals()) { | ||
168 | if (literal instanceof Atom atom) { | ||
169 | discardDerivedAtomState(atom); | ||
170 | } | ||
171 | if (literal instanceof NegativeLiteral negativeLiteral) { | ||
172 | negativeLiteral.getImplicitVariables().clear(); | ||
173 | discardDerivedAtomState(negativeLiteral.getAtom()); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | protected void discardDerivedAtomState(Atom atom) { | ||
180 | if (atom == null) { | ||
181 | return; | ||
182 | } | ||
183 | for (Argument argument : atom.getArguments()) { | ||
184 | if (argument instanceof VariableOrNodeArgument variableOrNodeArgument) { | ||
185 | variableOrNodeArgument.setSingletonVariable(null); | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java deleted file mode 100644 index 415db9a9..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.Set; | ||
5 | |||
6 | import org.eclipse.emf.ecore.EObject; | ||
7 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
8 | import org.eclipse.viatra.solver.language.model.problem.Assertion; | ||
9 | import org.eclipse.viatra.solver.language.model.problem.AssertionArgument; | ||
10 | import org.eclipse.viatra.solver.language.model.problem.NodeAssertionArgument; | ||
11 | import org.eclipse.viatra.solver.language.model.problem.NodeValueAssertion; | ||
12 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.Statement; | ||
15 | import org.eclipse.viatra.solver.language.naming.NamingUtil; | ||
16 | import org.eclipse.xtext.linking.impl.LinkingHelper; | ||
17 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | ||
18 | import org.eclipse.xtext.nodemodel.INode; | ||
19 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
20 | import org.eclipse.xtext.scoping.IScope; | ||
21 | import org.eclipse.xtext.scoping.IScopeProvider; | ||
22 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; | ||
23 | |||
24 | import com.google.common.collect.ImmutableSet; | ||
25 | import com.google.inject.Inject; | ||
26 | import com.google.inject.name.Named; | ||
27 | |||
28 | public class NodeNameCollector { | ||
29 | @Inject | ||
30 | private LinkingHelper linkingHelper; | ||
31 | |||
32 | @Inject | ||
33 | private IQualifiedNameConverter qualifiedNameConverter; | ||
34 | |||
35 | @Inject | ||
36 | @Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE) | ||
37 | private IScopeProvider scopeProvider; | ||
38 | |||
39 | private final ImmutableSet.Builder<String> nodeNames = ImmutableSet.builder(); | ||
40 | |||
41 | private IScope nodeScope; | ||
42 | |||
43 | public Set<String> getNodeNames() { | ||
44 | return nodeNames.build(); | ||
45 | } | ||
46 | |||
47 | public void collectNodeNames(Problem problem) { | ||
48 | nodeScope = scopeProvider.getScope(problem, ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE); | ||
49 | for (Statement statement : problem.getStatements()) { | ||
50 | collectStatementNodeNames(statement); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | protected void collectStatementNodeNames(Statement statement) { | ||
55 | if (statement instanceof Assertion assertion) { | ||
56 | collectAssertionNodeNames(assertion); | ||
57 | } else if (statement instanceof NodeValueAssertion nodeValueAssertion) { | ||
58 | collectNodeValueAssertionNodeNames(nodeValueAssertion); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | protected void collectAssertionNodeNames(Assertion assertion) { | ||
63 | for (AssertionArgument argument : assertion.getArguments()) { | ||
64 | if (argument instanceof NodeAssertionArgument) { | ||
65 | collectNodeNames(argument, ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | protected void collectNodeValueAssertionNodeNames(NodeValueAssertion nodeValueAssertion) { | ||
71 | collectNodeNames(nodeValueAssertion, ProblemPackage.Literals.NODE_VALUE_ASSERTION__NODE); | ||
72 | } | ||
73 | |||
74 | private void collectNodeNames(EObject eObject, EStructuralFeature feature) { | ||
75 | List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, feature); | ||
76 | for (INode node : nodes) { | ||
77 | var nodeName = linkingHelper.getCrossRefNodeAsString(node, true); | ||
78 | if (!NamingUtil.isValidId(nodeName)) { | ||
79 | continue; | ||
80 | } | ||
81 | var qualifiedName = qualifiedNameConverter.toQualifiedName(nodeName); | ||
82 | if (nodeScope.getSingleElement(qualifiedName) == null) { | ||
83 | nodeNames.add(nodeName); | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | } \ No newline at end of file | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java deleted file mode 100644 index 3c6c8273..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | ||
2 | |||
3 | import java.util.Collection; | ||
4 | import java.util.HashMap; | ||
5 | import java.util.HashSet; | ||
6 | import java.util.List; | ||
7 | import java.util.Map; | ||
8 | import java.util.Set; | ||
9 | import java.util.function.Function; | ||
10 | |||
11 | import org.eclipse.emf.common.notify.impl.AdapterImpl; | ||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | import org.eclipse.emf.ecore.resource.Resource; | ||
14 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
18 | import org.eclipse.viatra.solver.language.model.problem.ProblemFactory; | ||
19 | import org.eclipse.viatra.solver.language.model.problem.Statement; | ||
20 | import org.eclipse.xtext.Constants; | ||
21 | import org.eclipse.xtext.resource.DerivedStateAwareResource; | ||
22 | import org.eclipse.xtext.resource.IDerivedStateComputer; | ||
23 | import org.eclipse.xtext.resource.XtextResource; | ||
24 | import org.eclipse.xtext.scoping.IScopeProvider; | ||
25 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; | ||
26 | |||
27 | import com.google.inject.Inject; | ||
28 | import com.google.inject.Provider; | ||
29 | import com.google.inject.Singleton; | ||
30 | import com.google.inject.name.Named; | ||
31 | |||
32 | @Singleton | ||
33 | public class ProblemDerivedStateComputer implements IDerivedStateComputer { | ||
34 | public static final String NEW_NODE = "new"; | ||
35 | |||
36 | @Inject | ||
37 | @Named(Constants.LANGUAGE_NAME) | ||
38 | private String languageName; | ||
39 | |||
40 | @Inject | ||
41 | @Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE) | ||
42 | private IScopeProvider scopeProvider; | ||
43 | |||
44 | @Inject | ||
45 | private Provider<NodeNameCollector> nodeNameCollectorProvider; | ||
46 | |||
47 | @Inject | ||
48 | private DerivedVariableComputer derivedVariableComputer; | ||
49 | |||
50 | @Override | ||
51 | public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { | ||
52 | var problem = getProblem(resource); | ||
53 | if (problem != null) { | ||
54 | var adapter = getOrInstallAdapter(resource); | ||
55 | installDerivedProblemState(problem, adapter, preLinkingPhase); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | protected Problem getProblem(Resource resource) { | ||
60 | List<EObject> contents = resource.getContents(); | ||
61 | if (contents.isEmpty()) { | ||
62 | return null; | ||
63 | } | ||
64 | EObject object = contents.get(0); | ||
65 | if (object instanceof Problem problem) { | ||
66 | return problem; | ||
67 | } | ||
68 | return null; | ||
69 | } | ||
70 | |||
71 | protected void installDerivedProblemState(Problem problem, Adapter adapter, boolean preLinkingPhase) { | ||
72 | installNewNodes(problem, adapter); | ||
73 | if (preLinkingPhase) { | ||
74 | return; | ||
75 | } | ||
76 | Set<String> nodeNames = installDerivedNodes(problem); | ||
77 | derivedVariableComputer.installDerivedVariables(problem, nodeNames); | ||
78 | } | ||
79 | |||
80 | protected void installNewNodes(Problem problem, Adapter adapter) { | ||
81 | for (Statement statement : problem.getStatements()) { | ||
82 | if (statement instanceof ClassDeclaration declaration && !declaration.isAbstract() | ||
83 | && declaration.getNewNode() == null) { | ||
84 | var newNode = adapter.createNodeIfAbsent(declaration, key -> createNode(NEW_NODE)); | ||
85 | declaration.setNewNode(newNode); | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | protected Set<String> installDerivedNodes(Problem problem) { | ||
91 | var collector = nodeNameCollectorProvider.get(); | ||
92 | collector.collectNodeNames(problem); | ||
93 | Set<String> nodeNames = collector.getNodeNames(); | ||
94 | List<Node> grapNodes = problem.getNodes(); | ||
95 | for (String nodeName : nodeNames) { | ||
96 | var graphNode = createNode(nodeName); | ||
97 | grapNodes.add(graphNode); | ||
98 | } | ||
99 | return nodeNames; | ||
100 | } | ||
101 | |||
102 | protected Node createNode(String name) { | ||
103 | var node = ProblemFactory.eINSTANCE.createNode(); | ||
104 | node.setName(name); | ||
105 | return node; | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public void discardDerivedState(DerivedStateAwareResource resource) { | ||
110 | var problem = getProblem(resource); | ||
111 | if (problem != null) { | ||
112 | var adapter = getOrInstallAdapter(resource); | ||
113 | discardDerivedProblemState(problem, adapter); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | protected void discardDerivedProblemState(Problem problem, Adapter adapter) { | ||
118 | Set<ClassDeclaration> classDeclarations = new HashSet<>(); | ||
119 | problem.getNodes().clear(); | ||
120 | for (Statement statement : problem.getStatements()) { | ||
121 | if (statement instanceof ClassDeclaration classDeclaration) { | ||
122 | classDeclaration.setNewNode(null); | ||
123 | classDeclarations.add(classDeclaration); | ||
124 | } | ||
125 | } | ||
126 | adapter.retainAll(classDeclarations); | ||
127 | derivedVariableComputer.discardDerivedVariables(problem); | ||
128 | } | ||
129 | |||
130 | protected Adapter getOrInstallAdapter(Resource resource) { | ||
131 | if (!(resource instanceof XtextResource)) { | ||
132 | return new Adapter(); | ||
133 | } | ||
134 | String resourceLanguageName = ((XtextResource) resource).getLanguageName(); | ||
135 | if (!languageName.equals(resourceLanguageName)) { | ||
136 | return new Adapter(); | ||
137 | } | ||
138 | var adapter = (Adapter) EcoreUtil.getAdapter(resource.eAdapters(), Adapter.class); | ||
139 | if (adapter == null) { | ||
140 | adapter = new Adapter(); | ||
141 | resource.eAdapters().add(adapter); | ||
142 | } | ||
143 | return adapter; | ||
144 | } | ||
145 | |||
146 | protected static class Adapter extends AdapterImpl { | ||
147 | private Map<ClassDeclaration, Node> newNodes = new HashMap<>(); | ||
148 | |||
149 | public Node createNodeIfAbsent(ClassDeclaration classDeclaration, Function<ClassDeclaration, Node> createNode) { | ||
150 | return newNodes.computeIfAbsent(classDeclaration, createNode); | ||
151 | } | ||
152 | |||
153 | public void retainAll(Collection<ClassDeclaration> classDeclarations) { | ||
154 | newNodes.keySet().retainAll(classDeclarations); | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public boolean isAdapterForType(Object type) { | ||
159 | return Adapter.class == type; | ||
160 | } | ||
161 | } | ||
162 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java deleted file mode 100644 index bd05e8cf..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | ||
2 | |||
3 | import org.eclipse.emf.ecore.EObject; | ||
4 | import org.eclipse.viatra.solver.language.ProblemUtil; | ||
5 | import org.eclipse.viatra.solver.language.model.problem.ImplicitVariable; | ||
6 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
7 | import org.eclipse.xtext.resource.DefaultLocationInFileProvider; | ||
8 | import org.eclipse.xtext.util.ITextRegion; | ||
9 | |||
10 | public class ProblemLocationInFileProvider extends DefaultLocationInFileProvider { | ||
11 | @Override | ||
12 | protected ITextRegion doGetTextRegion(EObject obj, RegionDescription query) { | ||
13 | if (obj instanceof Node node) { | ||
14 | return getNodeTextRegion(node, query); | ||
15 | } | ||
16 | if (obj instanceof ImplicitVariable) { | ||
17 | return ITextRegion.EMPTY_REGION; | ||
18 | } | ||
19 | return super.doGetTextRegion(obj, query); | ||
20 | } | ||
21 | |||
22 | protected ITextRegion getNodeTextRegion(Node node, RegionDescription query) { | ||
23 | if (ProblemUtil.isUniqueNode(node)) { | ||
24 | return super.doGetTextRegion(node, query); | ||
25 | } | ||
26 | if (ProblemUtil.isNewNode(node)) { | ||
27 | EObject container = node.eContainer(); | ||
28 | return doGetTextRegion(container, query); | ||
29 | } | ||
30 | return ITextRegion.EMPTY_REGION; | ||
31 | } | ||
32 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java deleted file mode 100644 index cd5020e7..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java +++ /dev/null | |||
@@ -1,102 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | ||
2 | |||
3 | import org.eclipse.emf.ecore.EObject; | ||
4 | import org.eclipse.viatra.solver.language.ProblemUtil; | ||
5 | import org.eclipse.viatra.solver.language.model.problem.NamedElement; | ||
6 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
7 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
8 | import org.eclipse.viatra.solver.language.model.problem.Variable; | ||
9 | import org.eclipse.viatra.solver.language.naming.NamingUtil; | ||
10 | import org.eclipse.xtext.EcoreUtil2; | ||
11 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | ||
12 | import org.eclipse.xtext.naming.QualifiedName; | ||
13 | import org.eclipse.xtext.resource.EObjectDescription; | ||
14 | import org.eclipse.xtext.resource.IEObjectDescription; | ||
15 | import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; | ||
16 | import org.eclipse.xtext.util.IAcceptor; | ||
17 | |||
18 | import com.google.inject.Inject; | ||
19 | import com.google.inject.Singleton; | ||
20 | |||
21 | @Singleton | ||
22 | public class ProblemResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy { | ||
23 | @Inject | ||
24 | private IQualifiedNameConverter qualifiedNameConverter; | ||
25 | |||
26 | @Override | ||
27 | public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) { | ||
28 | if (!shouldExport(eObject)) { | ||
29 | return false; | ||
30 | } | ||
31 | var qualifiedName = getNameAsQualifiedName(eObject); | ||
32 | if (qualifiedName == null) { | ||
33 | return true; | ||
34 | } | ||
35 | var problem = EcoreUtil2.getContainerOfType(eObject, Problem.class); | ||
36 | var problemQualifiedName = getNameAsQualifiedName(problem); | ||
37 | boolean nameExported; | ||
38 | if (shouldExportSimpleName(eObject)) { | ||
39 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, acceptor); | ||
40 | nameExported = true; | ||
41 | } else { | ||
42 | nameExported = false; | ||
43 | } | ||
44 | var parent = eObject.eContainer(); | ||
45 | while (parent != null && parent != problem) { | ||
46 | var parentQualifiedName = getNameAsQualifiedName(parent); | ||
47 | if (parentQualifiedName == null) { | ||
48 | parent = parent.eContainer(); | ||
49 | continue; | ||
50 | } | ||
51 | qualifiedName = parentQualifiedName.append(qualifiedName); | ||
52 | if (shouldExportSimpleName(parent)) { | ||
53 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, acceptor); | ||
54 | nameExported = true; | ||
55 | } else { | ||
56 | nameExported = false; | ||
57 | } | ||
58 | parent = parent.eContainer(); | ||
59 | } | ||
60 | if (!nameExported) { | ||
61 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, acceptor); | ||
62 | } | ||
63 | return true; | ||
64 | } | ||
65 | |||
66 | protected QualifiedName getNameAsQualifiedName(EObject eObject) { | ||
67 | if (!(eObject instanceof NamedElement)) { | ||
68 | return null; | ||
69 | } | ||
70 | var namedElement = (NamedElement) eObject; | ||
71 | var name = namedElement.getName(); | ||
72 | if (NamingUtil.isNullOrEmpty(name)) { | ||
73 | return null; | ||
74 | } | ||
75 | return qualifiedNameConverter.toQualifiedName(name); | ||
76 | } | ||
77 | |||
78 | protected boolean shouldExport(EObject eObject) { | ||
79 | if (eObject instanceof Variable) { | ||
80 | // Variables are always private to the containing predicate definition. | ||
81 | return false; | ||
82 | } | ||
83 | if (eObject instanceof Node node) { | ||
84 | // Only enum literals and new nodes are visible across problem files. | ||
85 | return ProblemUtil.isUniqueNode(node) || ProblemUtil.isNewNode(node); | ||
86 | } | ||
87 | return true; | ||
88 | } | ||
89 | |||
90 | protected boolean shouldExportSimpleName(EObject eObject) { | ||
91 | if (eObject instanceof Node node) { | ||
92 | return !ProblemUtil.isNewNode(node); | ||
93 | } | ||
94 | return true; | ||
95 | } | ||
96 | |||
97 | private void acceptEObjectDescription(EObject eObject, QualifiedName prefix, QualifiedName qualifiedName, | ||
98 | IAcceptor<IEObjectDescription> acceptor) { | ||
99 | var qualifiedNameWithPrefix = prefix == null ? qualifiedName : prefix.append(qualifiedName); | ||
100 | acceptor.accept(EObjectDescription.create(qualifiedNameWithPrefix, eObject)); | ||
101 | } | ||
102 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemGlobalScopeProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemGlobalScopeProvider.java deleted file mode 100644 index 05da277a..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemGlobalScopeProvider.java +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.scoping; | ||
2 | |||
3 | import java.util.LinkedHashSet; | ||
4 | |||
5 | import org.eclipse.emf.common.util.URI; | ||
6 | import org.eclipse.emf.ecore.resource.Resource; | ||
7 | import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider; | ||
8 | |||
9 | public class ProblemGlobalScopeProvider extends ImportUriGlobalScopeProvider { | ||
10 | public static final String BUILTIN_LIBRARY_NAME = "builtin"; | ||
11 | |||
12 | public static final URI BULTIN_LIBRARY_URI = getLibraryUri(BUILTIN_LIBRARY_NAME); | ||
13 | |||
14 | @Override | ||
15 | protected LinkedHashSet<URI> getImportedUris(Resource resource) { | ||
16 | LinkedHashSet<URI> importedUris = new LinkedHashSet<>(); | ||
17 | importedUris.add(BULTIN_LIBRARY_URI); | ||
18 | return importedUris; | ||
19 | } | ||
20 | |||
21 | private static URI getLibraryUri(String libraryName) { | ||
22 | return URI.createURI(ProblemGlobalScopeProvider.class.getClassLoader() | ||
23 | .getResource("org/eclipse/viatra/solver/language/" + libraryName + ".problem").toString()); | ||
24 | } | ||
25 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemLocalScopeProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemLocalScopeProvider.java deleted file mode 100644 index e832bb09..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemLocalScopeProvider.java +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.language.scoping; | ||
2 | |||
3 | import java.util.List; | ||
4 | |||
5 | import org.eclipse.emf.ecore.EObject; | ||
6 | import org.eclipse.emf.ecore.resource.Resource; | ||
7 | import org.eclipse.xtext.naming.QualifiedName; | ||
8 | import org.eclipse.xtext.resource.IResourceDescriptions; | ||
9 | import org.eclipse.xtext.resource.IResourceDescriptionsProvider; | ||
10 | import org.eclipse.xtext.resource.ISelectable; | ||
11 | import org.eclipse.xtext.scoping.impl.ImportNormalizer; | ||
12 | import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider; | ||
13 | |||
14 | import com.google.inject.Inject; | ||
15 | |||
16 | public class ProblemLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider { | ||
17 | private static final QualifiedName BUILTIN_LIBRARY_QUALIFIED_NAME = QualifiedName | ||
18 | .create(ProblemGlobalScopeProvider.BUILTIN_LIBRARY_NAME); | ||
19 | |||
20 | @Inject | ||
21 | private IResourceDescriptionsProvider resourceDescriptionsProvider; | ||
22 | |||
23 | @Override | ||
24 | protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) { | ||
25 | return List.of(doCreateImportNormalizer(BUILTIN_LIBRARY_QUALIFIED_NAME, true, ignoreCase)); | ||
26 | } | ||
27 | |||
28 | @Override | ||
29 | protected List<ImportNormalizer> getImportedNamespaceResolvers(EObject context, boolean ignoreCase) { | ||
30 | return List.of(); | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | protected ISelectable internalGetAllDescriptions(Resource resource) { | ||
35 | // Force the use of ProblemResourceDescriptionStrategy to include all QualifiedNames of objects. | ||
36 | IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider | ||
37 | .getResourceDescriptions(resource.getResourceSet()); | ||
38 | return resourceDescriptions.getResourceDescription(resource.getURI()); | ||
39 | } | ||
40 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java b/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java deleted file mode 100644 index 56de6b1b..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.scoping; | ||
5 | |||
6 | import java.util.ArrayList; | ||
7 | import java.util.List; | ||
8 | |||
9 | import org.eclipse.emf.ecore.EObject; | ||
10 | import org.eclipse.emf.ecore.EReference; | ||
11 | import org.eclipse.viatra.solver.language.ProblemUtil; | ||
12 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.ExistentialQuantifier; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | ||
18 | import org.eclipse.viatra.solver.language.model.problem.Variable; | ||
19 | import org.eclipse.viatra.solver.language.model.problem.VariableOrNodeArgument; | ||
20 | import org.eclipse.xtext.EcoreUtil2; | ||
21 | import org.eclipse.xtext.scoping.IScope; | ||
22 | import org.eclipse.xtext.scoping.Scopes; | ||
23 | |||
24 | /** | ||
25 | * This class contains custom scoping description. | ||
26 | * | ||
27 | * See | ||
28 | * https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping | ||
29 | * on how and when to use it. | ||
30 | */ | ||
31 | public class ProblemScopeProvider extends AbstractProblemScopeProvider { | ||
32 | |||
33 | @Override | ||
34 | public IScope getScope(EObject context, EReference reference) { | ||
35 | var scope = super.getScope(context, reference); | ||
36 | if (reference == ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE | ||
37 | || reference == ProblemPackage.Literals.NODE_VALUE_ASSERTION__NODE) { | ||
38 | return getNodesScope(context, scope); | ||
39 | } | ||
40 | if (reference == ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE) { | ||
41 | return getVariableScope(context, scope); | ||
42 | } | ||
43 | if (reference == ProblemPackage.Literals.REFERENCE_DECLARATION__OPPOSITE) { | ||
44 | return getOppositeScope(context, scope); | ||
45 | } | ||
46 | return scope; | ||
47 | } | ||
48 | |||
49 | protected IScope getNodesScope(EObject context, IScope delegateScope) { | ||
50 | var problem = EcoreUtil2.getContainerOfType(context, Problem.class); | ||
51 | if (problem == null) { | ||
52 | return delegateScope; | ||
53 | } | ||
54 | return Scopes.scopeFor(problem.getNodes(), delegateScope); | ||
55 | } | ||
56 | |||
57 | protected IScope getVariableScope(EObject context, IScope delegateScope) { | ||
58 | List<Variable> variables = new ArrayList<>(); | ||
59 | EObject currentContext = context; | ||
60 | if (context instanceof VariableOrNodeArgument argument) { | ||
61 | Variable singletonVariable = argument.getSingletonVariable(); | ||
62 | if (singletonVariable != null) { | ||
63 | variables.add(singletonVariable); | ||
64 | } | ||
65 | } | ||
66 | while (currentContext != null && !(currentContext instanceof PredicateDefinition)) { | ||
67 | if (currentContext instanceof ExistentialQuantifier quantifier) { | ||
68 | variables.addAll(quantifier.getImplicitVariables()); | ||
69 | } | ||
70 | currentContext = currentContext.eContainer(); | ||
71 | } | ||
72 | if (currentContext != null) { | ||
73 | PredicateDefinition definition = (PredicateDefinition) currentContext; | ||
74 | variables.addAll(definition.getParameters()); | ||
75 | } | ||
76 | return Scopes.scopeFor(variables, getNodesScope(context, delegateScope)); | ||
77 | } | ||
78 | |||
79 | protected IScope getOppositeScope(EObject context, IScope delegateScope) { | ||
80 | var referenceDeclaration = EcoreUtil2.getContainerOfType(context, ReferenceDeclaration.class); | ||
81 | if (referenceDeclaration == null) { | ||
82 | return delegateScope; | ||
83 | } | ||
84 | var relation = referenceDeclaration.getReferenceType(); | ||
85 | if (!(relation instanceof ClassDeclaration)) { | ||
86 | return delegateScope; | ||
87 | } | ||
88 | var classDeclaration = (ClassDeclaration) relation; | ||
89 | var referenceDeclarations = ProblemUtil.getAllReferenceDeclarations(classDeclaration); | ||
90 | return Scopes.scopeFor(referenceDeclarations, delegateScope); | ||
91 | } | ||
92 | } | ||
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/validation/ProblemValidator.java b/language/src/main/java/org/eclipse/viatra/solver/language/validation/ProblemValidator.java deleted file mode 100644 index 96b656a3..00000000 --- a/language/src/main/java/org/eclipse/viatra/solver/language/validation/ProblemValidator.java +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.validation; | ||
5 | |||
6 | /** | ||
7 | * This class contains custom validation rules. | ||
8 | * | ||
9 | * See | ||
10 | * https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation | ||
11 | */ | ||
12 | public class ProblemValidator extends AbstractProblemValidator { | ||
13 | } | ||