Bug 421969 - [extract superclass] Extract Superclass refactoring should remove static member qualifiers
Summary: [extract superclass] Extract Superclass refactoring should remove static memb...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-18 09:04 EST by Palmer Eldritch CLA
Modified: 2019-03-08 14:44 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Palmer Eldritch CLA 2013-11-18 09:04:06 EST
public class TestExtractSuperclass {

	static void staticMethod() {}

	void instanceMethod() {
		TestExtractSuperclass.staticMethod();
	}
}


Highlight some of it and choose extract superclass. Tick both methods. You get :

public class Superclass {

	static void staticMethod() {}

	public Superclass() {
		super();
	}

	void instanceMethod() {
		TestExtractSuperclass.staticMethod();
	}
}

The line TestExtractSuperclass.staticMethod(); results in a compilation error

The static access modifier should be removed (btw it is redundant in the first place - is there a warning for it ?)
Comment 1 Noopur Gupta CLA 2013-11-19 06:18:27 EST
> The line TestExtractSuperclass.staticMethod(); results in a compilation error
To get the compilation error, have you set the Compiler Errors/Warnings preference for "Indirect access to static member" as Error? If it is set to "Ignore", we do not get any compile error.
 
In the example, the resulting code after extract superclass refactoring (with old static member qualifier in the superclass) would be incorrect if we add a new static member to the subclass that hides the one in superclass, as now the qualified access would refer to the new static member. 
Hence, the static member qualifiers should be removed while performing the extract superclass refactoring.

> (btw it is redundant in the first place - is there a warning for it ?)
There is no warning for the direct access to a static member.
Comment 2 Palmer Eldritch CLA 2013-11-19 07:51:02 EST
(In reply to Noopur Gupta from comment #1)
> > The line TestExtractSuperclass.staticMethod(); results in a compilation error
> To get the compilation error, have you set the Compiler Errors/Warnings
> preference for "Indirect access to static member" as Error? If it is set to
> "Ignore", we do not get any compile error.
Yes I did - but I also use the extract superclass to achieve Extract class - and when I break the inheritance chain between the classes it is then truly an error :)


> In the example, the resulting code after extract superclass refactoring
> (with old static member qualifier in the superclass) would be incorrect if
> we add a new static member to the subclass that hides the one in superclass,
> as now the qualified access would refer to the new static member. 
> Hence, the static member qualifiers should be removed while performing the
> extract superclass refactoring.
> 

Exactly !

> > (btw it is redundant in the first place - is there a warning for it ?)
> There is no warning for the direct access to a static member.

Added a request : https://bugs.eclipse.org/bugs/show_bug.cgi?id=422001
Added as a code cleanup request but a compiler warning would be better (more efficient) - what you say ?

Thanks !
Comment 3 Eclipse Genie CLA 2019-03-08 14:44:07 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.