mbien commented on code in PR #4278:
URL: https://github.com/apache/netbeans/pull/4278#discussion_r906362247
##########
java/java.hints/src/org/netbeans/modules/java/hints/suggestions/Tiny.java:
##########
@@ -400,4 +402,18 @@ protected void performRewrite(final TransformationContext
ctx) {
}
+ @Hint(displayName =
"#DN_org.netbeans.modules.java.hints.suggestions.Tiny.inlineRedundantVar",
description =
"#DESC_org.netbeans.modules.java.hints.suggestions.Tiny.inlineRedundantVar",
category="suggestions", severity=Severity.HINT)
+ @TriggerPattern(value="$before$; $type $var = $init; $statements$; return
$var;")
+ public static ErrorDescription inlineRedundantVar(HintContext ctx) {
+ TreePath var = ctx.getVariables().get("$var");
+ Collection<? extends TreePath> stats =
ctx.getMultiVariables().get("$statements$");
+ if (var != null && stats != null) {
+ Element element = ctx.getInfo().getTrees().getElement(var);
+ if (element != null && element.getKind() ==
ElementKind.LOCAL_VARIABLE && !Utilities.isReferencedIn(ctx.getInfo(), var,
stats)) {
Review Comment:
I like your first solution. I maintain a list of jackpot rules I used myself
over time (https://github.com/mbien/jackpot-inspections) and the first FAQ
entry is:
Q: Can I apply suggested inspections without code review and testing?
A: No.
I don't think all hints have to be fool proof it it is communicated to the
user that they can be risky. Like switching out StringBuffer with Builder will
work in 99% of the time, but fail in the one case when someone actually shared
it between threads. I believe this is completely OK.
Thats why I am somewhat for reverting it to the more aggressive version
which uses `!referencedIn` as best effort attempt to suggest the right thing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists