View | Details | Raw Unified | Return to bug 105668 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java (-1 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 673-678 Link Here
673
	}
673
	}
674
674
675
	/**
675
	/**
676
	 * Returns the variable binding of the node's parent <code>VariableDeclarationStatement</code>
677
	 * or <code>SingleVariableDeclaration</code> or <code>VariableDeclarationExpression</code> or
678
	 * <code>null</code> if node is not inside any of these.
679
	 * 
680
	 * @param node the ast node
681
	 * @return the variable binding of the node's parent <code>VariableDeclarationStatement</code>
682
	 *         or <code>SingleVariableDeclaration</code> or
683
	 *         <code>VariableDeclarationExpression</code> or <code>null</code> if node is not inside
684
	 *         any of these
685
	 * @since 3.6
686
	 */
687
	public static ASTNode findParentVariableDeclaration(ASTNode node) {
688
		while (node != null) {
689
			if (node instanceof BodyDeclaration)
690
				return null;
691
			if (node instanceof VariableDeclarationStatement || node instanceof SingleVariableDeclaration
692
					|| node instanceof VariableDeclarationExpression) {
693
				return node;
694
			}
695
			node= node.getParent();
696
		}
697
		return null;
698
	}
699
700
	/**
676
	 * Returns the method binding of the node's parent method declaration or <code>null</code> if
701
	 * Returns the method binding of the node's parent method declaration or <code>null</code> if
677
	 * the node is not inside a method.
702
	 * the node is not inside a method.
678
	 * 
703
	 * 
Lines 700-705 Link Here
700
		return node;
725
		return node;
701
	}
726
	}
702
727
728
	/**
729
	 * Returns the parent <code>AnonymousClassDeclaration</code> for the node if it exists or
730
	 * <code>null</code> otherwise.
731
	 * 
732
	 * @param node the ast node
733
	 * @return the parent <code>AnonymousClassDeclaration</code> for the node if it exists or
734
	 *         <code>null</code> otherwise
735
	 * @since 3.6
736
	 */
737
	public static ASTNode findParentAnonymousClassDeclaration(ASTNode node) {
738
		int nodeType= ASTNode.ANONYMOUS_CLASS_DECLARATION;
739
		while ((node != null) && (node.getNodeType() != nodeType)) {
740
			if (node instanceof BodyDeclaration && !(node instanceof Initializer))
741
				return null;
742
			node= node.getParent();
743
		}
744
		return node;
745
	}
