-
Notifications
You must be signed in to change notification settings - Fork 682
Add LocalVariableNameFactory. #3271
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
base: 4.0.x
Are you sure you want to change the base?
Conversation
10f4ee9
to
9d146dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @christophstrobl . I made a few minor suggestions. PTAL.
src/main/java/org/springframework/data/repository/aot/generate/LocalVariableNameFactory.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/repository/aot/generate/VariableNameFactory.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/repository/aot/generate/VariableNameFactory.java
Outdated
Show resolved
Hide resolved
...java/org/springframework/data/repository/aot/generate/LocalVariableNameFactoryUnitTests.java
Show resolved
Hide resolved
return new LocalVariableNameFactory(variables); | ||
} | ||
|
||
LocalVariableNameFactory(Iterable<String> predefinedVariableNames) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simplification of this could be:
LocalVariableNameFactory(Iterable<String> predefinedVariableNames) {
predefinedVariableNames.forEach((paramName) -> variables.put(paramName, 0L));
}
Wdyt?
Add a variable name factory that considers predefined names and resolves name clashes. Expose variable name clash resolution via the generation context of a single method.
9d146dc
to
4a48edc
Compare
} | ||
|
||
String targetName = suggestTargetName(intendedVariableName); | ||
variables.add(intendedVariableName, targetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update the original intendedVariableName
?
This code is fine but concurrency aside, I still think something like the following that would replace line62-86 would simplify things:
@Override
public String generateName(String suggestedName) {
var counter = variables.compute(suggestedName,
(__, currentCount) -> currentCount == null ? 0 : currentCount.longValue() + 1);
return counter == 0 ? suggestedName : "%s_%s".formatted(suggestedName, counter));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @christophstrobl - LGTM
Add a variable name factory that considers predefined names and resolves name clashes.
Expose variable name clash resolution via the generation context of a single method.