Skip to content

Commit 485cfe7

Browse files
committed
ListParseNode this-escape is hard to avoid and is fine
* sourceCharIndex/sourceLength are set before addInternal() is called, which calls extendPosition() and use those fields.
1 parent 5fe1361 commit 485cfe7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/org/truffleruby/parser/ast/ListParseNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class ListParseNode extends ParseNode {
4848
*
4949
* @param position where list is
5050
* @param firstNode first element of the list */
51+
@SuppressWarnings("this-escape")
5152
protected ListParseNode(SourceIndexLength position, ParseNode firstNode) {
5253
super(position);
5354

@@ -66,7 +67,7 @@ public NodeType getNodeType() {
6667
return NodeType.LISTNODE;
6768
}
6869

69-
protected void growList(int mustBeDelta) {
70+
private void growList(int mustBeDelta) {
7071
int newSize = list.length * 2;
7172
// Fairly arbitrary to scale 1.5 here but this means we are adding a lot so I think
7273
// we can taper the multiplier
@@ -79,7 +80,7 @@ protected void growList(int mustBeDelta) {
7980
list = newList;
8081
}
8182

82-
protected void addInternal(ParseNode node) {
83+
private void addInternal(ParseNode node) {
8384
if (size >= list.length) {
8485
growList(1);
8586
}

src/main/java/org/truffleruby/parser/ast/ParseNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public ParseNode(SourceIndexLength position) {
6262
this instanceof RequiredKeywordArgumentValueParseNode : this.getClass();
6363
}
6464

65-
public void setNewline() {
65+
public final void setNewline() {
6666
this.newline = true;
6767
}
6868

69-
public boolean isNewline() {
69+
public final boolean isNewline() {
7070
return newline;
7171
}
7272

@@ -79,7 +79,7 @@ public final SourceIndexLength getPosition() {
7979
return new SourceIndexLength(sourceCharIndex, sourceLength);
8080
}
8181

82-
public void extendPosition(ParseNode node) {
82+
public final void extendPosition(ParseNode node) {
8383
if (this.hasPosition() && node.hasPosition()) {
8484
int begin = Math.min(this.sourceCharIndex, node.sourceCharIndex);
8585
int end = Math.max(this.sourceCharIndex + this.sourceLength, node.sourceCharIndex + node.sourceLength);
@@ -88,7 +88,7 @@ public void extendPosition(ParseNode node) {
8888
}
8989
}
9090

91-
public void extendPosition(SourceIndexLength pos) {
91+
public final void extendPosition(SourceIndexLength pos) {
9292
if (this.hasPosition() && pos.isAvailable()) {
9393
int begin = Math.min(this.sourceCharIndex, pos.getCharIndex());
9494
int end = Math.max(this.sourceCharIndex + this.sourceLength, pos.getCharEnd());

0 commit comments

Comments
 (0)