You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/08/06 10:56:53 UTC

[GitHub] rtaneja1 commented on a change in pull request #650: [NETBEANS-1075]-Adding var hints for enhanced-for-loop

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_r207851120
 
 

 ##########
 File path: java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToVarHint.java
 ##########
 @@ -148,9 +172,16 @@ private static boolean preConditionChecker(HintContext ctx) {
         }
 
         TreePath treePath = ctx.getPath();
-
+        EnhancedForLoopTree efl = null;
+        TypeMirror expressionType = null;
+        if (treePath.getLeaf() instanceof EnhancedForLoopTree) {
+            efl = (EnhancedForLoopTree) treePath.getLeaf();
+            expressionType = ctx.getInfo().getTrees().getTypeMirror(new TreePath(treePath, efl.getExpression()));
+        }
+        
         // variable should have local scope
-        if (info.getTrees().getElement(treePath).getKind() != ElementKind.LOCAL_VARIABLE) {
+        //No need to DeclaredType check as primitive types can also be replaced with var in enhanced-for-loop
+        if ((info.getTrees().getElement(treePath)!=null && info.getTrees().getElement(treePath).getKind() != ElementKind.LOCAL_VARIABLE) && expressionType == null) {
 
 Review comment:
   Please run Source-format for newly added code. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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

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