Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2013-11-18 10:52:36 -0500
committerCamille Letavernier2013-11-18 10:52:36 -0500
commitccda2811a197106c52b6721a5b8148fac3106531 (patch)
tree86821a84caef6e9e9759e3435251f1919751e0f9 /extraplugins
parent849d032c694b3027fbc08311f9f7d17b99b231a6 (diff)
downloadorg.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.tar.gz
org.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.tar.xz
org.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.zip
Refactored the EMF facet queries that need only iterate over the
notation resources Conflicts: Cherry picked from b1016a in master. One of the plug-ins doesn't exist in Kepler. The files have been excluded from the cherry pick. Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr> Alsy-by: Camille Letavernier <camille.letavernier@cea.fr>
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java49
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java30
2 files changed, 29 insertions, 50 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
index c27a051bf40..35221d2ab62 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
@@ -15,22 +15,20 @@
package org.eclipse.papyrus.texteditor.modelexplorer.queries;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
+import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
/** Get the collection of all contained tables */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class GetContainedTextEditors extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<TextEditorModel>> {
@@ -39,32 +37,17 @@ public class GetContainedTextEditors extends AbstractEditorContainerQuery implem
* {@inheritDoc}
*/
public Collection<TextEditorModel> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EStructuralFeature.Setting> p = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(EStructuralFeature.Setting setting) {
- return (setting.getEObject() instanceof TextEditorModel);
+ List<TextEditorModel> result = new ArrayList<TextEditorModel>(3);
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return result;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof TextEditorModel) {
+ if (EcoreUtil.equals(((TextEditorModel)root).getEditedObject(), context))
+ result.add((TextEditorModel)root);
}
- };
-
- Function<EStructuralFeature.Setting, TextEditorModel> f = new Function<EStructuralFeature.Setting, TextEditorModel>() {
-
- public TextEditorModel apply(EStructuralFeature.Setting setting) {
- if (setting.getEObject() instanceof TextEditorModel) {
- return (TextEditorModel) setting.getEObject();
- }
- return null;
- }
-
- };
-
- Iterable<TextEditorModel> transform = Iterables.transform(Iterables.filter(EMFHelper.getUsages(context), p), f);
- transform = Iterables.filter(transform, new Predicate<TextEditorModel>() {
-
- public boolean apply(TextEditorModel table) {
- return table != null;
- }
- });
- return Sets.newHashSet(transform);
+ }
+ return result;
}
-
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
index cb1c209789b..07a423e048f 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
@@ -14,17 +14,17 @@
*****************************************************************************/
package org.eclipse.papyrus.texteditor.modelexplorer.queries;
+import java.util.Iterator;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
-import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModelPackage;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Predicate;
-
/** Returns true if the element contains a Table */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class IsTextEditorContainer extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Boolean> {
@@ -33,20 +33,16 @@ public class IsTextEditorContainer extends AbstractEditorContainerQuery implemen
* {@inheritDoc}
*/
public Boolean evaluate(final EObject context, ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EObject> p = new Predicate<EObject>() {
-
- public boolean apply(EObject arg0) {
- if(arg0 instanceof TextEditorModel) {
- TextEditorModel textEditorInstance = (TextEditorModel)arg0;
- if (textEditorInstance.getEditedObject() == context) {
- // System.err.println("isContainer = true: " + context); //$NON-NLS-1$
- }
- return (textEditorInstance.getEditedObject() == context);
- }
- return false;
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return false;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof TextEditorModel) {
+ if (EcoreUtil.equals(((TextEditorModel)root).getEditedObject(), context))
+ return true;
}
- };
-
- return NavigatorUtils.any(context, TextEditorModelPackage.eINSTANCE.getTextEditorModel(), false, p);
+ }
+ return false;
}
}

Back to the top