Skip to content

Commit 501873e

Browse files
authored
fixed object decl (#399)
* fixed object decl
1 parent 3ac3d78 commit 501873e

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- 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))
77
- Fixed BkOpen childs in token tree parser [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398)
88
- Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398)
9+
- Fixed object declaration handling [#399](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/399)
910
- Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393)
1011
- Improved wrapped code detection [#392](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/392)
1112

src/checkstyle/token/walk/WalkTypeNameDef.hx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ class WalkTypeNameDef {
1717
parent = questTok;
1818
}
1919
var name:TokenTree;
20+
var bAdd:Bool = true;
2021
switch (stream.token()) {
2122
case Kwd(KwdMacro), Kwd(KwdExtern), Kwd(KwdNew):
2223
name = stream.consumeToken();
2324
case Const(_):
2425
name = stream.consumeConst();
2526
case Dollar(_):
2627
name = stream.consumeToken();
28+
case POpen:
29+
name = WalkPOpen.walkPOpen(stream, parent);
30+
if (stream.is(Question)) {
31+
WalkQuestion.walkQuestion(stream, name);
32+
}
33+
bAdd = false;
2734
case Sharp(_):
2835
WalkSharp.walkSharp(stream, parent, WalkStatement.walkStatement);
2936
if (!stream.hasMore()) return parent.getFirstChild();
@@ -36,15 +43,21 @@ class WalkTypeNameDef {
3643
default:
3744
name = stream.consumeToken();
3845
}
39-
parent.addChild(name);
46+
if (bAdd) parent.addChild(name);
47+
walkTypeNameDefContinue(stream, name);
48+
return name;
49+
}
50+
51+
static function walkTypeNameDefContinue(stream:TokenStream, parent:TokenTree) {
52+
4053
if (stream.is(Dot)) {
4154
var dot:TokenTree = stream.consumeTokenDef(Dot);
42-
name.addChild(dot);
55+
parent.addChild(dot);
4356
WalkTypeNameDef.walkTypeNameDef(stream, dot);
44-
return name;
57+
return;
4558
}
46-
if (stream.is(Binop(OpLt))) WalkLtGt.walkLtGt(stream, name);
47-
WalkComment.walkComment(stream, name);
48-
return name;
59+
if (stream.is(Binop(OpLt))) WalkLtGt.walkLtGt(stream, parent);
60+
if (stream.is(BkOpen)) WalkArrayAccess.walkArrayAccess(stream, parent);
61+
WalkComment.walkComment(stream, parent);
4962
}
5063
}

test/token/TokenTreeBuilderParsingTest.hx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TokenTreeBuilderParsingTest {
3434
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_1);
3535
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_2);
3636
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3);
37+
assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY);
3738
}
3839

3940
public function assertCodeParses(code:String, ?pos:PosInfos) {
@@ -443,4 +444,16 @@ abstract TokenTreeBuilderParsingTests(String) to String {
443444
}
444445
}
445446
}";
447+
448+
var BLOCK_OBJECT_DECL_WITH_TERNARY = "
449+
class Test {
450+
public function new() {
451+
checkInfos[names[i]] = {
452+
name: names[i],
453+
clazz: cl,
454+
isAlias: i > 0,
455+
description: (i == 0) ? desc : desc + ' [DEPRECATED, use ' + names[0] + ' instead]'
456+
};
457+
}
458+
}";
446459
}

0 commit comments

Comments
 (0)