Cannot resolve binding of Custom ParameterizedType's attributes [message #1817163] |
Sun, 17 November 2019 05:02 |
Mohammad Rafid Ul Islam Messages: 9 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);
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03346 seconds