Skip to content

Commit aff1e71

Browse files
committed
add ignored chars to the AST
1 parent 6ddb87f commit aff1e71

Some content is hidden

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

50 files changed

+1044
-352
lines changed

src/main/antlr/GraphqlCommon.g4

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ fragment SourceCharacter :[\u0009\u000A\u000D\u0020-\uFFFF];
120120
121121
Comment: '#' ~[\n\r\u2028\u2029]* -> channel(2);
122122
123-
Ignored: (UnicodeBOM|Whitespace|LineTerminator|Comma) -> skip;
123+
//Ignored: (UnicodeBOM|Whitespace|LineTerminator|Comma) -> channel(3);
124124
125125
fragment EscapedChar : '\\' (["\\/bfnrt] | Unicode) ;
126126
fragment Unicode : 'u' Hex Hex Hex Hex ;
127127
fragment Hex : [0-9a-fA-F] ;
128128

129-
fragment LineTerminator: [\n\r\u2028\u2029];
129+
LF: [\n] -> channel(3);
130+
CR: [\r] -> channel(3);
131+
LineTerminator: [\u2028\u2029] -> channel(3);
130132

131-
fragment Whitespace : [\u0009\u0020];
132-
fragment Comma : ',';
133-
fragment UnicodeBOM : [\ufeff];
133+
Space : [\u0020] -> channel(3);
134+
Tab : [\u0009] -> channel(3);
135+
Comma : ',' -> channel(3);
136+
UnicodeBOM : [\ufeff] -> channel(3);

src/main/java/graphql/language/AbstractNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public abstract class AbstractNode<T extends Node> implements Node<T> {
1313

1414
private final SourceLocation sourceLocation;
1515
private final List<Comment> comments;
16+
private final IgnoredChars ignoredChars;
1617

17-
public AbstractNode(SourceLocation sourceLocation, List<Comment> comments) {
18+
public AbstractNode(SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars) {
1819
this.sourceLocation = sourceLocation;
1920
Assert.assertNotNull(comments, "comments can't be null");
2021
this.comments = new ArrayList<>(comments);
22+
this.ignoredChars = Assert.assertNotNull(ignoredChars, "ignoredChars can't be null");
2123
}
2224

2325
@Override
@@ -30,6 +32,10 @@ public List<Comment> getComments() {
3032
return new ArrayList<>(comments);
3133
}
3234

35+
@Override
36+
public IgnoredChars getIgnoredChars() {
37+
return ignoredChars;
38+
}
3339

3440
@SuppressWarnings("unchecked")
3541
protected <V extends Node> V deepCopy(V nullableObj) {

src/main/java/graphql/language/Argument.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public class Argument extends AbstractNode<Argument> implements NamedNode<Argume
1717
private Value value;
1818

1919
@Internal
20-
protected Argument(String name, Value value, SourceLocation sourceLocation, List<Comment> comments) {
21-
super(sourceLocation, comments);
20+
protected Argument(String name, Value value, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars) {
21+
super(sourceLocation, comments, ignoredChars);
2222
this.name = name;
2323
this.value = value;
2424
}
2525

2626
/**
2727
* alternative to using a Builder for convenience
2828
*
29-
* @param name of the argument
29+
* @param name of the argument
3030
* @param value of the argument
3131
*/
3232
public Argument(String name, Value value) {
33-
this(name, value, null, new ArrayList<>());
33+
this(name, value, null, new ArrayList<>(), IgnoredChars.EMPTY);
3434
}
3535

3636
@Override
@@ -60,8 +60,12 @@ public List<Node> getChildren() {
6060

6161
@Override
6262
public boolean isEqualTo(Node o) {
63-
if (this == o) return true;
64-
if (o == null || getClass() != o.getClass()) return false;
63+
if (this == o) {
64+
return true;
65+
}
66+
if (o == null || getClass() != o.getClass()) {
67+
return false;
68+
}
6569

6670
Argument that = (Argument) o;
6771

@@ -71,7 +75,7 @@ public boolean isEqualTo(Node o) {
7175

7276
@Override
7377
public Argument deepCopy() {
74-
return new Argument(name, deepCopy(value), getSourceLocation(), getComments());
78+
return new Argument(name, deepCopy(value), getSourceLocation(), getComments(), getIgnoredChars());
7579
}
7680

7781
@Override
@@ -106,6 +110,7 @@ public static final class Builder implements NodeBuilder {
106110
private List<Comment> comments = new ArrayList<>();
107111
private String name;
108112
private Value value;
113+
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
109114

110115
private Builder() {
111116
}
@@ -115,6 +120,7 @@ private Builder(Argument existing) {
115120
this.comments = existing.getComments();
116121
this.name = existing.getName();
117122
this.value = existing.getValue();
123+
this.ignoredChars = existing.getIgnoredChars();
118124
}
119125

120126
public Builder sourceLocation(SourceLocation sourceLocation) {
@@ -137,8 +143,13 @@ public Builder comments(List<Comment> comments) {
137143
return this;
138144
}
139145

146+
public Builder ignoredChars(IgnoredChars ignoredChars) {
147+
this.ignoredChars = ignoredChars;
148+
return this;
149+
}
150+
140151
public Argument build() {
141-
Argument argument = new Argument(name, value, sourceLocation, comments);
152+
Argument argument = new Argument(name, value, sourceLocation, comments, ignoredChars);
142153
return argument;
143154
}
144155
}

src/main/java/graphql/language/ArrayValue.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class ArrayValue extends AbstractNode<ArrayValue> implements Value<ArrayV
1616
private final List<Value> values = new ArrayList<>();
1717

1818
@Internal
19-
protected ArrayValue(List<Value> values, SourceLocation sourceLocation, List<Comment> comments) {
20-
super(sourceLocation, comments);
19+
protected ArrayValue(List<Value> values, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars) {
20+
super(sourceLocation, comments, ignoredChars);
2121
this.values.addAll(values);
2222
}
2323

@@ -27,7 +27,7 @@ protected ArrayValue(List<Value> values, SourceLocation sourceLocation, List<Com
2727
* @param values of the array
2828
*/
2929
public ArrayValue(List<Value> values) {
30-
this(values,null, new ArrayList<>());
30+
this(values, null, new ArrayList<>(), IgnoredChars.EMPTY);
3131
}
3232

3333
public List<Value> getValues() {
@@ -41,8 +41,12 @@ public List<Node> getChildren() {
4141

4242
@Override
4343
public boolean isEqualTo(Node o) {
44-
if (this == o) return true;
45-
if (o == null || getClass() != o.getClass()) return false;
44+
if (this == o) {
45+
return true;
46+
}
47+
if (o == null || getClass() != o.getClass()) {
48+
return false;
49+
}
4650

4751
return true;
4852
}
@@ -56,7 +60,7 @@ public String toString() {
5660

5761
@Override
5862
public ArrayValue deepCopy() {
59-
return new ArrayValue(deepCopy(values), getSourceLocation(), getComments());
63+
return new ArrayValue(deepCopy(values), getSourceLocation(), getComments(), getIgnoredChars());
6064
}
6165

6266
@Override
@@ -78,6 +82,7 @@ public static final class Builder implements NodeBuilder {
7882
private SourceLocation sourceLocation;
7983
private List<Value> values = new ArrayList<>();
8084
private List<Comment> comments = new ArrayList<>();
85+
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
8186

8287
private Builder() {
8388
}
@@ -86,6 +91,7 @@ private Builder(ArrayValue existing) {
8691
this.sourceLocation = existing.getSourceLocation();
8792
this.comments = existing.getComments();
8893
this.values = existing.getValues();
94+
this.ignoredChars = existing.getIgnoredChars();
8995
}
9096

9197
public Builder sourceLocation(SourceLocation sourceLocation) {
@@ -108,8 +114,13 @@ public Builder comments(List<Comment> comments) {
108114
return this;
109115
}
110116

117+
public Builder ignoredChars(IgnoredChars ignoredChars) {
118+
this.ignoredChars = ignoredChars;
119+
return this;
120+
}
121+
111122
public ArrayValue build() {
112-
ArrayValue arrayValue = new ArrayValue(values, sourceLocation, comments);
123+
ArrayValue arrayValue = new ArrayValue(values, sourceLocation, comments, ignoredChars);
113124
return arrayValue;
114125
}
115126
}

src/main/java/graphql/language/BooleanValue.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class BooleanValue extends AbstractNode<BooleanValue> implements ScalarVa
1616
private final boolean value;
1717

1818
@Internal
19-
protected BooleanValue(boolean value, SourceLocation sourceLocation, List<Comment> comments) {
20-
super(sourceLocation, comments);
19+
protected BooleanValue(boolean value, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars) {
20+
super(sourceLocation, comments, ignoredChars);
2121
this.value = value;
2222
}
2323

@@ -27,7 +27,7 @@ protected BooleanValue(boolean value, SourceLocation sourceLocation, List<Commen
2727
* @param value of the Boolean
2828
*/
2929
public BooleanValue(boolean value) {
30-
this(value, null, new ArrayList<>());
30+
this(value, null, new ArrayList<>(), IgnoredChars.EMPTY);
3131
}
3232

3333
public boolean isValue() {
@@ -41,8 +41,12 @@ public List<Node> getChildren() {
4141

4242
@Override
4343
public boolean isEqualTo(Node o) {
44-
if (this == o) return true;
45-
if (o == null || getClass() != o.getClass()) return false;
44+
if (this == o) {
45+
return true;
46+
}
47+
if (o == null || getClass() != o.getClass()) {
48+
return false;
49+
}
4650

4751
BooleanValue that = (BooleanValue) o;
4852

@@ -52,7 +56,7 @@ public boolean isEqualTo(Node o) {
5256

5357
@Override
5458
public BooleanValue deepCopy() {
55-
return new BooleanValue(value, getSourceLocation(), getComments());
59+
return new BooleanValue(value, getSourceLocation(), getComments(), getIgnoredChars());
5660
}
5761

5862
@Override
@@ -86,6 +90,7 @@ public static final class Builder implements NodeBuilder {
8690
private SourceLocation sourceLocation;
8791
private boolean value;
8892
private List<Comment> comments = new ArrayList<>();
93+
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
8994

9095
private Builder() {
9196
}
@@ -94,6 +99,7 @@ private Builder(BooleanValue existing) {
9499
this.sourceLocation = existing.getSourceLocation();
95100
this.comments = existing.getComments();
96101
this.value = existing.isValue();
102+
this.ignoredChars = existing.getIgnoredChars();
97103
}
98104

99105

@@ -112,8 +118,13 @@ public Builder comments(List<Comment> comments) {
112118
return this;
113119
}
114120

121+
public Builder ignoredChars(IgnoredChars ignoredChars) {
122+
this.ignoredChars = ignoredChars;
123+
return this;
124+
}
125+
115126
public BooleanValue build() {
116-
BooleanValue booleanValue = new BooleanValue(value, sourceLocation, comments);
127+
BooleanValue booleanValue = new BooleanValue(value, sourceLocation, comments, ignoredChars);
117128
return booleanValue;
118129
}
119130
}

src/main/java/graphql/language/Directive.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class Directive extends AbstractNode<Directive> implements NamedNode<Dire
1919
private final List<Argument> arguments = new ArrayList<>();
2020

2121
@Internal
22-
protected Directive(String name, List<Argument> arguments, SourceLocation sourceLocation, List<Comment> comments) {
23-
super(sourceLocation, comments);
22+
protected Directive(String name, List<Argument> arguments, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars) {
23+
super(sourceLocation, comments, ignoredChars);
2424
this.name = name;
2525
this.arguments.addAll(arguments);
2626
}
@@ -32,7 +32,7 @@ protected Directive(String name, List<Argument> arguments, SourceLocation source
3232
* @param arguments of the directive
3333
*/
3434
public Directive(String name, List<Argument> arguments) {
35-
this(name, arguments, null, new ArrayList<>());
35+
this(name, arguments, null, new ArrayList<>(), IgnoredChars.EMPTY);
3636
}
3737

3838

@@ -42,7 +42,7 @@ public Directive(String name, List<Argument> arguments) {
4242
* @param name of the directive
4343
*/
4444
public Directive(String name) {
45-
this(name, new ArrayList<>(), null, new ArrayList<>());
45+
this(name, new ArrayList<>(), null, new ArrayList<>(), IgnoredChars.EMPTY);
4646
}
4747

4848
public List<Argument> getArguments() {
@@ -71,8 +71,12 @@ public List<Node> getChildren() {
7171

7272
@Override
7373
public boolean isEqualTo(Node o) {
74-
if (this == o) return true;
75-
if (o == null || getClass() != o.getClass()) return false;
74+
if (this == o) {
75+
return true;
76+
}
77+
if (o == null || getClass() != o.getClass()) {
78+
return false;
79+
}
7680

7781
Directive that = (Directive) o;
7882

@@ -82,7 +86,7 @@ public boolean isEqualTo(Node o) {
8286

8387
@Override
8488
public Directive deepCopy() {
85-
return new Directive(name, deepCopy(arguments), getSourceLocation(), getComments());
89+
return new Directive(name, deepCopy(arguments), getSourceLocation(), getComments(), getIgnoredChars());
8690
}
8791

8892
@Override
@@ -113,6 +117,7 @@ public static final class Builder implements NodeBuilder {
113117
private List<Comment> comments = new ArrayList<>();
114118
private String name;
115119
private List<Argument> arguments = new ArrayList<>();
120+
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
116121

117122
private Builder() {
118123
}
@@ -122,6 +127,7 @@ private Builder(Directive existing) {
122127
this.comments = existing.getComments();
123128
this.name = existing.getName();
124129
this.arguments = existing.getArguments();
130+
this.ignoredChars = existing.getIgnoredChars();
125131
}
126132

127133

@@ -145,8 +151,13 @@ public Builder arguments(List<Argument> arguments) {
145151
return this;
146152
}
147153

154+
public Builder ignoredChars(IgnoredChars ignoredChars) {
155+
this.ignoredChars = ignoredChars;
156+
return this;
157+
}
158+
148159
public Directive build() {
149-
Directive directive = new Directive(name, arguments, sourceLocation, comments);
160+
Directive directive = new Directive(name, arguments, sourceLocation, comments, ignoredChars);
150161
return directive;
151162
}
152163
}

0 commit comments

Comments
 (0)