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

Unable to get the unresolved signature for a method with generic parameters #84

Closed
v-m opened this issue Oct 27, 2014 · 3 comments
Closed

Comments

@v-m
Copy link

v-m commented Oct 27, 2014

Hi,

When I explore references of a CtExecutable object, I am not able to get the unresolved method signature for a method with generic parameters (i.e. I am only able to get the signature with resolved types).

To illustrate the bug, let imagine such a class:

public class ClassWithGenericStaticMethod{
    public static <L> void aStaticMethod(Class<L> param1, L param2) {
        // my function...
    }

    public void aMethod(){
        String test = "";
        ClassWithGenericStaticMethod.aStaticMethod(String.class, test);
    }
}

Let type be a CtClass variable. I can explore the class references using:

List<CtReference> refs = Query.getReferences(type, 
    new AbstractReferenceFilter<CtReference>(CtReference.class){

    public boolean matches(CtReference reference) {
        return true;
    }
});

for(CtReference aReference : refs){
    if (aReference.toString().contains("aStaticMethod")) {
        // Here, aReference is equivallent to 

        if(aReference.getDeclaration() == null){
            System.out.println("Bad return value !");
        }
    }
}

I am able to get the method signature with resolved type (here
ClassWithGenericStaticMethod.aStaticMethod(java.lang.Class<java.lang.String>, java.lang.String)), but unable to get the unresolved signature, which I should obtain using aReference.getDeclaration(), but this method return null.

I created a test case on my spoon fork if needed.

@swolf91
Copy link
Contributor

swolf91 commented Dec 1, 2014

is that fixed?

@monperrus
Copy link
Collaborator

Yes, by #106

@GerardPaligot
Copy link
Contributor

Yes, sorry. I forgot to link my commit message of my PR #113 with this issue too.

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

No branches or pull requests

4 participants