Bug 170181 - [compiler] Could diagnose unused local types
Summary: [compiler] Could diagnose unused local types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-01-11 04:04 EST by Philipe Mulet CLA
Modified: 2007-06-06 17:52 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (2.09 KB, patch)
2007-01-11 04:08 EST, Philipe Mulet CLA
no flags Details | Diff
Philippe's patch + tests (modified and added) (46.25 KB, patch)
2007-01-12 13:35 EST, Eric Jodet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2007-01-11 04:04:49 EST
Build 3.3M4

The support for detecting unused private or local constructs does not flag unused local types.

e.g. 
public class X {
	private class M { // M unused
		private class Member {} // Member unused
		private class Member2 extends M { // Member2 unused
		}
	}
public static void main(String[] args) {
	class Local {} // Local unused
	class Local2 { // Local2 unused
		class LMember {} // used by field ref
		class LMember2 extends Local2 { // LMember2 unused
		}
		LMember m;
	}
	int i = 0;
}
}
Comment 1 Philipe Mulet CLA 2007-01-11 04:08:22 EST
Created attachment 56752 [details]
Proposed patch

With this patch, following diagnoses are emitted:

----------
1. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 2)
	private class M {
	              ^
The type X.M is never used locally
----------
2. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 3)
	private class Member {}
	              ^^^^^^
The type X.M.Member is never used locally
----------
3. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 4)
	private class Member2 extends M {
	              ^^^^^^^
The type X.M.Member2 is never used locally
----------
4. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 4)
	private class Member2 extends M {
	              ^^^^^^^
Access to enclosing constructor X.M() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance
----------
5. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 8)
	class Local {}
	      ^^^^^
The type Local is never used locally
----------
6. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 9)
	class Local2 {
	      ^^^^^^
The type Local2 is never used locally
----------
7. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 11)
	class LMember2 extends Local2 {
	      ^^^^^^^^
The type Local2.LMember2 is never used locally
----------
8. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 13)
	LMember m;
	        ^
The field Local2.m is never read locally
----------
9. WARNING in d:\eclipse\workspaces\dev3.3\plugins\Crap\src\X.java (at line 15)
	int i = 0;
	    ^
The local variable i is never read
----------
Comment 2 Philipe Mulet CLA 2007-01-11 04:09:44 EST
Eric - pls challenge the proposed patch
Comment 3 Eric Jodet CLA 2007-01-12 13:35:49 EST
Created attachment 56842 [details]
Philippe's patch + tests (modified and added)

All tests (modified and new ones) completed OK.
No modification to your original patch
Eric.
Comment 4 Philipe Mulet CLA 2007-01-15 04:59:07 EST
Thanks Eric.

Released for 3.3M5.
Fixed
Comment 5 Philipe Mulet CLA 2007-01-15 05:01:49 EST
CC'ed Martin, in case JDT/UI needs to adjust (quickfix/cleanup?)
Comment 6 David Audel CLA 2007-02-06 06:50:59 EST
Verified for 3.3 M5 using build I20070206-0010