Home » Language IDEs » Java Development Tools (JDT) » Type and Method binding not working properly in some cases
Type and Method binding not working properly in some cases [message #1811010] |
Fri, 23 August 2019 14:11 |
Mohammad Rafid Ul Islam Messages: 9 Registered: August 2019 |
Junior Member |
|
|
hello,
I am trying to build a call graph from source and I ran into two different scenarios.
First scenario:
I have multiple classes in one Java file. One of them is public and the others are without any access modifiers. Though it is not a good practice, it is syntactically correct. Also, I have another java file with a single public class. This class has a method named bar() and it invokes a method from one of the non-public classes of the other file. In this case, when I try to get the method binfding or the type binding of this method invocation or class instance creator, I get RecoveredTypeBinding instead of the source binding. And, I can't get any source data like ISourceRange or CompilationUnit from it.
Test case for this scenario:
I have a project say, ProjectA. Then it has two .java files one Main.java and other MyClass.java. in Main.java, I have one Main public class and other A, B, C, and D classes without any modifiers.
class A {
public A foo(A x) {
return x;
}
}
class B extends A {
public A foo(A x) {
return new D();
}
}
class C extends A {
public A foo(A x) {
D d = new D();
int i = 1;
d.foo(x, i);
return this;
}
}
class D extends A {
public A foo(A x) {
A b = new B();
b.foo(x);
return new A();
}
public A foo(A x, int i) {
return x;
}
}
public class Main {
public static void main(String[] args) {
A x = new A();
int i = 10;
while(i>0) {
x = x.foo(new B()); /*<<<<<8,12,12,12, b*/
i--;
}
A y = new C();
y.foo(x);
MyClass mc = new MyClass();
mc.bar();
System.out.println("END");
}
}
and In MyClass.java
public class MyClass{
int haha;
public int bar() {
A x = new D();
x.foo(new C());
return haha;
}
}
Now, I have a method say, getTypeDecOfClassInstance() where I am iterating through every .java file in the project and visiting the ClassInstanceCreations it has. I am trying to get the binding of these ClassInstanceCreations, but getting RecoveredTypeBinding when I visit and inside the bar() method of MyClass instead of SourceTypeBinding. And I can't get ISourceRange or ICompilationUnit for them instead getting null.
Second scenario:
I have a project that has separate sub projects in different directories. And there are dependencies between projects described by pom.xml file. But when I try to build a call-graph out of it, I always get 0 callers for each method invocation.
I also tried to get the binding of the supertypes of each class and in this case, if the supertype is in another subproject, I sometimes get the source binding and sometimes get the RecoveredTypeBinding from which I can't get any source data like the above case.
Test case for this scenario:
I have a project say, ProjectA. Then it has two sub projects named, SubProjectA and SubProjectB.
In SubProjectA, I have A, B, C, D, and Main classes in different files.
public class A {
public A foo(A x) {
return x;
}
}
public class B extends A {
public A foo(A x) {
return new D();
}
}
public class C extends A {
public A foo(A x) {
D d = new D();
int i = 1;
d.foo(x, i);
return this;
}
}
public class D extends A {
public A foo(A x) {
A b = new B();
b.foo(x);
return new A();
}
public A foo(A x, int i) {
return x;
}
}
public class Main {
public static void main(String[] args) {
A x = new A();
int i = 10;
while(i>0) {
x = x.foo(new B()); /*<<<<<8,12,12,12, b*/
i--;
}
A y = new C();
y.foo(x);
MyClass mc = new MyClass();
mc.bar();
System.out.println("END");
}
}
and in SubProjectB, I have MyClass.java
public class MyClass{
int haha;
public int bar() {
A x = new D();
x.foo(new C());
return haha;
}
}
Again, I am having the same problem with my getTypeDecOfClassInstance() method.
Thanks in Advance.
[Updated on: Fri, 30 August 2019 04:59] Report message to a moderator
|
|
| | | | | |
Goto Forum:
Current Time: Thu Dec 12 07:46:41 GMT 2024
Powered by FUDForum. Page generated in 0.12831 seconds
|