Bug 39098 - Call Trees do not handle anonymous inner-classes correctly
Summary: Call Trees do not handle anonymous inner-classes correctly
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-18 18:56 EDT by Simon Archer CLA
Modified: 2003-11-04 07:34 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.