Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make @API annotation available via Java reflection #375

Merged
merged 1 commit into from
Jul 25, 2016

Conversation

volkovs
Copy link
Contributor

@volkovs volkovs commented Jul 3, 2016

API annotation could be retrieved from byte code (e.g. by using org.reflections), however it would be much more convenient (for #144) to retrieve annotations via Java Reflection.


I hereby agree to the terms of the JUnit Contributor License Agreement.

@smoyer64
Copy link
Contributor

smoyer64 commented Jul 4, 2016

This would make #144 much easier.

@marcphilipp
Copy link
Member

Hmm, I'm not sure about this one. I've never used org.reflections. How hard would it be to access the annotations using it?

@smoyer64
Copy link
Contributor

smoyer64 commented Jul 4, 2016

@marcphilipp - I missed that and was thinking about runtime reflection via java.lang.reflect.

@volkovs
Copy link
Contributor Author

volkovs commented Jul 5, 2016

@marcphilipp > How hard would it be to access the annotations using it?

That would be as easy as:

    Reflections reflections = new Reflections(PACKAGE_TO_SCAN,
            new TypeAnnotationsScanner(),
            new MethodAnnotationsScanner()
    );

    Set<Class<?>> annotatedTypes = reflections.getTypesAnnotatedWith(API.class);
    Set<Method> annotatedMethods = reflections.getMethodsAnnotatedWith(API.class);
    Set<Constructor> annotatedConstructors = reflections.getConstructorsAnnotatedWith(API.class);

But as far as I know there is no way to define annotation parameter values as filters (to fetch only Internal or only Experimental classes). So, Java Reflection might still be required. And, as mentioned above, Java Reflection doesn't see annotations with CLASS Retention Policy.

@marcphilipp
Copy link
Member

@junit-team/junit-lambda I agree that it would be much easier to work with @API if we merged this change. Any objections?

@sbrannen
Copy link
Member

I do not have any objection to this PR.

However, if we're going to do this, I think we should also remove the @API(Internal) declaration on API itself (which I believe has also been suggested elsewhere).

@nipafx
Copy link
Contributor

nipafx commented Jul 13, 2016

However, if we're going to do this, I think we should also remove the @API(Internal) declaration on API itself (which I believe has also been suggested elsewhere).

That would be #317.

@marcphilipp
Copy link
Member

Shall we make it Experimental?

@sbrannen
Copy link
Member

sbrannen commented Jul 13, 2016

Shall we make it Experimental?

I honestly think we should just delete the declaration of @API on API completely and close #317 as invalid.

But... if you think that's too bold for the time being, I could also live with making it Experimental (and still closing #317). 😉

@sbrannen sbrannen modified the milestones: 5.0 M3, 5.0 M2 Jul 16, 2016
@sbrannen sbrannen changed the title Make API annotation available via Java Reflection Make @API annotation available via Java reflection Jul 25, 2016
@sbrannen sbrannen merged commit c2ac2f5 into junit-team:master Jul 25, 2016
@sbrannen
Copy link
Member

This has been merged into master.

@sbrannen sbrannen self-assigned this Jul 25, 2016
@sbrannen
Copy link
Member

FYI: this issue is related to #436.

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

Successfully merging this pull request may close these issues.

5 participants