Skip to content

Commit

Permalink
Fix source positions and failing DOM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthana committed Nov 12, 2023
1 parent 48d6488 commit 0693e4d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10075,7 +10075,7 @@ private void consumeTemplate(int token) {
}
}
this.scanner.withoutUnicodePtr = 0;
StringTemplate template = new StringTemplate(fragments, expressions, this.scanner.startPosition, this.scanner.currentPosition - 1);
StringTemplate template = new StringTemplate(fragments, expressions, fragments[0].sourceStart, fragments[expressions.length].sourceEnd);
pushOnExpressionStack(template);
}
private void consumeTextBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ protected int scanForStringLiteral() throws InvalidInputException {
if (isTextBlock) {
return scanForTextBlock();
} else {
int textFragmentStart = this.currentPosition;
int textFragmentStart = this.currentPosition - 1;
try {
// consume next character
this.unicodeAsBackSlash = false;
Expand Down Expand Up @@ -2002,7 +2002,7 @@ protected int scanForStringLiteral() throws InvalidInputException {
// mark the ending of the last fragment in the string template (before the closing quote)
if (this.jumpingOverEmbeddedExpression == 0) {
int textFragmentEnd = this.currentPosition - 2;
addStringTemplateComponent(new TextFragment(textFragmentStart, textFragmentEnd , getCurrentTokenInRange(textFragmentStart - this.startPosition, textFragmentEnd - this.startPosition)));
addStringTemplateComponent(new TextFragment(textFragmentStart, this.currentPosition - 1 , getCurrentTokenInRange(textFragmentStart - this.startPosition, textFragmentEnd - this.startPosition)));
}
return TokenNameStringTemplate;
}
Expand All @@ -2014,22 +2014,21 @@ protected int scanForTextBlock() throws InvalidInputException {
int lastQuotePos = 0;
try {
this.textBlockOffset = this.currentPosition - this.startPosition;
int textFragmentStart = this.currentPosition;
int textFragmentStart = this.startPosition;
while (this.currentPosition <= this.eofPosition) {
if (this.currentCharacter == '"') {
lastQuotePos = this.currentPosition;
// look for text block delimiter
if (scanForTextBlockClose()) {
this.currentPosition += 2; // move it past the triple quote
if (this.stringTemplateComponents != null) {
// mark the ending of the last fragment in the string template (before the closing quote)
if (this.jumpingOverEmbeddedExpression == 0) {
int textFragmentEnd = this.currentPosition - 2;
int textFragmentEnd = this.currentPosition - 1;
addStringTemplateComponent(new TextFragment(textFragmentStart, textFragmentEnd , getCurrentTokenInRange(textFragmentStart - this.startPosition, textFragmentEnd - this.startPosition)));
}
this.currentPosition += 2;
return TokenNameTextBlockTemplate;
}
this.currentPosition += 2;
return TerminalTokens.TokenNameTextBlock;
}
if (this.withoutUnicodePtr != 0) {
Expand Down Expand Up @@ -2131,7 +2130,7 @@ private int getAndStoreStringFragment(int lastFragmentStart) {
if (this.jumpingOverEmbeddedExpression == 0) {
// all offset calculations need to account for unicode
int textFragmentEnd = this.currentPosition - 2;
addStringTemplateComponent(new TextFragment(lastFragmentStart, textFragmentEnd , getCurrentTokenInRange(lastFragmentStart - this.startPosition, textFragmentEnd - this.startPosition)));
addStringTemplateComponent(new TextFragment(lastFragmentStart, textFragmentEnd - 1, getCurrentTokenInRange(lastFragmentStart - this.startPosition, textFragmentEnd - this.startPosition)));
int eeStart = this.currentPosition;
jumpOverEmbeddedExpression();
// verify that we are at } or handle error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ public void testBug130778x() throws JavaModelException {
"1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
" @AnAnnotation(\"a\", \"b\")\n" +
" ^\n" +
"Syntax error on token \",\", < expected\n",
"Syntax error on token \",\", . expected\n",
result);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ public void testBug130778x() throws JavaModelException {
"1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
" @AnAnnotation(\"a\", \"b\")\n" +
" ^\n" +
"Syntax error on token \",\", < expected\n",
"Syntax error on token \",\", . expected\n",
result);
}
public void testBug527351() throws JavaModelException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void testNodeClassForType() {
// oops - guess that's not valid
}
}
assertEquals("Wrong last known type", 114, hi); // last known one
assertEquals("Wrong last known type", 116, hi); // last known one
assertEquals("Wrong number of distinct types", hi, classes.size()); // all classes are distinct
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,8 @@ public StringTemplate convert(org.eclipse.jdt.internal.compiler.ast.StringTempla
}
List<Expression> expressions = strTemplate.expressions();
for (org.eclipse.jdt.internal.compiler.ast.Expression exp : template.values()) {
if (exp == null)
continue;
expressions.add(convert(exp));
}

Expand Down

0 comments on commit 0693e4d

Please sign in to comment.