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 167465 Details for
Bug 105668
[quick fix] place @SuppressWarnings on variables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch_v2 + tests
patch2_105668.txt (text/plain), 27.58 KB, created by
Raksha Vasisht
on 2010-05-07 09:06:18 EDT
(
hide
)
Description:
Patch_v2 + tests
Filename:
MIME Type:
Creator:
Raksha Vasisht
Created:
2010-05-07 09:06:18 EDT
Size:
27.58 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java,v >retrieving revision 1.114 >diff -u -r1.114 ASTResolving.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java 14 Oct 2009 17:59:00 -0000 1.114 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java 7 May 2010 12:53:22 -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 >@@ -673,6 +673,31 @@ > } > > /** >+ * Returns the variable binding of the node's parent <code>VariableDeclarationStatement</code> >+ * or <code>SingleVariableDeclaration</code> or <code>VariableDeclarationExpression</code> or >+ * <code>null</code> if node is not inside any of these. >+ * >+ * @param node the ast node >+ * @return the variable binding of the node's parent <code>VariableDeclarationStatement</code> >+ * or <code>SingleVariableDeclaration</code> or >+ * <code>VariableDeclarationExpression</code> or <code>null</code> if node is not inside >+ * any of these >+ * @since 3.6 >+ */ >+ public static ASTNode findParentVariableDeclaration(ASTNode node) { >+ while (node != null) { >+ if (node instanceof BodyDeclaration) >+ return null; >+ if (node instanceof VariableDeclarationStatement || node instanceof SingleVariableDeclaration >+ || node instanceof VariableDeclarationExpression) { >+ return node; >+ } >+ node= node.getParent(); >+ } >+ return null; >+ } >+ >+ /** > * Returns the method binding of the node's parent method declaration or <code>null</code> if > * the node is not inside a method. > * >@@ -700,6 +725,25 @@ > return node; > } > >+ /** >+ * Returns the parent <code>AnonymousClassDeclaration</code> for the node if it exists or >+ * <code>null</code> otherwise. >+ * >+ * @param node the ast node >+ * @return the parent <code>AnonymousClassDeclaration</code> for the node if it exists or >+ * <code>null</code> otherwise >+ * @since 3.6 >+ */ >+ public static ASTNode findParentAnonymousClassDeclaration(ASTNode node) { >+ int nodeType= ASTNode.ANONYMOUS_CLASS_DECLARATION; >+ while ((node != null) && (node.getNodeType() != nodeType)) { >+ if (node instanceof BodyDeclaration && !(node instanceof Initializer)) >+ return null; >+ node= node.getParent(); >+ } >+ return node; >+ } >+ > public static Statement findParentStatement(ASTNode node) { > while ((node != null) && (!(node instanceof Statement))) { > node= node.getParent(); >Index: ui/org/eclipse/jdt/internal/ui/text/correction/SuppressWarningsSubProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/SuppressWarningsSubProcessor.java,v >retrieving revision 1.15 >diff -u -r1.15 SuppressWarningsSubProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/SuppressWarningsSubProcessor.java 26 Feb 2010 14:35:06 -0000 1.15 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/SuppressWarningsSubProcessor.java 7 May 2010 12:53:22 -0000 >@@ -47,6 +47,7 @@ > import org.eclipse.jdt.core.dom.SingleVariableDeclaration; > import org.eclipse.jdt.core.dom.StringLiteral; > import org.eclipse.jdt.core.dom.TypeDeclaration; >+import org.eclipse.jdt.core.dom.VariableDeclarationExpression; > import org.eclipse.jdt.core.dom.VariableDeclarationFragment; > import org.eclipse.jdt.core.dom.VariableDeclarationStatement; > import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; >@@ -106,23 +107,44 @@ > if (node == null) { > return; > } >+ boolean isProposalAddedForVariable= false; > if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY) { > ASTNode parent= node.getParent(); > if (parent.getLocationInParent() == VariableDeclarationStatement.FRAGMENTS_PROPERTY) { > addSuppressWarningsProposal(context.getCompilationUnit(), parent.getParent(), warningToken, -2, proposals); >- return; >+ isProposalAddedForVariable= true; > } > } else if (node.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY) { > addSuppressWarningsProposal(context.getCompilationUnit(), node.getParent(), warningToken, -2, proposals); >- return; >+ isProposalAddedForVariable= true; > } else if (node.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) { >+ ASTNode target= ASTResolving.findParentVariableDeclaration(node); >+ if (target != null) { >+ addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals); >+ isProposalAddedForVariable= true; >+ } > node= ASTResolving.findParentBodyDeclaration(node); >- if (node instanceof FieldDeclaration) { >- node= node.getParent(); >+ } >+ ASTNode target; >+ if (!isProposalAddedForVariable) { >+ target= ASTResolving.findParentVariableDeclaration(node); >+ if (target != null) { >+ addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals); >+ isProposalAddedForVariable= true; >+ } >+ } >+ if (isProposalAddedForVariable) { >+ target= ASTResolving.findParentAnonymousClassDeclaration(node); >+ if (target != null) { >+ target= ASTResolving.findParentVariableDeclaration(target); >+ if (target != null) { >+ addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals); >+ return; >+ } > } > } > >- ASTNode target= ASTResolving.findParentBodyDeclaration(node); >+ target= ASTResolving.findParentBodyDeclaration(node); > if (target instanceof Initializer) { > target= ASTResolving.findParentBodyDeclaration(target.getParent()); > } >@@ -299,6 +321,10 @@ > property= EnumConstantDeclaration.MODIFIERS2_PROPERTY; > name= ((EnumConstantDeclaration) node).getName().getIdentifier(); > break; >+ case ASTNode.VARIABLE_DECLARATION_EXPRESSION: >+ property= VariableDeclarationExpression.MODIFIERS2_PROPERTY; >+ name= (getFirstFragmentName(((VariableDeclarationExpression)node).fragments())); >+ break; > default: > JavaPlugin.logErrorMessage("SuppressWarning quick fix: wrong node kind: " + node.getNodeType()); //$NON-NLS-1$ > return; >#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.164 >diff -u -r1.164 LocalCorrectionsQuickFixTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 30 Mar 2010 16:36:23 -0000 1.164 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 7 May 2010 12:55:09 -0000 >@@ -6559,7 +6559,7 @@ > ArrayList proposals= collectCorrections(cu, astRoot); > > assertCorrectLabels(proposals); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > > String[] expected= new String[1]; > buf= new StringBuffer(); >@@ -6599,7 +6599,7 @@ > ArrayList proposals= collectCorrections(cu, astRoot); > > assertCorrectLabels(proposals); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > > String[] expected= new String[1]; > buf= new StringBuffer(); >@@ -6783,16 +6783,16 @@ > ArrayList proposals= collectCorrections(cu, astRoot, 1); > > assertCorrectLabels(proposals); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > >- String[] expected= new String[2]; >+ String[] expected= new String[3]; > > buf= new StringBuffer(); > buf.append("package pack;\n"); > buf.append("import java.util.List;\n"); > buf.append("public class E {\n"); >- buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" public void test() {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" List l;\n"); > buf.append(" }\n"); > buf.append("}\n"); >@@ -6802,12 +6802,23 @@ > buf.append("package pack;\n"); > buf.append("import java.util.List;\n"); > buf.append("public class E {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" public void test() {\n"); >- buf.append(" List<?> l;\n"); >+ buf.append(" List l;\n"); > buf.append(" }\n"); > buf.append("}\n"); > expected[1]= buf.toString(); > >+ buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("import java.util.List;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void test() {\n"); >+ buf.append(" List<?> l;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[2]= buf.toString(); >+ > assertExpectedExistInProposals(proposals, expected); > } > >@@ -6831,16 +6842,16 @@ > ArrayList proposals= collectCorrections(cu, astRoot, 1); > > assertCorrectLabels(proposals); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > >- String[] expected= new String[2]; >+ String[] expected= new String[3]; > > buf= new StringBuffer(); > buf.append("package pack;\n"); > buf.append("public class E {\n"); > buf.append(" private class E1<P1, P2> {}\n"); >- buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" public void test() {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" E1 e1;\n"); > buf.append(" }\n"); > buf.append("}\n"); >@@ -6850,12 +6861,23 @@ > buf.append("package pack;\n"); > buf.append("public class E {\n"); > buf.append(" private class E1<P1, P2> {}\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); > buf.append(" public void test() {\n"); >- buf.append(" E1<?, ?> e1;\n"); >+ buf.append(" E1 e1;\n"); > buf.append(" }\n"); > buf.append("}\n"); > expected[1]= buf.toString(); > >+ buf= new StringBuffer(); >+ buf.append("package pack;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private class E1<P1, P2> {}\n"); >+ buf.append(" public void test() {\n"); >+ buf.append(" E1<?, ?> e1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[2]= buf.toString(); >+ > assertExpectedExistInProposals(proposals, expected); > } > >@@ -7227,10 +7249,20 @@ > CompilationUnit astRoot= getASTRoot(cu); > ArrayList proposals= collectCorrections(cu, astRoot); > >- assertNumberOfProposals(proposals, 2); >+ assertNumberOfProposals(proposals, 3); > assertCorrectLabels(proposals); > >- String[] expected= new String[1]; >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import java.util.List;\n"); >+ buf.append("\n"); >+ buf.append("public class E1 {\n"); >+ buf.append(" public void foo(@SuppressWarnings(\"rawtypes\") List<List> list) {\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ > buf= new StringBuffer(); > buf.append("package test1;\n"); > buf.append("import java.util.List;\n"); >@@ -7240,7 +7272,7 @@ > buf.append(" public void foo(List<List> list) {\n"); > buf.append(" }\n"); > buf.append("}\n"); >- expected[0]= buf.toString(); >+ expected[1]= buf.toString(); > > assertExpectedExistInProposals(proposals, expected); > } >Index: ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java,v >retrieving revision 1.58 >diff -u -r1.58 ModifierCorrectionsQuickFixTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java 12 Nov 2009 19:40:58 -0000 1.58 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java 7 May 2010 12:55:11 -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 >@@ -2538,8 +2538,17 @@ > CompilationUnit astRoot= getASTRoot(cu); > > ArrayList proposals= collectCorrections(cu, astRoot); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > assertCorrectLabels(proposals); >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" static {\n"); >+ buf.append(" @SuppressWarnings({\"unused\", \"nls\"}) String str= \"foo\";"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); > > buf= new StringBuffer(); > buf.append("package test1;\n"); >@@ -2549,7 +2558,8 @@ > buf.append(" @SuppressWarnings(\"unused\") String str= \"foo\";"); > buf.append(" }\n"); > buf.append("}\n"); >- assertExpectedExistInProposals(proposals, new String[] {buf.toString()}); >+ expected[1]= buf.toString(); >+ assertExpectedExistInProposals(proposals, expected); > } > > public void testSuppressNLSWarningAnnotation2() throws Exception { >@@ -2577,8 +2587,8 @@ > buf= new StringBuffer(); > buf.append("package test1; \n"); > buf.append("public class E {\n"); >- buf.append(" @SuppressWarnings(\"nls\")\n"); > buf.append(" private class Q {\n"); >+ buf.append(" @SuppressWarnings(\"nls\")\n"); > buf.append(" String s = \"\";\n"); > buf.append(" }\n"); > buf.append("}\n"); >@@ -2607,8 +2617,8 @@ > > buf= new StringBuffer(); > buf.append("package test1; \n"); >- buf.append("@SuppressWarnings(\"nls\")\n"); > buf.append("public class E {\n"); >+ buf.append(" @SuppressWarnings(\"nls\")\n"); > buf.append(" String s = \"\";\n"); > buf.append("}\n"); > assertExpectedExistInProposals(proposals, new String[] {buf.toString()}); >@@ -2633,8 +2643,17 @@ > CompilationUnit astRoot= getASTRoot(cu); > > ArrayList proposals= collectCorrections(cu, astRoot); >- assertNumberOfProposals(proposals, 3); >+ assertNumberOfProposals(proposals, 4); > assertCorrectLabels(proposals); >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings({\"unused\", \"nls\"}) String s = \"\";\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); > > buf= new StringBuffer(); > buf.append("package test1; \n"); >@@ -2644,7 +2663,8 @@ > buf.append(" @SuppressWarnings(\"unused\") String s = \"\";\n"); > buf.append(" }\n"); > buf.append("}\n"); >- assertExpectedExistInProposals(proposals, new String[] {buf.toString()}); >+ expected[1]= buf.toString(); >+ assertExpectedExistInProposals(proposals, expected); > } > > public void testSuppressNLSWarningAnnotation5() throws Exception { >@@ -2688,6 +2708,308 @@ > assertExpectedExistInProposals(proposals, expected); > } > >+ public void testSuppressWarningsForLocalVariables() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); >+ options.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.ArrayList;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings(\"unused\")\n"); >+ buf.append(" ArrayList localVar= new ArrayList();"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 2); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 4); >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.ArrayList;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings({\"unused\", \"rawtypes\"})\n"); >+ buf.append(" ArrayList localVar= new ArrayList();"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.ArrayList;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings(\"unused\")\n"); >+ buf.append(" ArrayList localVar= new ArrayList();"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[1]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } >+ >+ public void testSuppressWarningsForFieldVariables() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" List<String> myList = new ArrayList();\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 1); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 3); >+ >+ String[] expected= new String[1]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" @SuppressWarnings(\"unchecked\")\n"); >+ buf.append(" List<String> myList = new ArrayList();\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } >+ >+ public void testSuppressWarningsForFieldVariables2() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); >+ options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.ArrayList;\n"); >+ buf.append("\n"); >+ buf.append("class A {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); >+ buf.append(" ArrayList array;\n"); >+ buf.append(" boolean a= array.add(1), b= array.add(1);\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 2); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 3); >+ >+ String[] expected= new String[1]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.ArrayList;\n"); >+ buf.append("\n"); >+ buf.append("class A {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); >+ buf.append(" ArrayList array;\n"); >+ buf.append(" @SuppressWarnings(\"unchecked\")\n"); >+ buf.append(" boolean a= array.add(1), b= array.add(1);\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ >+ } >+ >+ public void testSuppressWarningsForMethodParameters() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public int foo(int param1, List param2) {\n"); >+ buf.append(" return param1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 1); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 4); >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public int foo(int param1, @SuppressWarnings(\"rawtypes\") List param2) {\n"); >+ buf.append(" return param1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" @SuppressWarnings(\"rawtypes\")\n"); >+ buf.append(" public int foo(int param1, List param2) {\n"); >+ buf.append(" return param1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ expected[1]= buf.toString(); >+ assertExpectedExistInProposals(proposals, expected); >+ >+ } >+ >+ public void testSuppressWarningsAnonymousClass1() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings(\"unused\")\n"); >+ buf.append(" final Object object = new Object() {\n"); >+ buf.append(" {\n"); >+ buf.append(" for (List l = new ArrayList(), x = new Vector();;) {\n"); >+ buf.append(" if (l == x)\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append(" };\n"); >+ buf.append("};\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 3); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 4); >+ String[] expected= new String[2]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings(\"unused\")\n"); >+ buf.append(" final Object object = new Object() {\n"); >+ buf.append(" {\n"); >+ buf.append(" for (@SuppressWarnings(\"rawtypes\")\n"); >+ buf.append(" List l = new ArrayList(), x = new Vector();;) {\n"); >+ buf.append(" if (l == x)\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append(" };\n"); >+ buf.append("};\n"); >+ expected[0]= buf.toString(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" @SuppressWarnings({\"unused\", \"rawtypes\"})\n"); >+ buf.append(" final Object object = new Object() {\n"); >+ buf.append(" {\n"); >+ buf.append(" for (List l = new ArrayList(), x = new Vector();;) {\n"); >+ buf.append(" if (l == x)\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append(" };\n"); >+ buf.append("};\n"); >+ expected[1]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } >+ >+ public void testSuppressWarningsAnonymousClass2() throws Exception { >+ Hashtable options= JavaCore.getOptions(); >+ options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); >+ JavaCore.setOptions(options); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" final Runnable r= new Runnable() {\n"); >+ buf.append(" public void run() {\n"); >+ buf.append(" boolean b;\n"); >+ buf.append(" for (b = new ArrayList().add(1);;) {\n"); >+ buf.append(" if (b)\n"); >+ buf.append(" return;\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 1); >+ >+ assertCorrectLabels(proposals); >+ assertNumberOfProposals(proposals, 2); >+ String[] expected= new String[1]; >+ buf= new StringBuffer(); >+ buf.append("package test1; \n"); >+ buf.append("import java.util.*;\n"); >+ buf.append("\n"); >+ buf.append("public class A {\n"); >+ buf.append(" final Runnable r= new Runnable() {\n"); >+ buf.append(" @SuppressWarnings(\"unchecked\")\n"); >+ buf.append(" public void run() {\n"); >+ buf.append(" boolean b;\n"); >+ buf.append(" for (b = new ArrayList().add(1);;) {\n"); >+ buf.append(" if (b)\n"); >+ buf.append(" return;\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append("}\n"); >+ expected[0]= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, expected); >+ } > public void testMisspelledSuppressToken() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("a", false, null); > StringBuffer buf= new StringBuffer();
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 105668
:
165827
|
167465
|
167978