Bug 39098

Summary: Call Trees do not handle anonymous inner-classes correctly
Product: [Eclipse Project] JDT Reporter: Simon Archer <sja.eclipse>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: nikolaymetchev
Version: 3.0   
Target Milestone: 3.0 M5   
Hardware: PC   
OS: All   
Whiteboard:

Description Simon Archer CLA 2003-06-18 18:56:52 EDT
Build: I20030611

Given the following class that contains an anonymous inner-class:

public class Foo {
  public void bar() {
    Runnable runnable = new Runnable() {
      public void run() {
        Foo.this.process();
      }
    };
	
    Thread thread = new Thread(runnable);
    thread.start();
  }

  private void process() {
    System.out.println("Processing...");
  }
}

Creating a Call Tree for the process() methods yields the following "Caller 
Hierarchy":

  ^process() - tree.Foo
    ^bar() - tree.Foo

This is INCORRECT since it claims that the bar() method is called from the 
process() method, when in fact the bar() method is called from the Thread's run
() method, which is obviously executed on a separate thread.

Certainly the method bar() is referenced in the code inside the process() 
method, but I don't think that this should shown by a call tree.
Comment 1 Simon Archer CLA 2003-06-18 19:03:19 EDT
Refactoring the code to use a nested inner-class, rather than an anonymous 
inner-class causes things to work much better:

public class Foo {
  private final class MyRunnable implements Runnable {
    public void run() {
      Foo.this.process();
    }
  }

  public void bar() {
    Runnable runnable = new MyRunnable() {
    Thread thread = new Thread(runnable);
    thread.start();
  }

  private void process() {
    System.out.println("Processing...");
  }
}

Creating a Call Tree for the process() methods yields the following "Caller 
Hierarchy":

  ^process() - tree.Foo
    ^run() - tree.Foo.MyRunnable
Comment 2 Philipe Mulet CLA 2003-06-19 06:26:05 EDT
JDT/Core currently has no representation of elements inside methods (e.g. 
anonymous types, local variables).

We are planning to impove this for the 3.0 release. 
Comment 3 Philipe Mulet CLA 2003-06-24 05:33:51 EDT

*** This bug has been marked as a duplicate of 8613 ***
Comment 4 Jerome Lanneluc CLA 2003-09-24 06:46:21 EDT
Reopening as even after adding contructs for local types, the problem is still 
there.
Comment 5 Jerome Lanneluc CLA 2003-11-04 07:34:19 EST
Verified this now works with I20031029.