forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#14424: Added option to skip HideUtilityClassConstruc…
…torCheck validation based on list of annotations
- Loading branch information
1 parent
a4b0fc7
commit 8684faa
Showing
10 changed files
with
351 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...esign/hideutilityclassconstructor/InputHideUtilityClassConstructorIgnoreAnnotationBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
HideUtilityClassConstructor | ||
ignoreAnnotatedBy = Skip, SkipWithParam, SkipWithAnnotationAsParam | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.design.hideutilityclassconstructor; | ||
|
||
@Skip | ||
public class InputHideUtilityClassConstructorIgnoreAnnotationBy { | ||
public static void func() {} | ||
} | ||
|
||
@SkipWithParam(name = "tool1") | ||
class ToolClass1 { | ||
public static void func() {} | ||
} | ||
|
||
@SkipWithAnnotationAsParam(skip = @Skip) | ||
class ToolClass2 { | ||
public static void func() {} | ||
} | ||
|
||
@CommonAnnot | ||
@Skip | ||
class ToolClass3 { | ||
public static void func() {} | ||
} | ||
|
||
@CommonAnnot // violation, should not have a public or default constructor | ||
class ToolClass4 { | ||
public static void func() {} | ||
} | ||
|
||
|
||
@interface Skip {} | ||
|
||
@interface SkipWithParam { | ||
String name(); | ||
} | ||
|
||
@interface SkipWithAnnotationAsParam { | ||
Skip skip(); | ||
} | ||
|
||
@interface CommonAnnot {} |
19 changes: 19 additions & 0 deletions
19
...lassconstructor/InputHideUtilityClassConstructorIgnoreAnnotationByFullyQualifiedName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
HideUtilityClassConstructor | ||
ignoreAnnotatedBy = java.lang.Deprecated | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.design.hideutilityclassconstructor; | ||
|
||
@Deprecated // violation, should not have a public or default constructor | ||
public class InputHideUtilityClassConstructorIgnoreAnnotationByFullyQualifiedName { | ||
public static void func() {} | ||
} | ||
|
||
@java.lang.Deprecated | ||
class DeprecatedClass { | ||
public static void func() {} | ||
} | ||
|
||
@interface Deprecated {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...s/com/puppycrawl/tools/checkstyle/checks/design/hideutilityclassconstructor/Example2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*xml | ||
<module name="Checker"> | ||
<module name="TreeWalker"> | ||
<module name="HideUtilityClassConstructor"> | ||
<property name="ignoreAnnotatedBy" | ||
value="SpringBootApplication, java.lang.Deprecated" /> | ||
</module> | ||
</module> | ||
</module> | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.design.hideutilityclassconstructor; | ||
|
||
// xdoc section -- start | ||
// ok below, skipped by annotation | ||
@java.lang.Deprecated | ||
class Example2 { | ||
|
||
public Example2() { | ||
} | ||
|
||
public static void fun() { | ||
} | ||
} | ||
|
||
class Foo2 { | ||
|
||
private Foo2() { | ||
} | ||
|
||
static int n; | ||
} | ||
|
||
class Bar2 { | ||
|
||
protected Bar2() { | ||
// prevents calls from subclass | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
||
@Deprecated // violation, 'should not have a public or default constructor' | ||
class UtilityClass2 { | ||
|
||
static float f; | ||
} | ||
// ok below, skipped by annotation | ||
@SpringBootApplication | ||
class Application2 { | ||
|
||
public static void main(String[] args) { | ||
} | ||
} | ||
// xdoc section -- end |
Oops, something went wrong.