Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Cannot resolve binding of Custom ParameterizedType's attributes
Cannot resolve binding of Custom ParameterizedType's attributes [message #1817163] Sun, 17 November 2019 05:02 Go to next message
Mohammad Rafid Ul Islam is currently offline Mohammad Rafid Ul IslamFriend
Messages: 7
Registered: August 2019
Junior Member
I have a custom class say, CustomVisitor which extends the ASTVisitor. And, for the following two examples, in the visit(QualifiedName node) method, I am trying to get the binding of the qualified names to get to their declarations and assigning them the new values. However, for the local ParameterizedType, Fist, if I dclare them with type arguments (like in Code 1), the binding of fist.item and fist.size become null. And, for the code 2 where fist is declared without a type argument, the binding of fist.item and fist.size is found correctly in the above mentioned visit method.
I should mention that I have compiled and ran both examples with Java 1.8 and both ran successfully and showed the same console output with just a warning.
But I can't figure out why resolveBinding for the QualifiedNames are returning null when the type argument is given for the parameterized types. And, it is only happening to the local objects, not to the fields. For example, the binding of pair.fst and pair.snd are resolving properly with the type arguments.
Any help would be appreciated.

Code 1:
class Pair<T, U>
{
    public T fst;
    public U snd;

    public Pair(T fst, U snd)
    {
        this.fst = fst;
        this.snd = snd;
    }
    
    public Pair()
    {
        
    }
}

class Fist<T> {
    public T item;
    public Integer size;
    
    public Fist() {
        
    }
}

class Foo {
    int a;
    String aa;
}

public class Test
{
    static Pair<Foo, Fist<String>> pair = new Pair();
    public static void main(String[] args)
    {
        String a = "haha";
        Integer b = 10;
        Foo foo = new Foo(); 
        foo.a = b;
        foo.aa = a;
        pair.fst = foo;
        Fist<String> fist = new Fist<String>();
        fist.item = a;
        fist.size = b;
        pair.snd = fist;
        System.out.println("item: "+pair.snd.item);
    }
}


Code 2:
class Pair<T, U>
{
    public T fst;
    public U snd;

    public Pair(T fst, U snd)
    {
        this.fst = fst;
        this.snd = snd;
    }
    
    public Pair()
    {
        
    }
}

class Fist<T> {
    public T item;
    public Integer size;
    
    public Fist() {
        
    }
}

class Foo {
    int a;
    String aa;
}

public class Test
{
    static Pair<Foo, Fist<String>> pair = new Pair();
    public static void main(String[] args)
    {
        String a = "haha";
        Integer b = 10;
        Foo foo = new Foo(); 
        foo.a = b;
        foo.aa = a;
        pair.fst = foo;
        Fist fist = new Fist();
        fist.item = a;
        fist.size = b;
        pair.snd = fist;
        System.out.println("item: "+pair.snd.item);
    }
}
Re: Cannot resolve binding of Custom ParameterizedType's attributes [message #1817179 is a reply to message #1817163] Mon, 18 November 2019 04:53 Go to previous messageGo to next message
Manoj Palat is currently offline Manoj PalatFriend
Messages: 10
Registered: October 2014
Junior Member
Can you please provide the program which you used to get the nodes and the bindings?

Manoj N Palat
Eclipse Java Development Tools (JDT).
Re: Cannot resolve binding of Custom ParameterizedType's attributes [message #1817239 is a reply to message #1817179] Tue, 19 November 2019 04:36 Go to previous messageGo to next message
Mohammad Rafid Ul Islam is currently offline Mohammad Rafid Ul IslamFriend
Messages: 7
Registered: August 2019
Junior Member
The program is like this...
public class CustomVisitor extends ASTVisitor {
         @Override
         public boolean visit(QualifiedName node){
                    IBinding binding = node.resolveBinding();
                    if(binding instanceof IVariableBinding){
                                // do something
                    }
        }
}


The problem is occurring in node.resolveBinding(). It is returning null for the above test cases I mentioned above.
Re: Cannot resolve binding of Custom ParameterizedType's attributes [message #1817492 is a reply to message #1817239] Sat, 23 November 2019 18:44 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
I don't have an answer, but I'd like to suggest using JDT's ASTView feature to investigate how exactly the given source code is represented by AST and bindings.
Previous Topic:Cannot generate entities from existing MySQL db using JPA Tools
Next Topic:[Solved] Message "Error creating Groovy: java.lang.ClassNotFoundException" when using JDT'
Goto Forum:
  


Current Time: Wed Oct 21 14:39:28 GMT 2020

Powered by FUDForum. Page generated in 0.01989 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top