Bug 94709 Quick fix to create method on annotation fails
Given code: import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface IsTest { String setUp() default ""; } class Exposer { private void foo() { IsTest annotation = getClass().getAnnotation(IsTest.class); String tearDown = annotation.tearDown(); } } There's a compile error on annotation.tearDown. Try to quick fix with "Create method 'tearDown'...". Nothing happens, and the following is logged in the Error Log: java.lang.ClassCastException: org.eclipse.jdt.core.dom.AnnotationTypeDeclaration at org.eclipse.jdt.internal.ui.text.correction.NewMethodCompletionProposal.evaluateModifiers(NewMethodCompletionProposal.java:69) at org.eclipse.jdt.internal.ui.text.correction.AbstractMethodCompletionProposal.getStub(AbstractMethodCompletionProposal.java:110) at org.eclipse.jdt.internal.ui.text.correction.AbstractMethodCompletionProposal.getRewrite(AbstractMethodCompletionProposal.java:82) at org.eclipse.jdt.internal.ui.text.correction.ASTRewriteCorrectionProposal.addEdits(ASTRewriteCorrectionProposal.java:61) at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.initializeTextChange(CUCorrectionProposal.java:135) at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.performChange(CUCorrectionProposal.java:272) at org.eclipse.jdt.internal.ui.text.correction.LinkedCorrectionProposal.performChange(LinkedCorrectionProposal.java:210) at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.apply(CUCorrectionProposal.java:303) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:457) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.selectProposalWithMask(CompletionProposalPopup.java:399) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:822) at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:630) at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:415) at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:55) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:866) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:851) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:659) at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5135) at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:4870) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:866) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:851) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:879) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:875) at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1182) at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3135) at org.eclipse.swt.widgets.Control.windowProc(Control.java:3038) at org.eclipse.swt.widgets.Display.windowProc(Display.java:3493) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1650) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2532) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1601) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1565) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:315) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:230) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:345) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:158) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.eclipse.core.launcher.Main.invokeFramework(Main.java:328) at org.eclipse.core.launcher.Main.basicRun(Main.java:272) at org.eclipse.core.launcher.Main.run(Main.java:974) at org.eclipse.core.launcher.Main.main(Main.java:950)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/NewMethodCompletionProposal.java
import org.eclipse.swt.graphics.Image;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.NamingConventions;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.eclipse.jdt.core.dom.ArrayType;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Bindings;
public class NewMethodCompletionProposal extends AbstractMethodCompletionProposal {
	private static final String KEY_NAME= "name"; 
	private static final String KEY_TYPE= "type";