feat: add indents for annotation defs (#4828)

- Add indent for `@interface` and `@Annotation(...)`
- Add notes for indent queries
This commit is contained in:
Pham Huy Hoang 2023-06-04 13:28:41 +09:00 committed by GitHub
parent 79aedc9675
commit 1281601cb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 9 deletions

View file

@ -1,13 +1,17 @@
[
(class_body)
(enum_body)
(interface_body)
(constructor_body)
(block)
(switch_block)
(array_initializer)
(argument_list)
(formal_parameters)
; ... refers to the portion that this indent query will have effects on
(class_body) ; { ... } of `class X`
(enum_body) ; { ... } of `enum X`
(interface_body) ; { ... } of `interface X`
(constructor_body) ; { `modifier` X() {...} } inside `class X`
(annotation_type_body) ; { ... } of `@interface X`
(block) ; { ... } that's not mentioned in this scope
(switch_block) ; { ... } in `switch X`
(array_initializer) ; [1, 2]
(argument_list) ; foo(...)
(formal_parameters) ; method foo(...)
(annotation_argument_list) ; @Annotation(...)
(element_value_array_initializer) ; { a, b } inside @Annotation()
] @indent.begin
(expression_statement (method_invocation) @indent.begin)
@ -21,6 +25,7 @@
"]"
] @indent.branch
(annotation_argument_list ")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`
"}" @indent.end
(line_comment) @indent.ignore

View file

@ -0,0 +1,3 @@
abstract public @interface Foo {
abstract public String Bar();
}

View file

@ -0,0 +1,8 @@
@ContextConfiguration(
classes = {
WireMockConfig.class,
}
)
public class Foo {
}

View file

@ -33,5 +33,7 @@ describe("indent Java:", function()
run:new_line("method_chaining.java", { on_line = 4, text = '.append("b");', indent = 6 })
run:new_line("constructor_with_arguments_on_multiple_lines.java", { on_line = 4, text = "}", indent = 2 })
run:new_line("method_with_arguments_on_multiple_lines.java", { on_line = 4, text = "}", indent = 2 })
run:new_line("annotation.java", { on_line = 1, text = "abstract public Foo(){}", indent = 2 })
run:new_line("annotation_2.java", { on_line = 2, text = "Bar.class", indent = 4 })
end)
end)