Add end position for variables coming from variableDeclaratorId().

This commit is contained in:
Archie L. Cobbs 2025-02-17 21:41:19 -06:00
parent 4fcc61269b
commit e235228708
2 changed files with 12 additions and 12 deletions

View File

@ -3944,7 +3944,9 @@ public class JavacParser implements Parser {
log.error(token.pos, Errors.WrongReceiver);
}
}
return toP(F.at(pos).ReceiverVarDef(mods, pn, type));
JCVariableDecl result = toP(F.at(pos).ReceiverVarDef(mods, pn, type));
storeEnd(result, S.prevToken().endPos);
return result;
}
} else {
/** if it is a lambda parameter and the token kind is not an identifier,
@ -3969,8 +3971,10 @@ public class JavacParser implements Parser {
name = names.empty;
}
return toP(F.at(pos).VarDef(mods, name, type, null,
JCVariableDecl result = toP(F.at(pos).VarDef(mods, name, type, null,
type != null && type.hasTag(IDENT) && ((JCIdent)type).name == names.var));
storeEnd(result, S.prevToken().endPos);
return result;
}
/** Resources = Resource { ";" Resources }

View File

@ -87,37 +87,33 @@ public class DeclarationEndPositions {
// JCModuleDecl
checkEndPosition(JCModuleDecl.class,
// 0 1 2 3 4 5
// 012345678901234567890123456789012345678901234567890123456789
"/* comment */ module fred { /* comment */ } /* comment */",
" ^ ");
// JCPackageDecl
checkEndPosition(JCPackageDecl.class,
// 0 1 2 3 4 5
// 012345678901234567890123456789012345678901234567890123456789
"/* comment */ package fred; /* comment */",
" ^ ");
// JCClassDecl
checkEndPosition(JCClassDecl.class,
// 0 1 2 3 4 5
// 012345678901234567890123456789012345678901234567890123456789
"/* comment */ class Fred { /* comment */ } /* comment */",
" ^ ");
// JCMethodDecl
checkEndPosition(JCMethodDecl.class,
// 0 1 2 3 4 5
// 012345678901234567890123456789012345678901234567890123456789
"/* comment */ class Fred { void m() { /* comment */ } } /* comment */",
" ^ ");
// JCVariableDecl
checkEndPosition(JCVariableDecl.class,
// 0 1 2 3 4 5
// 012345678901234567890123456789012345678901234567890123456789
"/* comment */ class Fred { int x; } /* comment */",
" ^ ");
checkEndPosition(JCVariableDecl.class,
"/* comment */ class Fred { int x = 123; } /* comment */",
" ^ ");
checkEndPosition(JCVariableDecl.class,
"/* comment */ class A { try {} catch (Error err) {} } /* comment */",
" ^ ");
}
}