mbien commented on code in PR #4278:
URL: https://github.com/apache/netbeans/pull/4278#discussion_r906306838


##########
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:
   could this be solved by listing all local vars of `$init` (maybe there is a 
utility for that) and running `!referencedIn` on `$statements$` for each of 
them?



-- 
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

Reply via email to