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 220032 Details for
Bug 216898
[quick fix] QuickFix proposes wrong visibility for overriding/overridden method
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]
Increase visibility if overriding method is private
bug_216898.patch (text/plain), 7.86 KB, created by
rgra Missing name
on 2012-08-18 14:15:05 EDT
(
hide
)
Description:
Increase visibility if overriding method is private
Filename:
MIME Type:
Creator:
rgra Missing name
Created:
2012-08-18 14:15:05 EDT
Size:
7.86 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java >index bc8c1f6..89993e9 100644 >--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java >+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] 'Remove invalid modifiers' does not appear for enums and annotations - https://bugs.eclipse.org/bugs/show_bug.cgi?id=110589 > * Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250 >+ * Rabea Gransberger <rgransberger@gmx.de> - [quick fix] QuickFix proposes wrong visibility for overriding/overridden method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=216898 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.quickfix; > >@@ -1655,6 +1656,45 @@ > buf.append("}\n"); > assertEqualString(preview, buf.toString()); > } >+ >+ public void testOverridingMethodIsPrivate() throws Exception { >+ IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null); >+ >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test2;\n"); >+ buf.append("public class C {\n"); >+ buf.append(" protected void foo() {\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ pack2.createCompilationUnit("C.java", buf.toString(), false, null); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import test2.C;\n"); >+ buf.append("public class E extends C {\n"); >+ buf.append(" private void foo() {\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); >+ assertNumberOfProposals(proposals, 1); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); >+ String preview= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import test2.C;\n"); >+ buf.append("public class E extends C {\n"); >+ buf.append(" protected void foo() {\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } > > public void testOverridesStaticMethod() throws Exception { > IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null); >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java >index ca25949..7ecb176 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessor.java >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] 'Remove invalid modifiers' does not appear for enums and annotations - https://bugs.eclipse.org/bugs/show_bug.cgi?id=110589 > * Benjamin Muskalla <b.muskalla@gmx.net> - [quick fix] Quick fix for missing synchronized modifier - https://bugs.eclipse.org/bugs/show_bug.cgi?id=245250 >+ * Rabea Gransberger <rgransberger@gmx.de> - [quick fix] QuickFix proposes wrong visibility for overriding/overridden method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=216898 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -257,35 +258,54 @@ > overriddenInClass= Bindings.findOverriddenMethodInType(curr, method); > } > if (overriddenInClass != null) { >- IMethodBinding overriddenDecl= overriddenInClass.getMethodDeclaration(); >- ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, context.getASTRoot(), overriddenDecl.getDeclaringClass()); >- if (targetCU != null) { >- String methodLabel= BasicElementLabels.getJavaElementName(curr.getName() + '.' + overriddenInClass.getName()); >- String label; >- int excludedModifiers; >- int includedModifiers; >- switch (kind) { >- case TO_VISIBLE: >+ final IMethodBinding overriddenDecl= overriddenInClass.getMethodDeclaration(); >+ final ICompilationUnit overriddenMethodCU= ASTResolving.findCompilationUnitForBinding(cu, context.getASTRoot(), overriddenDecl.getDeclaringClass()); >+ >+ IMethodBinding targetMethod= overriddenDecl; >+ ICompilationUnit targetCU= overriddenMethodCU; >+ >+ String methodLabel= BasicElementLabels.getJavaElementName(overriddenDecl.getDeclaringClass().getName() + '.' + overriddenDecl.getName()); >+ String label; >+ int excludedModifiers; >+ int includedModifiers; >+ switch (kind) { >+ case TO_VISIBLE: >+ if (JdtFlags.isPrivate(method)) { >+ // Propose to increase the visibility of this method, because decreasing to private is not possible. >+ targetMethod= method; >+ targetCU= cu; >+ >+ methodLabel= BasicElementLabels.getJavaElementName(method.getDeclaringClass().getName() + '.' + method.getName()); >+ >+ excludedModifiers= Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC; >+ includedModifiers= JdtFlags.getVisibilityCode(overriddenDecl); >+ } >+ else { > excludedModifiers= Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC; > includedModifiers= JdtFlags.getVisibilityCode(method); >- label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changeoverriddenvisibility_description, new String[] { methodLabel, getVisibilityString(includedModifiers) }); >- break; >- case TO_NON_FINAL: >- label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemethodtononfinal_description, methodLabel); >- excludedModifiers= Modifier.FINAL; >- includedModifiers= 0; >- break; >- case TO_NON_STATIC: >- label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemethodtononstatic_description, methodLabel); >- excludedModifiers= Modifier.STATIC; >- includedModifiers= 0; >- break; >- default: >- Assert.isTrue(false, "not supported"); //$NON-NLS-1$ >- return; >- } >+ } >+ label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changeoverriddenvisibility_description, >+ new String[] { methodLabel, getVisibilityString(includedModifiers) }); >+ break; >+ case TO_NON_FINAL: >+ label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemethodtononfinal_description, methodLabel); >+ excludedModifiers= Modifier.FINAL; >+ includedModifiers= 0; >+ break; >+ case TO_NON_STATIC: >+ label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemethodtononstatic_description, methodLabel); >+ excludedModifiers= Modifier.STATIC; >+ includedModifiers= 0; >+ break; >+ default: >+ Assert.isTrue(false, "not supported"); //$NON-NLS-1$ >+ return; >+ } >+ >+ if (targetCU != null) { > Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >- proposals.add(new ModifierChangeCorrectionProposal(label, targetCU, overriddenDecl, selectedNode, includedModifiers, excludedModifiers, IProposalRelevance.CHANGE_OVERRIDDEN_MODIFIER_2, image)); >+ proposals.add(new ModifierChangeCorrectionProposal(label, targetCU, targetMethod, selectedNode, includedModifiers, excludedModifiers, >+ IProposalRelevance.CHANGE_OVERRIDDEN_MODIFIER_2, image)); > } > } > }
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 216898
: 220032