diff --git a/CHANGES.md b/CHANGES.md index b61f53b4..c5bbf459 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ - Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398) - Fixed object declaration handling [#399](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/399) - Fixed false positives for files with UTF-8 characters when running as vscode-checkstyle [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402) -- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404) +- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404) + [#405](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/405) - Refactored content handling to use Bytes instead of String (should fix [#98](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/98)) [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402) - Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393) - Added unittests for TokenTree structure verification [#400](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/400) diff --git a/src/checkstyle/token/walk/WalkFieldDef.hx b/src/checkstyle/token/walk/WalkFieldDef.hx index a4055fb0..a072c2fb 100644 --- a/src/checkstyle/token/walk/WalkFieldDef.hx +++ b/src/checkstyle/token/walk/WalkFieldDef.hx @@ -13,6 +13,8 @@ class WalkFieldDef { parent = tok; case At: tempStore.push(WalkAt.walkAt(stream)); + case Comment(_), CommentLine(_): + WalkComment.walkComment(stream, parent); default: break; } diff --git a/test/token/TokenTreeBuilderParsingTest.hx b/test/token/TokenTreeBuilderParsingTest.hx index 3e956f45..cc4d7a07 100644 --- a/test/token/TokenTreeBuilderParsingTest.hx +++ b/test/token/TokenTreeBuilderParsingTest.hx @@ -36,6 +36,7 @@ class TokenTreeBuilderParsingTest { assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3); assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY); assertCodeParses(TYPEDEF_COMMENTS); + assertCodeParses(TYPEDEF_COMMENTS_2); } public function assertCodeParses(code:String, ?pos:PosInfos) { @@ -468,4 +469,13 @@ abstract TokenTreeBuilderParsingTests(String) to String { var index:Int; // æ@ð }"; + + var TYPEDEF_COMMENTS_2 = " + typedef CheckFile = { + // ° + var name:String; + var content:String; + // €łµ + var index:Int; + }"; } \ No newline at end of file diff --git a/test/token/verify/VerifyTokenTreeTest.hx b/test/token/verify/VerifyTokenTreeTest.hx index 91aedb6f..1ee23228 100644 --- a/test/token/verify/VerifyTokenTreeTest.hx +++ b/test/token/verify/VerifyTokenTreeTest.hx @@ -106,6 +106,35 @@ class VerifyTokenTreeTest { brOpen.childLast().is(BrClose).noChilds(); } + @Test + public function testTypedefComments2() { + var root:IVerifyTokenTree = buildTokenTree(TokenTreeBuilderParsingTests.TYPEDEF_COMMENTS_2); + + // typedef CheckFile + var type:IVerifyTokenTree = root.childFirst().is(Kwd(KwdTypedef)).oneChild().childFirst().is(Const(CIdent("CheckFile"))); + var brOpen:IVerifyTokenTree = type.childFirst().is(Binop(OpAssign)).oneChild().childFirst().is(BrOpen).childCount(6); + brOpen.childAt(0).is(CommentLine(" °")); + + // var name:String; + var v:IVerifyTokenTree = brOpen.childAt(1).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("name"))).childCount(2); + v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds(); + v.childLast().is(Semicolon).noChilds(); + + // var content:String; + v = brOpen.childAt(2).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("content"))).childCount(2); + v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds(); + v.childLast().is(Semicolon).noChilds(); + + brOpen.childAt(3).is(CommentLine(" €łµ")).noChilds(); + + // var index:Int; + v = brOpen.childAt(4).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("index"))).childCount(2); + v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("Int"))).noChilds(); + v.childLast().is(Semicolon).noChilds(); + + brOpen.childLast().is(BrClose).noChilds(); + } + function buildTokenTree(content:String):IVerifyTokenTree { var builder:TestTokenTreeBuilder = new TestTokenTreeBuilder(content); var root:TokenTree = new TokenTree(null, null, -1);