Keep type annotation on the same line with type in method declaration

This commit is contained in:
Yaroslav Lepenkin
2017-01-11 11:33:23 +03:00
parent f7970d5f7a
commit 616eb95766
2 changed files with 41 additions and 1 deletions
@@ -173,8 +173,12 @@ public class JavaChildWrapArranger {
else if (nodeType == JavaElementType.MODIFIER_LIST) {
if (childType == JavaElementType.ANNOTATION) {
ASTNode prev = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if (prev instanceof PsiKeyword) {
return null;
}
if (isTypeAnnotationOrFalseIfDumb(child)) {
ASTNode prev = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if (prev == null || prev.getElementType() != JavaElementType.ANNOTATION || isTypeAnnotationOrFalseIfDumb(prev)) {
return Wrap.createWrap(WrapType.NONE, false);
}
@@ -3293,5 +3293,41 @@ public void testSCR260() throws Exception {
"};"
);
}
public void testKeepTypeAnnotationNearType() {
doTextTest(
"import java.lang.annotation.ElementType;\n" +
"import java.lang.annotation.Retention;\n" +
"import java.lang.annotation.RetentionPolicy;\n" +
"import java.lang.annotation.Target;\n" +
"\n" +
"@Target(value=ElementType.TYPE_USE)\n" +
"@Retention(value= RetentionPolicy.RUNTIME)\n" +
"public @interface X {}\n" +
"class Q {\n" +
" @Override\n" +
" public @X List<Object> objects() {\n" +
" return null;\n" +
" }\n" +
"}",
"import java.lang.annotation.ElementType;\n" +
"import java.lang.annotation.Retention;\n" +
"import java.lang.annotation.RetentionPolicy;\n" +
"import java.lang.annotation.Target;\n" +
"\n" +
"@Target(value = ElementType.TYPE_USE)\n" +
"@Retention(value = RetentionPolicy.RUNTIME)\n" +
"public @interface X {\n" +
"}\n" +
"\n" +
"class Q {\n" +
" @Override\n" +
" public @X List<Object> objects() {\n" +
" return null;\n" +
" }\n" +
"}"
);
}
}