forked from checkstyle/checkstyle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#12486: NoWhitespaceAfter don't check synchronized me…
…thod
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
...ls/checkstyle/checks/whitespace/nowhitespaceafter/InputNoWhitespaceAfterSynchronized.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,53 @@ | ||
/* | ||
NoWhitespaceAfter | ||
allowLineBreaks = (default)true | ||
tokens = LITERAL_SYNCHRONIZED | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.whitespace.nowhitespaceafter; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
public class InputNoWhitespaceAfterSynchronized<T> { | ||
|
||
private final Object lock = new Object(); | ||
|
||
void m1() { | ||
synchronized (lock) {} // violation | ||
synchronized(lock) {} // ok | ||
} | ||
|
||
synchronized int m2() { // ok | ||
return 2; | ||
} | ||
|
||
synchronized private int[] m3() { // ok | ||
return new int[]{2}; | ||
} | ||
|
||
synchronized int[] m4() { // ok | ||
return new int[]{2}; | ||
} | ||
|
||
private final synchronized int m5() { // ok | ||
return 2; | ||
} | ||
|
||
synchronized T m6() { // ok | ||
return null; | ||
} | ||
|
||
@SyncAnno synchronized T m7() { // ok | ||
return null; | ||
} | ||
|
||
@SyncAnno private synchronized T m8() { // ok | ||
return null; | ||
} | ||
} | ||
|
||
@Target(ElementType.METHOD) | ||
@interface SyncAnno { | ||
} |