diff options
author | 2023-08-19 02:31:57 +0200 | |
---|---|---|
committer | 2023-08-19 02:31:57 +0200 | |
commit | 9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b (patch) | |
tree | fad77963c1dc9028b0a767ac3ad69a174c8eb8c6 /subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java | |
parent | feat: predicate semantics (diff) | |
download | refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.tar.gz refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.tar.zst refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.zip |
chore: import VIATRA source
Make our modifications more maintainable by editing the source code directly
instead of using reflection.
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java new file mode 100644 index 00000000..06989fdc --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java | |||
@@ -0,0 +1,91 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, Akos Horvath, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check.nobase; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.Objects; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EObject; | ||
17 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
18 | import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexObjectFilter; | ||
19 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
20 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
21 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
24 | |||
25 | /** | ||
26 | * This operation simply checks if a model element is part of the Query Scope | ||
27 | * | ||
28 | * @author Marton Bur | ||
29 | * | ||
30 | */ | ||
31 | public class ScopeCheck implements ISearchOperation { | ||
32 | private class Executor extends CheckOperationExecutor { | ||
33 | |||
34 | @Override | ||
35 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
36 | Objects.requireNonNull(frame.getValue(position), () -> String.format("Invalid plan, variable %d unbound", position)); | ||
37 | Object value = frame.getValue(position); | ||
38 | if(value instanceof EObject){ | ||
39 | EObject eObject = (EObject) value; | ||
40 | IBaseIndexObjectFilter filterConfiguration = scope.getOptions().getObjectFilterConfiguration(); | ||
41 | boolean filtered = false; | ||
42 | if(filterConfiguration != null){ | ||
43 | filtered = filterConfiguration.isFiltered(eObject); | ||
44 | } | ||
45 | if(filtered){ | ||
46 | return false; | ||
47 | } else { | ||
48 | return EcoreUtil.isAncestor(scope.getScopeRoots(), eObject); | ||
49 | } | ||
50 | } else { | ||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public ISearchOperation getOperation() { | ||
57 | return ScopeCheck.this; | ||
58 | } | ||
59 | |||
60 | } | ||
61 | |||
62 | private int position; | ||
63 | private EMFScope scope; | ||
64 | |||
65 | public ScopeCheck(int position, EMFScope scope) { | ||
66 | this.position = position; | ||
67 | this.scope = scope; | ||
68 | |||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public ISearchOperationExecutor createExecutor() { | ||
73 | return new Executor(); | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | public String toString() { | ||
78 | return toString(Object::toString); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public String toString(Function<Integer, String> variableMapping) { | ||
84 | return "check +"+variableMapping.apply(position) +" in scope "+scope; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public List<Integer> getVariablePositions() { | ||
89 | return Arrays.asList(position); | ||
90 | } | ||
91 | } | ||