239887 CCE in ReturnTypeSubProcessor for enum.
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java
index 2b8e686..3d549a5 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,9 +16,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.jdt.testplugin.JavaProjectHelper;
-import org.eclipse.jdt.testplugin.TestOptions;
-
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -26,17 +23,20 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-
import org.eclipse.jdt.ui.PreferenceConstants;
-import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.text.correction.proposals.ASTRewriteCorrectionProposal;
import org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal;
+import org.eclipse.jdt.testplugin.JavaProjectHelper;
+import org.eclipse.jdt.testplugin.TestOptions;
+
+import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
+
public class ReturnTypeQuickFixTest extends QuickFixTest {
private static final Class THIS= ReturnTypeQuickFixTest.class;
@@ -1123,4 +1123,36 @@
assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
}
+ public void testMethodInEnum_bug239887() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package p;\n");
+ buf.append("enum Bug {X;\n");
+ buf.append(" wrap(){}\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("Bug.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList proposals= collectCorrections(cu, astRoot);
+
+ assertCorrectLabels(proposals);
+ assertNumberOfProposals(proposals, 2);
+
+ String[] expected= new String[2];
+ buf= new StringBuffer();
+ buf.append("package p;\n");
+ buf.append("enum Bug {X;\n");
+ buf.append(" void wrap(){}\n");
+ buf.append("}\n");
+ expected[0]= buf.toString();
+
+ buf= new StringBuffer();
+ buf.append("package p;\n");
+ buf.append("enum Bug {X;\n");
+ buf.append(" Bug(){}\n");
+ buf.append("}\n");
+ expected[1]= buf.toString();
+
+ assertExpectedExistInProposals(proposals, expected);
+ }
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReturnTypeSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReturnTypeSubProcessor.java
index 2235b93..404a9fc 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReturnTypeSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ReturnTypeSubProcessor.java
@@ -269,7 +269,7 @@
if (parentType instanceof AbstractTypeDeclaration) {
boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
if (!isInterface) {
- String constructorName= ((TypeDeclaration) parentType).getName().getIdentifier();
+ String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
ASTNode nameNode= methodDeclaration.getName();
label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, 5));