diff --git a/e4tools/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF b/e4tools/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF index 8c540a8dd6d..a476ca2a244 100644 --- a/e4tools/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF +++ b/e4tools/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF @@ -27,7 +27,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0", org.eclipse.pde.core, org.eclipse.e4.core.commands;bundle-version="0.10.0", org.eclipse.e4.ui.dialogs;bundle-version="1.0.0", - org.eclipse.e4.emf.xpath, org.eclipse.ui.forms;bundle-version="3.7.200" Bundle-ActivationPolicy: lazy Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)", diff --git a/e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java b/e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java index a83bb03644f..2419fcf097f 100644 --- a/e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java +++ b/e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/StringModelFragment.java @@ -20,14 +20,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.runtime.ILog; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory; -import org.eclipse.e4.emf.xpath.XPathContext; -import org.eclipse.e4.emf.xpath.XPathContextFactory; import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass; import org.eclipse.e4.tools.emf.ui.common.Util; import org.eclipse.e4.tools.emf.ui.common.Util.InternalPackage; @@ -41,9 +38,9 @@ import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FindParentReferenceElementDialog; import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E; import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VSnippetsEditor; +import org.eclipse.e4.ui.model.ModelXPathEvaluator; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; -import org.eclipse.e4.ui.model.application.impl.ApplicationElementImpl; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; import org.eclipse.e4.ui.model.fragment.MModelFragment; import org.eclipse.e4.ui.model.fragment.MStringModelFragment; @@ -157,8 +154,7 @@ public FeaturePath[] getLabelProperties() { @Override public String getDetailLabel(Object element) { - if (element instanceof StringModelFragmentImpl) { - final StringModelFragmentImpl fragment = (StringModelFragmentImpl) element; + if (element instanceof StringModelFragmentImpl fragment) { String ret = ""; //$NON-NLS-1$ if (E.notEmpty(fragment.getFeaturename())) { ret += fragment.getFeaturename(); @@ -246,17 +242,17 @@ public static EClass findContainerType(MStringModelFragment modelFragment) { // Deal with non default MApplication IDs. if (xpath != null) { - if (o instanceof MApplication) { - EClass found = getTargetClassFromXPath((MApplication) o, xpath); + if (o instanceof MApplication application) { + EClass found = getTargetClassFromXPath(application, xpath); if (found != null) { return found; } } } else { // This is a standard search with ID. - if ((o instanceof MApplicationElement) + if ((o instanceof MApplicationElement appElement) && (o.eContainingFeature() != FragmentPackageImpl.Literals.MODEL_FRAGMENTS__IMPORTS) - && parentElementId.equals(((MApplicationElement) o).getElementId())) { + && parentElementId.equals(appElement.getElementId())) { return o.eClass(); } } @@ -581,24 +577,14 @@ public List getActions(Object element) { * @return the list of EClass(es) matching this xpath */ private static EClass getTargetClassFromXPath(MApplication application, String xpath) { - - XPathContextFactory f = EcoreXPathContextFactory.newInstance(); - XPathContext xpathContext = f.newContext((EObject) application); - Iterator i = xpathContext.iterate(xpath); - try { - while (i.hasNext()) { - Object obj = i.next(); - if (obj instanceof MApplicationElement) { - ApplicationElementImpl ae = (ApplicationElementImpl) obj; - return ae.eClass(); - } - } + return ModelXPathEvaluator.findMatchingElements(application, xpath, MApplicationElement.class) + .map(EObject.class::cast).map(EObject::eClass) // + .findFirst().orElse(null); } catch (Exception ex) { // custom xpath functions will throw exceptions - ex.printStackTrace(); + ILog.get().error("Failed to evaluate xpath: " + xpath, ex); //$NON-NLS-1$ } - return null; }