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 181829 Details for
Bug 328481
[quick fix] Adjust quick fixes for unused variable/field/param to improved problem detection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
fix + tests
quickfix1.txt (text/plain), 8.09 KB, created by
Deepak Azad
on 2010-10-27 09:15:18 EDT
(
hide
)
Description:
fix + tests
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2010-10-27 09:15:18 EDT
Size:
8.09 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java,v >retrieving revision 1.42 >diff -u -r1.42 UnusedCodeFix.java >--- core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java 2 Nov 2009 13:25:19 -0000 1.42 >+++ core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java 27 Oct 2010 13:14:00 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 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 >@@ -324,6 +324,14 @@ > } > } > } >+ } else if (nameParentType == ASTNode.POSTFIX_EXPRESSION || nameParentType == ASTNode.PREFIX_EXPRESSION) { >+ Expression expression= (Expression)parent; >+ ASTNode expressionParent= expression.getParent(); >+ if (expressionParent.getNodeType() == ASTNode.EXPRESSION_STATEMENT) { >+ rewrite.remove(expressionParent, group); >+ } else { >+ rewrite.remove(expression, group); >+ } > } > } > >#P org.eclipse.jdt.ui.tests >Index: ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java,v >retrieving revision 1.167 >diff -u -r1.167 LocalCorrectionsQuickFixTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 23 Oct 2010 11:28:16 -0000 1.167 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 27 Oct 2010 13:14:03 -0000 >@@ -3352,6 +3352,67 @@ > assertExpectedExistInProposals(proposals, expected); > } > >+ public void testUnusedPrivateFieldBug328481() throws Exception { >+ Hashtable hashtable= JavaCore.getOptions(); >+ hashtable.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); >+ JavaCore.setOptions(hashtable); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private int count;\n"); >+ buf.append(" void foo(){;\n"); >+ buf.append(" count++;\n"); >+ buf.append(" count--;\n"); >+ buf.append(" --count;\n"); >+ buf.append(" ++count;\n"); >+ buf.append(" for ( ; ; count++) {\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); >+ assertNumberOfProposals(proposals, 2); >+ assertCorrectLabels(proposals); >+ >+ String[] expected= new String[2]; >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo(){;\n"); >+ buf.append(" for ( ; ;) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private int count;\n"); >+ buf.append(" void foo(){;\n"); >+ buf.append(" setCount(getCount() + 1);\n"); >+ buf.append(" setCount(getCount() - 1);\n"); >+ buf.append(" setCount(getCount() - 1);\n"); >+ buf.append(" setCount(getCount() + 1);\n"); >+ buf.append(" for ( ; ; count++) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" public int getCount() {\n"); >+ buf.append(" return count;\n"); >+ buf.append(" }\n"); >+ buf.append(" public void setCount(int count) {\n"); >+ buf.append(" this.count = count;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[1]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } > > public void testUnusedVariable() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); >@@ -3540,7 +3601,7 @@ > assertEqualString(preview, buf.toString()); > } > >- public void testUnusedVariables5() throws Exception { >+ public void testUnusedVariable5() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); >@@ -3582,7 +3643,7 @@ > > } > >- public void testUnusedVariables6() throws Exception { >+ public void testUnusedVariable6() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); >@@ -3630,7 +3691,7 @@ > } > > >- public void testUnusedVariables7() throws Exception { >+ public void testUnusedVariable7() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER, JavaCore.ERROR); >@@ -3682,7 +3743,7 @@ > assertExpectedExistInProposals(proposals, expected); > } > >- public void testUnusedVariables8() throws Exception { >+ public void testUnusedVariable8() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); > JavaCore.setOptions(hashtable); >@@ -3739,8 +3800,58 @@ > assertExpectedExistInProposals(proposals, expected); > } > >+ public void testUnusedVariableBug328481() throws Exception { >+ Hashtable hashtable= JavaCore.getOptions(); >+ hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); >+ hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER, JavaCore.ERROR); >+ JavaCore.setOptions(hashtable); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private void foo() {\n"); >+ buf.append(" int a= 10;\n"); >+ buf.append(" a++;\n"); >+ buf.append(" a--;\n"); >+ buf.append(" --a;\n"); >+ buf.append(" ++a;\n"); >+ buf.append(" for ( ; ; a++) {\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); >+ assertNumberOfProposals(proposals, 2); >+ assertCorrectLabels(proposals); >+ >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private void foo() {\n"); >+ buf.append(" for ( ; ;) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private void foo() {\n"); >+ buf.append(" for ( ; ;) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[1]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } > >- public void testUnusedVariablesAsSwitchStatement() throws Exception { >+ public void testUnusedVariableAsSwitchStatement() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); > hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER, JavaCore.ERROR);
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 328481
:
181829
|
181841