Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 90140 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java (+51 lines)
Lines 10-15 Link Here
10
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
10
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
11
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
11
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
13
 *     Sandra Lions <sandra.lions-piron@oracle.com> - Bug 90140 - [quick fix] for qualified enum constants in switch-case labels 
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.ui.tests.quickfix;
15
package org.eclipse.jdt.ui.tests.quickfix;
15
16
Lines 9173-9178 public class LocalCorrectionsQuickFixTest extends QuickFixTest { Link Here
9173
		assertExpectedExistInProposals(proposals, expected);
9174
		assertExpectedExistInProposals(proposals, expected);
9174
	}
9175
	}
9175
9176
9177
	public void testReplaceWithUnqualifiedEnumConstant() throws Exception {
9178
		final IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null);
9179
		StringBuffer buf= new StringBuffer();
9180
		buf.append("package pack;\n");
9181
		buf.append("public class E {\n");
9182
		buf.append("    public enum color {black, white}\n");
9183
		buf.append("    public void foo(color c) {\n");
9184
		buf.append("		switch (c) {\n");
9185
		buf.append("            case color.black:\n");
9186
		buf.append("                System.out.println(\"Black\");\n");
9187
		buf.append("                break;\n");
9188
		buf.append("            case color.white:\n");
9189
		buf.append("                System.out.println(\"White\");\n");
9190
		buf.append("                break;\n");
9191
		buf.append("            default:\n");
9192
		buf.append("                break;\n");
9193
		buf.append("        }\n");
9194
		buf.append("    }\n");
9195
		buf.append("}\n");
9196
		final ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
9197
9198
		final CompilationUnit astRoot= getASTRoot(cu);
9199
		final ArrayList proposals= collectCorrections(cu, astRoot, 2);
9200
9201
		assertNumberOfProposals(proposals, 1);
9202
		assertCorrectLabels(proposals);
9203
9204
		final CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0);
9205
		final String preview= getPreviewContent(proposal);
9206
9207
		buf= new StringBuffer();
9208
		buf.append("package pack;\n");
9209
		buf.append("public class E {\n");
9210
		buf.append("    public enum color {black, white}\n");
9211
		buf.append("    public void foo(color c) {\n");
9212
		buf.append("		switch (c) {\n");
9213
		buf.append("            case black:\n");
9214
		buf.append("                System.out.println(\"Black\");\n");
9215
		buf.append("                break;\n");
9216
		buf.append("            case color.white:\n");
9217
		buf.append("                System.out.println(\"White\");\n");
9218
		buf.append("                break;\n");
9219
		buf.append("            default:\n");
9220
		buf.append("                break;\n");
9221
		buf.append("        }\n");
9222
		buf.append("    }\n");
9223
		buf.append("}\n");
9224
		assertEqualString(preview, buf.toString());
9225
	}
9226
	
