Eclipse JDTの簡単なAST訪問者を書いています。私はそれぞれMethodVisitor
とFieldVisitor
クラスを持ち、それぞれがASTVisitor
を拡張しています。たとえば、MethodVisitor
を取る。そのクラスのVisit
メソッド(オーバーライド)では、MethodDeclaration
ノードのそれぞれを見つけることができます。私がこれらのノードの1つを持っているとき、Modifiers
を見て、それがpublic
かprivate
(そしておそらく他の修飾子であるかどうか)を調べたいと思います。 getModifiers()
というメソッドがありますが、これを使用して、特定のMethodDeclaration
に適用されている修飾子のタイプを判断する方法は私には不明です。私のコードは以下に掲載されています。進める方法があれば教えてください。ドキュメントの状態としてEclipse JDTのメソッドまたはフィールドの修飾子を特定する方法は?
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;
}
}