746
703
	public static Statement findParentStatement(ASTNode node) {
747
	public static Statement findParentStatement(ASTNode node) {
704
		while ((node != null) && (!(node instanceof Statement))) {
748
		while ((node != null) && (!(node instanceof Statement))) {
705
			node= node.getParent();
749
			node= node.getParent();
(-)ui/org/eclipse/jdt/internal/ui/text/correction/SuppressWarningsSubProcessor.java (-5 / +31 lines)
Lines 47-52 Link Here
47
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
47
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
48
import org.eclipse.jdt.core.dom.StringLiteral;
48
import org.eclipse.jdt.core.dom.StringLiteral;
49
import org.eclipse.jdt.core.dom.TypeDeclaration;
49
import org.eclipse.jdt.core.dom.TypeDeclaration;
50
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
50
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
51
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
51
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
52
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
52
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
53
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
Lines 106-128 Link Here
106
		if (node == null) {
107
		if (node == null) {
107
			return;
108
			return;
108
		}
109
		}
110
		boolean isProposalAddedForVariable= false;
109
		if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY) {
111
		if (node.getLocationInParent() == VariableDeclarationFragment.NAME_PROPERTY) {
110
			ASTNode parent= node.getParent();
112
			ASTNode parent= node.getParent();
111
			if (parent.getLocationInParent() == VariableDeclarationStatement.FRAGMENTS_PROPERTY) {
113
			if (parent.getLocationInParent() == VariableDeclarationStatement.FRAGMENTS_PROPERTY) {
112
				addSuppressWarningsProposal(context.getCompilationUnit(), parent.getParent(), warningToken, -2, proposals);
114
				addSuppressWarningsProposal(context.getCompilationUnit(), parent.getParent(), warningToken, -2, proposals);
113
				return;
115
				isProposalAddedForVariable= true;
114
			}
116
			}
115
		} else if (node.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY) {
117
		} else if (node.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY) {
116
			addSuppressWarningsProposal(context.getCompilationUnit(), node.getParent(), warningToken, -2, proposals);
118
			addSuppressWarningsProposal(context.getCompilationUnit(), node.getParent(), warningToken, -2, proposals);
117
			return;
119
			isProposalAddedForVariable= true;
118
		} else if (node.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
120
		} else if (node.getLocationInParent() == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
121
			ASTNode target= ASTResolving.findParentVariableDeclaration(node);
122
			if (target != null) {
123
				addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals);
124
				isProposalAddedForVariable= true;
125
			}
119
			node= ASTResolving.findParentBodyDeclaration(node);
126
			node= ASTResolving.findParentBodyDeclaration(node);
120
			if (node instanceof FieldDeclaration) {
127
		}
121
				node= node.getParent();
128
		ASTNode target;
129
		if (!isProposalAddedForVariable) {
130
			target= ASTResolving.findParentVariableDeclaration(node);
131
			if (target != null) {
132
				addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals);
133
				isProposalAddedForVariable= true;
134
			}
135
		}
136
		if (isProposalAddedForVariable) {
137
			target= ASTResolving.findParentAnonymousClassDeclaration(node);
138
			if (target != null) {
139
				target= ASTResolving.findParentVariableDeclaration(target);
140
				if (target != null) {
141
					addSuppressWarningsProposal(context.getCompilationUnit(), target, warningToken, -2, proposals);
142
					return;
143
				}
122
			}
144
			}
123
		}
145
		}
124
146
125
		ASTNode target= ASTResolving.findParentBodyDeclaration(node);
147
		target= ASTResolving.findParentBodyDeclaration(node);
126
		if (target instanceof Initializer) {
148
		if (target instanceof Initializer) {
127
			target= ASTResolving.findParentBodyDeclaration(target.getParent());
149
			target= ASTResolving.findParentBodyDeclaration(target.getParent());
128
		}
150
		}
Lines 299-304 Link Here
299
				property= EnumConstantDeclaration.MODIFIERS2_PROPERTY;
321
				property= EnumConstantDeclaration.MODIFIERS2_PROPERTY;
300
				name= ((EnumConstantDeclaration) node).getName().getIdentifier();
322
				name= ((EnumConstantDeclaration) node).getName().getIdentifier();
301
				break;
323
				break;
324
			case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
325
				property= VariableDeclarationExpression.MODIFIERS2_PROPERTY;
326
				name= (getFirstFragmentName(((VariableDeclarationExpression)node).fragments()));
327
				break;			
302
			default:
328
			default:
303
				JavaPlugin.logErrorMessage("SuppressWarning quick fix: wrong node kind: " + node.getNodeType()); //$NON-NLS-1$
329
				JavaPlugin.logErrorMessage("SuppressWarning quick fix: wrong node kind: " + node.getNodeType()); //$NON-NLS-1$
304
				return;
330
				return;
(-)ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java (-13 / +45 lines)
Lines 6559-6565 Link Here
6559
		ArrayList proposals= collectCorrections(cu, astRoot);
6559
		ArrayList proposals= collectCorrections(cu, astRoot);
6560
6560
6561
		assertCorrectLabels(proposals);
6561
		assertCorrectLabels(proposals);
6562
		assertNumberOfProposals(proposals, 3);
6562
		assertNumberOfProposals(proposals, 4);
6563
6563
6564
		String[] expected= new String[1];
6564
		String[] expected= new String[1];
6565
		buf= new StringBuffer();
6565
		buf= new StringBuffer();
Lines 6599-6605 Link Here
6599
		ArrayList proposals= collectCorrections(cu, astRoot);
6599
		ArrayList proposals= collectCorrections(cu, astRoot);
6600
6600
6601
		assertCorrectLabels(proposals);
6601
		assertCorrectLabels(proposals);
6602
		assertNumberOfProposals(proposals, 3);
6602
		assertNumberOfProposals(proposals, 4);
6603
6603
6604
		String[] expected= new String[1];
6604
		String[] expected= new String[1];
6605
		buf= new StringBuffer();
6605
		buf= new StringBuffer();
Lines 6783-6798 Link Here
6783
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
6783
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
6784
6784
6785
		assertCorrectLabels(proposals);
6785
		assertCorrectLabels(proposals);
6786
		assertNumberOfProposals(proposals, 3);
6786
		assertNumberOfProposals(proposals, 4);
6787
6787
6788
		String[] expected= new String[2];
6788
		String[] expected= new String[3];
6789
6789
6790
		buf= new StringBuffer();
6790
		buf= new StringBuffer();
6791
		buf.append("package pack;\n");
6791
		buf.append("package pack;\n");
6792
		buf.append("import java.util.List;\n");
6792
		buf.append("import java.util.List;\n");
6793
		buf.append("public class E {\n");
6793
		buf.append("public class E {\n");
6794
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
6795
		buf.append("    public void test() {\n");
6794
		buf.append("    public void test() {\n");
6795
		buf.append("        @SuppressWarnings(\"rawtypes\")\n");
6796
		buf.append("        List l;\n");
6796
		buf.append("        List l;\n");
6797
		buf.append("    }\n");
6797
		buf.append("    }\n");
6798
		buf.append("}\n");
6798
		buf.append("}\n");
Lines 6802-6813 Link Here
6802
		buf.append("package pack;\n");
6802
		buf.append("package pack;\n");
6803
		buf.append("import java.util.List;\n");
6803
		buf.append("import java.util.List;\n");
6804
		buf.append("public class E {\n");
6804
		buf.append("public class E {\n");
6805
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
6805
		buf.append("    public void test() {\n");
6806
		buf.append("    public void test() {\n");
6806
		buf.append("        List<?> l;\n");
6807
		buf.append("        List l;\n");
6807
		buf.append("    }\n");
6808
		buf.append("    }\n");
6808
		buf.append("}\n");
6809
		buf.append("}\n");
6809
		expected[1]= buf.toString();
6810
		expected[1]= buf.toString();
6810
6811
6812
		buf= new StringBuffer();
6813
		buf.append("package pack;\n");
6814
		buf.append("import java.util.List;\n");
6815
		buf.append("public class E {\n");
6816
		buf.append("    public void test() {\n");
6817
		buf.append("        List<?> l;\n");
6818
		buf.append("    }\n");
6819
		buf.append("}\n");
6820
		expected[2]= buf.toString();
6821
6811
		assertExpectedExistInProposals(proposals, expected);
6822
		assertExpectedExistInProposals(proposals, expected);
6812
	}
