Bug 433226 - ClasspathTypeProvider.JavaURIConverter difficult / impossible to customize, make inner class protected instead private?
Summary: ClasspathTypeProvider.JavaURIConverter difficult / impossible to customize, m...
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.5.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-22 10:54 EDT by Michael Vorburger CLA
Modified: 2014-04-22 11:16 EDT (History)
1 user (show)

See Also:


Attachments
failed attempt to subclass to customize ClasspathTypeProvider (4.20 KB, text/x-java)
2014-04-22 10:55 EDT, Michael Vorburger CLA
no flags Details
failed attempt to subclass to customize ClasspathTypeProviderFactory (901 bytes, text/x-java)
2014-04-22 10:56 EDT, Michael Vorburger CLA
no flags Details
Reflection-based workaround/hack illustrating how we overcame this issue (2.75 KB, text/x-java)
2014-04-22 10:56 EDT, Michael Vorburger CLA
no flags Details
Reflection-based workaround/hack illustrating how we overcame this issue (2.99 KB, text/x-java)
2014-04-22 10:59 EDT, Michael Vorburger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Vorburger CLA 2014-04-22 10:54:46 EDT
The ClasspathTypeProvider.JavaURIConverter is difficult / impossible to customize. As it's a private inner class, it cannot be extended in user code. Because the (public) ClasspathTypeProvider constructor has a hard-coded cast to this private JavaURIConverter, it's not even possible to copy/paste the private inner class and use that instead.

The practical use case why we needed this, if justification is required, is that in-house we have a custom URIConverter, for legacy reasons. That CustomURIConverter holds a reference to something which we need to get hold off. There is some (heavily used) helper util code which, given a Resource, via resource.getResourceSet().getURIConverter() casts to the CustomURIConverter and then getSomething() from it. In that helper, ideally, we would have want to do something like if (uriConverter instanceof ClasspathTypeProvider.JavaURIConverter) and cast then getExisting().

The attached PatchedClasspathTypeProviderFactory extends ClasspathTypeProviderFactory and PatchedClasspathTypeProvider extends ClasspathTypeProvider illustrate futile attempts to customize - not currently possible.

The attached ClasspathTypeProviderJavaURIConverterUtil.java illustrates a Reflection-based approach how we were eventually able to get around it - but that's quite ugly of course - ideally this Xtext class should be more extensible.

A quick one line change to address this would be to simply make the inner class ClasspathTypeProvider.JavaURIConverter if not entirely public, then at least protected; with that one could probably (not tried) successfully do what I tried in attached, without Reflection. -- Or, and/or make the JavaURIConverter implementation used Guice configurable, so that one can fully customize that, as other APIs.
Comment 1 Michael Vorburger CLA 2014-04-22 10:55:46 EDT
Created attachment 242201 [details]
failed attempt to subclass to customize ClasspathTypeProvider
Comment 2 Michael Vorburger CLA 2014-04-22 10:56:10 EDT
Created attachment 242202 [details]
failed attempt to subclass to customize ClasspathTypeProviderFactory
Comment 3 Michael Vorburger CLA 2014-04-22 10:56:42 EDT
Created attachment 242204 [details]
Reflection-based workaround/hack illustrating how we overcame this issue
Comment 4 Michael Vorburger CLA 2014-04-22 10:59:04 EDT
Created attachment 242205 [details]
Reflection-based workaround/hack illustrating how we overcame this issue