Skip to content

Commit d14366d

Browse files
committed
0.15.6 - Support parameter default values, update unit tests.
1 parent b1176a9 commit d14366d

22 files changed

+129
-81
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.15.5](N/A) - 2018-09-14
7+
### [0.15.6](N/A) - 2018-09-22
8+
#### Added
9+
* Parameter default value parsing support added to `MethodParametersParser`
10+
* Added `DataTypeExtractor.isDefaultValueLiteral()` to check for field/parameter default values
11+
12+
#### Changed
13+
* Renamed `CsKeyword.Inst` -> `CsKeyword.CsKeywordUtil`
14+
* Renamed `JavaKeyword.Inst` -> `JavaKeyword.JavaKeywordUtil`
15+
* Unit tests changed to use static imports of `TypeAssert.ary()` instead of `new Object[] {...}` and `TypeAssert.ls()` instead of `Arrays.asList()`
16+
17+
18+
--------
19+
### [0.15.5](https://github.com/TeamworkGuy2/JParseCode/commit/cac4e10c769b47ec3b73e2e716befc19ab1876f4) - 2018-09-14
820
#### Changed
921
* `ParserWorkFlow` returns the `-help` message if no arguments are given when run
1022

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
JParseCode
22
==============
3-
version: 0.15.5
3+
version: 0.15.6
44

55
In progress C#/Java/TypeScript parser tools built atop [JTextParser](https://github.com/TeamworkGuy2/JTextParser), [Jackson](https://github.com/FasterXML/jackson-core/) (core, databind, annotations) and half a dozen other utility libraries.
66

bin/jparse_code-with-tests.jar

914 Bytes
Binary file not shown.

bin/jparse_code.jar

729 Bytes
Binary file not shown.

package-lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.15.5",
2+
"version" : "0.15.6",
33
"name" : "jparse-code",
44
"description" : "An in-progress suite of parsing/transpilation tools for C#, Java, and TypeScript code. Generates simple JSON ASTs.",
55
"homepage" : "https://github.com/TeamworkGuy2/JParseCode",

