lahodaj commented on code in PR #7075:
URL: https://github.com/apache/netbeans/pull/7075#discussion_r1508885040


##########
java/spi.java.hints/src/org/netbeans/spi/java/hints/JavaFixUtilities.java:
##########
@@ -243,34 +245,55 @@ public static Fix safelyRemoveFromParent(HintContext ctx, 
String displayName, Tr
         return RemoveFromParent.canSafelyRemove(ctx.getInfo(), what) ? new 
RemoveFromParent(displayName, ctx.getInfo(), what, true).toEditorFix() : null;
     }
 
-    private static String defaultFixDisplayName(CompilationInfo info, 
Map<String, TreePath> variables, String replaceTarget) {
-        Map<String, String> stringsForVariables = new HashMap<>();
+    @SuppressWarnings("AssignmentToMethodParameter")
+    private static String defaultFixDisplayName(CompilationInfo info, 
Map<String, TreePath> variables, Map<String, Collection<? extends TreePath>> 
parametersMulti, String replaceTarget) {
+        Map<String, String> stringsForVariables = new LinkedHashMap<>();
 
-        for (Entry<String, TreePath> e : variables.entrySet()) {
-            Tree t = e.getValue().getLeaf();
-            SourcePositions sp = info.getTrees().getSourcePositions();
-            int startPos = (int) 
sp.getStartPosition(info.getCompilationUnit(), t);
-            int endPos = (int) sp.getEndPosition(info.getCompilationUnit(), t);
-
-            if (startPos >= 0 && endPos >= 0) {
-                stringsForVariables.put(e.getKey(), 
info.getText().substring(startPos, endPos));
-            } else {
+        // replace multi vars first
+        for (Entry<String, Collection<? extends TreePath>> e : 
parametersMulti.entrySet()) {
+            if (e.getKey().startsWith("$$")) {
+                continue;
+            }
+            if (e.getValue().isEmpty()) {
+                stringsForVariables.put(e.getKey()+";", "");    // could be a 
statement
                 stringsForVariables.put(e.getKey(), "");
+            } else if (e.getValue().size() == 1) {
+                String text = treeToString(e.getValue().iterator().next(), 
info);
+                stringsForVariables.put(e.getKey()+";", text);  // could be a 
statement
+                stringsForVariables.put(e.getKey(), text);
+            } else {
+                // keep the varible in the text for more complex cases, but we 
have to escape it somehow

Review Comment:
   ```suggestion
                   // keep the variable in the text for more complex cases, but 
we have to escape it somehow
   ```



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