diff --git a/src/comments.ts b/src/comments.ts index def3ab94..f7833251 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -279,11 +279,7 @@ function getMemberChainRoot(node: SyntaxNode): SyntaxNode { function handleModifiersComments(commentNode: CommentNode) { const { precedingNode } = commentNode; - if ( - precedingNode?.type === SyntaxType.Annotation || - precedingNode?.type === SyntaxType.MarkerAnnotation || - precedingNode?.type === SyntaxType.Modifiers - ) { + if (precedingNode?.type === SyntaxType.Modifiers) { util.addTrailingComment(precedingNode, commentNode); return true; } diff --git a/test/unit-test/prettier-ignore/annotation/_input.java b/test/unit-test/prettier-ignore/annotation/_input.java new file mode 100644 index 00000000..d7bca42e --- /dev/null +++ b/test/unit-test/prettier-ignore/annotation/_input.java @@ -0,0 +1,36 @@ +public class PrettierIgnoreAnnotation { + + @Marker + // prettier-ignore + @SuppressFBWarnings({ "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", "LEST_LOST_EXCEPTION_STACK_TRACE", "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" }) + @Another({ "a", "b" }) + void method() { + } + + @Marker + /* prettier-ignore */ + @SuppressFBWarnings({ "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", "LEST_LOST_EXCEPTION_STACK_TRACE", "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" }) + int field = 1; + + @Marker + // prettier-ignore + @Other + public static class Nested { + int x; + } + + @Marker + // just a comment + @Other({ "a", "b" }) + void other() {} + + @A({"a" + }) // prettier-ignore + @B({"b" + }) + void sameLine() {} + + @Marker + // comment + class Commented {} +} diff --git a/test/unit-test/prettier-ignore/annotation/_output.java b/test/unit-test/prettier-ignore/annotation/_output.java new file mode 100644 index 00000000..7ae93104 --- /dev/null +++ b/test/unit-test/prettier-ignore/annotation/_output.java @@ -0,0 +1,35 @@ +public class PrettierIgnoreAnnotation { + + @Marker + // prettier-ignore + @SuppressFBWarnings({ "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", "LEST_LOST_EXCEPTION_STACK_TRACE", "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" }) + @Another({ "a", "b" }) + void method() {} + + @Marker + /* prettier-ignore */ + @SuppressFBWarnings({ "AFBR_ABNORMAL_FINALLY_BLOCK_RETURN", "LEST_LOST_EXCEPTION_STACK_TRACE", "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" }) + int field = 1; + + @Marker + // prettier-ignore + @Other + public static class Nested { + + int x; + } + + @Marker + // just a comment + @Other({ "a", "b" }) + void other() {} + + @A({"a" + }) // prettier-ignore + @B({ "b" }) + void sameLine() {} + + @Marker + // comment + class Commented {} +} diff --git a/test/unit-test/prettier-ignore/prettier-ignore-spec.ts b/test/unit-test/prettier-ignore/prettier-ignore-spec.ts index f28b4597..f6f8d463 100644 --- a/test/unit-test/prettier-ignore/prettier-ignore-spec.ts +++ b/test/unit-test/prettier-ignore/prettier-ignore-spec.ts @@ -5,6 +5,7 @@ import { testSample } from "../../test-utils.ts"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); describe("prettier-java: try catch", () => { + testSample(path.resolve(__dirname, "./annotation")); testSample(path.resolve(__dirname, "./block")); testSample(path.resolve(__dirname, "./classDeclaration")); testSample(path.resolve(__dirname, "./method"));