ASTのノード呼び出しAPI


ASTのノード呼び出しのAPIまとめ、これらはすべて私がプロジェクトを書く時に使ったASTに関するAPIで、今まとめて以下のように整理して、もちろんこれらは不完全で、後で補充の修正をしなければなりません.
TypeDeclarationクラス宣言
Type Declarationはクラスに関する宣言で、getNameを呼び出してクラス名を得ることができ、getSuperclassType()を呼び出して親クラス名を得ることができ、getSuperclassType()を呼び出して親クラスパスを得ることができる.
public boolean visit(TypeDeclaration node) {
  System.out.println("Class:\t" + node.getName());//    
  if(node.getSuperclassType()!=null){
   System.out.println("superClass:"+node.getSuperclassType());//     
   String SuperclassName=""+node.getSuperclassType();//    
   return true;
  }

Expressionクラスは、すべてのEclipse ASTにおける式ノードクラスのベースクラスであり、それによって多くのクラスが派生する.SimpleMiniJOOLプログラムを表す場合、MethodInvocation、Assignment、InfixExpression、PrefixExpression、ParenthesizedExpression、NumberLiteral、Nameといった式ノードクラスのみが対象となります. 
1.MethodInvocationクラス(メソッド呼び出し)
MethodInvocation Javaプログラムのメソッド呼び出しを表すために使用されます.
 public boolean visit(MethodInvocation node) {
 <span style="white-space:pre">	</span>System.out.println(node.getName());//             
<span style="white-space:pre">	</span>System.out.println(node.getExpression());//         ,  commandline.createArgument().setValue("-root_dir"); 
 <span style="white-space:pre">	</span>//       commandline.createArgument(),commandline,null
 <span style="white-space:pre">	</span>return true;  
 <span style="white-space:pre">	</span>}

========================================================================================
MethodDeclarationメソッド宣言
MethodDeclarationクラス内のメソッドの宣言を表します
public boolean visit(MethodDeclaration node) {
	System.out.println("Method:\t" + node.getName());//     
System.out.println("the character length of the method is:"+node.getLength());//     ,            ,       //  
	 System.out.println("Parameter list of Method:\t" + node.parameters());//         
return true;}

==============================================================================================
FieldDeclaration変数宣言
FieldDeclarationは変数の宣言であり、VariableDeclarationFragmentは変数名であり、forループループで得ることができる.
	@Override
	public boolean visit(FieldDeclaration node) {
		
		for (Object obj: node.fragments()) {
			VariableDeclarationFragment v = (VariableDeclarationFragment)obj;
			System.out.println("Field:\t" + v.getName());
		}
		return true;
	}

========================================================================================
SwitchStatement
SwitchStatementは、コード内のSwitch case関連文ブロックを得る論理である.
 public boolean visit(SwitchStatement node) {
	 System.out.println("SwitchStatement  "+node.getStartPosition());//  switch     
	 System.out.println("SwitchStatement "+node.getExpression());//  switch case      switch(x) x    
	 //System.out.println("SwitchStatement "+node.getRoot());//  switch        
	 System.out.println("SwitchStatement "+node.getParent());//       ,         
	 return true;
	 }