aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java')
-rw-r--r--subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java40
1 files changed, 8 insertions, 32 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java
index 7690daf6..182bb466 100644
--- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java
+++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/impl/BasePatternMatch.java
@@ -3,25 +3,23 @@
3 * This program and the accompanying materials are made available under the 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 4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html. 5 * http://www.eclipse.org/legal/epl-v20.html.
6 * 6 *
7 * SPDX-License-Identifier: EPL-2.0 7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/ 8 *******************************************************************************/
9 9
10package tools.refinery.viatra.runtime.api.impl; 10package tools.refinery.viatra.runtime.api.impl;
11 11
12import tools.refinery.viatra.runtime.api.IPatternMatch;
13
12import java.util.Arrays; 14import java.util.Arrays;
13import java.util.Collections; 15import java.util.Collections;
14import java.util.List; 16import java.util.List;
15 17
16import org.eclipse.emf.ecore.EObject;
17import org.eclipse.emf.ecore.EStructuralFeature;
18import tools.refinery.viatra.runtime.api.IPatternMatch;
19
20/** 18/**
21 * Base implementation of IPatternMatch. 19 * Base implementation of IPatternMatch.
22 * 20 *
23 * @author Bergmann Gábor 21 * @author Bergmann Gábor
24 * 22 *
25 */ 23 */
26public abstract class BasePatternMatch implements IPatternMatch { 24public abstract class BasePatternMatch implements IPatternMatch {
27 25
@@ -29,36 +27,14 @@ public abstract class BasePatternMatch implements IPatternMatch {
29 protected static <T> List<T> makeImmutableList(T... elements) { 27 protected static <T> List<T> makeImmutableList(T... elements) {
30 return Collections.unmodifiableList(Arrays.asList(elements)); 28 return Collections.unmodifiableList(Arrays.asList(elements));
31 } 29 }
32 30
33 public static String prettyPrintValue(Object o) { 31 public static String prettyPrintValue(Object o) {
34 if (o == null) { 32 if (o == null) {
35 return "(null)"; 33 return "(null)";
36 } 34 }
37 String name = prettyPrintFeature(o, "name");
38 if (name != null) {
39 return name;
40 }
41 /*
42 * if (o instanceof EObject) { EStructuralFeature feature = ((EObject)o).eClass().getEStructuralFeature("name");
43 * if (feature != null) { Object name = ((EObject)o).eGet(feature); if (name != null) return name.toString(); }
44 * }
45 */
46 return o.toString(); 35 return o.toString();
47 } 36 }
48 37
49 public static String prettyPrintFeature(Object o, String featureName) {
50 if (o instanceof EObject) {
51 EStructuralFeature feature = ((EObject) o).eClass().getEStructuralFeature(featureName);
52 if (feature != null) {
53 Object value = ((EObject) o).eGet(feature);
54 if (value != null) {
55 return value.toString();
56 }
57 }
58 }
59 return null;
60 }
61
62 // TODO performance can be improved here somewhat 38 // TODO performance can be improved here somewhat
63 39
64 @Override 40 @Override
@@ -83,7 +59,7 @@ public abstract class BasePatternMatch implements IPatternMatch {
83 public String toString() { 59 public String toString() {
84 return "Match<" + patternName() + ">{" + prettyPrint() + "}"; 60 return "Match<" + patternName() + ">{" + prettyPrint() + "}";
85 } 61 }
86 62
87 @Override 63 @Override
88 public boolean isCompatibleWith(IPatternMatch other) { 64 public boolean isCompatibleWith(IPatternMatch other) {
89 if(other == null) { 65 if(other == null) {
@@ -102,7 +78,7 @@ public abstract class BasePatternMatch implements IPatternMatch {
102 } 78 }
103 return true; 79 return true;
104 } 80 }
105 81
106 @Override 82 @Override
107 public String patternName() { 83 public String patternName() {
108 return specification().getFullyQualifiedName(); 84 return specification().getFullyQualifiedName();