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 (+85 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> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.ui.tests.quickfix;
15
package org.eclipse.jdt.ui.tests.quickfix;
15
16
Lines 9173-9178 Link Here
9173
		assertExpectedExistInProposals(proposals, expected);
9174
		assertExpectedExistInProposals(proposals, expected);
9174
	}
9175
	}
9175
9176
9177
	public void testReplaceWithUnqualifiedEnumConstant1() throws Exception {
9178
		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("        }\n");
9189
		buf.append("    }\n");
9190
		buf.append("}\n");
9191
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
9192
9193
		CompilationUnit astRoot= getASTRoot(cu);
9194
		ArrayList proposals= collectCorrections(cu, astRoot, 2, 1);
9195
9196
		assertNumberOfProposals(proposals, 1);
9197
		assertCorrectLabels(proposals);
9198
9199
		CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0);
9200
		String preview= getPreviewContent(proposal);
9201
9202
		buf= new StringBuffer();
9203
		buf.append("package pack;\n");
9204
		buf.append("public class E {\n");
9205
		buf.append("    public enum color {black, white}\n");
9206
		buf.append("    public void foo(color c) {\n");
9207
		buf.append("		switch (c) {\n");
9208
		buf.append("            case black:\n");
9209
		buf.append("                System.out.println(\"Black\");\n");
9210
		buf.append("                break;\n");
9211
		buf.append("        }\n");
9212
		buf.append("    }\n");
9213
		buf.append("}\n");
9214
		assertEqualString(preview, buf.toString());
9215
		String expected= buf.toString();
9216
		assertExpectedExistInProposals(proposals, new String[] { expected });
9217
	}
9218
9219
	public void testReplaceWithUnqualifiedEnumConstant2() throws Exception {
9220
		IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null);
9221
		StringBuffer buf= new StringBuffer();
9222
		buf.append("package pack;\n");
9223
		buf.append("public class E {\n");
9224
		buf.append("    public enum color {black, white}\n");
9225
		buf.append("    public void foo(color c) {\n");
9226
		buf.append("		switch (c) {\n");
9227
		buf.append("            case (color.black):\n");
9228
		buf.append("                System.out.println(\"Black\");\n");
9229
		buf.append("                break;\n");
9230
		buf.append("        }\n");
9231
		buf.append("    }\n");
9232
		buf.append("}\n");
9233
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
9234
9235
		CompilationUnit astRoot= getASTRoot(cu);
9236
		ArrayList proposals= collectCorrections(cu, astRoot, 3, 2);
9237
9238
		assertNumberOfProposals(proposals, 1);
9239
		assertCorrectLabels(proposals);
9240
9241
		CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0);
9242
		String preview= getPreviewContent(proposal);
9243
9244
		buf= new StringBuffer();
9245
		buf.append("package pack;\n");
9246
		buf.append("public class E {\n");
9247
		buf.append("    public enum color {black, white}\n");
9248
		buf.append("    public void foo(color c) {\n");
9249
		buf.append("		switch (c) {\n");
9250
		buf.append("            case black:\n");
9251
		buf.append("                System.out.println(\"Black\");\n");
9252
		buf.append("                break;\n");
9253
		buf.append("        }\n");
9254
		buf.append("    }\n");
9255
		buf.append("}\n");
9256
		assertEqualString(preview, buf.toString());
9257
		String expected= buf.toString();
9258
		assertExpectedExistInProposals(proposals, new String[] { expected });
9259
	}
