Skip to content

Conversation

@HannesWell
Copy link
Member

As found in #2290, these methods seem not to provide any real value and just complicate the implementation.

I'm contemplating to even remove XPathContext.getValue() as it also complicates the implementation and has no real usage in the SimRel:

Object getValue(String xpath);
/**
* Evaluates the xpath, converts the result to the specified class and
* returns the resulting object.
*
* @param xpath
* to evaluate
* @param requiredType
* required type
* @return Object found
*/
<T> T getValue(String xpath, Class<T> requiredType);

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2025

Test Results

 1 818 files  ±0   1 818 suites  ±0   1h 28m 47s ⏱️ - 8m 32s
 7 721 tests ±0   7 493 ✅ +1  228 💤 ±0  0 ❌  - 1 
24 324 runs  ±0  23 575 ✅ +1  749 💤 ±0  0 ❌  - 1 

Results for commit b20f60c. ± Comparison against base commit 4e127ef.

♻️ This comment has been updated with latest results.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 6ecf8b0 to fbd8216 Compare February 12, 2025 07:21
@eclipse-platform-bot
Copy link
Contributor

eclipse-platform-bot commented Feb 12, 2025

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

bundles/org.eclipse.e4.ui.model.workbench/META-INF/MANIFEST.MF

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From fade84ed63fba949c9d34c6cf4f0581cf233c381 Mon Sep 17 00:00:00 2001
From: Eclipse Platform Bot <[email protected]>
Date: Sat, 15 Feb 2025 18:46:02 +0000
Subject: [PATCH] Version bump(s) for 4.35 stream


diff --git a/bundles/org.eclipse.e4.ui.model.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.model.workbench/META-INF/MANIFEST.MF
index c3a661b45c..5a27e839f9 100644
--- a/bundles/org.eclipse.e4.ui.model.workbench/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.ui.model.workbench/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ 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
-- 
2.48.1

Further information are available in Common Build Issues - Missing version increments.

@HannesWell HannesWell marked this pull request as ready for review February 12, 2025 07:25
@HannesWell
Copy link
Member Author

@ptziegler as you contributed test-cases and worked on the parent-context handling, I wonder if you are actually using it and therefore have objections against deprecating XPathContextFactory.newContext(XPathContext parentContext, T contextBean).

The same question applies to XPathContext.getValue() to you ore anybody else?

@laeubi
Copy link
Contributor

laeubi commented Feb 12, 2025

I know it is an "API break" but should we not mark XPathContextFactory with @NoExtend?

@HannesWell
Copy link
Member Author

I know it is an "API break" but should we not mark XPathContextFactory with @NoExtend?

I ask this question to myself as well. On one hand the Eclipse SDK only provide one specific implementation of that class that can only handle a specific type of model, while the interface is designed (maybe over-engineered) generic. So there could be a demand to have other implementations that can handle other type of models.
On the other hand, there is no benefit from doing that as there is nothing that would work with such other specialization in the SDK and third-parties that would want to do that, could just use their own classes and abstraction.

The same question also applies to XPathContext. In the end I'm not sure about it as this entire API seems to be over-engineered to me for the use-cases we have in the SDK. So a lot could be reduced just from POV of the Eclipse SDK.

@laeubi
Copy link
Contributor

laeubi commented Feb 12, 2025

I think the only interesting use-case would be to query the Model programmatically with an xpath expression, maybe it was though of a way to be used with other EMF model, but tin this case it would have ben better be implemented/provided by emf itself.

For this purpose, I would rather want to have a method in org.eclipse.e4.ui.workbench.modeling.EModelService similar to the findElements or an XPathSelector that implements org.eclipse.e4.ui.workbench.Selector.

As all of this basically boils down to org.eclipse.e4.ui.model.workbench one could even thing about deprecate the whole bundle (PDE now supports a warning for users), and with the next release copy the now much simpler implementation into org.eclipse.e4.ui.model.workbench... then we won't need any "public" API anymore and if there is really users they can still use the "old" impl and platform can just not include the emf.xpath anymore.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from caf475f to 72caaab Compare February 12, 2025 18:00
@HannesWell
Copy link
Member Author

