1 /* 2 SuppressWarningsFilter 3 4 com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder 5 aliasList = com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=paramnum 6 7 com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck 8 id = ignore 9 format = (default)^[a-z][a-zA-Z0-9]*$ 10 applyToPublic = (default)true 11 applyToProtected = (default)true 12 applyToPackage = (default)true 13 applyToPrivate = (default)true 14 15 com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck 16 id = 17 format = (default)^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ 18 applyToPublic = (default)true 19 applyToProtected = (default)true 20 applyToPackage = (default)true 21 applyToPrivate = (default)true 22 23 com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck 24 id = ignore 25 excludedClasses = (default)^$ 26 27 com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck 28 max = (default)7 29 ignoreOverriddenMethods = (default)false 30 tokens = (default)METHOD_DEF, CTOR_DEF 31 32 com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck 33 illegalClassNames = (default)Error, Exception, RuntimeException, Throwable, java.lang.Error, \ 34 java.lang.Exception, java.lang.RuntimeException, java.lang.Throwable 35 36 com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck 37 scope = PRIVATE 38 excludeScope = (default)null 39 skipAnnotations = (default)Generated 40 tokens = (default)INTERFACE_DEF, CLASS_DEF, ENUM_DEF, ANNOTATION_DEF, RECORD_DEF 41 42 */ 43 package com.puppycrawl.tools.checkstyle.filters.suppresswarningsfilter; 44 /** @author Trevor Robinson */ 45 @SuppressWarnings("foo") // coverage: no following AST 46 class InputSuppressWarningsFilter { 47 // AST coverage 48 @SuppressWarnings("foo") interface I { } // violation 'Missing a Javadoc comment' 49 @SuppressWarnings("foo") enum E { } // violation 'Missing a Javadoc comment' 50 @SuppressWarnings("foo") InputSuppressWarningsFilter() { } 51 @SuppressWarnings("foo") @interface A { } // violation 'Missing a Javadoc comment' 52 53 // include a non-checkstyle suppression; suppression on same line 54 @SuppressWarnings("unused") int I; // violation ''I' must match .* \Q'^[a-z][a-zA-Z0-9]*$'\E' 55 @SuppressWarnings({"membername"}) 56 private int J; // filtered violation 'Name 'J' must match pattern \Q'^[a-z][a-zA-Z0-9]*$'\E' 57 private int K; // violation 'Name 'K' must match pattern \Q'^[a-z][a-zA-Z0-9]*$'\E' 58 59 // DO NOT REFORMAT: L and X should be on the same line 60 @SuppressWarnings(value="membername") 61 private int L; private int X; // violation 62 // filtered violation above 63 64 // test "checkstyle:" prefix 65 @SuppressWarnings("checkstyle:ConstantName") 66 private static final int m = 0; // filtered violation 67 private static final int n = 0; // violation 68 69 // test explicit warning alias 70 @SuppressWarnings("paramnum") 71 // should NOT fail ParameterNumberCheck 72 void foo(@SuppressWarnings("unused") int a, // filtered violation 'More than 7 param.* (.* 8)' 73 int b, int c, int d, int e, int f, int g, int h) { 74 @SuppressWarnings("unused") int z; 75 try { } 76 catch (Exception ex) { // violation 'Catching 'Exception' is not allowed' 77 // should fail IllegalCatchCheck 78 } 79 } 80 81 // test fully qualified annotation name 82 @java.lang.SuppressWarnings("illegalCatch") 83 public void needsToCatchException() { 84 try { } 85 catch (Exception ex) { // filtered violation 'Catching 'Exception' is not allowed' 86 // should NOT fail IllegalCatchCheck 87 } 88 } 89 90 enum AnEnum { // violation 'Missing a Javadoc comment' 91 @SuppressWarnings("rawtypes") 92 ELEMENT; 93 } 94 private static final String UNUSED="UnusedDeclaration"; 95 96 @SuppressWarnings(UNUSED) 97 public void annotationUsingStringConstantValue(){ } 98 99 @SuppressWarnings("checkstyle:uncommentedmain") // filtered violation 'Uncommented main method' 100 public static void main(String[] args) { } 101 102 static class TestClass1 { // violation 'Missing a Javadoc comment' 103 @SuppressWarnings("uncommentedmain") // filtered violation 'Uncommented main method found' 104 public static void main(String[] args) { } 105 } 106 107 static class TestClass2 { // violation 'Missing a Javadoc comment' 108 @SuppressWarnings("UncommentedMain") // filtered violation 'Uncommented main method found' 109 public static void main(String[] args) { } 110 } 111 112 static class TestClass3 { // violation 'Missing a Javadoc comment' 113 @SuppressWarnings("checkstyle:UncommentedMain") // filtered violation 'Uncomm.* main method' 114 public static void main(String[] args) { } 115 } 116 117 @SuppressWarnings("checkstyle:javadoctype") // violation 'Missing a Javadoc comment' 118 public static abstract class Task { } 119 }