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

  • SEARCH
  • Home
  • 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 5838761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:30:09+00:00 2026-05-22T11:30:09+00:00

I have to find all the methods in a class that use a particular

  • 0

I have to find all the methods in a class that use a particular member variable. (like “References” in eclipse but I want to implement using code…)I use AST visitor pattern that visits FieldDeclaration to get the name and type of all the member variables. I also use visitor pattern that visits MethodDeclaration nodes to get the content of each method using getBody(). Now I have the field variable name, type and member method details. I thought I can use a string search on the content of each member method but for a variable name “a”, search may return true for keywords like “class” and others too!!! Is there a way to find the usage of a particular variable corresponding to a fieldDeclaration?? (like Binding or something??) If so, what is the AST Node or Class?

Here’s the code I used…

 SimpleNameVisitor simpleNameVisitor=new SimpleNameVisitor();
 //SimpleNameVisitor is the visitor pattern for SimpleName
 simpleNameVisitor.process(mthd.getMethodBlock());
 //mthd is the object that stores method details
 for(SimpleName simpName:simpleNameVisitor.getIdentifiers()){
    if(varName.contentEquals(simpName.getFullyQualifiedName())){
        //varName is the field variable name
        System.out.println("MethodName: "+mthd.getName());
        return;
    }
  }

Here’s the code that solved the problem(suggested by wjans;changed equals to contentEquals)

VariableDeclarationFragment fragment = ... ;
IBinding binding = fragment.getName().resolveBinding();


public boolean visitNode(SimpleName simpleName) throws Exception {
if (binding.toString().contentEquals(simpleName.resolveBinding().toString()) {
    ....
}

}

  • 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-22T11:30:09+00:00Added an answer on May 22, 2026 at 11:30 am

    You can do something like this:

    Keep a reference to the binding of your FieldDeclaration,

    VariableDeclarationFragment fragment = ... ;
    IBinding binding = fragment.getName().resolveBinding();
    

    and use this to compare it with the bindings when visiting SimpleName’s inside your MethodDeclaration

    public boolean visitNode(SimpleName simpleName) throws Exception {
        if (binding.equals(simpleName.resolveBinding()) {
            ....
        }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Eclipse have a feature that lets you search a project to find all
I have a pdf file.I need to find all the hyperlinks available in that
I'm trying to find all data items that have long/lats that are contained by
I have general question regarding the use of pointers vs. references in this particular
I looked all over the NSString class reference but I can't seem to find
We have a model association that looks something like this: class Example < ActiveRecord::Base
I have a model that fetches all the games from a particular city. When
I have a number of classes that call say Trace.WriteLine(LogSomethingClassSpecific), in various methods all
I have a need to find all of the writable storage devices attached to
How to find all files in directory? I have HTML page in some directory.

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.