Removing reading of the nullness data from the project metadata, using only nullness annotations.
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 19 Apr 2012 21:04:16 +0200
changeset 17818361013e4690a
parent 17815 5df2d064fa29
child 17819 c912ef634638
Removing reading of the nullness data from the project metadata, using only nullness annotations.
javahints/src/org/netbeans/modules/javahints/NPECheck.java
     1.1 --- a/javahints/src/org/netbeans/modules/javahints/NPECheck.java	Mon Apr 16 15:13:19 2012 -0400
     1.2 +++ b/javahints/src/org/netbeans/modules/javahints/NPECheck.java	Thu Apr 19 21:04:16 2012 +0200
     1.3 @@ -49,7 +49,6 @@
     1.4  import com.sun.source.util.TreePath;
     1.5  import com.sun.source.util.TreePathScanner;
     1.6  import java.util.ArrayList;
     1.7 -import java.util.Collections;
     1.8  import java.util.EnumSet;
     1.9  import java.util.HashMap;
    1.10  import java.util.HashSet;
    1.11 @@ -58,7 +57,6 @@
    1.12  import java.util.Map;
    1.13  import java.util.Map.Entry;
    1.14  import java.util.Set;
    1.15 -import java.util.WeakHashMap;
    1.16  import javax.lang.model.element.AnnotationMirror;
    1.17  import javax.lang.model.element.Element;
    1.18  import javax.lang.model.element.ElementKind;
    1.19 @@ -66,20 +64,12 @@
    1.20  import javax.lang.model.element.TypeElement;
    1.21  import javax.lang.model.element.VariableElement;
    1.22  import org.netbeans.api.java.source.CompilationInfo;
    1.23 -import org.netbeans.api.java.source.SourceUtils;
    1.24 -import org.netbeans.api.project.FileOwnerQuery;
    1.25 -import org.netbeans.api.project.Project;
    1.26 -import org.netbeans.api.project.ProjectUtils;
    1.27  import org.netbeans.modules.java.hints.spi.AbstractHint;
    1.28  import org.netbeans.modules.java.hints.spi.support.FixFactory;
    1.29  import org.netbeans.spi.editor.hints.ErrorDescription;
    1.30  import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
    1.31  import org.netbeans.spi.editor.hints.Fix;
    1.32 -import org.netbeans.spi.project.AuxiliaryConfiguration;
    1.33 -import org.openide.filesystems.FileObject;
    1.34  import org.openide.util.NbBundle;
    1.35 -import org.w3c.dom.Node;
    1.36 -import org.w3c.dom.NodeList;
    1.37  
    1.38  import static org.netbeans.modules.javahints.NPECheck.State.*;
    1.39  
    1.40 @@ -577,7 +567,7 @@
    1.41              for (AnnotationMirror am : e.getAnnotationMirrors()) {
    1.42                  String simpleName = ((TypeElement) am.getAnnotationType().asElement()).getSimpleName().toString();
    1.43  
    1.44 -                if ("Nullable".equals(simpleName)) {
    1.45 +                if ("Nullable".equals(simpleName) || "NullAllowed".equals(simpleName)) {
    1.46                      return State.POSSIBLE_NULL_REPORT;
    1.47                  }
    1.48  
    1.49 @@ -585,32 +575,15 @@
    1.50                      return State.POSSIBLE_NULL_REPORT;
    1.51                  }
    1.52  
    1.53 -                if ("NotNull".equals(simpleName)) {
    1.54 +                if ("NotNull".equals(simpleName) || "NonNull".equals(simpleName)) {
    1.55                      return State.NOT_NULL;
    1.56                  }
    1.57              }
    1.58 -            
    1.59 -            if (e.getKind() == ElementKind.METHOD) {
    1.60 -                String fqn = getFQN((ExecutableElement) e);
    1.61 -                Project owner = findProject(info, e);
    1.62 -                
    1.63 -                if (owner != null && findCheckForNullNames(owner).contains(fqn)) {
    1.64 -                    return State.POSSIBLE_NULL_REPORT;
    1.65 -                }
    1.66 -            }
    1.67  
    1.68              return def;
    1.69          }
    1.70      }
    1.71      
    1.72 -    private String getFQN(ExecutableElement ee) {
    1.73 -        TypeElement te = (TypeElement) ee.getEnclosingElement();
    1.74 -        
    1.75 -        return te.getQualifiedName().toString() + "." + ee.getSimpleName().toString();
    1.76 -    }
    1.77 -    
    1.78 -    private static final Set<ElementKind> LOCAL_VARIABLES = EnumSet.of(ElementKind.EXCEPTION_PARAMETER, ElementKind.LOCAL_VARIABLE, ElementKind.PARAMETER);
    1.79 -    
    1.80      static enum State {
    1.81          NULL,
    1.82          POSSIBLE_NULL,
    1.83 @@ -695,56 +668,6 @@
    1.84          
    1.85      }
    1.86      
    1.87 -    private static final Map<TypeElement, Project> class2Project = new WeakHashMap<TypeElement, Project>();
    1.88 -    
    1.89 -    private static Project findProject(CompilationInfo info, Element e) {
    1.90 -        TypeElement owner = info.getElementUtilities().outermostTypeElement(e);
    1.91 -        
    1.92 -        if (owner == null) return null;
    1.93 -        
    1.94 -        Project p = class2Project.get(owner);
    1.95 -        
    1.96 -        if (p == null) {
    1.97 -            FileObject source = SourceUtils.getFile(e, info.getClasspathInfo());
    1.98 -
    1.99 -            if (source != null) {
   1.100 -                p = FileOwnerQuery.getOwner(source);
   1.101 -                
   1.102 -                if (p != null) {
   1.103 -                    class2Project.put(owner, p);
   1.104 -                }
   1.105 -            }
   1.106 -        }
   1.107 -        
   1.108 -        return p;
   1.109 -    }
   1.110 -    
   1.111 -    private static final Map<Project, Set<String>> project2CheckForNullNames = new WeakHashMap<Project, Set<String>>();
   1.112 -    
   1.113 -    private static Set<String> findCheckForNullNames(Project p) {
   1.114 -        Set<String> set = project2CheckForNullNames.get(p);
   1.115 -        
   1.116 -        if (set == null) {
   1.117 -            project2CheckForNullNames.put(p, set = new HashSet<String>());
   1.118 -            AuxiliaryConfiguration ac = ProjectUtils.getAuxiliaryConfiguration(p);
   1.119 -
   1.120 -            if (ac != null) {
   1.121 -                org.w3c.dom.Element configurationFragment = ac.getConfigurationFragment("npe-check-hints", "http://www.netbeans.org/ns/npe-check-hints/1", true);
   1.122 -
   1.123 -                if (configurationFragment != null) {
   1.124 -                    NodeList nl = configurationFragment.getElementsByTagName("check-for-null");
   1.125 -
   1.126 -                    for (int cntr = 0; cntr < nl.getLength(); cntr++) {
   1.127 -                        Node n = nl.item(cntr);
   1.128 -                        set.add(n.getTextContent());
   1.129 -                    }
   1.130 -                }
   1.131 -            }
   1.132 -        }
   1.133 -        
   1.134 -        return set;
   1.135 -    }
   1.136 -    
   1.137      private static boolean isVariableElement(Element ve) {
   1.138          return ve != null && VARIABLE_ELEMENT.contains(ve.getKind());
   1.139      }