문제

I am writing some simple AST visitors for the Eclipse JDT. I have a MethodVisitor and FieldVisitor class which each extend the ASTVisitor. Take the MethodVisitor for instance. In that class' Visit method (which is an override), I am able to find each of the MethodDeclaration nodes. When I have one of those nodes, I want to look at its Modifiers to see whether it is public or private (and perhaps other modifiers as well). There is a method called getModifiers(), but it is unclear to me how to use this to determine the type of modifier applied to the particular MethodDeclaration. My code is posted below, please let me know if you have any ideas how to proceed.

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;
    }
}

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top