From 44346360a8a70423aa4e633989e44cb187bbb2db Mon Sep 17 00:00:00 2001 From: Axel Howind Date: Mon, 11 Nov 2024 13:30:02 +0100 Subject: [PATCH] allow whitespace in annotation on module declaration --- .../groovy/org/beryx/jlink/util/Util.groovy | 2 +- .../groovy/org/beryx/jlink/UtilSpec.groovy | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/org/beryx/jlink/util/Util.groovy b/src/main/groovy/org/beryx/jlink/util/Util.groovy index 5cbb7af7..5e92fbd7 100644 --- a/src/main/groovy/org/beryx/jlink/util/Util.groovy +++ b/src/main/groovy/org/beryx/jlink/util/Util.groovy @@ -68,7 +68,7 @@ class Util { private static final String IMPORT_DECLARATION = 'import' + IGNORE + '(static' + IGNORE + ')?' + QUALIFIED_NAME + '(\\.\\*' + ')?' + IGNORE + ';' private static final String IMPORT_DECLARATIONS = '(' + IMPORT_DECLARATION + IGNORE + ')*' - private static final String ANNOTATION = '(@' + QUALIFIED_NAME + '((' + WS + ')*(\\([^)]*\\)))?)' + private static final String ANNOTATION = '(@' + IGNORE + QUALIFIED_NAME + '((' + IGNORE + ')(\\([^)]*\\)))?)' private static final String MODULE_ANNOTATIONS = '(' + ANNOTATION + IGNORE + ')*' private static final String MODULE_DECLARATION = '(?s)' + IGNORE + IMPORT_DECLARATIONS + MODULE_ANNOTATIONS + '(open' + IGNORE + ')?' + 'module' + IGNORE + '(?' + QUALIFIED_NAME + ').*?' diff --git a/src/test/groovy/org/beryx/jlink/UtilSpec.groovy b/src/test/groovy/org/beryx/jlink/UtilSpec.groovy index bd5db361..94c43cb8 100644 --- a/src/test/groovy/org/beryx/jlink/UtilSpec.groovy +++ b/src/test/groovy/org/beryx/jlink/UtilSpec.groovy @@ -44,15 +44,17 @@ class UtilSpec extends Specification { Util.getModuleNameFrom(text) == moduleName where: - text | moduleName - 'module a.b.c\n{' | 'a.b.c' - 'open module a.b.c{}' | 'a.b.c' - ' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c' - '/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c' - 'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c' - 'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' - 'import x.y.z.*;\n@Annotation\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' - 'import x.y.z.*;\n@Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' + text | moduleName + 'module a.b.c\n{' | 'a.b.c' + 'open module a.b.c{}' | 'a.b.c' + ' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c' + '/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c' + 'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c' + 'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' + 'import x.y.z.*;\n@Annotation\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' + 'import x.y.z.*;\n@Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' + 'import x.y.z.*;\n@ Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' + 'import x.y.z.*;\n@Annotation\n(\n var = "text"\n)\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c' } @Unroll