6823
	}
6813
6824
Lines 6831-6846 Link Here
6831
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
6842
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
6832
6843
6833
		assertCorrectLabels(proposals);
6844
		assertCorrectLabels(proposals);
6834
		assertNumberOfProposals(proposals, 3);
6845
		assertNumberOfProposals(proposals, 4);
6835
6846
6836
		String[] expected= new String[2];
6847
		String[] expected= new String[3];
6837
6848
6838
		buf= new StringBuffer();
6849
		buf= new StringBuffer();
6839
		buf.append("package pack;\n");
6850
		buf.append("package pack;\n");
6840
		buf.append("public class E {\n");
6851
		buf.append("public class E {\n");
6841
		buf.append("    private class E1<P1, P2> {}\n");
6852
		buf.append("    private class E1<P1, P2> {}\n");
6842
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
6843
		buf.append("    public void test() {\n");
6853
		buf.append("    public void test() {\n");
6854
		buf.append("        @SuppressWarnings(\"rawtypes\")\n");
6844
		buf.append("        E1 e1;\n");
6855
		buf.append("        E1 e1;\n");
6845
		buf.append("    }\n");
6856
		buf.append("    }\n");
6846
		buf.append("}\n");
6857
		buf.append("}\n");
Lines 6850-6861 Link Here
6850
		buf.append("package pack;\n");
6861
		buf.append("package pack;\n");
6851
		buf.append("public class E {\n");
6862
		buf.append("public class E {\n");
6852
		buf.append("    private class E1<P1, P2> {}\n");
6863
		buf.append("    private class E1<P1, P2> {}\n");
6864
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
6853
		buf.append("    public void test() {\n");
6865
		buf.append("    public void test() {\n");
6854
		buf.append("        E1<?, ?> e1;\n");
6866
		buf.append("        E1 e1;\n");
6855
		buf.append("    }\n");
