Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 410170 - [1.8][quick fix] Remove invalid modifier on static and default interface methods
Summary: [1.8][quick fix] Remove invalid modifier on static and default interface methods
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Martin Mathew CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 400977
Blocks:
  Show dependency tree
 
Reported: 2013-06-07 07:53 EDT by Noopur Gupta CLA
Modified: 2014-04-13 22:11 EDT (History)
3 users (show)

See Also:
noopur_gupta: review+


Attachments
Patch with testcases. (16.98 KB, patch)
2013-06-24 03:50 EDT, Martin Mathew CLA
no flags Details | Diff
Updated Patch with tests (1.22 KB, patch)
2013-09-06 02:00 EDT, Martin Mathew CLA
no flags Details | Diff
Correct patch + tests (5.52 KB, patch)
2014-04-09 02:03 EDT, Martin Mathew CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2013-06-07 07:53:13 EDT
interface I {
	private static void foo() { // Error [1]
	}
	
	private default void bar() { // Error [2]
	}	
}

[1] 
'Remove invalid modifier' quick fix removes 'static' modifier also along with 'private'. 

[2] 
No quick fix is available.

The quick fix should be updated to handle static and default interface methods at ModifierCorrectionSubProcessor.addRemoveInvalidModifiersProposal(..).
Comment 1 Martin Mathew CLA 2013-06-11 06:21:02 EDT
We also need to handle the case when there are illegal visibility modifier combination in Interface method.
e.g. public abstract static void m1(){}
     public abstract default void m2(){}
     public default static void  m3(){}
All the above have illegal modifier combinations.

For this a new problem id has to generated in core that can be similar to IllegalVisibilityModifierCombinationForInterfaceMethod. This will be handled in bug 400977 in JDT Core.
Comment 2 Martin Mathew CLA 2013-06-24 03:50:05 EDT
Created attachment 232685 [details]
Patch with testcases.

I have used the patch provided by Manoj from bug 400977 to complete this task. Provided valid quick fixes for invalid access modifier if used for static and default interface methods.
No quick fix is provided for invalid modifier combination (IProblem#IllegalModifierCombinationForInterfaceMethod), the error marker informs user of the problem.
Added testcases to cover the scenario.
@Noopur: Kindly review and give an initial feedback.
Comment 3 Martin Mathew CLA 2013-09-06 02:00:06 EDT
Created attachment 235219 [details]
Updated Patch with tests

Created fresh patch from the newly created remote branch after eliminating duplicate changes.
Comment 4 Martin Mathew CLA 2014-04-09 02:03:54 EDT
Created attachment 241759 [details]
Correct patch + tests

Previous patch did not contain all the changes.
Comment 5 Noopur Gupta CLA 2014-04-10 05:51:08 EDT
Review comments:

- Is there an example for modifying the case for "IllegalModifierForInterfaceMethod" with Java 8 condition in ModifierCorrectionSubProcessor? I could not see a corresponding test case also.

- It would be good to place the case for "IllegalModifierForInterfaceMethod18" near other cases for interfaces, like after "IllegalModifierForInterfaceMethod", in both the files.

- Can we handle "IllegalStrictfpForAbstractInterfaceMethod" also? For example:
    strictfp void fun1();
    strictfp abstract void fun2();
Comment 6 Martin Mathew CLA 2014-04-11 03:05:08 EDT
(In reply to Noopur Gupta from comment #5)
> Review comments:

(In reply to Noopur Gupta from comment #5)
> Review comments:
> 
> - Is there an example for modifying the case for
> "IllegalModifierForInterfaceMethod" with Java 8 condition in
> ModifierCorrectionSubProcessor? I could not see a corresponding test case
> also.
> 
This change was unnecessary, reverted it.

> - It would be good to place the case for
> "IllegalModifierForInterfaceMethod18" near other cases for interfaces, like
> after "IllegalModifierForInterfaceMethod", in both the files.
> 
done.
> - Can we handle "IllegalStrictfpForAbstractInterfaceMethod" also? For
> example:
>     strictfp void fun1();
>     strictfp abstract void fun2();

Isn't the error message clear enough?
"strictfp is not permitted for abstract interface method fun2". For this same reason currently there is no quick fix provided for IProblem#IllegalModifierCombinationForInterfaceMethod.
Comment 7 Noopur Gupta CLA 2014-04-11 08:09:33 EDT
(In reply to Manju Mathew from comment #6) 
> > - Can we handle "IllegalStrictfpForAbstractInterfaceMethod" also? For
> > example:
> >     strictfp void fun1();
> >     strictfp abstract void fun2();
> 
> Isn't the error message clear enough?
> "strictfp is not permitted for abstract interface method fun2". For this
> same reason currently there is no quick fix provided for
> IProblem#IllegalModifierCombinationForInterfaceMethod.

I was suggesting to add the quick fix that will remove 'strictfp' as suggested by the error message that it is not permitted here. But we can leave it for now and add it later, if required.
Comment 8 Martin Mathew CLA 2014-04-13 22:11:29 EDT
Thanks Noopur. Released the fix as : http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=93033f2a57fd8b34d836f67639f3daed6b4e0f75