I think the only interesting use-case would be to query the Model programmatically with an xpath expression, maybe it was though of a way to be used with other EMF model, but tin this case it would have ben better be implemented/provided by emf itself.

There is also one other user in PDE, see e.g.

For this purpose, I would rather want to have a method in org.eclipse.e4.ui.workbench.modeling.EModelService similar to the findElements or an XPathSelector that implements org.eclipse.e4.ui.workbench.Selector.

Adding something like EModelService.findMatchingElements(MApplicationElement contextBean, String xpath, Class<T> clazz) sounds like a good idea. It would boil down the actually used API to the minimum and would make it more accessible.
I added this in a very first prototype.
However using the new method in the StringModelFragmentImpl class to replace the reference to the existing XPathContext, is not possible as o.e.e4.ui.model.workbench doesn't depend on o.e.e4.ui.workbench but the other way round.

As all of this basically boils down to org.eclipse.e4.ui.model.workbench one could even thing about deprecate the whole bundle (PDE now supports a warning for users), and with the next release copy the now much simpler implementation into org.eclipse.e4.ui.model.workbench... then we won't need any "public" API anymore and if there is really users they can still use the "old" impl and platform can just not include the emf.xpath anymore.

If we make the approach from above work, then we could deprecate the entire bundle and inline it's content to wherever the new API lands when the bundle is finally removed.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from cd38c71 to c02a880 Compare February 12, 2025 18:16
@HannesWell
Copy link
Member Author

However using the new method in the StringModelFragmentImpl class to replace the reference to the existing XPathContext, is not possible as o.e.e4.ui.model.workbench doesn't depend on o.e.e4.ui.workbench but the other way round.

We could also add it as something internal in o.e.e4.ui.model.workbench use it there and make it public only through EModelService.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from b63a75f to d810b46 Compare February 12, 2025 18:35
@HannesWell
Copy link
Member Author

Adding something like EModelService.findMatchingElements(MApplicationElement contextBean, String xpath, Class<T> clazz) sounds like a good idea. It would boil down the actually used API to the minimum and would make it more accessible.

This also allows us to avoid the clean-up of the parameteriziation problem of XPathContextFactory.newInstance().

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from d810b46 to 33cc9a7 Compare February 12, 2025 18:38
@HannesWell HannesWell changed the title [E4 XPath] Deprecate unsuitable XPathContextFactory methods for removal [E4 XPath] Add new API in EModelService to find elements via Xpath and deprecate E4-XPath bundle for removal Feb 12, 2025
@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 5f90f87 to 7dfc567 Compare February 13, 2025 19:24
@HannesWell
Copy link
Member Author

I have looked at the usage in PDE of the new API and in general it looks good, the only thing that makes using this cumbersome is the fact that the new API is an instance method and not a class/static method and one needs an EModelService instance. This makes it cumbersome to use in static methods (which is the case in PDE).

@laeubi
Copy link
Contributor

laeubi commented Feb 14, 2025

I'm not sure I found the right place but the only one I can found in PDE is

org.eclipse.e4.tools.emf.ui.internal.common.component.StringModelFragment.getTargetClassFromXPath(MApplication, String)

As it has the MApplication you can do:

EModelService modelService = application.getContext().get(EModelService.class);

if you want avoid an additional parameter.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from eef6bd6 to b691369 Compare February 15, 2025 00:27
@HannesWell HannesWell requested a review from laeubi February 15, 2025 00:34
@HannesWell
Copy link
Member Author

I have now added the missing documentation and think this is ready for submission.
I would like to land this for the upcoming 2025-03 release and think it's save to do this as this just deprecate methods and a bundle and adds one alternative API.

@laeubi are you fine with this now? @merks do you also want to have a look?

As it has the MApplication you can do:

EModelService modelService = application.getContext().get(EModelService.class);

if you want avoid an additional parameter.

