aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java
diff options
context:
space:
mode:
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.java91
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.localsearch.operations.check.nobase;
10
11import java.util.Arrays;
12import java.util.List;
13import java.util.Objects;
14import java.util.function.Function;
15
16import org.eclipse.emf.ecore.EObject;
17import org.eclipse.emf.ecore.util.EcoreUtil;
18import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexObjectFilter;
19import tools.refinery.viatra.runtime.emf.EMFScope;
20import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
21import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
22import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor;
23import 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 */
31public 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}