9176
	public void testCollectionsFieldMethodReplacement() throws Exception {
9227
	public void testCollectionsFieldMethodReplacement() throws Exception {
9177
		Hashtable options= JavaCore.getOptions();
9228
		Hashtable options= JavaCore.getOptions();
9178
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
9229
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java (+1 lines)
Lines 392-397 public final class CorrectionMessages extends NLS { Link Here
392
	public static String LocalCorrectionsSubProcessor_insert_cases_omitted;
392
	public static String LocalCorrectionsSubProcessor_insert_cases_omitted;
393
	public static String LocalCorrectionsSubProcessor_insert_fall_through;
393
	public static String LocalCorrectionsSubProcessor_insert_fall_through;
394
	public static String LocalCorrectionsSubProcessor_override_hashCode_description;
394
	public static String LocalCorrectionsSubProcessor_override_hashCode_description;
395
	public static String LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant;
395
	public static String LocalCorrectionsSubProcessor_throw_allocated_description;
396
	public static String LocalCorrectionsSubProcessor_throw_allocated_description;
396
	public static String SuppressWarningsSubProcessor_fix_suppress_token_label;
397
	public static String SuppressWarningsSubProcessor_fix_suppress_token_label;
397
	public static String SuppressWarningsSubProcessor_remove_annotation_label;
398
	public static String SuppressWarningsSubProcessor_remove_annotation_label;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties (+1 lines)
Lines 117-122 LocalCorrectionsSubProcessor_qualify_left_hand_side_description=Qualify left han Link Here
117
LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}''
117
LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}''
118
LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object
118
LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object
119
LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object
119
LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object
120
LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant=Replace with unqualified enum constant ''{0}''
120
TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}''
121
TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}''
121
TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}''
122
TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}''
122
TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}''
123
TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}''
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java (+1 lines)
Lines 180-185 public interface IProposalRelevance { Link Here
180
	public static final int CORRECT_PACKAGE_DECLARATION= 5;
180
	public static final int CORRECT_PACKAGE_DECLARATION= 5;
181
	public static final int TYPE_ARGUMENTS_FROM_CONTEXT= 5;
181
	public static final int TYPE_ARGUMENTS_FROM_CONTEXT= 5;
182
	public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5;
182
	public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5;
183
	public static final int REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT= 5;
183
184
184
	public static final int ADD_MISSING_TAG= 4;
185
	public static final int ADD_MISSING_TAG= 4;
185
	public static final int INSERT_FALL_THROUGH= 4;
186
	public static final int INSERT_FALL_THROUGH= 4;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java (+19 lines)
Lines 10-15 Link Here
10
 *     Renaud Waldura &lt;renaud+eclipse@waldura.com&gt; - Access to static proposal
10
 *     Renaud Waldura &lt;renaud+eclipse@waldura.com&gt; - Access to static proposal
11
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
11
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
13
 *     Sandra Lions <sandra.lions-piron@oracle.com> - Bug 90140 - [quick fix] for qualified enum constants in switch-case labels 
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.ui.text.correction;
15
package org.eclipse.jdt.internal.ui.text.correction;
15
16
Lines 765-770 public class LocalCorrectionsSubProcessor { Link Here
765
		}
766
		}
766
767
767
	}
768
	}
769
	
770
	public static void addIllegalQualifiedEnumConstantLabelProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
771
		ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
772
		if (!(coveringNode instanceof QualifiedName)) {
773
			return;
774
		}
775
		final QualifiedName qualifiedName= (QualifiedName) coveringNode;
776
		final SimpleName simpleName= qualifiedName.getName();
777
778
		final AST ast= coveringNode.getAST();
779
		final ASTRewrite rewrite= ASTRewrite.create(ast);
780
		rewrite.replace(coveringNode, simpleName, null);
781
782
		final String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant, BasicElementLabels.getJavaElementName(simpleName.getIdentifier()));
783
		final Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
784
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT, image);
785
		proposals.add(proposal);
786
	}
768
787
769
	public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
788
	public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
770
		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
789
		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java (+4 lines)
Lines 161-166 public class QuickFixProcessor implements IQuickFixProcessor { Link Here
161
			case IProblem.DuplicateMethod:
161
			case IProblem.DuplicateMethod:
162
			case IProblem.DuplicateTypeVariable:
162
			case IProblem.DuplicateTypeVariable:
163
			case IProblem.DuplicateNestedType:
163
			case IProblem.DuplicateNestedType:
164
			case IProblem.IllegalQualifiedEnumConstantLabel:
164
			case IProblem.IllegalModifierForInterfaceMethod:
165
			case IProblem.IllegalModifierForInterfaceMethod:
165
			case IProblem.IllegalModifierForInterfaceMethod18:
166
			case IProblem.IllegalModifierForInterfaceMethod18:
166
			case IProblem.IllegalModifierForInterface:
167
			case IProblem.IllegalModifierForInterface:
Lines 760-765 public class QuickFixProcessor implements IQuickFixProcessor { Link Here
760
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
761
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
761
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
762
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
762
				break;
763
				break;
764
			case IProblem.IllegalQualifiedEnumConstantLabel:
765
				LocalCorrectionsSubProcessor.addIllegalQualifiedEnumConstantLabelProposal(context, problem, proposals);
766
				break;
763
			default:
767
			default:
764
		}
768
		}
765
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
769
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {

Return to bug 90140