Bug 17171 Quickfix: no proposal for wrong inst var initialization
- create the following code: public class Test { int fFoo= 1.2; } - a Quickfix bulb and a wiggly line appears for fFoo. However, pressing Cntr-1 does not show any proposals but the .log contains: java.lang.ClassCastException: org.eclipse.jdt.core.dom.FieldDeclaration at org.eclipse.jdt.internal.ui.text.correction.LocalCorrectionsSubProcessor.addCast Proposals(LocalCorrectionsSubProcessor.java:90) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectCorre ctions(JavaCorrectionProcessor.java:193) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.computeCompl etionProposals(JavaCorrectionProcessor.java:127) at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals (ContentAssistant.java:1205) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals (CompletionProposalPopup.java:104) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$3 (CompletionProposalPopup.java:103) at org.eclipse.jface.text.contentassist.CompletionProposalPopup$1.run (CompletionProposalPopup.java:72) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:56) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals (CompletionProposalPopup.java:67) at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions (ContentAssistant.java:1140) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionSourceViewer.doOperati on(JavaCorrectionSourceViewer.java:47) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer .doOperation(CompilationUnitEditor.java:217) at org.eclipse.ui.texteditor.TextOperationAction.run (TextOperationAction.java:88) at org.eclipse.ui.texteditor.RetargetTextEditorAction.run (RetargetTextEditorAction.java:127) at org.eclipse.jface.action.Action.runWithEvent(Action.java:590) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java:361) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:75) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1527) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1289) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1085) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1068) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:739) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:200) at org.eclipse.core.launcher.Main.run(Main.java:643) at org.eclipse.core.launcher.Main.main(Main.java:476)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java
int pos= problemPos.getOffset();
		if (selectedNode != null && selectedNode.getParent() != null) {
			int parentNodeType= selectedNode.getParent().getNodeType();
			if (parentNodeType == ASTNode.ASSIGNMENT) {
				Assignment assign= (Assignment) selectedNode.getParent();
				if (selectedNode.equals(assign.getLeftHandSide())) {
					pos= assign.getRightHandSide().getStartPosition();
				}
			} else if (parentNodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
				VariableDeclarationFragment frag= (VariableDeclarationFragment) selectedNode.getParent();
				if (selectedNode.equals(frag.getName())) {
					pos= frag.getInitializer().getStartPosition();
				}
			}
		}
		String simpleCastDestType= Signature.getSimpleName(castDestType);
		
		String cast= '(' + simpleCastDestType + ')';
		String formatted= StubUtility.codeFormat(cast + 'x', 0, "");  
		if (formatted.charAt(formatted.length() - 1) == 'x') {
			cast= formatted.substring(0, formatted.length() - 1);
		}
					
		String label= CorrectionMessages.getFormattedString("LocalCorrectionsSubProcessor.addcast.description", castDestType); 
		InsertCorrectionProposal proposal= new InsertCorrectionProposal(label, cu, pos, cast, 1);
		
		CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
		ImportEdit edit= new ImportEdit(cu, settings);
		edit.addImport(castDestType);
		proposal.getCompilationUnitChange().addTextEdit("import", edit);