Skip to content

Commit

Permalink
fixed object decl (#399)
Browse files Browse the repository at this point in the history
* fixed object decl
  • Loading branch information
AlexHaxe authored Apr 27, 2018
1 parent 3ac3d78 commit 501873e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [#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)

Expand Down
25 changes: 19 additions & 6 deletions src/checkstyle/token/walk/WalkTypeNameDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ class WalkTypeNameDef {
parent = questTok;
}
var name:TokenTree;
var bAdd:Bool = true;
switch (stream.token()) {
case Kwd(KwdMacro), Kwd(KwdExtern), Kwd(KwdNew):
name = stream.consumeToken();
case Const(_):
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();
Expand All @@ -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);
}
}
13 changes: 13 additions & 0 deletions test/token/TokenTreeBuilderParsingTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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]'
};
}
}";
}

0 comments on commit 501873e

Please sign in to comment.