9260
9176
	public void testCollectionsFieldMethodReplacement() throws Exception {
9261
	public void testCollectionsFieldMethodReplacement() throws Exception {
9177
		Hashtable options= JavaCore.getOptions();
9262
		Hashtable options= JavaCore.getOptions();
9178
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
9263
		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 (+2 lines)
Lines 10-15 Link Here
10
 *     Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
10
 *     Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
11
 *     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
11
 *     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
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> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.ui.text.correction;
15
package org.eclipse.jdt.internal.ui.text.correction;
15
16
Lines 392-397 Link Here
392
	public static String LocalCorrectionsSubProcessor_insert_cases_omitted;
393
	public static String LocalCorrectionsSubProcessor_insert_cases_omitted;
393
	public static String LocalCorrectionsSubProcessor_insert_fall_through;
394
	public static String LocalCorrectionsSubProcessor_insert_fall_through;
394
	public static String LocalCorrectionsSubProcessor_override_hashCode_description;
395
	public static String LocalCorrectionsSubProcessor_override_hashCode_description;
396
	public static String LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant;
395
	public static String LocalCorrectionsSubProcessor_throw_allocated_description;
397
	public static String LocalCorrectionsSubProcessor_throw_allocated_description;
396
	public static String SuppressWarningsSubProcessor_fix_suppress_token_label;
398
	public static String SuppressWarningsSubProcessor_fix_suppress_token_label;
397
	public static String SuppressWarningsSubProcessor_remove_annotation_label;
399
	public static String SuppressWarningsSubProcessor_remove_annotation_label;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties (+2 lines)
Lines 10-15 Link Here
10
#     Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
10
#     Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250
11
#     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
11
#     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
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> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
13
###############################################################################
14
###############################################################################
14
15
15
# ------ SerialVersionProposal
16
# ------ SerialVersionProposal
Lines 117-122 Link Here
117
LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}''
118
LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}''
118
LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object
119
LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object
119
LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object
120
LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object
121
LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant=Replace with unqualified enum constant ''{0}''
120
TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}''
122
TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}''
121
TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}''
123
TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}''
122
TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}''
124
TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}''
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java (+2 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
10
 *     Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632
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
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.internal.ui.text.correction;
14
package org.eclipse.jdt.internal.ui.text.correction;
14
15
Lines 180-185 Link Here
180
	public static final int CORRECT_PACKAGE_DECLARATION= 5;
181
	public static final int CORRECT_PACKAGE_DECLARATION= 5;
181
	public static final int TYPE_ARGUMENTS_FROM_CONTEXT= 5;
182
	public static final int TYPE_ARGUMENTS_FROM_CONTEXT= 5;
182
	public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5;
183
	public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5;
184
	public static final int REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT= 5;
183
185
184
	public static final int ADD_MISSING_TAG= 4;
186
	public static final int ADD_MISSING_TAG= 4;
185
	public static final int INSERT_FALL_THROUGH= 4;
187
	public static final int INSERT_FALL_THROUGH= 4;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java (+23 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> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.ui.text.correction;
15
package org.eclipse.jdt.internal.ui.text.correction;
15
16
Lines 766-771 Link Here
766
767
767
	}
768
	}
768
769
770
	public static void addIllegalQualifiedEnumConstantLabelProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
771
		ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
772
773
		ASTNode curr= coveringNode;
774
		while (curr instanceof ParenthesizedExpression) {
775
			curr= ((ParenthesizedExpression) curr).getExpression();
776
		}
777
778
		if (!(curr instanceof QualifiedName)) {
779
			return;
780
		}
781
782
		SimpleName simpleName= ((QualifiedName) curr).getName();
783
		final ASTRewrite rewrite= ASTRewrite.create(curr.getAST());
784
		rewrite.replace(coveringNode, simpleName, null);
785
786
		String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant, BasicElementLabels.getJavaElementName(simpleName.getIdentifier()));
787
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
788
		ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT, image);
789
		proposals.add(proposal);
790
	}
791
769
	public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
792
	public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
770
		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
793
		ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
771
		selectedNode= ASTNodes.getNormalizedNode(selectedNode);
794
		selectedNode= ASTNodes.getNormalizedNode(selectedNode);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java (+5 lines)
Lines 14-19 Link Here
14
 *								[quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086
14
 *								[quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086
15
 *								[quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555
15
 *								[quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555
16
 *     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
16
 *     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
17
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140
17
 *******************************************************************************/
18
 *******************************************************************************/
18
package org.eclipse.jdt.internal.ui.text.correction;
19
package org.eclipse.jdt.internal.ui.text.correction;
19
20
Lines 161-166 Link Here
161
			case IProblem.DuplicateMethod:
162
			case IProblem.DuplicateMethod:
162
			case IProblem.DuplicateTypeVariable:
163
			case IProblem.DuplicateTypeVariable:
163
			case IProblem.DuplicateNestedType:
164
			case IProblem.DuplicateNestedType:
165
			case IProblem.IllegalQualifiedEnumConstantLabel:
164
			case IProblem.IllegalModifierForInterfaceMethod:
166
			case IProblem.IllegalModifierForInterfaceMethod:
165
			case IProblem.IllegalModifierForInterfaceMethod18:
167
			case IProblem.IllegalModifierForInterfaceMethod18:
166
			case IProblem.IllegalModifierForInterface:
168
			case IProblem.IllegalModifierForInterface:
Lines 760-765 Link Here
760
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
762
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
761
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
763
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
762
				break;
764
				break;
765
			case IProblem.IllegalQualifiedEnumConstantLabel:
766
				LocalCorrectionsSubProcessor.addIllegalQualifiedEnumConstantLabelProposal(context, problem, proposals);
767
				break;
763
			default:
768
			default:
764
		}
769
		}
765
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
770
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {

Return to bug 90140