6867
		buf.append("    }\n");
6856
		buf.append("}\n");
6868
		buf.append("}\n");
6857
		expected[1]= buf.toString();
6869
		expected[1]= buf.toString();
6858
6870
6871
		buf= new StringBuffer();
6872
		buf.append("package pack;\n");
6873
		buf.append("public class E {\n");
6874
		buf.append("    private class E1<P1, P2> {}\n");
6875
		buf.append("    public void test() {\n");
6876
		buf.append("        E1<?, ?> e1;\n");
6877
		buf.append("    }\n");
6878
		buf.append("}\n");
6879
		expected[2]= buf.toString();
6880
6859
		assertExpectedExistInProposals(proposals, expected);
6881
		assertExpectedExistInProposals(proposals, expected);
6860
	}
6882
	}
6861
6883
Lines 7227-7236 Link Here
7227
		CompilationUnit astRoot= getASTRoot(cu);
7249
		CompilationUnit astRoot= getASTRoot(cu);
7228
		ArrayList proposals= collectCorrections(cu, astRoot);
7250
		ArrayList proposals= collectCorrections(cu, astRoot);
7229
		
7251
		
7230
		assertNumberOfProposals(proposals, 2);
7252
		assertNumberOfProposals(proposals, 3);
7231
		assertCorrectLabels(proposals);
7253
		assertCorrectLabels(proposals);
7232
7254
7233
		String[] expected= new String[1];
7255
		String[] expected= new String[2];
7256
		buf= new StringBuffer();
7257
		buf.append("package test1;\n");
7258
		buf.append("import java.util.List;\n");
7259
		buf.append("\n");
7260
		buf.append("public class E1 {\n");
7261
		buf.append("    public void foo(@SuppressWarnings(\"rawtypes\") List<List> list) {\n");
7262
		buf.append("    }\n");
7263
		buf.append("}\n");
7264
		expected[0]= buf.toString();
7265
7234
		buf= new StringBuffer();
7266
		buf= new StringBuffer();
7235
		buf.append("package test1;\n");
7267
		buf.append("package test1;\n");
7236
		buf.append("import java.util.List;\n");
7268
		buf.append("import java.util.List;\n");
Lines 7240-7246 Link Here
7240
		buf.append("    public void foo(List<List> list) {\n");
7272
		buf.append("    public void foo(List<List> list) {\n");
7241
		buf.append("    }\n");
7273
		buf.append("    }\n");
7242
		buf.append("}\n");
7274
		buf.append("}\n");
7243
		expected[0]= buf.toString();
7275
		expected[1]= buf.toString();
7244
7276
7245
		assertExpectedExistInProposals(proposals, expected);
7277
		assertExpectedExistInProposals(proposals, expected);
7246
	}
7278
	}
(-)ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java (-7 / +329 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 2538-2545 Link Here
2538
		CompilationUnit astRoot= getASTRoot(cu);
2538
		CompilationUnit astRoot= getASTRoot(cu);
2539
2539
2540
		ArrayList proposals= collectCorrections(cu, astRoot);
2540
		ArrayList proposals= collectCorrections(cu, astRoot);
2541
		assertNumberOfProposals(proposals, 3);
2541
		assertNumberOfProposals(proposals, 4);
2542
		assertCorrectLabels(proposals);
2542
		assertCorrectLabels(proposals);
2543
		String[] expected= new String[2];
2544
		buf= new StringBuffer();
2545
		buf.append("package test1;\n");
2546
		buf.append("public class E {\n");
2547
		buf.append("    static {\n");
2548
		buf.append("        @SuppressWarnings({\"unused\", \"nls\"}) String str= \"foo\";");
2549
		buf.append("    }\n");
2550
		buf.append("}\n");
2551
		expected[0]= buf.toString();
2543
2552
2544
		buf= new StringBuffer();
2553
		buf= new StringBuffer();
2545
		buf.append("package test1;\n");
2554
		buf.append("package test1;\n");
Lines 2549-2555 Link Here
2549
		buf.append("        @SuppressWarnings(\"unused\") String str= \"foo\";");
2558
		buf.append("        @SuppressWarnings(\"unused\") String str= \"foo\";");
2550
		buf.append("    }\n");
2559
		buf.append("    }\n");
2551
		buf.append("}\n");
2560
		buf.append("}\n");
2552
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
2561
		expected[1]= buf.toString();
2562
		assertExpectedExistInProposals(proposals, expected);
2553
	}