I tried this but it looks like it doesn't work in all cases, because (at least in some cases) that actually an MApplication loaded from a resource/file of an Editor and not the 'active' application model of the running application. And in that case the context is not set to these model-elements and getContext() therefore returns null.

So for PDE I either need to get the context purely static (not sure if that's possible) or pass an EModelService instance as parameter.

@laeubi
Copy link
Contributor

laeubi commented Feb 15, 2025

So for PDE I either need to get the context purely static

Du to the nature of E4 this is not reliable possible but I think the case of an editor is rather special.

But I think we have some cases:

  1. PDE can simply "fake" it by setting its own EclipseContext to the loaded model
  2. PDE can call an (internal) API on e4 for this purpose and become a friend of the package.

Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

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

Can the method that is currently at XPathHelper maybe betterl ife in ModelServiceImpl or StringModelFragmentImpl?

* {@link 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.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 5ddec76 to 6c99753 Compare February 15, 2025 12:43
@HannesWell
Copy link
Member Author

Can the method that is currently at XPathHelper maybe betterl ife in ModelServiceImpl or StringModelFragmentImpl?

Moving it to ModelServiceImpl is not feasible due to dependency structure and StringModelFragmentImpl would be a class were I would expect such functionality.
And as the comment in XPathHelper suggests, this class is intended to contain all the (then used) code that's currently in JavaXPathContextFactoryImpl when the org.eclipse.e4.emf.xpath bundle is finally removed. So it won't be that empty as it's now on the long run. With that in mind, having a separate class for it seems suitable to me (and as it's all internal it can be changed easily in the future if necessary).

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 5ef6d8f to bcfd112 Compare February 15, 2025 12:48
@HannesWell
Copy link
Member Author

@laeubi I would like to submit this PR this evening so that I can apply the new API/methods in PDE tomorrow after the next I-build.
I think the most critical part is the new API method in EModelService:
<T> Stream<T> findMatchingElements(MApplicationElement searchRoot, String xPath, Class<T> clazz);

But I think that's fine. Everything else is internal and can be changed at any time later, if necessary. Do you have any critical points that should definitively be addressed?

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 0e6dd1f to 28c5d5a Compare February 15, 2025 13:09
@laeubi
Copy link
Contributor

laeubi commented Feb 15, 2025

Then I won't call it XPathHelper .. there are way to much "helper", "util" and a like and they tend to grow over time with no real scope. What about name it ModelXPathSupport or similar then? Beside that I think it is fine and goes into the right direction.

e.g. we already have three P2Utils (and two of them in PDE):
grafik

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from 3fafed1 to 934235e Compare February 15, 2025 15:57
@HannesWell
Copy link
Member Author

Then I won't call it XPathHelper .. there are way to much "helper", "util" and a like and they tend to grow over time with no real scope. What about name it ModelXPathSupport or similar then? Beside that I think it is fine and goes into the right direction.

Ok, as discussed in a private conversion I have renamed it to ModelXPathEvaluator.

@HannesWell HannesWell requested a review from laeubi February 15, 2025 15:58
Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!
New EModelService method should maybe mention in N&N

@HannesWell HannesWell added the noteworthy Noteworthy feature label Feb 15, 2025
@HannesWell
Copy link
Member Author

You are welcome. I'm happy if that whole XPath topic is finally reduced to the actually used minimum.

New EModelService method should maybe mention in N&N

Yes. Together with the replacement of JXPath. That might be interesting for others as well.

@HannesWell HannesWell force-pushed the deprecate-xpath-factory-methods branch from a984974 to bfd0279 Compare February 15, 2025 18:41
@HannesWell HannesWell merged commit 328646d into eclipse-platform:master Feb 15, 2025
17 checks passed
@HannesWell HannesWell deleted the deprecate-xpath-factory-methods branch February 15, 2025 19:31
@HannesWell
Copy link
Member Author

New EModelService method should maybe mention in N&N

Yes. Together with the replacement of JXPath. That might be interesting for others as well.

Done via eclipse-platform/www.eclipse.org-eclipse#276.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

noteworthy Noteworthy feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants