Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #12486: NoWhitespaceAfter shouldn't check synchronized method
- Loading branch information
Showing
5 changed files
with
96 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
...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,59 @@ | ||
/* | ||
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; | ||
} | ||
|
||
// Note that we do not check 'synchronized' as a modifier, | ||
// convention is to have type parameters of a generic method | ||
// be surrounded by whitespace. | ||
synchronized <T2> void m9() {} // ok | ||
synchronized<T2> void m10() {} // ok | ||
} | ||
|
||
@Target(ElementType.METHOD) | ||
@interface SyncAnno { | ||
} |
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