src/twg2/ast/interm/field/FieldDef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void initializerToJson(SimpleTree<CodeToken> astNode, boolean preC
7373
boolean isNumOrBoolOrNull = false;
7474
if(astNode != null && !astNode.hasChildren() && (data = astNode.getData()) != null &&
7575
(data.getTokenType() == CodeTokenType.STRING ||
76-
(isNumOrBoolOrNull = (data.getTokenType() == CodeTokenType.NUMBER || DataTypeExtractor.isBooleanLiteral(data) || DataTypeExtractor.isNullLiteral(data))))) {
76+
(isNumOrBoolOrNull = DataTypeExtractor.isDefaultValueLiteral(data)))) {
7777
if(preClosingComma) {
7878
dst.append(", ");
7979
}

src/twg2/parser/codeParser/csharp/CsBlockParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public AstParser<List<FieldSig>> createFieldParser(BlockAst<CsBlock> block, AstP
8484
public AstParser<List<MethodSigSimple>> createMethodParser(BlockAst<CsBlock> block, AstParser<List<AnnotationSig>> annotationParser, AstParser<List<String>> commentParser) {
8585
val lang = CodeLanguageOptions.C_SHARP;
8686
val typeParser = new DataTypeExtractor(lang, true);
87-
return new MethodExtractor(lang.displayName(), CsKeyword.check, block, typeParser, annotationParser, commentParser);
87+
return new MethodExtractor(lang.displayName(), CsKeyword.check, lang.getOperatorUtil(), block, typeParser, annotationParser, commentParser);
8888
}
8989

9090

src/twg2/parser/codeParser/csharp/CsKeyword.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public enum CsKeyword implements AccessModifier {
9494
WHILE("while");
9595

9696

97-
public static final CsKeyword.Inst check = new CsKeyword.Inst();
97+
public static final CsKeyword.CsKeywordUtil check = new CsKeyword.CsKeywordUtil();
9898

9999
public final String srcName;
100100
public final boolean isType;
@@ -146,7 +146,7 @@ public String toSrc() {
146146
* @since 2016-1-14
147147
*/
148148
@Accessors(fluent = true)
149-
public static class Inst implements KeywordUtil<CsKeyword> {
149+
public static class CsKeywordUtil implements KeywordUtil<CsKeyword> {
150150
public final String[] keywords;
151151
private final CsKeyword[] values;
152152
private final String[] primitives;

src/twg2/parser/codeParser/extractors/DataTypeExtractor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,27 @@ public static <T> boolean isPossiblyType(KeywordUtil<? extends AccessModifier> k
129129
}
130130

131131

132-
/** Check if a tree node is a boolean literal
132+
/** Check if a {@link CodeToken} is a boolean literal
133133
*/
134134
public static boolean isBooleanLiteral(CodeToken node) {
135135
return node.getTokenType() == CodeTokenType.KEYWORD && ("true".equals(node.getText()) || "false".equals(node.getText()));
136136
}
137137

138138

139-
/** Check if a tree node is a null literal
139+
/** Check if a {@link CodeToken} is a null literal
140140
*/
141141
public static boolean isNullLiteral(CodeToken node) {
142142
return node.getTokenType() == CodeTokenType.KEYWORD && "null".equals(node.getText());
143143
}
144144

145145

146+
/** Check if a {@link CodeToken} is a numeric literal, a boolean literal, or a null literal
147+
*/
148+
public static boolean isDefaultValueLiteral(CodeToken node) {
149+
return (node.getTokenType() == CodeTokenType.NUMBER || DataTypeExtractor.isBooleanLiteral(node) || DataTypeExtractor.isNullLiteral(node));
150+
}
151+
152+
146153
/** Check if one or two nodes are a number with an optional -/+ sign
147154
* @param node1
148155
* @param node2Optional

src/twg2/parser/codeParser/extractors/MethodExtractor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import twg2.parser.codeParser.AccessModifier;
1212
import twg2.parser.codeParser.BlockType;
1313
import twg2.parser.codeParser.KeywordUtil;
14+
import twg2.parser.codeParser.Operator;
15+
import twg2.parser.codeParser.OperatorUtil;
1416
import twg2.parser.codeParser.tools.NameUtil;
1517
import twg2.parser.fragment.AstFragType;
1618
import twg2.parser.fragment.CodeToken;
@@ -37,6 +39,7 @@ static enum State {
3739

3840

3941
KeywordUtil<? extends AccessModifier> keywordUtil;
42+
OperatorUtil<? extends Operator> operatorUtil;
4043
AstParser<List<AnnotationSig>> annotationParser;
4144
AstParser<List<String>> commentParser;
4245
AstParser<TypeSig.TypeSigSimple> typeParser;
@@ -51,10 +54,11 @@ static enum State {
5154
* @param annotationParser this annotation parser should be being run external from this instance. When this instance finds a method signature,
5255
* the annotation parser should already contain results (i.e. {@link AstParser#getParserResult()}) for the method's annotations
5356
*/
54-
public MethodExtractor(String langName, KeywordUtil<? extends AccessModifier> keywordUtil, BlockAst<? extends BlockType> parentBlock,
57+
public MethodExtractor(String langName, KeywordUtil<? extends AccessModifier> keywordUtil, OperatorUtil<? extends Operator> operatorUtil, BlockAst<? extends BlockType> parentBlock,
5558
AstParser<TypeSig.TypeSigSimple> typeParser, AstParser<List<AnnotationSig>> annotationParser, AstParser<List<String>> commentParser) {
5659
super(langName, "method signature", parentBlock, State.COMPLETE, State.FAILED);
5760
this.keywordUtil = keywordUtil;
61+
this.operatorUtil = operatorUtil;
5862
this.methods = new ArrayList<>();
5963
this.typeParser = typeParser;
6064
this.annotationParser = annotationParser;
@@ -170,7 +174,7 @@ private Consume findingParams(SimpleTree<CodeToken> tokenNode) {
170174
val comments = new ArrayList<>(commentParser.getParserResult());
171175
commentParser.recycle();
172176

173-
val params = MethodParametersParser.extractParamsFromSignature(keywordUtil, annotationParser, tokenNode);
177+
val params = MethodParametersParser.extractParamsFromSignature(keywordUtil, operatorUtil, annotationParser, tokenNode);
174178
val accessMods = new ArrayList<>(accessModifiers);
175179
annotationParser.recycle();
176180

@@ -199,7 +203,7 @@ public MethodExtractor recycle() {
199203

200204
@Override
201205
public MethodExtractor copy() {
202-
val copy = new MethodExtractor(this.langName, this.keywordUtil, this.parentBlock, this.typeParser.copy(), this.annotationParser.copy(), this.commentParser.copy());
206+
val copy = new MethodExtractor(this.langName, this.keywordUtil, this.operatorUtil, this.parentBlock, this.typeParser.copy(), this.annotationParser.copy(), this.commentParser.copy());
203207
return copy;
204208
}
205209

0 commit comments

Comments
 (0)