2563
	}
2554
2564
2555
	public void testSuppressNLSWarningAnnotation2() throws Exception {
2565
	public void testSuppressNLSWarningAnnotation2() throws Exception {
Lines 2577-2584 Link Here
2577
		buf= new StringBuffer();
2587
		buf= new StringBuffer();
2578
		buf.append("package test1; \n");
2588
		buf.append("package test1; \n");
2579
		buf.append("public class E {\n");
2589
		buf.append("public class E {\n");
2580
		buf.append("    @SuppressWarnings(\"nls\")\n");
2581
		buf.append("    private class Q {\n");
2590
		buf.append("    private class Q {\n");
2591
		buf.append("        @SuppressWarnings(\"nls\")\n");
2582
		buf.append("        String s = \"\";\n");
2592
		buf.append("        String s = \"\";\n");
2583
		buf.append("    }\n");
2593
		buf.append("    }\n");
2584
		buf.append("}\n");
2594
		buf.append("}\n");
Lines 2607-2614 Link Here
2607
2617
2608
		buf= new StringBuffer();
2618
		buf= new StringBuffer();
2609
		buf.append("package test1; \n");
2619
		buf.append("package test1; \n");
2610
		buf.append("@SuppressWarnings(\"nls\")\n");
2611
		buf.append("public class E {\n");
2620
		buf.append("public class E {\n");
2621
		buf.append("    @SuppressWarnings(\"nls\")\n");
2612
		buf.append("    String s = \"\";\n");
2622
		buf.append("    String s = \"\";\n");
2613
		buf.append("}\n");
2623
		buf.append("}\n");
2614
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
2624
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
Lines 2633-2640 Link Here
2633
		CompilationUnit astRoot= getASTRoot(cu);
2643
		CompilationUnit astRoot= getASTRoot(cu);
2634
2644
2635
		ArrayList proposals= collectCorrections(cu, astRoot);
2645
		ArrayList proposals= collectCorrections(cu, astRoot);
2636
		assertNumberOfProposals(proposals, 3);
2646
		assertNumberOfProposals(proposals, 4);
2637
		assertCorrectLabels(proposals);
2647
		assertCorrectLabels(proposals);
2648
		String[] expected= new String[2];
2649
		buf= new StringBuffer();
2650
		buf.append("package test1; \n");
2651
		buf.append("public class E {\n");
2652
		buf.append("    public void foo() {\n");
2653
		buf.append("        @SuppressWarnings({\"unused\", \"nls\"}) String s = \"\";\n");
2654
		buf.append("    }\n");
2655
		buf.append("}\n");
2656
		expected[0]= buf.toString();
2638
2657
2639
		buf= new StringBuffer();
2658
		buf= new StringBuffer();
2640
		buf.append("package test1; \n");
2659
		buf.append("package test1; \n");
Lines 2644-2650 Link Here
2644
		buf.append("        @SuppressWarnings(\"unused\") String s = \"\";\n");
2663
		buf.append("        @SuppressWarnings(\"unused\") String s = \"\";\n");
2645
		buf.append("    }\n");
2664
		buf.append("    }\n");
2646
		buf.append("}\n");
2665
		buf.append("}\n");
2647
		assertExpectedExistInProposals(proposals, new String[] {buf.toString()});
2666
		expected[1]= buf.toString();
2667
		assertExpectedExistInProposals(proposals, expected);
2648
	}
2668
	}
2649
2669
2650
	public void testSuppressNLSWarningAnnotation5() throws Exception {
2670
	public void testSuppressNLSWarningAnnotation5() throws Exception {
Lines 2688-2693 Link Here
2688
		assertExpectedExistInProposals(proposals, expected);
2708
		assertExpectedExistInProposals(proposals, expected);
2689
	}
2709
	}
2690
2710
2711
	public void testSuppressWarningsForLocalVariables() throws Exception {
2712
		Hashtable options= JavaCore.getOptions();
2713
		options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
2714
		options.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.WARNING);
2715
		JavaCore.setOptions(options);
2716
2717
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2718
		StringBuffer buf= new StringBuffer();
2719
		buf.append("package test1; \n");
2720
		buf.append("import java.util.ArrayList;\n");
2721
		buf.append("\n");
2722
		buf.append("public class A {\n");
2723
		buf.append("    public void foo() {\n");
2724
		buf.append("         @SuppressWarnings(\"unused\")\n");
2725
		buf.append("         ArrayList localVar= new ArrayList();");
2726
		buf.append("    }\n");
2727
		buf.append("}\n");
2728
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2729
2730
		CompilationUnit astRoot= getASTRoot(cu);
2731
		ArrayList proposals= collectCorrections(cu, astRoot, 2);
2732
2733
		assertCorrectLabels(proposals);
2734
		assertNumberOfProposals(proposals, 4);
2735
		String[] expected= new String[2];
2736
		buf= new StringBuffer();
2737
		buf.append("package test1; \n");
2738
		buf.append("import java.util.ArrayList;\n");
2739
		buf.append("\n");
2740
		buf.append("public class A {\n");
2741
		buf.append("    public void foo() {\n");
2742
		buf.append("         @SuppressWarnings({\"unused\", \"rawtypes\"})\n");
2743
		buf.append("         ArrayList localVar= new ArrayList();");
2744
		buf.append("    }\n");
2745
		buf.append("}\n");
2746
		expected[0]= buf.toString();
2747
2748
		buf= new StringBuffer();
2749
		buf.append("package test1; \n");
2750
		buf.append("import java.util.ArrayList;\n");
2751
		buf.append("\n");
2752
		buf.append("public class A {\n");
2753
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
2754
		buf.append("    public void foo() {\n");
2755
		buf.append("         @SuppressWarnings(\"unused\")\n");
2756
		buf.append("         ArrayList localVar= new ArrayList();");
2757
		buf.append("    }\n");
2758
		buf.append("}\n");
2759
		expected[1]= buf.toString();
2760
2761
		assertExpectedExistInProposals(proposals, expected);
2762
	}
2763
2764
	public void testSuppressWarningsForFieldVariables() throws Exception {
2765
		Hashtable options= JavaCore.getOptions();
2766
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
2767
		JavaCore.setOptions(options);
2768
2769
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2770
		StringBuffer buf= new StringBuffer();
2771
		buf.append("package test1; \n");
2772
		buf.append("import java.util.*;\n");
2773
		buf.append("\n");
2774
		buf.append("public class A {\n");
2775
		buf.append("    List<String> myList = new ArrayList();\n");
2776
		buf.append("}\n");
2777
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2778
2779
		CompilationUnit astRoot= getASTRoot(cu);
2780
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
2781
2782
		assertCorrectLabels(proposals);
2783
		assertNumberOfProposals(proposals, 3);
2784
2785
		String[] expected= new String[1];
2786
		buf= new StringBuffer();
2787
		buf.append("package test1; \n");
2788
		buf.append("import java.util.*;\n");
2789
		buf.append("\n");
2790
		buf.append("public class A {\n");
2791
		buf.append("    @SuppressWarnings(\"unchecked\")\n");
2792
		buf.append("    List<String> myList = new ArrayList();\n");
2793
		buf.append("}\n");
2794
		expected[0]= buf.toString();
2795
2796
		assertExpectedExistInProposals(proposals, expected);
2797
	}
2798
2799
	public void testSuppressWarningsForFieldVariables2() throws Exception {
2800
		Hashtable options= JavaCore.getOptions();
2801
		options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
2802
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
2803
		JavaCore.setOptions(options);
2804
2805
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2806
		StringBuffer buf= new StringBuffer();
2807
		buf.append("package test1; \n");
2808
		buf.append("import java.util.ArrayList;\n");
2809
		buf.append("\n");
2810
		buf.append("class A {\n");
2811
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
2812
		buf.append("    ArrayList array;\n");
2813
		buf.append("    boolean a= array.add(1), b= array.add(1);\n");
2814
		buf.append("}\n");
2815
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2816
2817
		CompilationUnit astRoot= getASTRoot(cu);
2818
		ArrayList proposals= collectCorrections(cu, astRoot, 2);
2819
2820
		assertCorrectLabels(proposals);
2821
		assertNumberOfProposals(proposals, 3);
2822
2823
		String[] expected= new String[1];
2824
		buf= new StringBuffer();
2825
		buf.append("package test1; \n");
2826
		buf.append("import java.util.ArrayList;\n");
2827
		buf.append("\n");
2828
		buf.append("class A {\n");
2829
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
2830
		buf.append("    ArrayList array;\n");
2831
		buf.append("    @SuppressWarnings(\"unchecked\")\n");
2832
		buf.append("    boolean a= array.add(1), b= array.add(1);\n");
2833
		buf.append("}\n");
2834
		expected[0]= buf.toString();
2835
2836
		assertExpectedExistInProposals(proposals, expected);
2837
2838
	}
