Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.e4.emf.xpath
Bundle-SymbolicName: org.eclipse.e4.emf.xpath;deprecated:="This bundle is deprecated since 2025-03 (removal in 2027-03 or later)"
Bundle-Version: 0.6.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.35.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
* @since 1.0
*/
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
public class EcoreXPathContextFactory {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2024 BestSolution.at and others.
* Copyright (c) 2010, 2025 BestSolution.at and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,7 +23,11 @@
* Context in which the xpath is executed
*
* @since 1.0
* @deprecated To query an E4-model use
* {@code org.eclipse.e4.ui.workbench.modeling.EModelService#findMatchingElements(org.eclipse.e4.ui.model.application.MApplicationElement, String, Class)}
* instead.
*/
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
public interface XPathContext {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2024 BestSolution.at and others.
* Copyright (c) 2010, 2025 BestSolution.at and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,7 +19,11 @@
* Factory responsible to create an XPath-Context
*
* @param <T> the object type the XPath is created for
* @deprecated To query an E4-model use
* {@code org.eclipse.e4.ui.workbench.modeling.EModelService#findMatchingElements(org.eclipse.e4.ui.model.application.MApplicationElement, String, Class)}
* instead.
*/
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need any deprecation here if we deprecate the bundle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the additional deprecation of some methods, but the explicit deprecation of the classes should be kept as one otherwise doesn't get a corresponding warning in the code. And from my experience warnings in Manifests are overlooked more easily than in code.
Furthermore the deprecation javadoc contains additional information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the explicit deprecation of the classes should be kept as one otherwise doesn't get a corresponding warning in the code.

You should already get a warning in the Manifest about the deprecation.

public abstract class XPathContextFactory<T> {

/**
Expand All @@ -38,10 +42,15 @@ public abstract class XPathContextFactory<T> {
* @param parentContext parent context
* @param contextBean Object
* @return XPathContext
* @deprecated The parent-context does not provide any real value. Just use
* {@link #newContext(Object)}
*/
public abstract XPathContext newContext(XPathContext parentContext, T contextBean);

/**
* Creates a new {@code XPathContextFactory<EObject>} that's suitable to query
* the E4-model.
*
* @param <T> the object type the xpath is created for
* @return Create a new XPath-Factory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @since 0.6
*/
@Deprecated(forRemoval = true, since = "2025-03 (removal in 2027-03 or later)")
public class XPathNotFoundException extends IllegalArgumentException {
private static final long serialVersionUID = -4174244860692153739L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

@SuppressWarnings({ "deprecation", "removal" })
public class JavaXPathContextFactoryImpl<T> extends XPathContextFactory<T> {

private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.e4.ui.model.workbench;singleton:=true
Bundle-Version: 2.4.400.qualifier
Bundle-Version: 2.4.500.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.e4.ui.model;x-friends:="org.eclipse.e4.ui.workbench,org.eclipse.e4.ui.workbench.swt,org.eclipse.ui.workbench",
Export-Package: org.eclipse.e4.ui.model;
x-friends:="org.eclipse.e4.ui.workbench,
org.eclipse.e4.ui.workbench.swt,
org.eclipse.ui.workbench,
org.eclipse.e4.tools.emf.ui",
org.eclipse.e4.ui.model.application,
org.eclipse.e4.ui.model.application.commands,
org.eclipse.e4.ui.model.application.commands.impl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2025 Hannes Wellmann and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Hannes Wellmann - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.ui.model;

import java.util.stream.Stream;
import org.eclipse.e4.emf.xpath.XPathContextFactory;
import org.eclipse.e4.ui.model.application.MApplicationElement;

public class ModelXPathEvaluator {

@SuppressWarnings({ "deprecation", "removal" })
public static <T> Stream<T> findMatchingElements(MApplicationElement searchRoot, String xPath, Class<T> clazz) {
return XPathContextFactory.newInstance().newContext(searchRoot).stream(xPath, clazz);
}

// Inline the then still used part of JavaXPathContextFactoryImpl here once the
// e4.emf.xpath bundle is finally removed
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
import org.eclipse.e4.emf.xpath.XPathContext;
import org.eclipse.e4.emf.xpath.XPathContextFactory;
import org.eclipse.core.runtime.ILog;
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.fragment.MStringModelFragment;
Expand Down Expand Up @@ -282,10 +281,10 @@ public boolean eIsSet(int featureID) {
return FEATURENAME_EDEFAULT == null ? featurename != null : !FEATURENAME_EDEFAULT.equals(featurename);
case FragmentPackageImpl.STRING_MODEL_FRAGMENT__PARENT_ELEMENT_ID:
return PARENT_ELEMENT_ID_EDEFAULT == null ? parentElementId != null
: !PARENT_ELEMENT_ID_EDEFAULT.equals(parentElementId);
: !PARENT_ELEMENT_ID_EDEFAULT.equals(parentElementId);
case FragmentPackageImpl.STRING_MODEL_FRAGMENT__POSITION_IN_LIST:
return POSITION_IN_LIST_EDEFAULT == null ? positionInList != null
: !POSITION_IN_LIST_EDEFAULT.equals(positionInList);
: !POSITION_IN_LIST_EDEFAULT.equals(positionInList);
default:
return super.eIsSet(featureID);
}
Expand Down Expand Up @@ -355,14 +354,13 @@ private void mergeXPath(MApplication application, List<MApplicationElement> ret,
if ("/".equals(xPath)) {
targetElements = List.of(application);
} else {
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
XPathContext xpathContext = f.newContext((EObject) application);
try {
targetElements = xpathContext.stream(xPath, MApplicationElement.class).toList();
targetElements = ModelXPathEvaluator.findMatchingElements(application, xPath, MApplicationElement.class)
.toList();
} catch (Exception ex) {
targetElements = List.of();
// custom xpath functions will throw exceptions
ex.printStackTrace();
ILog.get().error("Failed to evaluate xpath: " + xPath, ex); //$NON-NLS-1$
}
}
for (MApplicationElement targetElement : targetElements) {
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.ui.workbench;singleton:=true
Bundle-Version: 1.16.100.qualifier
Bundle-Version: 1.17.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.model.ModelXPathEvaluator;
import org.eclipse.e4.ui.model.application.MAddon;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.MApplicationElement;
Expand Down Expand Up @@ -434,6 +436,11 @@ public <T> List<T> findElements(MApplicationElement searchRoot, Class<T> clazz,
return new ArrayList<>(elements);
}

@Override
public <T> Stream<T> findMatchingElements(MApplicationElement searchRoot, String xPath, Class<T> clazz) {
return ModelXPathEvaluator.findMatchingElements(searchRoot, xPath, clazz);
}

private <T> Iterable<T> findPerspectiveElements(MUIElement searchRoot, String id,
Class<T> clazz,
List<String> tagsToMatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.eclipse.e4.ui.workbench.modeling;

import java.util.List;
import java.util.stream.Stream;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
Expand Down Expand Up @@ -279,6 +280,22 @@ <T> List<T> findElements(MUIElement searchRoot, String id, Class<T> clazz,
<T> List<T> findElements(MApplicationElement searchRoot, Class<T> clazz,
int searchFlags, Selector matcher);

/**
* Returns a stream of any elements that are matched by the specified
* {@code XPath} expression relative to the given {@code searchRoot}.
*
* @param <T> The generic type of the returned stream
* @param searchRoot The element relative to which the {@code XPath} expression
* is evaluated. This element must be non-null.
* @param xPath the {@code XPath (XML Path Language)} expression matched
* against the root
* @param clazz The type of element to be searched for.
* @return The stream of matching elements.
*
* @since 1.17
*/
<T> Stream<T> findMatchingElements(MApplicationElement searchRoot, String xPath, Class<T> clazz);

/**
* Returns the first element, recursively searching under the specified search
* root (inclusive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.List;

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.ui.internal.workbench.E4XMIResourceFactory;
Expand All @@ -43,6 +42,7 @@
import org.junit.Before;
import org.junit.Test;

@SuppressWarnings({ "deprecation", "removal" })
public class ExampleQueriesApplicationTest {

private ResourceSet resourceSet;
Expand All @@ -69,11 +69,11 @@ public void setUp() {

URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Application.e4xmi", true);
resource = resourceSet.getResource(uri, true);
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
XPathContextFactory<EObject> f = XPathContextFactory.newInstance();
xpathContext = f.newContext(resource.getContents().get(0));
URI childUri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/fragment.e4xmi", true);
childResource = resourceSet.getResource(childUri, true);
xpathChildContext = f.newContext(xpathContext, childResource.getContents().get(0));
xpathChildContext = f.newContext(childResource.getContents().get(0));
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Iterator;
import java.util.List;

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.emf.xpath.XPathNotFoundException;
Expand All @@ -44,6 +43,7 @@
import org.junit.Before;
import org.junit.Test;

@SuppressWarnings({ "deprecation", "removal" })
public class ExampleQueriesTestCase {

private ResourceSet resourceSet;
Expand All @@ -61,7 +61,7 @@ public void setUp() {
resourceSet.getPackageRegistry().put(XpathtestPackage.eNS_URI, XpathtestPackage.eINSTANCE);
URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Test.xmi", true);
resource = resourceSet.getResource(uri, true);
xpathContextFactory = EcoreXPathContextFactory.newInstance();
xpathContextFactory = XPathContextFactory.newInstance();
xpathContext = xpathContextFactory.newContext(resource.getContents().get(0));
}

Expand Down
Loading