Skip to content

Commit f86e406

Browse files
[Text blocks] Code review driven incremental clean up (eclipse-jdt#4138)
1 parent a6f1b58 commit f86e406

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ private void reportNLSProblems() {
704704
int i = 0;
705705
stringLiteralsLoop: for (; i < stringLiteralsLength; i++) {
706706
literal = this.stringLiterals[i];
707-
final int literalLineNumber = literal instanceof TextBlock ? ((TextBlock)literal).endLineNumber : literal.getLineNumber();
707+
final int literalLineNumber = literal instanceof TextBlock textBlock ? textBlock.endLineNumber : literal.getLineNumber();
708708
if (lastLineNumber != literalLineNumber) {
709709
indexInLine = 1;
710710
lastLineNumber = literalLineNumber;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TextBlock.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ public class TextBlock extends StringLiteral {
1818

1919
public int endLineNumber;
2020

21-
private TextBlock(char[] token, int start, int end, int lineNumber, int endLineNumber) {
21+
public TextBlock(char[] token, int start, int end, int lineNumber, int endLineNumber) {
2222
super(token, start,end, lineNumber);
23-
this.endLineNumber= endLineNumber - 1; // line number is 1 based
24-
}
25-
public static TextBlock createTextBlock(char[] token, int start, int end, int lineNumber, int endLineNumber) {
26-
return new TextBlock(token, start,end, lineNumber, endLineNumber);
23+
this.endLineNumber = endLineNumber - 1; // line number is 1 based
2724
}
25+
2826
@Override
2927
public StringBuilder printExpression(int indent, StringBuilder output) {
3028
output.append("\"\"\"\n"); //$NON-NLS-1$
31-
for (char c:this.source()) {
29+
for (char c: this.source()) {
3230
Util.appendEscapedChar(output, c, true);
3331
}
3432
output.append("\"\"\""); //$NON-NLS-1$
3533
return output;
3634
}
37-
}
35+
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9156,34 +9156,15 @@ protected void consumeStaticOnly() {
91569156
}
91579157
private void consumeTextBlock() {
91589158
problemReporter().validateJavaFeatureSupport(JavaFeature.TEXT_BLOCKS, this.scanner.startPosition, this.scanner.currentPosition - 1);
9159-
char[] allchars = this.scanner.getCurrentTextBlock();
9160-
TextBlock textBlock = createTextBlock(allchars, this.scanner.startPosition, this.scanner.currentPosition - 1);
9161-
pushOnExpressionStack(textBlock);
9162-
}
9163-
private TextBlock createTextBlock(char[] allchars, int start, int end) {
9164-
TextBlock textBlock;
9165-
if (this.recordStringLiterals &&
9166-
!this.reparsingFunctionalExpression &&
9167-
this.checkExternalizeStrings &&
9168-
this.lastPosistion < this.scanner.currentPosition &&
9169-
!this.statementRecoveryActivated) {
9170-
textBlock =
9171-
TextBlock.createTextBlock(
9172-
allchars,
9173-
start,
9174-
end,
9175-
Util.getLineNumber(this.scanner.startPosition, this.scanner.lineEnds, 0, this.scanner.linePtr),
9176-
Util.getLineNumber(this.scanner.currentPosition - 1, this.scanner.lineEnds, 0, this.scanner.linePtr));
9159+
boolean shouldRecordStringLiterals = this.recordStringLiterals && !this.reparsingFunctionalExpression && this.checkExternalizeStrings &&
9160+
this.lastPosistion < this.scanner.currentPosition && !this.statementRecoveryActivated;
9161+
9162+
TextBlock textBlock = new TextBlock(this.scanner.getCurrentTextBlock(), this.scanner.startPosition, this.scanner.currentPosition - 1,
9163+
shouldRecordStringLiterals ? Util.getLineNumber(this.scanner.startPosition, this.scanner.lineEnds, 0, this.scanner.linePtr) : 0,
9164+
shouldRecordStringLiterals ? Util.getLineNumber(this.scanner.currentPosition - 1, this.scanner.lineEnds, 0, this.scanner.linePtr) : 0);
9165+
if (shouldRecordStringLiterals)
91779166
this.compilationUnit.recordStringLiteral(textBlock, this.currentElement != null);
9178-
} else {
9179-
textBlock = TextBlock.createTextBlock(
9180-
allchars,
9181-
start,
9182-
end,
9183-
0,
9184-
0);
9185-
}
9186-
return textBlock;
9167+
pushOnExpressionStack(textBlock);
91879168
}
91889169
protected void consumeSwitchBlock(boolean hasContents) {
91899170
// SwitchBlock ::= '{' { SwitchBlockStatements SwitchLabels } '}'

org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,8 @@ public Expression convert(org.eclipse.jdt.internal.compiler.ast.Expression expre
20532053
if (expression instanceof org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral) {
20542054
return convert((org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral) expression);
20552055
}
2056-
if (expression instanceof org.eclipse.jdt.internal.compiler.ast.TextBlock) {
2057-
return convert((org.eclipse.jdt.internal.compiler.ast.TextBlock) expression);
2056+
if (expression instanceof org.eclipse.jdt.internal.compiler.ast.TextBlock textBlock) {
2057+
return convert(textBlock);
20582058
}
20592059
if (expression instanceof org.eclipse.jdt.internal.compiler.ast.StringLiteral) {
20602060
return convert((org.eclipse.jdt.internal.compiler.ast.StringLiteral) expression);

0 commit comments

Comments
 (0)