aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java')
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java58
1 files changed, 0 insertions, 58 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java
deleted file mode 100644
index dc288ba0..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java
+++ /dev/null
@@ -1,58 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2015, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.pquery.rewriter;
10
11import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
12import org.eclipse.viatra.query.runtime.matchers.context.surrogate.SurrogateQueryRegistry;
13import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
14import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
15import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
16import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
17import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction;
18import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
19import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyCopier;
20import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PDisjunctionRewriter;
21import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
22import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
23
24import java.util.LinkedHashSet;
25import java.util.Set;
26
27public class RefinerySurrogateQueryRewriter extends PDisjunctionRewriter {
28 @Override
29 public PDisjunction rewrite(PDisjunction disjunction) {
30 Set<PBody> replacedBodies = new LinkedHashSet<>();
31 for (PBody body : disjunction.getBodies()) {
32 PBodyCopier copier = new RefineryPBodyCopier(body, getTraceCollector()) {
33
34 @Override
35 protected void copyTypeConstraint(TypeConstraint typeConstraint) {
36 PVariable[] mappedVariables = extractMappedVariables(typeConstraint);
37 Tuple variablesTuple = Tuples.flatTupleOf((Object[]) mappedVariables);
38 final IInputKey supplierKey = typeConstraint.getSupplierKey();
39 if (SurrogateQueryRegistry.instance().hasSurrogateQueryFQN(supplierKey)) {
40 PQuery surrogateQuery = SurrogateQueryRegistry.instance().getSurrogateQuery(supplierKey);
41 if (surrogateQuery == null) {
42 throw new IllegalStateException("Surrogate query for feature %s not found"
43 .formatted(supplierKey.getPrettyPrintableName()));
44 }
45 addTrace(typeConstraint, new PositivePatternCall(getCopiedBody(), variablesTuple,
46 surrogateQuery));
47 } else {
48 addTrace(typeConstraint, new TypeConstraint(getCopiedBody(), variablesTuple, supplierKey));
49 }
50 }
51 };
52 PBody modifiedBody = copier.getCopiedBody();
53 replacedBodies.add(modifiedBody);
54 modifiedBody.setStatus(PQuery.PQueryStatus.OK);
55 }
56 return new PDisjunction(replacedBodies);
57 }
58}