页: 1 I Field or IJavaElement reference for all factors in my source Code. 我使用花gin,获得一个大学,我能够从中阅读所有顶级物体,使用:
(IJavaElement i:unit.getTypes(0).getChildren())
or
(IJavaElement i:unit.getAllTypes())
我如何能够获取当地变量? 我正试图将ICompilationUnit调往Unit,在那里,I能够取得每个领域的ATNode,但随后是。 I m 无法将其转化成I Field。 任何想法?
//edit: For example: For a class:
公共职务 试 测
int global1; int global2; void a() { global1 = 4; int local1; int local2 = 5; iii
iii
我请我发言。
for (IType type : unit.getTypes()) { System.out.println("itype "+type); for (IField iField : type.getFields()) { System.out.println("iField "+iField); iiiiii
产出是:
itype class Test [in [Working copy] Test.java [in [in src [in testowy]]]] int global1 int global2 void a() iField int global1 [in Test [in [Working copy] Test.java [in [in src [in testowy]]]]] iField int global2 [in Test [in [Working copy] Test.java [in [in src [in testowy]]]]]
因此,没有发现当地变量......
//added - still struggling: Actually it s not the behavior I was expecting.
for( IMethod i:unit.getAllTypes()[0].getMethods() )
{
System.out.println("index to h:"+h+" type "+i.getSource()+" name: "+i.getElementName());
h++;
int o =0;
for( IJavaElement j: i.getChildren() )
{
System.out.println("index to o: "+o+j+" type "+j.getElementType()+" name: "+j.getElementName());
o++;
iii
iii
该法典第一版预计会找到所有方法(这些方法可行),并从方法(即工作)中获取所有当地变量。 它从未进入田间。 它正确地印刷功能声明,以确保它看到所有变量......
And as for using INodes, I can visit all nodes, but how can I change type from Node to IField/IJavaElement which I need?
感谢: