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(); |