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 9162547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:14:12+00:00 2026-06-17T14:14:12+00:00

In this code, prosseek.B#bar() method invokes prosseek.SuperA#foo(). package prosseek; public class SuperA { int

  • 0

In this code, prosseek.B#bar() method invokes prosseek.SuperA#foo().

package prosseek;

public class SuperA {
    int i = 0;
    public void foo()
    {
        System.out.println(i);
    }
}

public class B {
    public void bar()
    {
        SuperA a = new SuperA();
        a.foo();
    }
}

I need to detect the type of foo() invoked in bar().
I use ASTVisitor to detect the MethodInvocation code (a.foo()), but I’m not sure what should I do in order to get the SuperA type from it.

ICompilationUnit icu = type.getCompilationUnit();
final ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(icu);
parser.setResolveBindings(true); // we need bindings later on
CompilationUnit unit = (CompilationUnit) parser.createAST(null);

unit.accept(new ASTVisitor() {
    public boolean visit(MethodInvocation methodInvocation)
    {
        // ???

        return false;
    }
}

ADDED

I got the hint from JDT fundamentals tutorial.

enter image description here

I tried the following code:

IBinding binding = methodInvocation.resolveTypeBinding();
IType type = (IType)binding.getJavaElement();
if (type == null)
    return false;

However, I got null for the return value of binding.getJavaElement();

  • 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-06-17T14:14:13+00:00Added an answer on June 17, 2026 at 2:14 pm

    Instead of taking the type of the MethodInvocation, may be you need to take the type from the Expression. I have not tested this, but this might help.

    public boolean visit(MethodInvocation node) {
        Expression exp = node.getExpression();
        ITypeBinding typeBinding = node.getExpression().resolveTypeBinding();
        System.out.println("Type: " + typeBinding.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: public void foo() { new Thread() { @Override public void run() {
This code does not compile. public class Diamond { public static void diamondOfAsterisks(String *
This code is totally simplified, but reproduces my problem: BackingBean.java public String reload(){ System.out.println(FacesContext.getCurrentInstance()
this code runs after startActivity, but setting it after: @Override public void onCreate(Bundle savedInstanceState){
This code works fine in Java 1.6: public static String padLeft(String s, int n)
This code is used to demonstrate double-checked-locking anti-pattern: @NotThreadSafe public class DoubleCheckedLocking { private
This code: public class PhotoDescriptor { public DateTime DateCreatedUtc { get; set; } }
This code is not pretty, but I want to print out the last generated
This code produces a different output in Python 2 and Python 3 . class
This code is running on Blackberry JDE v4.2.1 It's in a method that makes

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.