From b106e2118db6663b84363217a1d034a6bb43ab43 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Sat, 28 Apr 2018 00:45:13 +0200 Subject: [PATCH 1/2] fixed object decl --- CHANGES.md | 1 + src/checkstyle/token/walk/WalkTypeNameDef.hx | 25 +++++++++++++++----- test/token/TokenTreeBuilderParsingTest.hx | 13 ++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 123e753b..5a6724bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - Fixed parser errors when handling block and object declarations, fixes [#396](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/396) ([#397](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/397)) - Fixed BkOpen childs in token tree parser [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398) - Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398) +- Fixed object declaration handling - Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393) - Improved wrapped code detection [#392](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/392) diff --git a/src/checkstyle/token/walk/WalkTypeNameDef.hx b/src/checkstyle/token/walk/WalkTypeNameDef.hx index 220a0fa6..b4ff9106 100644 --- a/src/checkstyle/token/walk/WalkTypeNameDef.hx +++ b/src/checkstyle/token/walk/WalkTypeNameDef.hx @@ -17,6 +17,7 @@ class WalkTypeNameDef { parent = questTok; } var name:TokenTree; + var bAdd:Bool = true; switch (stream.token()) { case Kwd(KwdMacro), Kwd(KwdExtern), Kwd(KwdNew): name = stream.consumeToken(); @@ -24,6 +25,12 @@ class WalkTypeNameDef { name = stream.consumeConst(); case Dollar(_): name = stream.consumeToken(); + case POpen: + name = WalkPOpen.walkPOpen(stream, parent); + if (stream.is(Question)) { + WalkQuestion.walkQuestion(stream, name); + } + bAdd = false; case Sharp(_): WalkSharp.walkSharp(stream, parent, WalkStatement.walkStatement); if (!stream.hasMore()) return parent.getFirstChild(); @@ -36,15 +43,21 @@ class WalkTypeNameDef { default: name = stream.consumeToken(); } - parent.addChild(name); + if (bAdd) parent.addChild(name); + walkTypeNameDefContinue(stream, name); + return name; + } + + static function walkTypeNameDefContinue(stream:TokenStream, parent:TokenTree) { + if (stream.is(Dot)) { var dot:TokenTree = stream.consumeTokenDef(Dot); - name.addChild(dot); + parent.addChild(dot); WalkTypeNameDef.walkTypeNameDef(stream, dot); - return name; + return; } - if (stream.is(Binop(OpLt))) WalkLtGt.walkLtGt(stream, name); - WalkComment.walkComment(stream, name); - return name; + if (stream.is(Binop(OpLt))) WalkLtGt.walkLtGt(stream, parent); + if (stream.is(BkOpen)) WalkArrayAccess.walkArrayAccess(stream, parent); + WalkComment.walkComment(stream, parent); } } \ No newline at end of file diff --git a/test/token/TokenTreeBuilderParsingTest.hx b/test/token/TokenTreeBuilderParsingTest.hx index 5a273ada..31286630 100644 --- a/test/token/TokenTreeBuilderParsingTest.hx +++ b/test/token/TokenTreeBuilderParsingTest.hx @@ -34,6 +34,7 @@ class TokenTreeBuilderParsingTest { assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_1); assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_2); assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3); + assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY); } public function assertCodeParses(code:String, ?pos:PosInfos) { @@ -443,4 +444,16 @@ abstract TokenTreeBuilderParsingTests(String) to String { } } }"; + + var BLOCK_OBJECT_DECL_WITH_TERNARY = " + class Test { + public function new() { + checkInfos[names[i]] = { + name: names[i], + clazz: cl, + isAlias: i > 0, + description: (i == 0) ? desc : desc + ' [DEPRECATED, use ' + names[0] + ' instead]' + }; + } + }"; } \ No newline at end of file From bb955ecd2636a6d0587863447013f04daac91007 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Sat, 28 Apr 2018 00:46:31 +0200 Subject: [PATCH 2/2] updated CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5a6724bd..4e6ea6ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,7 @@ - Fixed parser errors when handling block and object declarations, fixes [#396](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/396) ([#397](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/397)) - Fixed BkOpen childs in token tree parser [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398) - Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398) -- Fixed object declaration handling +- Fixed object declaration handling [#399](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/399) - Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393) - Improved wrapped code detection [#392](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/392)