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

Type of arguments is missing in CtReference #106

Closed
GerardPaligot opened this issue Nov 19, 2014 · 1 comment
Closed

Type of arguments is missing in CtReference #106

GerardPaligot opened this issue Nov 19, 2014 · 1 comment

Comments

@GerardPaligot
Copy link
Contributor

When a processor process a CtExecutable on a class with some constructors (executables) whom reference others constructors in the same classe, a Query.getReference(...) on the current executable returns references without these arguments.

For example, a class MyClass with 3 constructors. The first constructor reference the second and the second reference the third.

public class MyClass {
    public MyClass() {
        this("Default");
    }

    public MyClass(String param) {
        this(param, 0);
    }

    public MyClass(String param, int paramint) {

    }
}

In the processor, when we retrieve all references of the current constructor, we can't know what is the constructor referenced because arguments aren't available in the interface of references.

public class MyProcessor extends AbstractProcessor<CtExecutable<?>>{

    public void process(CtExecutable<?> element) {

        List<CtReference> refs = Query.getReferences(element, new AbstractReferenceFilter<CtReference>(CtReference.class) {
            public boolean matches(CtReference reference) {
                return true;
            }
        });

        Set<CtReference> unduplicate = new HashSet<CtReference>(refs);

        for(CtReference aReference : unduplicate){
            // ...
        }
    }
}
@monperrus
Copy link
Collaborator

The type of arguments is in ref.getDeclaration().
The bug may come from a wrong result of getDeclaration().

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

2 participants