rtaneja1 commented on a change in pull request #650: [NETBEANS-1075]-Adding var 
hints for enhanced-for-loop
URL: https://github.com/apache/incubator-netbeans/pull/650#discussion_r211162851
 
 

 ##########
 File path: 
java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToVarHint.java
 ##########
 @@ -209,17 +228,18 @@ private static boolean isValidVarType(HintContext ctx) {
                 default:
                     break;
             }
+            // variable initializer type should be same as variable type.
+            TypeMirror initTypeMirror = 
ctx.getInfo().getTrees().getTypeMirror(initTreePath);
+            TypeMirror variableTypeMirror = 
ctx.getInfo().getTrees().getElement(treePath).asType();
+            if ((!Utilities.isValidType(initTypeMirror)) || 
(!ctx.getInfo().getTypes().isSameType(variableTypeMirror, 
Utilities.resolveCapturedType(ctx.getInfo(), initTypeMirror)))) {
+                return false;
+            }
+            return true;
+        } else if (expressionTreePath != null) {
+            ExecutableElement iterator = 
ExpandEnhancedForLoop.findIterable(ctx.getInfo());
+            return (iterator != null);
 
 Review comment:
   Please add type check here as well, convert to var hint should show up if 
variable type is same as array or collection data type.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to