Skip to content

Commit 679778b

Browse files
committed
0.9.0 - Added comment parsing for methods and fields. Moved and renamed intermAst package and classes to 'twg2.ast.interm', separated resolution methods into separate 'twg2.parser.resolver' classes.
1 parent 32ee2a5 commit 679778b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+885
-585
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ParserToolsTmp
22
==============
3-
version: 0.8.0
3+
version: 0.9.0
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.8.0",
2+
"version" : "0.9.0",
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/intermAst/annotation/AnnotationSig.java src/twg2/ast/interm/annotation/AnnotationSig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package twg2.parser.intermAst.annotation;
1+
package twg2.ast.interm.annotation;
22

33
import java.io.IOException;
44
import java.util.List;

src/twg2/parser/intermAst/block/IntermBlock.java src/twg2/ast/interm/block/BlockAst.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package twg2.parser.intermAst.block;
1+
package twg2.ast.interm.block;
22

33
import lombok.Getter;
44
import twg2.annotations.Immutable;
5+
import twg2.ast.interm.classes.ClassSig;
56
import twg2.parser.baseAst.CompoundBlock;
67
import twg2.parser.codeParser.CodeFragmentType;
78
import twg2.parser.documentParser.DocumentFragmentText;
8-
import twg2.parser.intermAst.classes.IntermClassSig;
99
import twg2.treeLike.simpleTree.SimpleTree;
1010

