Skip to content

Commit b12e400

Browse files
committed
Implement (most of) option openjdk#2 from discussion in PR openjdk#25664.
There is still one test failure (SourceTreeScannerTest.java).
1 parent 4434c13 commit b12e400

File tree

8 files changed

+262
-163
lines changed

8 files changed

+262
-163
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,9 +5717,9 @@ private Type capture(Type type) {
57175717
private void setSyntheticVariableType(JCVariableDecl tree, Type type) {
57185718
if (type.isErroneous()) {
57195719
tree.vartype = make.at(tree.pos()).Erroneous();
5720-
} else if (tree.declaredUsingVar()) { // set the type's start and end positions to match the "var" keyword
5720+
} else if (tree.declaredUsingVar()) {
57215721
Assert.check(tree.typePos != Position.NOPOS);
5722-
tree.vartype = make.at(tree.typePos, tree.typePos + names.var.length(), env.toplevel.endPositions).Type(type);
5722+
tree.vartype = make.at(tree.typePos).Type(type);
57235723
} else {
57245724
tree.vartype = make.at(tree.pos()).Type(type);
57255725
}

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,7 @@ public String toString() {
463463
/** Set position field and return this tree.
464464
*/
465465
public JCTree setPos(int pos) {
466-
return setPos(pos, Position.NOPOS, null);
467-
}
468-
469-
/** Set start and end position and return this tree.
470-
*/
471-
public JCTree setPos(int pos, int endPos, EndPosTable endPosTable) {
472466
this.pos = pos;
473-
if (endPos != Position.NOPOS && endPosTable != null)
474-
endPosTable.storeEnd(this, endPos);
475467
return this;
476468
}
477469

@@ -1091,7 +1083,13 @@ public boolean declaredUsingVar() {
10911083
@DefinedBy(Api.COMPILER_TREE)
10921084
public JCExpression getNameExpression() { return nameexpr; }
10931085
@DefinedBy(Api.COMPILER_TREE)
1094-
public JCTree getType() { return vartype; }
1086+
public JCTree getType() {
1087+
return switch (declKind) {
1088+
case EXPLICIT -> vartype;
1089+
case IMPLICIT -> null;
1090+
case VAR -> name != null ? new JCIdent(name.table.names.var, sym) : null;
1091+
};
1092+
}
10951093
@DefinedBy(Api.COMPILER_TREE)
10961094
public JCExpression getInitializer() {
10971095
return init;

0 commit comments

Comments
 (0)