Bug 434188 - [quick fix] shows sign of quick fix, but says no suggestions available.
Summary: [quick fix] shows sign of quick fix, but says no suggestions available.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.4 RC1   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 437927 430818
Blocks:
  Show dependency tree
 
Reported: 2014-05-06 06:33 EDT by Manoj N Palat CLA
Modified: 2014-06-27 11:40 EDT (History)
6 users (show)

See Also:
daniel_megert: review+


Attachments
Fix (3.53 KB, patch)
2014-05-14 15:00 EDT, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manoj N Palat CLA 2014-05-06 06:33:52 EDT
@FunctionalInterface
interface I {
	public int foo(I i);
}
public class X {
	public static int bar(I i) { return 0;}
	public int foo(I i) {
		I i1 = X::;// shows probable quick fix but says no suggestions.
		return 0;
	}
}

[not java 8 specific]
Comment 1 Dani Megert CLA 2014-05-06 07:37:26 EDT
(In reply to Manoj Palat from comment #0)
> @FunctionalInterface
> interface I {
> 	public int foo(I i);
> }
> public class X {
> 	public static int bar(I i) { return 0;}
> 	public int foo(I i) {
> 		I i1 = X::;// shows probable quick fix but says no suggestions.
> 		return 0;
> 	}
> }
> 
> [not java 8 specific]

In 4.3 no quick fix is suggested.

The error in 4.4 is:
Syntax error, insert "Identifier" to complete Expression

Should be fixed during RC1 if possible.
Comment 2 Dani Megert CLA 2014-05-06 07:53:47 EDT
(In reply to Dani Megert from comment #1)
> In 4.3 no quick fix is suggested.

Sorry, I meant 4.2 / 3.8.
Comment 3 Markus Keller CLA 2014-05-07 15:48:04 EDT
This is due to the "generate for loop" quick fix, which is currently broken (bug 430818).

QuickFixProcessor#hasCorrections(ICompilationUnit, int) needs to be very fast, (see Javadoc), and it doesn't get the necessary context to do any further analysis on the actual problem location.

Unfortunately, the compile error ParsingErrorInsertToComplete is not very specific and occurs in many cases where LocalCorrectionsSubProcessor#getGenerateForLoopProposals(..) won't find a quick fix.

We will have to see how this works after bug 430818 or bug 430336 is fixed. Maybe we should just remove handling of ParsingErrorInsertToComplete in the QuickFixProcessor. The QuickAssistProcessor should still show the fix in that case on Ctrl+1. It won't show up in the Quick Fix hover, but that's an acceptable price for not showing false quick fix lightbulbs elsewhere.
Comment 4 Markus Keller CLA 2014-05-14 15:00:23 EDT
Created attachment 243099 [details]
Fix

(In reply to Markus Keller from comment #3)
> Maybe we should just remove handling of ParsingErrorInsertToComplete in the
> QuickFixProcessor. The QuickAssistProcessor should still show the fix in
> that case on Ctrl+1. It won't show up in the Quick Fix hover, but that's an
> acceptable price for not showing false quick fix lightbulbs elsewhere.

The fix implements this.
Comment 5 Markus Keller CLA 2014-05-14 15:01:34 EDT
Dani could you please review and push this?
Comment 6 Dani Megert CLA 2014-05-14 17:19:10 EDT
Note that your test cases pass without the fix. Would be good to have some tests that are red before the fix and green afterwards.

Committed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=51a68d396c4f907bb13e4f3854465718e4ee9aa2
Comment 7 Markus Keller CLA 2014-05-15 13:50:02 EDT
There's a myriad of ways you can create IProblem.ParsingErrorInsertToComplete, so all a negative test could do is ensure there are no quick fixes for one of them. We also don't do that for all the other IProblems for which we don't have quick fixes.

Just to give a small example that shows 4 different ways for getting the problemID that the for-loop quick fixed tries to handle:

class E2 {
    public class MyLayout {
        int indent;
    }
    public void foo() {
        new MyLayout().indent // no real quick fix
    }
    
    private int[] fField;
    public void bar() {
        fField[0] // no quick fix
    }
    void // no quick fix
    void foo(Map<String, String> map) {
        map..keySet(); // no quick fix
    }
}

In all these cases, we wrongly showed a quick fix lightbulb -- and there are many more.
Comment 8 Martin Mathew CLA 2014-05-18 23:04:02 EDT
Verified using Build id: I20140515-1230 that the code snippet from comment 0 and comment 7 do not show bogus quick fix sign.
Comment 9 Markus Keller CLA 2014-06-23 11:17:51 EDT
(In reply to Dani Megert from comment #6)
> Note that your test cases pass without the fix. Would be good to have some
> tests that are red before the fix and green afterwards.

Added http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=df7fe5bb670aee8facb0cd636646bf2f102d7ae4 to prevent cases like bug 338785 comment 11. Needs to be revisited when we try to fix bug 437927.
Comment 10 Markus Keller CLA 2014-06-24 08:24:14 EDT
From Manju:
> The new test added "testNoFixFor_ParsingErrorInsertToComplete" pass with or without the fix from Sandra. I understood that the cases being tested are those for which there can't be any real quick fix possible. Hence is there a way we can test if the light bulbs are added for those invalid cases when a quick fix for a valid case is provided? e.g when Sandra's patch from bug 338785 is applied, light bulbs appear for the invalid cases, how to make the test fail in such a case?

Thanks for raising that. I really intended the test to do that, but was tricked by our bad testing infrastructure. Added Javadoc warnings and fixed the test with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=157d905b49ee6fa2cff213ebecddf82e47b3ee80
Comment 11 Markus Keller CLA 2014-06-27 11:40:33 EDT
And finally the right fix that asserts the absence of the lightbulb also without the cheat that comment 10 inserted into the test CU source:
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=b0ce2b48b7caf8f557aff6ae8372c9d50d076cbf