This is an automated email from the ASF dual-hosted git repository.

jlahoda pushed a commit to branch release90
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git

commit 368b001e28552c0a90b959ee2da7644fca5e59b4
Author: rtaneja <[email protected]>
AuthorDate: Wed May 30 22:57:04 2018 -0700

    [NETBEANS-774] : disable var hint for anonymous types
---
 .../modules/java/hints/errors/Utilities.java       | 12 ++++++++++
 .../java/hints/jdk/ConvertVarToExplicitType.java   | 26 ++++++++--------------
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git 
a/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java 
b/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java
index 4fb6e5f..414fa5f 100644
--- a/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java
+++ b/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java
@@ -138,6 +138,7 @@ import com.sun.tools.javac.util.JCDiagnostic;
 import com.sun.tools.javac.util.Log;
 import java.net.URI;
 import java.util.concurrent.Callable;
+import javax.lang.model.element.NestingKind;
 import javax.lang.model.type.ErrorType;
 import javax.lang.model.type.UnionType;
 import javax.tools.Diagnostic;
@@ -2995,4 +2996,15 @@ public class Utilities {
     public static boolean isModular(CompilationInfo info) {
         return getModuleInfo(info) != null;
     }
+    
+    public static boolean isAnonymousType(TypeMirror type) {
+        if (type.getKind() == TypeKind.DECLARED) {
+            DeclaredType dt = (DeclaredType) type;
+            TypeElement typeElem = (TypeElement) dt.asElement();
+            if (typeElem.getNestingKind() == NestingKind.ANONYMOUS) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
diff --git 
a/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertVarToExplicitType.java
 
b/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertVarToExplicitType.java
index 798ae0d..db826e7 100644
--- 
a/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertVarToExplicitType.java
+++ 
b/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertVarToExplicitType.java
@@ -19,14 +19,11 @@
 package org.netbeans.modules.java.hints.jdk;
 
 import com.sun.source.tree.CompilationUnitTree;
-import com.sun.source.tree.NewClassTree;
 import com.sun.source.tree.Tree;
 import com.sun.source.tree.VariableTree;
 import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import javax.lang.model.SourceVersion;
 import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.TypeElement;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
@@ -154,22 +151,17 @@ public class ConvertVarToExplicitType {
     //filter anonymous class and intersection types
     private static boolean isValidType(HintContext ctx) {
         TreePath treePath = ctx.getPath();
-        TreePath initTreePath = ctx.getVariables().get("$init");  //NOI18N
         TypeMirror variableTypeMirror = 
ctx.getInfo().getTrees().getElement(treePath).asType();
 
-        if (initTreePath.getLeaf().getKind() == Tree.Kind.NEW_CLASS) {
-            NewClassTree nct = ((NewClassTree) initTreePath.getLeaf());
-            if (nct.getClassBody() != null) {
-                return false;
-            }
-        } else if (initTreePath.getLeaf().getKind() == 
Tree.Kind.METHOD_INVOCATION) {
-            //filter anonymous class type return type
-            if (variableTypeMirror.getKind() == TypeKind.DECLARED) {
-                DeclaredType dt = (DeclaredType) variableTypeMirror;
-                TypeElement typeElem = (TypeElement) dt.asElement();
-                ClassSymbol sym = (ClassSymbol) typeElem;
-                if (sym.isAnonymous()) {
-                    return false;
+        if (Utilities.isAnonymousType(variableTypeMirror)) {
+            return false;
+        } else if (variableTypeMirror.getKind() == TypeKind.DECLARED) {
+            DeclaredType dt = (DeclaredType) variableTypeMirror;
+            if (dt.getTypeArguments().size() > 0) {
+                for (TypeMirror paramType : dt.getTypeArguments()) {
+                    if (Utilities.isAnonymousType(paramType)) {
+                        return false;
+                    }
                 }
             }
         }

-- 
To stop receiving notification emails like this one, please contact
[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