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

isGenerics always returns false for CtType #2989

Closed
Egor18 opened this issue May 25, 2019 · 2 comments · Fixed by #2994
Closed

isGenerics always returns false for CtType #2989

Egor18 opened this issue May 25, 2019 · 2 comments · Fixed by #2994

Comments

@Egor18
Copy link
Contributor

Egor18 commented May 25, 2019

isGenerics() method always returns false when called on a top-level type (even if it has generic parameters):

@Override
public boolean isGenerics() {
return false;
}

I think it should be something like this instead:

@Override
public boolean isGenerics() {
    for (CtTypeParameter ref : formalCtTypeParameters) {
        if (ref.isGenerics()) {
            return true;
        }
    }
    return false;
}

Here is an example:
class A <T> { /* ... */ }

CtType<?> a = model.getAllTypes().stream().filter(t -> t.getSimpleName().equals("A")).findFirst().get();
a.isGenerics() // => false (I think it should be true)

WDYT?

@monperrus
Copy link
Collaborator

Reading again the specification of the method in the Javadoc (improved in #2990):

isGenerics(): Returns true if it refers to a type parameter (ie not a concrete class, eg "T foo"). It can refer to it directly (eg T), or indirectly (eg List<T>, or Set<List<T>>).

It's pretty clear that you found a bug.

@Egor18
Copy link
Contributor Author

Egor18 commented May 26, 2019

Ok, I'll fix that.

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

Successfully merging a pull request may close this issue.

2 participants