rachavz / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Finding subtypes of a class does not work if intermediate types in the hierarchy are not in the search url #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create class A in a url "url1"
2. Create class B, where B extends A, in a url "url2"
3. Create class C, where C extends B, in a url "url3".
4. Find the set of subtypes of class A in "url3" with the following code:

ConfigurationBuilder config = new ConfigurationBuilder();
config.addUrls(url3);
Reflections reflections = new Reflections(config);
Set<Class<? extends A>> set = reflections.getSubTypesOf(A.class)
System.out.println(set);

What is the expected output? What do you see instead?
The expected output is class C. However, an empty set is shown instead.

What version of the product are you using? On what operating system?
0.9.8, OSX Lion.

Please provide any additional information below.
I do not know in advance the url of all the intermediate classes in the class 
hierarchy (in the example, only B is between A and C, but they could be more 
classes of course). Currently I need to ask the users of my library to 
explicitly add those urls. But since the class that should be found is in the 
filtered url, and the predicate over it holds (C is indeed a transitive 
subclass of A), I would have expected it to be found without any additional 
settings.
If there are no plans to change this behavior any pointer to how I could extend 
Reflections to do this would be highly appreciated.

Original issue reported on code.google.com by sergio...@gmail.com on 16 Oct 2012 at 5:07

GoogleCodeExporter commented 9 years ago
choose your urls carefully, know your classpath. otherwise scan everything! 
(ClasspathHelper.forClassLoader(<noarg>))

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:11

GoogleCodeExporter commented 9 years ago
Unfortunately, I was not able to scan everything with reflections. 

What would the code look like? I only managed to scan  by providing the first 
part of a package (i.e. "com" or "info").

Original comment by sniffert...@gmail.com on 20 Feb 2013 at 9:19

GoogleCodeExporter commented 9 years ago
just new Reflections() with the trunk snapshot version
than the urls are effectively ClasspathHelper.forClassLoader()

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:41

GoogleCodeExporter commented 9 years ago
I see. I was using 0.9.8 at the moment.
Is there a simple way to do it with 0.9.8 aswell?

Original comment by sniffert...@gmail.com on 20 Feb 2013 at 9:43

GoogleCodeExporter commented 9 years ago
on 0.9.8 use new Reflections(ClasspathHelper.forClassLoader())

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:47

GoogleCodeExporter commented 9 years ago
Thank you. This seems to work, but unfortunately, my tests won't run anymore, 
as the surfire maven plugin seems to load its classes from somewhere else. 

I managed to get it running using 
.setUrls(ClasspathHelper.forPackage("", ClasspathHelper.classLoaders()))

Not sure why this works. 

Do you have an example of a junit test?
Maybe I should aks there questions somewhere else... Where?

Thanks

Original comment by sniffert...@gmail.com on 20 Feb 2013 at 10:30

GoogleCodeExporter commented 9 years ago
see if any of these helps you
http://code.google.com/p/reflections/issues/list?can=1&q=surefire

Original comment by ronm...@gmail.com on 20 Feb 2013 at 11:06