2839
2840
	public void testSuppressWarningsForMethodParameters() throws Exception {
2841
		Hashtable options= JavaCore.getOptions();
2842
		options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
2843
		JavaCore.setOptions(options);
2844
2845
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2846
		StringBuffer buf= new StringBuffer();
2847
		buf.append("package test1; \n");
2848
		buf.append("import java.util.*;\n");
2849
		buf.append("\n");
2850
		buf.append("public class A {\n");
2851
		buf.append("    public int foo(int param1, List param2) {\n");
2852
		buf.append("         return param1;\n");
2853
		buf.append("    }\n");
2854
		buf.append("}\n");
2855
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2856
2857
		CompilationUnit astRoot= getASTRoot(cu);
2858
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
2859
2860
		assertCorrectLabels(proposals);
2861
		assertNumberOfProposals(proposals, 4);
2862
		String[] expected= new String[2];
2863
		buf= new StringBuffer();
2864
		buf.append("package test1; \n");
2865
		buf.append("import java.util.*;\n");
2866
		buf.append("\n");
2867
		buf.append("public class A {\n");
2868
		buf.append("    public int foo(int param1, @SuppressWarnings(\"rawtypes\") List param2) {\n");
2869
		buf.append("         return param1;\n");
2870
		buf.append("    }\n");
2871
		buf.append("}\n");
2872
		expected[0]= buf.toString();
2873
2874
		buf= new StringBuffer();
2875
		buf.append("package test1; \n");
2876
		buf.append("import java.util.*;\n");
2877
		buf.append("\n");
2878
		buf.append("public class A {\n");
2879
		buf.append("    @SuppressWarnings(\"rawtypes\")\n");
2880
		buf.append("    public int foo(int param1, List param2) {\n");
2881
		buf.append("         return param1;\n");
2882
		buf.append("    }\n");
2883
		buf.append("}\n");
2884
		expected[1]= buf.toString();
2885
		assertExpectedExistInProposals(proposals, expected);
2886
2887
	}
2888
2889
	public void testSuppressWarningsAnonymousClass1() throws Exception {
2890
		Hashtable options= JavaCore.getOptions();
2891
		options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
2892
		JavaCore.setOptions(options);
2893
2894
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2895
		StringBuffer buf= new StringBuffer();
2896
		buf.append("package test1; \n");
2897
		buf.append("import java.util.*;\n");
2898
		buf.append("\n");
2899
		buf.append("public class A {\n");
2900
		buf.append("    public void foo() {\n");
2901
		buf.append("        @SuppressWarnings(\"unused\")\n");
2902
		buf.append("        final Object object = new Object() {\n");
2903
		buf.append("            {\n");
2904
		buf.append("                for (List l = new ArrayList(), x = new Vector();;) {\n");
2905
		buf.append("                    if (l == x)\n");
2906
		buf.append("                        break;\n");
2907
		buf.append("                }\n");
2908
		buf.append("            }\n");
2909
		buf.append("        };\n");
2910
		buf.append("    };\n");
2911
		buf.append("};\n");
2912
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2913
2914
		CompilationUnit astRoot= getASTRoot(cu);
2915
		ArrayList proposals= collectCorrections(cu, astRoot, 3);
2916
2917
		assertCorrectLabels(proposals);
2918
		assertNumberOfProposals(proposals, 4);
2919
		String[] expected= new String[2];
2920
		buf= new StringBuffer();
2921
		buf.append("package test1; \n");
2922
		buf.append("import java.util.*;\n");
2923
		buf.append("\n");
2924
		buf.append("public class A {\n");
2925
		buf.append("    public void foo() {\n");
2926
		buf.append("        @SuppressWarnings(\"unused\")\n");
2927
		buf.append("        final Object object = new Object() {\n");
2928
		buf.append("            {\n");
2929
		buf.append("                for (@SuppressWarnings(\"rawtypes\")\n");
2930
		buf.append("                List l = new ArrayList(), x = new Vector();;) {\n");
2931
		buf.append("                    if (l == x)\n");
2932
		buf.append("                        break;\n");
2933
		buf.append("                }\n");
2934
		buf.append("            }\n");
2935
		buf.append("        };\n");
2936
		buf.append("    };\n");
2937
		buf.append("};\n");
2938
		expected[0]= buf.toString();
2939
2940
		buf= new StringBuffer();
2941
		buf.append("package test1; \n");
2942
		buf.append("import java.util.*;\n");
2943
		buf.append("\n");
2944
		buf.append("public class A {\n");
2945
		buf.append("    public void foo() {\n");
2946
		buf.append("        @SuppressWarnings({\"unused\", \"rawtypes\"})\n");
2947
		buf.append("        final Object object = new Object() {\n");
2948
		buf.append("            {\n");
2949
		buf.append("                for (List l = new ArrayList(), x = new Vector();;) {\n");
2950
		buf.append("                    if (l == x)\n");
2951
		buf.append("                        break;\n");
2952
		buf.append("                }\n");
2953
		buf.append("            }\n");
2954
		buf.append("        };\n");
2955
		buf.append("    };\n");
2956
		buf.append("};\n");
2957
		expected[1]= buf.toString();
2958
2959
		assertExpectedExistInProposals(proposals, expected);
2960
	}
