Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 243673 Details for
Bug 90140
[quick fix] for qualified enum constants in switch-case labels
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Updated Patch
bug90140-qualified_enum_const.patch (text/plain), 14.24 KB, created by
Noopur Gupta
on 2014-05-29 06:08:09 EDT
(
hide
)
Description:
Updated Patch
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2014-05-29 06:08:09 EDT
Size:
14.24 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java >index c855562..18b143f 100644 >--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java >+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java >@@ -10,6 +10,7 @@ > * Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature > * 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 > * 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 >+ * Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.quickfix; > >@@ -9173,6 +9174,90 @@ > assertExpectedExistInProposals(proposals, expected); > } > >+ public void testReplaceWithUnqualifiedEnumConstant1() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public enum color {black, white}\n"); >+ buf.append(" public void foo(color c) {\n"); >+ buf.append(" switch (c) {\n"); >+ buf.append(" case color.black:\n"); >+ buf.append(" System.out.println(\"Black\");\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 2, 1); >+ >+ assertNumberOfProposals(proposals, 1); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public enum color {black, white}\n"); >+ buf.append(" public void foo(color c) {\n"); >+ buf.append(" switch (c) {\n"); >+ buf.append(" case black:\n"); >+ buf.append(" System.out.println(\"Black\");\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ String expected= buf.toString(); >+ assertExpectedExistInProposals(proposals, new String[] { expected }); >+ } >+ >+ public void testReplaceWithUnqualifiedEnumConstant2() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public enum color {black, white}\n"); >+ buf.append(" public void foo(color c) {\n"); >+ buf.append(" switch (c) {\n"); >+ buf.append(" case (color.black):\n"); >+ buf.append(" System.out.println(\"Black\");\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 3, 2); >+ >+ assertNumberOfProposals(proposals, 1); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public enum color {black, white}\n"); >+ buf.append(" public void foo(color c) {\n"); >+ buf.append(" switch (c) {\n"); >+ buf.append(" case black:\n"); >+ buf.append(" System.out.println(\"Black\");\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ String expected= buf.toString(); >+ assertExpectedExistInProposals(proposals, new String[] { expected }); >+ } >+ > public void testCollectionsFieldMethodReplacement() throws Exception { > Hashtable options= JavaCore.getOptions(); > options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java >index 146c181..67f3066 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java >@@ -10,6 +10,7 @@ > * Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250 > * Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632 > * 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 >+ * Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -392,6 +393,7 @@ > public static String LocalCorrectionsSubProcessor_insert_cases_omitted; > public static String LocalCorrectionsSubProcessor_insert_fall_through; > public static String LocalCorrectionsSubProcessor_override_hashCode_description; >+ public static String LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant; > public static String LocalCorrectionsSubProcessor_throw_allocated_description; > public static String SuppressWarningsSubProcessor_fix_suppress_token_label; > public static String SuppressWarningsSubProcessor_remove_annotation_label; >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties >index 567ab7c..d15fe54 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties >@@ -10,6 +10,7 @@ > # Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250 > # Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632 > # 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 >+# Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > ############################################################################### > > # ------ SerialVersionProposal >@@ -117,6 +118,7 @@ > LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}'' > LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object > LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object >+LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant=Replace with unqualified enum constant ''{0}'' > TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}'' > TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}'' > TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}'' >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java >index db38590..d74373f 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Billy Huang <billyhuang31@gmail.com> - [quick assist] concatenate/merge string literals - https://bugs.eclipse.org/77632 > * 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 >+ * Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -180,6 +181,7 @@ > public static final int CORRECT_PACKAGE_DECLARATION= 5; > public static final int TYPE_ARGUMENTS_FROM_CONTEXT= 5; > public static final int REMOVE_REDUNDANT_NULLNESS_ANNOTATION= 5; >+ public static final int REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT= 5; > > public static final int ADD_MISSING_TAG= 4; > public static final int INSERT_FALL_THROUGH= 4; >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >index a91c77e..2c77f38 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >@@ -10,6 +10,7 @@ > * Renaud Waldura <renaud+eclipse@waldura.com> - Access to static proposal > * Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature > * 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 >+ * Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -766,6 +767,28 @@ > > } > >+ public static void addIllegalQualifiedEnumConstantLabelProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { >+ ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot()); >+ >+ ASTNode curr= coveringNode; >+ while (curr instanceof ParenthesizedExpression) { >+ curr= ((ParenthesizedExpression) curr).getExpression(); >+ } >+ >+ if (!(curr instanceof QualifiedName)) { >+ return; >+ } >+ >+ SimpleName simpleName= ((QualifiedName) curr).getName(); >+ final ASTRewrite rewrite= ASTRewrite.create(curr.getAST()); >+ rewrite.replace(coveringNode, simpleName, null); >+ >+ String label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_replace_with_unqualified_enum_constant, BasicElementLabels.getJavaElementName(simpleName.getIdentifier())); >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REPLACE_WITH_UNQUALIFIED_ENUM_CONSTANT, image); >+ proposals.add(proposal); >+ } >+ > public static void addUnnecessaryThrownExceptionProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { > ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); > selectedNode= ASTNodes.getNormalizedNode(selectedNode); >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >index 0ef12af..a7eeaa0 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >@@ -14,6 +14,7 @@ > * [quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086 > * [quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555 > * 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 >+ * Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] for qualified enum constants in switch-case labels - https://bugs.eclipse.org/bugs/90140 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -161,6 +162,7 @@ > case IProblem.DuplicateMethod: > case IProblem.DuplicateTypeVariable: > case IProblem.DuplicateNestedType: >+ case IProblem.IllegalQualifiedEnumConstantLabel: > case IProblem.IllegalModifierForInterfaceMethod: > case IProblem.IllegalModifierForInterfaceMethod18: > case IProblem.IllegalModifierForInterface: >@@ -760,6 +762,9 @@ > NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals); > NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals); > break; >+ case IProblem.IllegalQualifiedEnumConstantLabel: >+ LocalCorrectionsSubProcessor.addIllegalQualifiedEnumConstantLabelProposal(context, problem, proposals); >+ break; > default: > } > if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 90140
:
243292
|
243645
| 243673