diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1385a..7f1a52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## dev branch / next version (1.x.x) +## version 1.0.7 (2018-07-26) + - Added `TokenTreeCheckUtils.isTypeStructure()` [#36](https://github.com/HaxeCheckstyle/tokentree/issues/36) + [#50](https://github.com/HaxeCheckstyle/tokentree/issues/50) - Added `TokenTreeCheckUtils.isTypeEnum()` [#40](https://github.com/HaxeCheckstyle/tokentree/issues/40) - Added `TokenTreeCheckUtils.isMacroClass()` [#42](https://github.com/HaxeCheckstyle/tokentree/issues/42) @@ -27,7 +29,7 @@ - Fixed handling of const type parameters [#57](https://github.com/HaxeCheckstyle/tokentree/issues/57) - Fixed `case var` handling [#58](https://github.com/HaxeCheckstyle/tokentree/issues/58) - Fixed `case Pattern(var foo, var bar)` handling [#59](https://github.com/HaxeCheckstyle/tokentree/issues/59) -- Fixed comments in if…else [#60](https://github.com/HaxeCheckstyle/tokentree/issues/60) +- Fixed comments in if…else [#60](https://github.com/HaxeCheckstyle/tokentree/issues/60) +[#72](https://github.com/HaxeCheckstyle/tokentree/issues/72) - Fixed comments in typedefs [#62](https://github.com/HaxeCheckstyle/tokentree/issues/62) - Fixed handling of array items [#62](https://github.com/HaxeCheckstyle/tokentree/issues/62) - Fixed handling of `null`, `true` and `false` as body of if [#63](https://github.com/HaxeCheckstyle/tokentree/issues/63) diff --git a/haxelib.json b/haxelib.json index b2fe7ad..f685dd0 100644 --- a/haxelib.json +++ b/haxelib.json @@ -8,7 +8,7 @@ "AlexHaxe" ], "releasenote": "Added helper functions TokenTreeCheckUtils and bugfixes - see CHANGELOG", - "version": "1.0.6", + "version": "1.0.7", "url": "https://github.com/HaxeCheckstyle/tokentree", "dependencies": {} } \ No newline at end of file diff --git a/package.json b/package.json index b183c5f..a5256d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.0.6", + "version": "1.0.7", "description": "TokenTree library used by haxe-checkstyle", "repository": { "type": "git", diff --git a/src/tokentree/walk/WalkComment.hx b/src/tokentree/walk/WalkComment.hx index 9c523f6..00c8cec 100644 --- a/src/tokentree/walk/WalkComment.hx +++ b/src/tokentree/walk/WalkComment.hx @@ -13,4 +13,25 @@ class WalkComment { } } } + + public static function tryWalkComment(stream:TokenStream, parent:TokenTree, expect:TokenDef) { + var currentPos:Int = stream.getCurrentPos(); + var progress:TokenStreamProgress = new TokenStreamProgress(stream); + var comments:Array = []; + while (stream.hasMore() && progress.streamHasChanged()) { + switch (stream.token()) { + case Comment(_), CommentLine(_): + comments.push(stream.consumeToken()); + default: + if (stream.is(expect)) { + for (comment in comments) { + parent.addChild(comment); + } + return; + } + stream.rewindTo(currentPos); + return; + } + } + } } \ No newline at end of file diff --git a/src/tokentree/walk/WalkIf.hx b/src/tokentree/walk/WalkIf.hx index 7dbae75..4f0a9f7 100644 --- a/src/tokentree/walk/WalkIf.hx +++ b/src/tokentree/walk/WalkIf.hx @@ -25,6 +25,7 @@ class WalkIf { if (stream.is(DblDot)) return; // if-expr WalkBlock.walkBlock(stream, ifTok); + WalkComment.tryWalkComment(stream, ifTok, Kwd(KwdElse)); if (stream.is(Kwd(KwdElse))) { var elseTok:TokenTree = stream.consumeTokenDef(Kwd(KwdElse)); ifTok.addChild(elseTok); diff --git a/test/tokentree/TokenTreeBuilderParsingTest.hx b/test/tokentree/TokenTreeBuilderParsingTest.hx index 8f40ad6..548c26f 100644 --- a/test/tokentree/TokenTreeBuilderParsingTest.hx +++ b/test/tokentree/TokenTreeBuilderParsingTest.hx @@ -54,6 +54,7 @@ class TokenTreeBuilderParsingTest { assertCodeParses(COMMENTS_IN_IF_ELSE); assertCodeParses(COMMENTS_IN_TYPEDEF); assertCodeParses(ADVANCED_ARRAY_ITEMS); + assertCodeParses(IF_ELSE_COMMENTS); } public function assertCodeParses(code:String, ?pos:PosInfos) { @@ -721,4 +722,30 @@ abstract TokenTreeBuilderParsingTests(String) to String { ]); } "; + + var IF_ELSE_COMMENTS = " + class Main { + function recycle() { + // rotated recycling + if (maxSize > 0) { + // create new instance + if (length < maxSize) { + return recycleCreateObject(ObjectClass, ObjectFactory); + } + // get the next member if at capacity + else { + if (Revive) + basic.revive(); + } + } + // grow-style recycling - grab a basic with exists == false or create a new one + else { + if (basic != null) { + if (Revive) + basic.revive(); + } + } + } + } + "; } \ No newline at end of file