2961
2962
	public void testSuppressWarningsAnonymousClass2() throws Exception {
2963
		Hashtable options= JavaCore.getOptions();
2964
		options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
2965
		JavaCore.setOptions(options);
2966
2967
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2968
		StringBuffer buf= new StringBuffer();
2969
		buf.append("package test1; \n");
2970
		buf.append("import java.util.*;\n");
2971
		buf.append("\n");
2972
		buf.append("public class A {\n");
2973
		buf.append("    final Runnable r= new Runnable() {\n");
2974
		buf.append("        public void run() {\n");
2975
		buf.append("            boolean b;\n");
2976
		buf.append("            for (b = new ArrayList().add(1);;) {\n");
2977
		buf.append("                if (b)\n");
2978
		buf.append("                    return;\n");
2979
		buf.append("                        break;\n");
2980
		buf.append("            }\n");
2981
		buf.append("        }\n");
2982
		buf.append("    };\n");
2983
		buf.append("}\n");
2984
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null);
2985
2986
		CompilationUnit astRoot= getASTRoot(cu);
2987
		ArrayList proposals= collectCorrections(cu, astRoot, 1);
2988
2989
		assertCorrectLabels(proposals);
2990
		assertNumberOfProposals(proposals, 2);
2991
		String[] expected= new String[1];
2992
		buf= new StringBuffer();
2993
		buf.append("package test1; \n");
2994
		buf.append("import java.util.*;\n");
2995
		buf.append("\n");
2996
		buf.append("public class A {\n");
2997
		buf.append("    final Runnable r= new Runnable() {\n");
2998
		buf.append("        @SuppressWarnings(\"unchecked\")\n");
2999
		buf.append("        public void run() {\n");
3000
		buf.append("            boolean b;\n");
3001
		buf.append("            for (b = new ArrayList().add(1);;) {\n");
3002
		buf.append("                if (b)\n");
3003
		buf.append("                    return;\n");
3004
		buf.append("                        break;\n");
3005
		buf.append("            }\n");
3006
		buf.append("        }\n");
3007
		buf.append("    };\n");
3008
		buf.append("}\n");
3009
		expected[0]= buf.toString();
3010
3011
		assertExpectedExistInProposals(proposals, expected);
3012
	}
2691
	public void testMisspelledSuppressToken() throws Exception {
3013
	public void testMisspelledSuppressToken() throws Exception {
2692
		IPackageFragment pack1= fSourceFolder.createPackageFragment("a", false, null);
3014
		IPackageFragment pack1= fSourceFolder.createPackageFragment("a", false, null);
2693
		StringBuffer buf= new StringBuffer();
3015
		StringBuffer buf= new StringBuffer();

Return to bug 105668