Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZoltan Ujhelyi2017-07-06 13:17:39 +0000
committerZoltan Ujhelyi2017-07-11 09:46:03 +0000
commit6e8603fa71bf000c110b14124330de6c8b150b0b (patch)
tree42870594c2aa0d3eb6f0ad02bb62720aea044bfc
parent93b8b9243c74b6c1e67fb58cec27813295f9dded (diff)
downloadorg.eclipse.viatra-6e8603fa71bf000c110b14124330de6c8b150b0b.tar.gz
org.eclipse.viatra-6e8603fa71bf000c110b14124330de6c8b150b0b.tar.xz
org.eclipse.viatra-6e8603fa71bf000c110b14124330de6c8b150b0b.zip
[469149] Refactored old commands to also use runtime context
This allowed us to remove direct base index access from the runtime context as well. Change-Id: I46fa46656829de71cb8b9585f6807342b93c109c Signed-off-by: Zoltan Ujhelyi <ujhelyiz@incquerylabs.com>
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters34
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java36
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java10
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java15
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java6
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEClassInstances.java12
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java16
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java33
-rw-r--r--query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureTarget.java67
9 files changed, 80 insertions, 149 deletions
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
index 7f2c14c51..00ea71416 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/.settings/.api_filters
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.viatra.query.runtime.localsearch" version="2">
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java" type="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext">
+ <filter comment="Internal API update" id="405901410">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext"/>
+ <message_argument value="getBaseIndex()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java" type="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext$SearchContext">
<filter id="338722907">
<message_arguments>
@@ -7,6 +15,12 @@
<message_argument value="SearchContext(IBaseIndex, IQueryResultProviderAccess, QueryEvaluationHint)"/>
</message_arguments>
</filter>
+ <filter comment="Internal API update" id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext.SearchContext"/>
+ <message_argument value="getBaseIndex()"/>
+ </message_arguments>
+ </filter>
<filter comment="Internal API implementation" id="576725006">
<message_arguments>
<message_argument value="ISearchContext"/>
@@ -38,6 +52,26 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java" type="org.eclipse.viatra.query.runtime.localsearch.operations.extend.IterateOverEStructuralFeatureInstances">
+ <filter comment="Internal API update" id="388018290">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.operations.extend.IterateOverEStructuralFeatureInstances"/>
+ <message_argument value="it"/>
+ </message_arguments>
+ </filter>
+ <filter comment="Internal API update" id="389300331">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.operations.extend.IterateOverEStructuralFeatureInstances.it"/>
+ <message_argument value="java.lang.Object"/>
+ </message_arguments>
+ </filter>
+ <filter comment="Internal API update" id="389300331">
+ <message_arguments>
+ <message_argument value="org.eclipse.viatra.query.runtime.localsearch.operations.extend.IterateOverEStructuralFeatureInstances.it"/>
+ <message_argument value="org.eclipse.emf.ecore.EObject"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/viatra/query/runtime/localsearch/plan/IPlanProvider.java" type="org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider">
<filter comment="Internal API modification" id="403804204">
<message_arguments>
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
index d3e767b09..626f9fa57 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/ISearchContext.java
@@ -16,12 +16,8 @@ import java.util.Set;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.viatra.query.runtime.api.scope.IBaseIndex;
import org.eclipse.viatra.query.runtime.base.api.IndexingLevel;
import org.eclipse.viatra.query.runtime.base.api.NavigationHelper;
-import org.eclipse.viatra.query.runtime.emf.EMFBaseIndexWrapper;
-import org.eclipse.viatra.query.runtime.emf.EMFQueryRuntimeContext;
-import org.eclipse.viatra.query.runtime.exception.ViatraQueryException;
import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchException;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.IAdornmentProvider;
import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions;
@@ -37,8 +33,6 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
import org.eclipse.viatra.query.runtime.matchers.util.ICache;
import org.eclipse.viatra.query.runtime.matchers.util.IProvider;
-import com.google.common.base.Preconditions;
-
/**
* The {@link ISearchContext} interface allows search operations to reuse platform services such as the indexer.
*
@@ -51,12 +45,6 @@ import com.google.common.base.Preconditions;
public interface ISearchContext {
/**
- * Provides access to the EMF-specific base index for search operation; do not use if not on EMF Scope
- * @throws IllegalStateException if called on a non-EMF backend
- */
- NavigationHelper getBaseIndex();
-
- /**
* Provides access to the generic query runtime context of the current engine
* @since 1.7
*/
@@ -101,23 +89,9 @@ public interface ISearchContext {
private final ICache backendLevelCache;
/**
- * Initializes a search context using an EMF context
- */
- public SearchContext(IQueryBackendContext backendContext, IBaseIndex baseIndex, QueryEvaluationHint overrideHints, ICache backendLevelCache) throws ViatraQueryException {
- this.runtimeContext = backendContext.getRuntimeContext();
- Preconditions.checkArgument(runtimeContext instanceof EMFQueryRuntimeContext, "EMF-specific context only works with EMF runtime context");
- //XXX this is a problematic (and in long-term unsupported) solution, see bug 456815
- this.navigationHelper = ((EMFBaseIndexWrapper)baseIndex).getNavigationHelper();
- this.resultProviderAccess = backendContext.getResultProviderAccess();
- this.overrideHints = overrideHints;
-
- this.backendLevelCache = backendLevelCache;
- }
-
- /**
* Initializes a search context using an arbitrary backend context
*/
- public SearchContext(IQueryBackendContext backendContext, QueryEvaluationHint overrideHints, ICache backendLevelCache) throws ViatraQueryException {
+ public SearchContext(IQueryBackendContext backendContext, QueryEvaluationHint overrideHints, ICache backendLevelCache) {
this.runtimeContext = backendContext.getRuntimeContext();
this.navigationHelper = null;
this.resultProviderAccess = backendContext.getResultProviderAccess();
@@ -134,14 +108,6 @@ public interface ISearchContext {
this.navigationHelper.registerObservedTypes(classes, dataTypes, features, IndexingLevel.FULL);
}
- @Override
- public NavigationHelper getBaseIndex() {
- if (navigationHelper == null) {
- throw new IllegalStateException("The EMF API of the Base index is not available");
- }
- return navigationHelper;
- }
-
/**
* @throws QueryProcessingException
* @since 1.5
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java
index 4d42d5933..fa2b98ef8 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java
@@ -20,7 +20,6 @@ import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
-import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine;
import org.eclipse.viatra.query.runtime.exception.ViatraQueryException;
import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame;
import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchException;
@@ -66,7 +65,6 @@ public class LocalSearchResultProvider implements IQueryResultProvider {
private final LocalSearchBackend backend;
private final IQueryBackendHintProvider hintProvider;
- private final AdvancedViatraQueryEngine engine;
private final IQueryRuntimeContext runtimeContext;
private final PQuery query;
private final IQueryResultProviderAccess resultProviderAccess;
@@ -157,19 +155,13 @@ public class LocalSearchResultProvider implements IQueryResultProvider {
this.backend = backend;
this.resultProviderAccess = context.getResultProviderAccess();
this.hintProvider = context.getHintProvider();
- // XXX this is a problematic (and in long-term unsupported) solution, see bug 456815
- engine = (AdvancedViatraQueryEngine) hintProvider;
this.query = query;
this.planProvider = planProvider;
this.userHints = userHints;
this.runtimeContext = context.getRuntimeContext();
- try {
- searchContext = new ISearchContext.SearchContext(context, engine.getBaseIndex(), userHints, backend.getCache());
- } catch (ViatraQueryException e) {
- throw new QueryProcessingException("Could not create search context for {1}", new String[]{query.getFullyQualifiedName()}, e.getMessage(), query, e);
- }
+ this.searchContext = new ISearchContext.SearchContext(context, userHints, backend.getCache());
}
/**
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java
index 80f80294d..f13e487d4 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.operations.extend;
-import java.util.Collection;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
@@ -21,7 +20,9 @@ import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame;
import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext;
import org.eclipse.viatra.query.runtime.localsearch.operations.IIteratingSearchOperation;
import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
+import org.eclipse.viatra.query.runtime.matchers.tuple.FlatTuple;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
@@ -33,11 +34,13 @@ public class ExtendToEStructuralFeatureSource extends ExtendOperation<EObject> i
private int targetPosition;
private EStructuralFeature feature;
+ private final IInputKey type;
public ExtendToEStructuralFeatureSource(int sourcePosition, int targetPosition, EStructuralFeature feature) {
super(sourcePosition);
this.targetPosition = targetPosition;
this.feature = feature;
+ type = new EStructuralFeatureInstancesKey(feature);
}
public EStructuralFeature getFeature() {
@@ -46,11 +49,9 @@ public class ExtendToEStructuralFeatureSource extends ExtendOperation<EObject> i
@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) {
- final Collection<EObject> values = context.getBaseIndex().findByFeatureValue(frame.getValue(targetPosition), feature);
- // System.out.println("**FeatureSource " + feature.getContainerClass().getName() + "." + feature.getName() + " "
- // + values.size());
- it = values
- .iterator();
+ Iterable<? extends Object> values = context.getRuntimeContext().enumerateValues(type,
+ new FlatTuple(null, frame.getValue(targetPosition)));
+ it = Iterables.filter(values, EObject.class).iterator();
}
@Override
@@ -68,7 +69,7 @@ public class ExtendToEStructuralFeatureSource extends ExtendOperation<EObject> i
*/
@Override
public IInputKey getIteratedInputKey() {
- return new EStructuralFeatureInstancesKey(feature);
+ return type;
}
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java
index fd3c5cd6e..59571218f 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java
@@ -16,7 +16,6 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.viatra.query.runtime.base.api.NavigationHelper;
import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame;
import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchException;
import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext;
@@ -25,10 +24,7 @@ import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
/**
- * Iterates over all sources of {@link EStructuralFeature} using an {@link NavigationHelper VIATRA Base indexer}.
- * It is assumed that the indexer is initialized for the selected {@link EStructuralFeature}.
- *
- *
+ * Iterates over all sources of {@link EStructuralFeature}
*/
public class ExtendToEStructuralFeatureTarget extends ExtendOperation<Object> {
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEClassInstances.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEClassInstances.java
index b9de24daa..a289a6bb8 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEClassInstances.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEClassInstances.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.operations.extend;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EClass;
@@ -32,20 +33,25 @@ import com.google.common.collect.Lists;
*/
public class IterateOverEClassInstances extends ExtendOperation<EObject> implements IIteratingSearchOperation{
- private EClass clazz;
+ private final EClass clazz;
+ private final EClassTransitiveInstancesKey type;
public IterateOverEClassInstances(int position, EClass clazz) {
super(position);
this.clazz = clazz;
+ type = new EClassTransitiveInstancesKey(clazz);
}
public EClass getClazz() {
return clazz;
}
+ @SuppressWarnings("unchecked")
@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) {
- it = context.getBaseIndex().getAllInstances(clazz).iterator();
+ Iterable<? extends Object> values = context.getRuntimeContext().enumerateValues(type, null);
+ // XXX This casting is only required for API backwards compatibility
+ it = (Iterator<EObject>) values.iterator();
}
@Override
@@ -63,7 +69,7 @@ public class IterateOverEClassInstances extends ExtendOperation<EObject> impleme
*/
@Override
public IInputKey getIteratedInputKey() {
- return new EClassTransitiveInstancesKey(clazz);
+ return type;
}
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java
index 06c318852..d8817d88e 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.operations.extend;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EDataType;
@@ -29,24 +30,25 @@ import com.google.common.collect.Lists;
*/
public class IterateOverEDatatypeInstances extends ExtendOperation<Object> implements IIteratingSearchOperation{
- private EDataType dataType;
+ private final EDataType dataType;
+ private final EDataTypeInSlotsKey type;
- /**
- * @param position
- * @param dataType
- */
public IterateOverEDatatypeInstances(int position, EDataType dataType) {
super(position);
this.dataType = dataType;
+ type = new EDataTypeInSlotsKey(dataType);
}
public EDataType getDataType() {
return dataType;
}
+ @SuppressWarnings("unchecked")
@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) {
- it = context.getBaseIndex().getDataTypeInstances(dataType).iterator();
+ Iterable<? extends Object> values = context.getRuntimeContext().enumerateValues(type, null);
+ // XXX This casting is only required for API backwards compatibility
+ it = (Iterator<Object>) values.iterator();
}
@@ -65,7 +67,7 @@ public class IterateOverEDatatypeInstances extends ExtendOperation<Object> imple
*/
@Override
public IInputKey getIteratedInputKey() {
- return new EDataTypeInSlotsKey(dataType);
+ return type;
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java
index ebbb4beb5..5770b0f81 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java
@@ -12,12 +12,8 @@ package org.eclipse.viatra.query.runtime.localsearch.operations.extend;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.viatra.query.runtime.base.api.IEStructuralFeatureProcessor;
import org.eclipse.viatra.query.runtime.base.api.NavigationHelper;
import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame;
@@ -25,9 +21,9 @@ import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchExcept
import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext;
import org.eclipse.viatra.query.runtime.localsearch.operations.IIteratingSearchOperation;
import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
/**
* Iterates all available {@link EStructuralFeature} elements using an {@link NavigationHelper VIATRA Base
@@ -36,14 +32,16 @@ import com.google.common.collect.Maps;
*/
public class IterateOverEStructuralFeatureInstances implements IIteratingSearchOperation{
- private EStructuralFeature feature;
- private int sourcePosition, targetPosition;
- protected Iterator<Entry<EObject, Object>> it;
+ private final EStructuralFeature feature;
+ private final int sourcePosition, targetPosition;
+ private final EStructuralFeatureInstancesKey type;
+ private Iterator<Tuple> it;
public IterateOverEStructuralFeatureInstances(int sourcePosition, int targetPosition, EStructuralFeature feature) {
this.sourcePosition = sourcePosition;
this.targetPosition = targetPosition;
this.feature = feature;
+ type = new EStructuralFeatureInstancesKey(feature);
}
public EStructuralFeature getFeature() {
@@ -59,24 +57,17 @@ public class IterateOverEStructuralFeatureInstances implements IIteratingSearchO
@Override
public void onInitialize(MatchingFrame frame, ISearchContext context) {
- final Map<EObject, Object> instances = Maps.newHashMap();
- context.getBaseIndex().processAllFeatureInstances(feature, new IEStructuralFeatureProcessor() {
+ Iterable<Tuple> tuples = context.getRuntimeContext().enumerateTuples(type, null);
- @Override
- public void process(EStructuralFeature feature, EObject source, Object target) {
- instances.put(source, target);
- }
- });
-
- it = instances.entrySet().iterator();
+ it = tuples.iterator();
}
@Override
public boolean execute(MatchingFrame frame, ISearchContext context) {
if (it.hasNext()) {
- final Entry<EObject, Object> next = it.next();
- frame.setValue(sourcePosition, next.getKey());
- frame.setValue(targetPosition, next.getValue());
+ final Tuple next = it.next();
+ frame.setValue(sourcePosition, next.get(0));
+ frame.setValue(targetPosition, next.get(1));
return true;
} else {
return false;
@@ -98,7 +89,7 @@ public class IterateOverEStructuralFeatureInstances implements IIteratingSearchO
*/
@Override
public IInputKey getIteratedInputKey() {
- return new EStructuralFeatureInstancesKey(feature);
+ return type;
}
}
diff --git a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureTarget.java b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureTarget.java
index ae7281779..f428a55a7 100644
--- a/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureTarget.java
+++ b/query/plugins/org.eclipse.viatra.query.runtime.localsearch/src/org/eclipse/viatra/query/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureTarget.java
@@ -10,74 +10,17 @@
*******************************************************************************/
package org.eclipse.viatra.query.runtime.localsearch.operations.extend.nobase;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame;
-import org.eclipse.viatra.query.runtime.localsearch.exceptions.LocalSearchException;
-import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext;
-import org.eclipse.viatra.query.runtime.localsearch.operations.extend.ExtendOperation;
-
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
/**
- * Iterates over all sources of {@link EStructuralFeature} without using an {@link NavigationHelper VIATRA Base indexer}.
- *
+ * Iterates over all sources of {@link EStructuralFeature}
+ * @deprecated this class was introduced because an incorrect javadoc specification; use superclass instead
*/
-public class ExtendToEStructuralFeatureTarget extends ExtendOperation<Object> {
-
- private int sourcePosition;
- private EStructuralFeature feature;
+@Deprecated
+public class ExtendToEStructuralFeatureTarget extends org.eclipse.viatra.query.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureTarget {
public ExtendToEStructuralFeatureTarget(int sourcePosition, int targetPosition, EStructuralFeature feature) {
- super(targetPosition);
- this.sourcePosition = sourcePosition;
- this.feature = feature;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public void onInitialize(MatchingFrame frame, ISearchContext context) throws LocalSearchException {
- try {
- final EObject value = (EObject) frame.getValue(sourcePosition);
- // This is to ensure that the feature exists for the given type
- if(! feature.getEContainingClass().isSuperTypeOf(value.eClass()) ){
- // TODO planner should ensure the proper supertype relation
- it = Collections.emptyIterator();
- return;
- }
- final Object featureValue = value.eGet(feature);
- if (feature.isMany()) {
- if (featureValue != null) {
- final Collection<Object> objectCollection = (Collection<Object>) featureValue;
- it = objectCollection.iterator();
- } else {
- it = Collections.emptyIterator();
- }
- } else {
- if (featureValue != null) {
- it = Iterators.singletonIterator(featureValue);
- } else {
- it = Collections.emptyIterator();
- }
- }
- } catch (ClassCastException e) {
- throw new LocalSearchException("Invalid feature source in parameter" + Integer.toString(sourcePosition), e);
- }
- }
-
- @Override
- public String toString() {
- return "extend "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(+"+sourcePosition+", -"+position+")";
- }
-
- @Override
- public List<Integer> getVariablePositions() {
- return Lists.asList(sourcePosition, position, new Integer[0]);
+ super(sourcePosition, targetPosition, feature);
}
}

Back to the top