Skip to content

Commit c9ff08c

Browse files
committed
0.14.2 - Fixed issue parsing C# and Java classes that extend/implement multiple types, these are now parsed and returned in the correct order
1 parent 53806a5 commit c9ff08c

23 files changed

+162
-107
lines changed

CHANGELOG.md

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

55

66
--------
7-
###[0.14.1](N/A) - 2016-12-03
7+
###[0.14.2](N/A) - 2017-02-06
8+
#### Changed
9+
* Removed lombok.val usage/dependency from from test classes.
10+
11+
#### Fixed
12+
* Fixed parsing C# classes that extend/implement multiple types, unrecognized types are assumed to possibly be interfaces.
13+
* Fixed parsing Java classes that implement multiple types, unrecognized types are assumed to possibly be interfaces.
14+
15+
16+
--------
17+
###[0.14.1](https://github.com/TeamworkGuy2/JParseCode/commit/53806a53d3b8152b35e3166a81dbe9a81a49f354) - 2016-12-03
818
#### Changed
919
* Updated dependencies to latest versions: jtext-parser@0.11.0, jtext-tokenizer@0.2.0, jparser-primitive@0.2.0
1020
* This includes a new parsing strategy which tries to parse non-compound tokens from start to finish using one parser at a time without passing the characters to compound parser, this improves performance and simplifies some of the compound parsers, but makes some compound parsers more difficult, such as ending conditions that try to keep track of characters between the start and end of the compound parser segment

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.14.1
3+
version: 0.14.2
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

-692 Bytes
Binary file not shown.

bin/jparse_code.jar

-1.06 KB
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.14.1",
2+
"version" : "0.14.2",
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",

rsc/csharp/ParserExamples/Models/TrackInfo.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Runtime.Serialization;
23

34
namespace ParserExamples.Models {
@@ -9,7 +10,7 @@ namespace ParserExamples.Models {
910
/// This class is mutable. And it is not thread-safe.
1011
/// </threadsafety>
1112
[DataContract]
12-
public class TrackInfo {
13+
public class TrackInfo : ISerializable, IComparable<TrackInfo> {
1314

1415
/// <value>The track name.</value>
1516
[DataMember]
@@ -25,6 +26,15 @@ public class TrackInfo {
2526
/// <value>The track duration in milliseconds</value>
2627
public long contentId;
2728

29+
30+
public int CompareTo(Implementer other) {
31+
return other != null ? (this.Name != null ? this.Name.CompareTo(other.Name) : (other.Name != null ? 1 : 0)) : (this.Name != null ? -1 : 0);
32+
}
33+
34+
35+
public void GetObjectData(SerializationInfo info, StreamingContext context) {
36+
}
37+
2838
}
2939

3040
}

rsc/java/ParserExamples/Models/TrackInfo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ParserExamples.Models;
22

3+
import java.io.Serializable;
4+
35
import System.Runtime.Serialization;
46

57
/// <summary>
@@ -9,7 +11,7 @@
911
/// This class is mutable. And it is not thread-safe.
1012
/// </threadsafety>
1113
[DataContract]
12-
public class TrackInfo {
14+
public class TrackInfo implements Serializable, Comparable<TrackInfo> {
1315

1416
/// <value>The track name.</value>
1517
@DataMember
@@ -25,4 +27,10 @@ public class TrackInfo {
2527
/// <value>The track duration in milliseconds</value>
2628
public long contentId;
2729

30+
31+
@Override
32+
public int compareTo(TrackInfo o) {
33+
return other != null ? (this.Name != null ? this.Name.CompareTo(other.Name) : (other.Name != null ? 1 : 0)) : (this.Name != null ? -1 : 0);
34+
}
35+
2836
}

src/twg2/parser/codeParser/KeywordUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public interface KeywordUtil<T_KEYWORD extends AccessModifier> {
2020
*/
2121
public T_KEYWORD tryToKeyword(String str);
2222

23+
/** Check if a string is an inheritance keyword (i.e. ':' in C# or 'extends' and 'implements' in Java and TypeScript */
24+
public boolean isInheritanceKeyword(String str);
25+
2326
/** Check if a string is a keyword */
2427
public boolean isKeyword(String str);
2528

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,18 @@ private static Entry<String, List<String>> readClassIdentifierAndExtends(Enhance
181181
SimpleTree<CodeToken> prevNode = iter.hasPrevious() ? iter.previous() : null;
182182

183183
// TODO should read ', ' between each name, currently only works with 1 extend/implement class name
184-
while(prevNode != null && AstFragType.isIdentifierOrKeyword(prevNode.getData()) && !lang.getKeywordUtil().blockModifiers().is(prevNode.getData())) {
184+
while(prevNode != null && AstFragType.isIdentifierOrKeyword(prevNode.getData()) && !lang.getKeywordUtil().blockModifiers().is(prevNode.getData()) && !lang.getKeywordUtil().isInheritanceKeyword(prevNode.getData().getText())) {
185185
names.add(prevNode.getData().getText());
186186
prevNode = iter.hasPrevious() ? iter.previous() : null;
187187
if(iter.hasPrevious()) { prevCount++; }
188188
}
189189

190190
// if the class signature extends/implements, then the identifiers just read are the class/interface names, next read the actual class name
191-
if(prevNode != null && prevNode.getData().getText().trim().equals(":")) {
191+
if(prevNode != null && prevNode.getData().getText().equals(":")) {
192192
prevNode = iter.hasPrevious() ? iter.previous() : null;
193193
if(iter.hasPrevious()) { prevCount++; }
194194
if(prevNode != null && AstFragType.isIdentifierOrKeyword(prevNode.getData()) && !lang.getKeywordUtil().blockModifiers().is(prevNode.getData())) {
195+
Collections.reverse(names);
195196
val extendImplementNames = names;
196197
val className = prevNode.getData().getText();
197198
nameCompoundRes = Tuples.of(className, extendImplementNames);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ public CsKeyword tryToKeyword(String str) {
211211
}
212212

213213

214+
@Override
215+
public boolean isInheritanceKeyword(String str) {
216+
return ":".equals(str);
217+
}
218+
219+
214220
@Override
215221
public boolean isKeyword(String str) {
216222
return Arrays.binarySearch(keywords, str) > -1;

0 commit comments

Comments
 (0)