EclipseJDT用の簡単なASTビジターをいくつか書いています。それぞれがを拡張するクラスがありMethodVisitor
ます。たとえば、そのクラスのメソッド(オーバーライド)では、各ノードを見つけることができます。それらのノードの1つがある場合、それがそうであるかどうか(そしておそらく他の修飾子も)を確認するためにそのノードを調べたいと思います。と呼ばれるメソッドがありますが、これを使用して特定のに適用される修飾子のタイプを判別する方法がわかりません。私のコードは以下に掲載されています。進め方について何かアイデアがあれば教えてください。FieldVisitor
ASTVisitor
MethodVisitor
Visit
MethodDeclaration
Modifiers
public
private
getModifiers()
MethodDeclaration
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.MethodDeclaration;
public class MethodVisitor extends ASTVisitor {
private List<MethodDeclaration> methods;
// Constructor(s)
public MethodVisitor() {
this.methods = new ArrayList<MethodDeclaration>();
}
/**
* visit - this overrides the ASTVisitor's visit and allows this
* class to visit MethodDeclaration nodes in the AST.
*/
@Override
public boolean visit(MethodDeclaration node) {
this.methods.add(node);
//*** Not sure what to do at this point ***
int mods = node.getModifiers();
return super.visit(node);
}
/**
* getMethods - this is an accessor methods to get the methods
* visited by this class.
* @return List<MethodDeclaration>
*/
public List<MethodDeclaration> getMethods() {
return this.methods;
}
}