Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7077363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:24:51+00:00 2026-05-28T06:24:51+00:00

I am writing some simple AST visitors for the Eclipse JDT. I have a

  • 0

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;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:24:51+00:00Added an answer on May 28, 2026 at 6:24 am

    As the documentation states, the result of calling getModifiers() is a bit-wise “or” of the relevant Modifier constants. So for example, if you want to find out whether or not the method is final you’d use:

    int modifiers = node.getModifiers();
    if (modifiers & Modifier.FINAL != 0) {
        // It's final
    }
    

    Or you can use the convenience methods in the Modifier class:

    int modifiers = node.getModifiers();
    if (Modifier.isFinal(modifiers)) {
        // It's final
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some code which could really do with some simple compile time metaprogramming.
I'm writing an application which reads large arrays of floats and performs some simple
I have some pyunit unit tests for a simple command line programme I'm writing.
I'm writing a simple eclipse plugin, which is a code generator. User can choose
I'm writing a s:ItemRenderer to render some simple graphical components in my app. Each
I've been writing some simple test cases for one of my assignments, and have
I am trying to start writing some simple jQuery plugins and for my first
I'm playing around with writing some simple Spring-based web apps and deploying them to
I'd like to play around with writing some very small, simple web-based games (checkers,
This might be a simple answer, but I am having some issues writing this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.