Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify code in ReloadableJavaParserVisitor#visitVariables() #4263

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1585,10 +1585,10 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm

Space namedVarPrefix = sourceBefore(n.getName().toString());

JavaType type = typeMapping.type(n);
JavaType.Variable type = typeMapping.variableType(n.sym);
J.Identifier name = new J.Identifier(randomId(), EMPTY, Markers.EMPTY, emptyList(), n.getName().toString(),
type instanceof JavaType.Variable ? ((JavaType.Variable) type).getType() : type,
type instanceof JavaType.Variable ? (JavaType.Variable) type : null);
type != null ? type.getType() : null,
type);
Comment on lines +1590 to +1591
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the same for our Java 21 parser to carry this improvement forward?

J.Identifier name = new J.Identifier(randomId(), EMPTY, Markers.EMPTY, emptyList(), n.getName().toString(),
type instanceof JavaType.Variable ? ((JavaType.Variable) type).getType() : type,
type instanceof JavaType.Variable ? (JavaType.Variable) type : null);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah we posted the same insight in the same minute. :)

List<JLeftPadded<Space>> dimensionsAfterName = arrayDimensions();

vars.add(
Expand All @@ -1597,7 +1597,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
name,
dimensionsAfterName,
n.init != null ? padLeft(sourceBefore("="), convertOrNull(n.init)) : null,
(JavaType.Variable) typeMapping.type(n)
typeMapping.variableType(n.sym)
),
i == nodes.size() - 1 ? EMPTY : sourceBefore(",")
)
Expand Down
Loading