1111
/**
1212
* @author TeamworkGuy2
1313
* @since 2015-12-5
1414
*/
1515
@Immutable
16-
public class IntermBlock<T_BLOCK extends CompoundBlock> {
17-
private final @Getter IntermClassSig.SimpleImpl declaration;
16+
public class BlockAst<T_BLOCK extends CompoundBlock> {
17+
private final @Getter ClassSig.SimpleImpl declaration;
1818
private final @Getter SimpleTree<DocumentFragmentText<CodeFragmentType>> blockTree;
1919
private final @Getter T_BLOCK blockType;
2020

2121

22-
public IntermBlock(IntermClassSig.SimpleImpl declaration, SimpleTree<DocumentFragmentText<CodeFragmentType>> blockTree, T_BLOCK blockType) {
22+
public BlockAst(ClassSig.SimpleImpl declaration, SimpleTree<DocumentFragmentText<CodeFragmentType>> blockTree, T_BLOCK blockType) {
2323
this.declaration = declaration;
2424
this.blockTree = blockTree;
2525
this.blockType = blockType;

src/twg2/parser/intermAst/classes/IntermClass.java src/twg2/ast/interm/classes/ClassAst.java

+30-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package twg2.parser.intermAst.classes;
1+
package twg2.ast.interm.classes;
22

33
import java.io.IOException;
44
import java.util.List;
55

66
import lombok.Getter;
77
import lombok.val;
88
import twg2.annotations.Immutable;
9+
import twg2.ast.interm.field.FieldSig;
10+
import twg2.ast.interm.field.FieldSigResolved;
11+
import twg2.ast.interm.method.MethodSig;
12+
import twg2.ast.interm.method.ParameterSig;
13+
import twg2.ast.interm.method.ParameterSigResolved;
914
import twg2.io.write.JsonWrite;
1015
import twg2.parser.baseAst.CompoundBlock;
1116
import twg2.parser.baseAst.tools.NameUtil;
12-
import twg2.parser.intermAst.field.IntermFieldSig;
13-
import twg2.parser.intermAst.field.ResolvedFieldSig;
14-
import twg2.parser.intermAst.method.IntermMethodSig;
15-
import twg2.parser.intermAst.method.IntermParameterSig;
16-
import twg2.parser.intermAst.method.ResolvedParameterSig;
1717
import twg2.parser.output.JsonWritableSig;
1818
import twg2.parser.output.WriteSettings;
1919
import twg2.text.stringUtils.StringJoin;
@@ -22,7 +22,7 @@
2222
* @author TeamworkGuy2
2323
* @since 2015-12-4
2424
*/
25-
public interface IntermClass<T_SIG extends IntermClassSig, T_METHOD extends JsonWritableSig, T_BLOCK extends CompoundBlock> extends JsonWritableSig {
25+
public interface ClassAst<T_SIG extends ClassSig, T_METHOD extends JsonWritableSig, T_BLOCK extends CompoundBlock> extends JsonWritableSig {
2626

2727
public T_SIG getSignature();
2828

@@ -40,8 +40,8 @@ public interface IntermClass<T_SIG extends IntermClassSig, T_METHOD extends Json
4040
* @since 2015-12-4
4141
*/
4242
@Immutable
43-
public static class Impl<T_SIG extends IntermClassSig, T_FIELD extends JsonWritableSig, T_METHOD extends JsonWritableSig, T_PARAM extends JsonWritableSig, T_BLOCK extends CompoundBlock>
44-
implements IntermClass<T_SIG, T_METHOD, T_BLOCK> {
43+
public static class Impl<T_SIG extends ClassSig, T_FIELD extends JsonWritableSig, T_METHOD extends JsonWritableSig, T_PARAM extends JsonWritableSig, T_BLOCK extends CompoundBlock>
44+
implements ClassAst<T_SIG, T_METHOD, T_BLOCK> {
4545
private final @Getter T_SIG signature;
4646
private final @Getter List<List<String>> usingStatements;
4747
private final @Getter List<T_FIELD> fields;
@@ -67,22 +67,30 @@ public Impl(T_SIG signature, List<List<String>> usingStatements, List<? extends
6767
public void toJson(Appendable dst, WriteSettings st) throws IOException {
6868
dst.append("{\n");
6969

70-
dst.append("\"classSignature\": ");
70+
dst.append("\t\"classSignature\": ");
7171
signature.toJson(dst, st);
7272
dst.append(",\n");
7373

74-
dst.append("\"blockType\": \"" + blockType + "\",\n");
74+
dst.append("\t\"blockType\": \"" + blockType + "\",\n");
7575

76-
dst.append("\"using\": [");
76+
dst.append("\t\"using\": [");
7777
JsonWrite.joinStr(usingStatements, ", ", dst, (us) -> '"' + NameUtil.joinFqName(us) + '"');
7878
dst.append("],\n");
7979

80-
dst.append("\"fields\": [");
81-
JsonWrite.joinStrConsume(fields, ", ", dst, (f) -> f.toJson(dst, st));
80+
dst.append("\t\"fields\": [");
81+
if(fields.size() > 0) {
82+
dst.append("\n\t\t");
83+
JsonWrite.joinStrConsume(fields, ",\n\t\t", dst, (f) -> f.toJson(dst, st));
84+
dst.append("\n\t");
85+
}
8286
dst.append("],\n");
8387

84-
dst.append("\"methods\": [");
85-
JsonWrite.joinStrConsume(methods, ", ", dst, (m) -> m.toJson(dst, st));
88+
dst.append("\t\"methods\": [");
89+
if(methods.size() > 0) {
90+
dst.append("\n\t\t");
91+
JsonWrite.joinStrConsume(methods, ",\n\t\t", dst, (m) -> m.toJson(dst, st));
92+
dst.append("\n\t");
93+
}
8694
dst.append("]\n");
8795

8896
dst.append("}");
@@ -104,10 +112,10 @@ public String toString() {
104112
* @since 2016-1-2
105113
*/
106114
@Immutable
107-
public static class SimpleImpl<T_BLOCK extends CompoundBlock> extends Impl<IntermClassSig.SimpleImpl, IntermFieldSig, IntermMethodSig.SimpleImpl, IntermParameterSig, T_BLOCK> {
115+
public static class SimpleImpl<T_BLOCK extends CompoundBlock> extends Impl<ClassSig.SimpleImpl, FieldSig, MethodSig.SimpleImpl, ParameterSig, T_BLOCK> {
108116

109-
public SimpleImpl(IntermClassSig.SimpleImpl signature, List<List<String>> usingStatements, List<? extends IntermFieldSig> fields,
110-
List<? extends IntermMethodSig.SimpleImpl> methods, T_BLOCK blockType) {
117+
public SimpleImpl(ClassSig.SimpleImpl signature, List<List<String>> usingStatements, List<? extends FieldSig> fields,
118+
List<? extends MethodSig.SimpleImpl> methods, T_BLOCK blockType) {
111119
super(signature, usingStatements, fields, methods, blockType);
112120
}
113121

@@ -121,10 +129,10 @@ public SimpleImpl(IntermClassSig.SimpleImpl signature, List<List<String>> usingS
121129
* @since 2015-12-4
122130
*/
123131
@Immutable
124-
public static class ResolvedImpl<T_BLOCK extends CompoundBlock> extends Impl<IntermClassSig.ResolvedImpl, ResolvedFieldSig, IntermMethodSig.ResolvedImpl, ResolvedParameterSig, T_BLOCK> {
132+
public static class ResolvedImpl<T_BLOCK extends CompoundBlock> extends Impl<ClassSig.ResolvedImpl, FieldSigResolved, MethodSig.ResolvedImpl, ParameterSigResolved, T_BLOCK> {
125133

126-
public ResolvedImpl(IntermClassSig.ResolvedImpl signature, List<List<String>> usingStatements, List<? extends ResolvedFieldSig> fields,
127-
List<? extends IntermMethodSig.ResolvedImpl> methods, T_BLOCK blockType) {
134+
public ResolvedImpl(ClassSig.ResolvedImpl signature, List<List<String>> usingStatements, List<? extends FieldSigResolved> fields,
135+
List<? extends MethodSig.ResolvedImpl> methods, T_BLOCK blockType) {
128136
super(signature, usingStatements, fields, methods, blockType);
129137
}
130138

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package twg2.ast.interm.classes;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import twg2.annotations.Immutable;
9+
import twg2.ast.interm.type.TypeSig;
10+
import twg2.io.write.JsonWrite;
11+
import twg2.parser.baseAst.AccessModifier;
12+
import twg2.parser.baseAst.tools.NameUtil;
13+
import twg2.parser.output.JsonWritableSig;
14+
import twg2.parser.output.WriteSettings;
15+
16+
/**
17+
* @author TeamworkGuy2
18+
* @since 2015-12-5
19+
*/
20+
public interface ClassSig extends JsonWritableSig {
21+
22+
public AccessModifier getAccessModifier();
23+
24+
public List<String> getFullName();
25+
26+
public String getDeclarationType();
27+
28+
public String getSimpleName();
29+
30+
31+
32+
33+
@Immutable
34+
@AllArgsConstructor
35+
public static class SimpleImpl implements ClassSig {
36+
private final @Getter List<String> fullName;
37+
/** This type's generic type parameters, if any */
38+
private final @Getter List<TypeSig.Simple> params;
39+
/** The block's type (i.e. 'interface', 'class', 'enum', etc.) */
40+
private final @Getter AccessModifier accessModifier;
41+
private final @Getter String declarationType;
42+
private final @Getter List<String> extendImplementSimpleNames;
43+
44+
45+
@Override
46+
public String getSimpleName() {
47+
return fullName.get(fullName.size() - 1);
48+
}
49+
50+
51+
public boolean isGeneric() {
52+
return params.size() > 0;
53+
}
54+
55+
56+
@Override
57+
public void toJson(Appendable dst, WriteSettings st) throws IOException {
58+
dst.append("{ ");
59+
dst.append("\"access\": \"" + accessModifier + "\", ");
60+
dst.append("\"name\": \"" + (st.fullClassName ? NameUtil.joinFqName(fullName) : fullName.get(fullName.size() - 1)) + "\"");
61+
62+
if(declarationType != null) {
63+
dst.append(", ");
64+
dst.append("\"declarationType\": \"" + declarationType + "\"");
65+
}
66+
67+
if(params != null && params.size() > 0) {
68+
dst.append(", ");
69+
dst.append("\"genericParameters\": [");
70+
JsonWrite.joinStrConsume(params, ", ", dst, (p) -> p.toJson(dst, st));
71+
dst.append("]");
72+
}
73+
74+
if(extendImplementSimpleNames.size() > 0) {
75+
dst.append(", ");
76+
dst.append("\"extendImplementClassNames\": [");
77+
JsonWrite.joinStr(extendImplementSimpleNames, ", ", dst, (n) -> '"' + n + '"');
78+
dst.append("] ");
79+
}
80+
81+
dst.append(" }");
82+
}
83+
84+
85+
@Override
86+
public String toString() {
87+
return accessModifier.toSrc() + " " + declarationType + " " + NameUtil.joinFqName(fullName);
88+
}
89+
90+
}
91+
92+
93+
94+
95+
/**
96+
* @author TeamworkGuy2
97+
* @since 2015-12-5
98+
*/
99+
@Immutable
100+
@AllArgsConstructor
101+
public static class ResolvedImpl implements ClassSig {
102+
private final @Getter List<String> fullName;
103+
/** This type's generic type parameters, if any */
104+
private final @Getter List<TypeSig.Resolved> params;
105+
private final @Getter AccessModifier accessModifier;
106+
/** The block's type (i.e. 'interface', 'class', 'enum', etc.) */
107+
private final @Getter String declarationType;
108+
private final @Getter TypeSig.Resolved extendClass;
109+
private final @Getter List<TypeSig.Resolved> implementInterfaces;
110+
111+
112+
@Override
113+
public String getSimpleName() {
114+
return fullName.get(fullName.size() - 1);
115+
}
116+
117+
118+
public boolean isGeneric() {
119+
return params.size() > 0;
120+
}
121+
122+
123+
@Override
124+
public void toJson(Appendable dst, WriteSettings st) throws IOException {
125+
dst.append("{ ");
126+
dst.append("\"access\": \"" + accessModifier + "\", ");
127+
dst.append("\"name\": \"" + (st.fullClassName ? NameUtil.joinFqName(fullName) : fullName.get(fullName.size() - 1)) + "\", ");
128+
dst.append("\"declarationType\": \"" + declarationType + "\"");
129+
130+
if(params != null && params.size() > 0) {
131+
dst.append(", ");
132+
dst.append("\"genericParameters\": [");
133+
JsonWrite.joinStrConsume(params, ", ", dst, (p) -> p.toJson(dst, st));
134+
dst.append("]");
135+
}
136+
137+
if(extendClass != null) {
138+
dst.append(", ");
139+
dst.append("\"extendClassName\": ");
140+
extendClass.toJson(dst, st);
141+
}
142+
143+
if(implementInterfaces.size() > 0) {
144+
dst.append(", ");
145+
dst.append("\"implementClassNames\": [");
146+
JsonWrite.joinStrConsume(implementInterfaces, ", ", dst, (intfType) -> intfType.toJson(dst, st));
147+
dst.append("] ");
148+
}
149+
150+
dst.append(" }");
151+
}
152+
153+
154+
@Override
155+
public String toString() {
156+
return accessModifier.toSrc() + " " + declarationType + " " + NameUtil.joinFqName(fullName);
157+
}
158+
159+
}
160+
161+
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
package twg2.parser.intermAst.field;
1+
package twg2.ast.interm.field;
22

33
import java.io.IOException;
4-
import java.util.Collection;
54
import java.util.List;
65

76
import lombok.AllArgsConstructor;
87
import lombok.Getter;
98
import twg2.annotations.Immutable;
9+
import twg2.ast.interm.annotation.AnnotationSig;
10+
import twg2.ast.interm.type.TypeSig;
1011
import twg2.io.write.JsonWrite;
1112
import twg2.parser.baseAst.AccessModifier;
12-
import twg2.parser.baseAst.CompoundBlock;
1313
import twg2.parser.baseAst.tools.NameUtil;
14-
import twg2.parser.intermAst.annotation.AnnotationSig;
15-
import twg2.parser.intermAst.classes.IntermClass;
16-
import twg2.parser.intermAst.classes.IntermClassSig;
17-
import twg2.parser.intermAst.project.ProjectClassSet;
18-
import twg2.parser.intermAst.type.TypeSig;
1914
import twg2.parser.output.JsonWritableSig;
2015
import twg2.parser.output.WriteSettings;
16+
import twg2.text.stringEscape.StringEscapeJson;
2117

2218
/**
2319
* @author TeamworkGuy2
2420
* @since 2015-12-4
2521
*/
2622
@Immutable
2723
@AllArgsConstructor
28-
public class IntermFieldSig implements JsonWritableSig {
24+
public class FieldSig implements JsonWritableSig {
2925
private final @Getter String name;
3026
private final @Getter List<String> fullName;
3127
private final @Getter TypeSig.Simple fieldType;
3228
private final @Getter List<AccessModifier> accessModifiers;
3329
private final @Getter List<AnnotationSig> annotations;
30+
private final @Getter List<String> comments;
3431

3532

3633
@Override
@@ -48,6 +45,10 @@ public void toJson(Appendable dst, WriteSettings st) throws IOException {
4845

4946
dst.append("\"annotations\": [");
5047
JsonWrite.joinStrConsume(annotations, ", ", dst, (ann) -> ann.toJson(dst, st));
48+
dst.append("], ");
49+
50+
dst.append("\"comments\": [");
51+
JsonWrite.joinStrConsume(comments, ", ", dst, (str) -> { dst.append('"'); dst.append(StringEscapeJson.toJsonString(str)); dst.append('"'); });
5152
dst.append("]");
5253

5354
dst.append(" }");
@@ -59,16 +60,4 @@ public String toString() {
5960
return fieldType + " " + NameUtil.joinFqName(fullName);
6061
}
6162

62-
63-
/** Resolves simple name fields from {@link IntermFieldSig} into fully qualifying names and creates a new {@link IntermClassSig} with all other fields the same
64-
*/
65-
public static <T_FIELD extends IntermFieldSig> ResolvedFieldSig resolveFrom(T_FIELD intermField, IntermClass.SimpleImpl<? extends CompoundBlock> namespaceClass,
66-
ProjectClassSet.Simple<?, ? extends CompoundBlock> projFiles, Collection<List<String>> missingNamespacesDst) {
67-
// TODO also resolve annotations
68-
69-
TypeSig.Resolved resolvedFieldType = TypeSig.resolveFrom(intermField.getFieldType(), namespaceClass, projFiles, missingNamespacesDst);
70-
71-
return new ResolvedFieldSig(intermField.getName(), intermField.getFullName(), resolvedFieldType, intermField.getAccessModifiers(), intermField.getAnnotations());
72-
}
73-
7463
}

0 commit comments

Comments
 (0)