Skip to content

Commit 8e23339

Browse files
committed
Clean-up and simplify usage of E4's XPathContext in E4-tools
1 parent 975f72b commit 8e23339

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

e4tools/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0",
2727
org.eclipse.pde.core,
2828
org.eclipse.e4.core.commands;bundle-version="0.10.0",
2929
org.eclipse.e4.ui.dialogs;bundle-version="1.0.0",
30-
org.eclipse.e4.emf.xpath,
3130
org.eclipse.ui.forms;bundle-version="3.7.200"
3231
Bundle-ActivationPolicy: lazy
3332
Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)",

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Collections;
23-
import java.util.Iterator;
2423
import java.util.List;
2524

2625
import org.eclipse.core.databinding.observable.list.IObservableList;
26+
import org.eclipse.core.runtime.ILog;
2727
import org.eclipse.e4.core.contexts.IEclipseContext;
28-
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
29-
import org.eclipse.e4.emf.xpath.XPathContext;
30-
import org.eclipse.e4.emf.xpath.XPathContextFactory;
3128
import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass;
3229
import org.eclipse.e4.tools.emf.ui.common.Util;
3330
import org.eclipse.e4.tools.emf.ui.common.Util.InternalPackage;
@@ -41,9 +38,9 @@
4138
import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FindParentReferenceElementDialog;
4239
import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
4340
import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VSnippetsEditor;
41+
import org.eclipse.e4.ui.model.ModelXPathEvaluator;
4442
import org.eclipse.e4.ui.model.application.MApplication;
4543
import org.eclipse.e4.ui.model.application.MApplicationElement;
46-
import org.eclipse.e4.ui.model.application.impl.ApplicationElementImpl;
4744
import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
4845
import org.eclipse.e4.ui.model.fragment.MModelFragment;
4946
import org.eclipse.e4.ui.model.fragment.MStringModelFragment;
@@ -581,24 +578,14 @@ public List<Action> getActions(Object element) {
581578
* @return the list of EClass(es) matching this xpath
582579
*/
583580
private static EClass getTargetClassFromXPath(MApplication application, String xpath) {
584-
585-
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
586-
XPathContext xpathContext = f.newContext((EObject) application);
587-
Iterator<Object> i = xpathContext.iterate(xpath);
588-
589581
try {
590-
while (i.hasNext()) {
591-
Object obj = i.next();
592-
if (obj instanceof MApplicationElement) {
593-
ApplicationElementImpl ae = (ApplicationElementImpl) obj;
594-
return ae.eClass();
595-
}
596-
}
582+
return ModelXPathEvaluator.findMatchingElements(application, xpath, MApplicationElement.class)
583+
.map(EObject.class::cast).map(EObject::eClass) //
584+
.findFirst().orElse(null);
597585
} catch (Exception ex) {
598586
// custom xpath functions will throw exceptions
599-
ex.printStackTrace();
587+
ILog.get().error("Failed to evaluate xpath: " + xpath, ex); //$NON-NLS-1$
600588
}
601-
602589
return null;
603590
}
604591

0 commit comments

Comments
 (0)