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#3117: Add ability to differentiate annotation placem…
…ent in foreach, for loops, parameter definition
- Loading branch information
Showing
4 changed files
with
164 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
50 changes: 50 additions & 0 deletions
50
...resources/com/puppycrawl/tools/checkstyle/checks/annotation/InputAnnotationLocation4.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,50 @@ | ||
package com.puppycrawl.tools.checkstyle.checks.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
public class InputAnnotationLocation4 { | ||
@Deprecated // <--class, separate line | ||
public class Annotation | ||
{ | ||
@Deprecated // <--method, separate line | ||
public void test(@MyAnnotation String s) { // <--parameter, same line | ||
@MyAnnotation // <--variable, separate line | ||
Integer i; | ||
for (@MyAnnotation char c : s.toCharArray()) { // <--variable in for each, same line | ||
} | ||
} | ||
} | ||
|
||
public class Test { | ||
public void foo1() { | ||
try { | ||
// some code | ||
} | ||
catch (@MyAnnotation Exception ex) { | ||
|
||
} | ||
} | ||
|
||
public void foo2() { | ||
for (@MyAnnotation int i = 0; i < 10; i++) { | ||
|
||
} | ||
} | ||
|
||
public void foo3() { | ||
MathOperation c = (@MyAnnotation int a, @MyAnnotation int b) -> a + b; | ||
} | ||
|
||
public void foo4(@MyAnnotation int a, @MyAnnotation int b) {} | ||
|
||
public void foo5(@SuppressWarnings("unchecked") int a) {} | ||
} | ||
|
||
interface MathOperation { | ||
int operation(int a, int b); | ||
} | ||
|
||
@Target(ElementType.TYPE_USE) | ||
public @interface MyAnnotation {} | ||
} |
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