Skip to content

Commit b9daa86

Browse files
committed
0.10.1 - Fixed minor annotation named parameter parsing issue when annotation only had one parameter.
1 parent 3e8a324 commit b9daa86

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ParserToolsTmp
22
==============
3-
version: 0.10.0
3+
version: 0.10.1
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

package-lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.10.0",
2+
"version" : "0.10.1",
33
"name" : "jparser-tools",
44
"description" : "An in-progress suite of parsing tools for C#, Java, and TypeScript source code",
55
"homepage" : "https://github.com/TeamworkGuy2/JFileIo",

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static AnnotationSig parseAnnotationBlock(CodeLanguage lang, CodeFragment
3131
if(annotNameType != CodeFragmentType.IDENTIFIER) { throw new IllegalArgumentException("annotation node expected to contain identifier, found '" + annotName + "'"); }
3232

3333
val params = new HashMap<String, String>();
34+
boolean firstParamUnnamed = false;
3435

3536
// parse an annotation '(arguments, ...)'
3637
if(size > 0) {
@@ -52,6 +53,9 @@ public static AnnotationSig parseAnnotationBlock(CodeLanguage lang, CodeFragment
5253
}
5354
else {
5455
paramName = "arg" + (params.size() + 1);
56+
if(params.size() == 0) {
57+
firstParamUnnamed = true;
58+
}
5559
}
5660

5761
// parse the annotation argument value
@@ -93,7 +97,7 @@ else if(paramType == CodeFragmentType.IDENTIFIER) {
9397
else {
9498
}
9599

96-
if(params.size() == 1) {
100+
if(params.size() == 1 && firstParamUnnamed) {
97101
params.put("value", params.get("arg1"));
98102
params.remove("arg1");
99103
}

src/twg2/parser/main/MainParser.java

-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import twg2.parser.language.CodeLanguage;
2323
import twg2.parser.output.WriteSettings;
2424
import twg2.parser.project.ProjectClassSet;
25-
import twg2.parser.test.JavaClassParseTest;
2625
import twg2.text.stringUtils.StringJoin;
2726

2827
/**
@@ -79,11 +78,6 @@ public static void main(String[] args) throws IOException, FileFormatException {
7978
ExecutorService executor = multithread ? Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) : null;
8079
FileReadUtil fileReader = FileReadUtil.threadLocalInst();
8180

82-
new JavaClassParseTest().simpleJavaParseTest();
83-
if(3.5/1.1 > 1.2) {
84-
return;
85-
}
86-
8781
if(args.length > 0) {
8882
// TODO for VisualVM pause
8983
//Scanner in = new Scanner(System.in);

test/twg2/parser/test/CsClassParseTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class CsClassParseTest {
4848
" [IntAnnotation(-1)]\n" +
4949
" [BoolAnnotation(true)]\n" +
5050
" [IdentifierAnnotation(Integer.TYPE)]\n" +
51-
" [StringAnnotation(\"\")]\n" +
51+
" [StringAnnotation(Name = \"\")]\n" +
5252
" [MultiArgAnnotation(\"abc\", false , 1.23)]\n" +
5353
" [MultiNamedArgAnnotation(num =1.23, flag=false ,value = \"abc\")]\n" +
5454
" private int mod;\n" +
@@ -149,8 +149,8 @@ public void simpleCsParseTest() {
149149
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 2, "BoolAnnotation", new String[] { "value" }, "true");
150150
// annotation: IdentifierAnnotation(Integer.TYPE)
151151
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 3, "IdentifierAnnotation", new String[] { "value" }, "Integer.TYPE");
152-
// annotation: StringAnnotation("")
153-
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 4, "StringAnnotation", new String[] { "value" }, "");
152+
// annotation: StringAnnotation(Name = "")
153+
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 4, "StringAnnotation", new String[] { "Name" }, "");
154154
// annotation: MultiArgAnnotation(\"abc\", false, 1.23)
155155
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 5, "MultiArgAnnotation", new String[] { "arg1", "arg2", "arg3" }, "abc", "false", "1.23");
156156
// annotations: MultiNamedArgAnnotation(num =1.23, flag=false ,value = "abc")

test/twg2/parser/test/JavaClassParseTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class JavaClassParseTest {
4848
" @IntAnnotation(-1)]\n" +
4949
" @BoolAnnotation(true)]\n" +
5050
" @IdentifierAnnotation(Integer.TYPE)]\n" +
51-
" @StringAnnotation(\"\")]\n" +
51+
" @StringAnnotation(Name = \"\")]\n" +
5252
" @MultiArgAnnotation(\"abc\", false , 1.23)\n" +
5353
" @MultiNamedArgAnnotation(num =1.23, flag=false ,value = \"abc\")\n" +
5454
" private int mod;\n" +
@@ -145,8 +145,8 @@ public void simpleJavaParseTest() {
145145
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 2, "BoolAnnotation", new String[] { "value" }, "true");
146146
// annotations: IdentifierAnnotation(Integer.TYPE)
147147
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 3, "IdentifierAnnotation", new String[] { "value" }, "Integer.TYPE");
148-
// annotations: StringAnnotation("")
149-
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 4, "StringAnnotation", new String[] { "value" }, "");
148+
// annotations: StringAnnotation(Name = "")
149+
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 4, "StringAnnotation", new String[] { "Name" }, "");
150150
// annotations: MultiArgAnnotation("abc", false , 1.23)
151151
ParseAnnotationTest.assertAnnotation(f.getAnnotations(), 5, "MultiArgAnnotation", new String[] { "arg1", "arg2", "arg3" }, "abc", "false", "1.23");
152152
// annotations: MultiNamedArgAnnotation(num =1.23, flag=false ,value = "abc")

versions.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
--------
22
####0.10.0
3-
date: 2016-4-12
3+
date: 2016-4-13
44

55
commit: ?
66

7+
* Fixed minor bug in annotation named parameter parsing when annotation only had one parameter
8+
9+
10+
--------
11+
####0.10.0
12+
date: 2016-4-12
13+
14+
commit: 3e8a324ccada6af273339e6f29ae569795e3abcd
15+
716
* Added better annotation parsing, including support for negative numbers as arguments
17+
* Fixed ParserWorkflow to generate and group all results by destination file before writing (previously a writer was opened in overwrite mode for each destination group, thereby overwriting data written to the same file by a previous destination group during the same program execution)
818
* Added CodeFragment which extends 'DocumentFragmentText<CodeFragmentType>' so don't have to keep typing that every time, updated most of the code to use CodeFragment
919
* Added OperatorUtil and Operator (with C# and Java implementation enums) similar to the existing Keyword enums
1020
* Refactored how we use EnumSubSet and enum sub-categorization

0 commit comments

Comments
 (0)