Updating the java.hints.scripting sketch to code-hints
authorJan Lahoda <jlahoda@netbeans.org>
Sun, 24 Apr 2016 22:23:36 +0200
changeset 18365230c663a8e62
parent 18364 7f27e0517c1b
child 18366 25e40be87b80
Updating the java.hints.scripting sketch to code-hints
java.hints.scripting/nbproject/project.properties
java.hints.scripting/nbproject/project.xml
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/ClasspathProviderImpl.java
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/HintsTask.java
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/TestsHint.java
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/UberHint.java
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/Utilities.java
java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/layer.xml
     1.1 --- a/java.hints.scripting/nbproject/project.properties	Wed Mar 30 19:21:05 2016 +0200
     1.2 +++ b/java.hints.scripting/nbproject/project.properties	Sun Apr 24 22:23:36 2016 +0200
     1.3 @@ -1,4 +1,4 @@
     1.4  javac.compilerargs=-Xlint -Xlint:-serial
     1.5 -javac.source=1.5
     1.6 +javac.source=1.8
     1.7  release.external/java-engine.jar=modules/ext/java-engine.jar
     1.8  spec.version.base=1.0.0
     2.1 --- a/java.hints.scripting/nbproject/project.xml	Wed Mar 30 19:21:05 2016 +0200
     2.2 +++ b/java.hints.scripting/nbproject/project.xml	Sun Apr 24 22:23:36 2016 +0200
     2.3 @@ -23,6 +23,15 @@
     2.4                      </run-dependency>
     2.5                  </dependency>
     2.6                  <dependency>
     2.7 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
     2.8 +                    <build-prerequisite/>
     2.9 +                    <compile-dependency/>
    2.10 +                    <run-dependency>
    2.11 +                        <release-version>1</release-version>
    2.12 +                        <implementation-version/>
    2.13 +                    </run-dependency>
    2.14 +                </dependency>
    2.15 +                <dependency>
    2.16                      <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
    2.17                      <build-prerequisite/>
    2.18                      <compile-dependency/>
    2.19 @@ -49,6 +58,23 @@
    2.20                      </run-dependency>
    2.21                  </dependency>
    2.22                  <dependency>
    2.23 +                    <code-name-base>org.netbeans.modules.java.source.base</code-name-base>
    2.24 +                    <build-prerequisite/>
    2.25 +                    <compile-dependency/>
    2.26 +                    <run-dependency>
    2.27 +                        <specification-version>2.14</specification-version>
    2.28 +                    </run-dependency>
    2.29 +                </dependency>
    2.30 +                <dependency>
    2.31 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
    2.32 +                    <build-prerequisite/>
    2.33 +                    <compile-dependency/>
    2.34 +                    <run-dependency>
    2.35 +                        <release-version>1</release-version>
    2.36 +                        <specification-version>1.43</specification-version>
    2.37 +                    </run-dependency>
    2.38 +                </dependency>
    2.39 +                <dependency>
    2.40                      <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
    2.41                      <build-prerequisite/>
    2.42                      <compile-dependency/>
    2.43 @@ -58,6 +84,14 @@
    2.44                      </run-dependency>
    2.45                  </dependency>
    2.46                  <dependency>
    2.47 +                    <code-name-base>org.netbeans.spi.java.hints</code-name-base>
    2.48 +                    <build-prerequisite/>
    2.49 +                    <compile-dependency/>
    2.50 +                    <run-dependency>
    2.51 +                        <implementation-version/>
    2.52 +                    </run-dependency>
    2.53 +                </dependency>
    2.54 +                <dependency>
    2.55                      <code-name-base>org.openide.awt</code-name-base>
    2.56                      <build-prerequisite/>
    2.57                      <compile-dependency/>
    2.58 @@ -105,6 +139,14 @@
    2.59                          <specification-version>7.12</specification-version>
    2.60                      </run-dependency>
    2.61                  </dependency>
    2.62 +                <dependency>
    2.63 +                    <code-name-base>org.openide.util.lookup</code-name-base>
    2.64 +                    <build-prerequisite/>
    2.65 +                    <compile-dependency/>
    2.66 +                    <run-dependency>
    2.67 +                        <specification-version>8.33</specification-version>
    2.68 +                    </run-dependency>
    2.69 +                </dependency>
    2.70              </module-dependencies>
    2.71              <public-packages/>
    2.72              <class-path-extension>
     3.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/ClasspathProviderImpl.java	Wed Mar 30 19:21:05 2016 +0200
     3.2 +++ b/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/ClasspathProviderImpl.java	Sun Apr 24 22:23:36 2016 +0200
     3.3 @@ -45,7 +45,6 @@
     3.4  import java.util.ArrayList;
     3.5  import java.util.Collections;
     3.6  import java.util.List;
     3.7 -import java.util.logging.ErrorManager;
     3.8  import java.util.regex.Pattern;
     3.9  import org.netbeans.api.java.classpath.ClassPath;
    3.10  import org.netbeans.api.java.classpath.GlobalPathRegistry;
    3.11 @@ -55,26 +54,31 @@
    3.12  import org.openide.filesystems.FileStateInvalidException;
    3.13  import org.openide.filesystems.FileUtil;
    3.14  import org.openide.util.Exceptions;
    3.15 +import org.openide.util.lookup.ServiceProvider;
    3.16  
    3.17  /**
    3.18   *
    3.19   * @author Jan Lahoda
    3.20   */
    3.21 -@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.java.classpath.ClassPathProvider.class)
    3.22 +@ServiceProvider(service=ClassPathProvider.class, position=0)
    3.23  public class ClasspathProviderImpl implements ClassPathProvider {
    3.24  
    3.25      private ClassPath boot;
    3.26      private ClassPath compile;
    3.27      private ClassPath source;
    3.28 -    
    3.29 +
    3.30      public synchronized ClassPath findClassPath(FileObject file, String type) {
    3.31 -        if (FileUtil.isParentOf(Utilities.getFolder(), file)) {
    3.32 +        FileObject rootCand = file.getFileObject("../../..");
    3.33 +
    3.34 +        String relPath = rootCand != null ? FileUtil.getRelativePath(rootCand, file) : null;
    3.35 +
    3.36 +        if (relPath != null && relPath.startsWith("META-INF/upgrade/")) {
    3.37              if (ClassPath.BOOT.equals(type)) {
    3.38                  if (boot == null) {
    3.39                      boot = ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
    3.40                      GlobalPathRegistry.getDefault().register(type, new ClassPath[] {boot});
    3.41                  }
    3.42 -                
    3.43 +
    3.44                  return boot;
    3.45              }
    3.46              if (ClassPath.COMPILE.equals(type)) {
    3.47 @@ -82,7 +86,7 @@
    3.48                      List<URL> cp = Utilities.computeCP();
    3.49                      URL[] us = new URL[cp.size()];
    3.50                      int index = 0;
    3.51 -                    
    3.52 +
    3.53                      for (URL u : cp) {
    3.54                          if (FileUtil.isArchiveFile(u)) {
    3.55                              us[index++] = FileUtil.getArchiveRoot(u);
    3.56 @@ -90,23 +94,23 @@
    3.57                              us[index++] = u;
    3.58                          }
    3.59                      }
    3.60 -                    
    3.61 +
    3.62                      compile = ClassPathSupport.createClassPath(us);
    3.63                      GlobalPathRegistry.getDefault().register(type, new ClassPath[] {compile});
    3.64                  }
    3.65 -                
    3.66 +
    3.67                  return compile;
    3.68              }
    3.69              if (ClassPath.SOURCE.equals(type)) {
    3.70                  if (source == null) {
    3.71 -                    source = ClassPathSupport.createClassPath(Utilities.getFolder());
    3.72 +                    source = ClassPathSupport.createClassPath(file.getParent());
    3.73                      GlobalPathRegistry.getDefault().register(type, new ClassPath[] {source});
    3.74                  }
    3.75 -                
    3.76 +
    3.77                  return source;
    3.78              }
    3.79          }
    3.80 -        
    3.81 +
    3.82          return null;
    3.83      }
    3.84  
    3.85 @@ -140,5 +144,5 @@
    3.86              return Collections.emptyList();
    3.87          }
    3.88      }
    3.89 -    
    3.90 +
    3.91  }
     4.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/HintsTask.java	Wed Mar 30 19:21:05 2016 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,268 +0,0 @@
     4.4 -/*
     4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 - *
     4.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     4.8 - *
     4.9 - * The contents of this file are subject to the terms of either the GNU
    4.10 - * General Public License Version 2 only ("GPL") or the Common
    4.11 - * Development and Distribution License("CDDL") (collectively, the
    4.12 - * "License"). You may not use this file except in compliance with the
    4.13 - * License. You can obtain a copy of the License at
    4.14 - * http://www.netbeans.org/cddl-gplv2.html
    4.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.16 - * specific language governing permissions and limitations under the
    4.17 - * License.  When distributing the software, include this License Header
    4.18 - * Notice in each file and include the License file at
    4.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    4.20 - * particular file as subject to the "Classpath" exception as provided
    4.21 - * by Sun in the GPL Version 2 section of the License file that
    4.22 - * accompanied this code. If applicable, add the following below the
    4.23 - * License Header, with the fields enclosed by brackets [] replaced by
    4.24 - * your own identifying information:
    4.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    4.26 - *
    4.27 - * Contributor(s):
    4.28 - *
    4.29 - * The Original Software is NetBeans. The Initial Developer of the Original
    4.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    4.31 - * Microsystems, Inc. All Rights Reserved.
    4.32 - *
    4.33 - * If you wish your version of this file to be governed by only the CDDL
    4.34 - * or only the GPL Version 2, indicate your decision by adding
    4.35 - * "[Contributor] elects to include this software in this distribution
    4.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.37 - * single choice of license, a recipient has the option to distribute
    4.38 - * your version of this file under either the CDDL, the GPL Version 2 or
    4.39 - * to extend the choice of license to its licensees as provided above.
    4.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.41 - * Version 2 license, then the option applies only if the new code is
    4.42 - * made subject to such option by the copyright holder.
    4.43 - */
    4.44 -package org.netbeans.modules.java.hints.scripting;
    4.45 -
    4.46 -import com.sun.source.tree.BlockTree;
    4.47 -import com.sun.source.tree.ClassTree;
    4.48 -import com.sun.source.tree.MethodTree;
    4.49 -import com.sun.source.tree.Tree;
    4.50 -import com.sun.source.tree.Tree.Kind;
    4.51 -import com.sun.source.tree.VariableTree;
    4.52 -import com.sun.source.util.TreePath;
    4.53 -import java.io.IOException;
    4.54 -import java.util.ArrayList;
    4.55 -import java.util.Collections;
    4.56 -import java.util.HashSet;
    4.57 -import java.util.Iterator;
    4.58 -import java.util.LinkedList;
    4.59 -import java.util.List;
    4.60 -import java.util.Map;
    4.61 -import java.util.Set;
    4.62 -import java.util.Stack;
    4.63 -import java.util.concurrent.atomic.AtomicBoolean;
    4.64 -import java.util.logging.Level;
    4.65 -import java.util.logging.Logger;
    4.66 -import javax.lang.model.element.AnnotationMirror;
    4.67 -import javax.lang.model.element.AnnotationValue;
    4.68 -import javax.lang.model.element.Element;
    4.69 -import javax.lang.model.element.ExecutableElement;
    4.70 -import javax.lang.model.element.TypeElement;
    4.71 -import javax.swing.text.Document;
    4.72 -import org.netbeans.api.java.source.CancellableTask;
    4.73 -import org.netbeans.api.java.source.CompilationInfo;
    4.74 -import org.netbeans.api.java.source.support.CancellableTreePathScanner;
    4.75 -import org.netbeans.editor.GuardedDocument;
    4.76 -import org.netbeans.editor.MarkBlock;
    4.77 -import org.netbeans.editor.MarkBlockChain;
    4.78 -import org.netbeans.modules.java.hints.infrastructure.RulesManager;
    4.79 -import org.netbeans.modules.java.hints.options.HintsSettings;
    4.80 -import org.netbeans.modules.java.hints.spi.AbstractHint;
    4.81 -import org.netbeans.modules.java.hints.spi.TreeRule;
    4.82 -import org.netbeans.spi.editor.hints.ErrorDescription;
    4.83 -import org.netbeans.spi.editor.hints.HintsController;
    4.84 -import org.openide.util.Exceptions;
    4.85 -
    4.86 -/**
    4.87 - *
    4.88 - * @author Jan Lahoda
    4.89 - */
    4.90 -public class HintsTask {
    4.91 -
    4.92 -    private Map<Kind, List<TreeRule>> hints;
    4.93 -    
    4.94 -    public HintsTask() {
    4.95 -    }
    4.96 -    
    4.97 -    public HintsTask(Map<Kind, List<TreeRule>> hints) {
    4.98 -        this.hints = hints;
    4.99 -    }
   4.100 -    
   4.101 -    public List<? extends ErrorDescription> compute(CompilationInfo info) throws Exception {
   4.102 -        Map<Kind, List<TreeRule>> hints = this.hints == null ? RulesManager.getInstance().getHints() : this.hints;
   4.103 -        
   4.104 -        if (hints.isEmpty()) {
   4.105 -            return Collections.emptyList();
   4.106 -        }
   4.107 -        
   4.108 -        List<ErrorDescription> result = new ArrayList<ErrorDescription>();
   4.109 -
   4.110 -        new ScannerImpl(info, new AtomicBoolean(), hints).scan(info.getCompilationUnit(), result);
   4.111 -
   4.112 -        return result;
   4.113 -    }
   4.114 -    
   4.115 -    private static final class ScannerImpl extends CancellableTreePathScanner<Void, List<ErrorDescription>> {
   4.116 -        
   4.117 -        private Stack<Set<String>> suppresWarnings = new Stack<Set<String>>();
   4.118 -        private CompilationInfo info;
   4.119 -        private Map<Kind, List<TreeRule>> hints;
   4.120 -        
   4.121 -        public ScannerImpl(CompilationInfo info, AtomicBoolean cancel, Map<Kind, List<TreeRule>> hints) {
   4.122 -            super(cancel);
   4.123 -            this.info = info;
   4.124 -            this.hints = hints;
   4.125 -        }
   4.126 -        
   4.127 -        private void runAndAdd(TreePath path, List<TreeRule> rules, List<ErrorDescription> d) {
   4.128 -            if (rules != null && !isInGuarded(info, path)) {
   4.129 -                for (TreeRule tr : rules) {
   4.130 -                    if (isCanceled()) {
   4.131 -                        return ;
   4.132 -                    }
   4.133 -                    
   4.134 -                    boolean enabled = true;
   4.135 -                    String[] suppressedBy = null;
   4.136 -                    
   4.137 -                    if (tr instanceof AbstractHint) {
   4.138 -                        enabled = HintsSettings.isEnabled((AbstractHint)tr);
   4.139 -                        suppressedBy = HintsSettings.getSuppressedBy((AbstractHint)tr);
   4.140 -                    }
   4.141 -                    
   4.142 -                    if ( suppressedBy != null && suppressedBy.length != 0 ) {
   4.143 -                        for (String wname : suppressedBy) {
   4.144 -                            if( !suppresWarnings.empty() && suppresWarnings.peek().contains(wname)) {
   4.145 -                                return;
   4.146 -                            }
   4.147 -                        }
   4.148 -                    }
   4.149 -                    
   4.150 -                    if (enabled) {
   4.151 -                        List<ErrorDescription> errors = tr.run(info, path);
   4.152 -                        
   4.153 -                        if (errors != null) {
   4.154 -                            d.addAll(errors);
   4.155 -                        }
   4.156 -                    }
   4.157 -                }
   4.158 -            }
   4.159 -        }
   4.160 -        
   4.161 -        @Override
   4.162 -        public Void scan(Tree tree, List<ErrorDescription> p) {
   4.163 -            if (tree == null)
   4.164 -                return null;
   4.165 -            
   4.166 -            TreePath tp = new TreePath(getCurrentPath(), tree);
   4.167 -            Kind k = tree.getKind();
   4.168 -            
   4.169 -            runAndAdd(tp, hints.get(k), p);
   4.170 -            
   4.171 -            if (isCanceled()) {
   4.172 -                return null;
   4.173 -            }
   4.174 -            
   4.175 -            return super.scan(tree, p);
   4.176 -        }
   4.177 -        
   4.178 -        @Override
   4.179 -        public Void scan(TreePath path, List<ErrorDescription> p) {
   4.180 -            Kind k = path.getLeaf().getKind();
   4.181 -            runAndAdd(path, hints.get(k), p);
   4.182 -            
   4.183 -            if (isCanceled()) {
   4.184 -                return null;
   4.185 -            }
   4.186 -            
   4.187 -            return super.scan(path, p);
   4.188 -        }
   4.189 -
   4.190 -        @Override
   4.191 -        public Void visitMethod(MethodTree tree, List<ErrorDescription> arg1) {
   4.192 -            pushSuppressWarrnings();
   4.193 -            Void r = super.visitMethod(tree, arg1);
   4.194 -            suppresWarnings.pop();
   4.195 -            return r;
   4.196 -        }
   4.197 -
   4.198 -        @Override
   4.199 -        public Void visitClass(ClassTree tree, List<ErrorDescription> arg1) {
   4.200 -            pushSuppressWarrnings();
   4.201 -            Void r = super.visitClass(tree, arg1);
   4.202 -            suppresWarnings.pop();
   4.203 -            return r;
   4.204 -        }
   4.205 -
   4.206 -        @Override
   4.207 -        public Void visitVariable(VariableTree tree, List<ErrorDescription> arg1) {
   4.208 -            pushSuppressWarrnings();
   4.209 -            Void r = super.visitVariable(tree, arg1);
   4.210 -            suppresWarnings.pop();
   4.211 -            return r;
   4.212 -        }
   4.213 -        
   4.214 -        private void pushSuppressWarrnings( ) {
   4.215 -            Set<String> current = suppresWarnings.size() == 0 ? null : suppresWarnings.peek();
   4.216 -            Set<String> nju = current == null ? new HashSet<String>() : new HashSet<String>(current);
   4.217 -            
   4.218 -            Element e = info.getTrees().getElement(getCurrentPath());
   4.219 -            
   4.220 -            if ( e != null) {
   4.221 -                for (AnnotationMirror am : e.getAnnotationMirrors()) {
   4.222 -                    String name = ((TypeElement)am.getAnnotationType().asElement()).getQualifiedName().toString();
   4.223 -                    if ( "java.lang.SuppressWarnings".equals(name) ) { // NOI18N
   4.224 -                        Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = am.getElementValues();
   4.225 -                        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
   4.226 -                            if( "value".equals(entry.getKey().getSimpleName().toString()) ) { // NOI18N
   4.227 -                                Object value = entry.getValue().getValue();
   4.228 -                                if ( value instanceof List) {
   4.229 -                                    for (Object av : (List)value) {
   4.230 -                                        if( av instanceof AnnotationValue ) {
   4.231 -                                            Object wname = ((AnnotationValue)av).getValue();
   4.232 -                                            if ( wname instanceof String ) {
   4.233 -                                                nju.add((String)wname);
   4.234 -                                            }
   4.235 -                                        }
   4.236 -                                    }
   4.237 -                                    
   4.238 -                                }                                                                
   4.239 -                            }
   4.240 -                        }
   4.241 -
   4.242 -                    }
   4.243 -                }                
   4.244 -            }
   4.245 -            
   4.246 -            suppresWarnings.push(nju);
   4.247 -        }
   4.248 -    }
   4.249 -
   4.250 -    static boolean isInGuarded(CompilationInfo info, TreePath tree) {
   4.251 -        try {
   4.252 -            Document doc = info.getDocument();
   4.253 -
   4.254 -            if (doc instanceof GuardedDocument) {
   4.255 -                int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tree.getLeaf());
   4.256 -                int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), tree.getLeaf());
   4.257 -                GuardedDocument gdoc = (GuardedDocument) doc;
   4.258 -                MarkBlockChain guardedBlockChain = gdoc.getGuardedBlockChain();
   4.259 -
   4.260 -                if ((guardedBlockChain.compareBlock(start, end) & MarkBlock.INSIDE) != 0) {
   4.261 -                    return true;
   4.262 -                }
   4.263 -            }
   4.264 -        } catch (IOException ex) {
   4.265 -            Exceptions.printStackTrace(ex);
   4.266 -        }
   4.267 -        
   4.268 -        return false;
   4.269 -    }
   4.270 -    
   4.271 -}
     5.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/TestsHint.java	Wed Mar 30 19:21:05 2016 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,315 +0,0 @@
     5.4 -/*
     5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 - *
     5.7 - * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
     5.8 - *
     5.9 - * The contents of this file are subject to the terms of either the GNU
    5.10 - * General Public License Version 2 only ("GPL") or the Common
    5.11 - * Development and Distribution License("CDDL") (collectively, the
    5.12 - * "License"). You may not use this file except in compliance with the
    5.13 - * License. You can obtain a copy of the License at
    5.14 - * http://www.netbeans.org/cddl-gplv2.html
    5.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.16 - * specific language governing permissions and limitations under the
    5.17 - * License.  When distributing the software, include this License Header
    5.18 - * Notice in each file and include the License file at
    5.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    5.20 - * particular file as subject to the "Classpath" exception as provided
    5.21 - * by Sun in the GPL Version 2 section of the License file that
    5.22 - * accompanied this code. If applicable, add the following below the
    5.23 - * License Header, with the fields enclosed by brackets [] replaced by
    5.24 - * your own identifying information:
    5.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    5.26 - *
    5.27 - * Contributor(s):
    5.28 - *
    5.29 - * The Original Software is NetBeans. The Initial Developer of the Original
    5.30 - * Software is Sun Microsystems, Inc. Portions Copyright 2008 Sun
    5.31 - * Microsystems, Inc. All Rights Reserved.
    5.32 - *
    5.33 - * If you wish your version of this file to be governed by only the CDDL
    5.34 - * or only the GPL Version 2, indicate your decision by adding
    5.35 - * "[Contributor] elects to include this software in this distribution
    5.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.37 - * single choice of license, a recipient has the option to distribute
    5.38 - * your version of this file under either the CDDL, the GPL Version 2 or
    5.39 - * to extend the choice of license to its licensees as provided above.
    5.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.41 - * Version 2 license, then the option applies only if the new code is
    5.42 - * made subject to such option by the copyright holder.
    5.43 - */
    5.44 -package org.netbeans.modules.java.hints.scripting;
    5.45 -
    5.46 -import com.sun.source.tree.Tree.Kind;
    5.47 -import com.sun.source.util.TreePath;
    5.48 -import java.io.FileOutputStream;
    5.49 -import java.io.FileWriter;
    5.50 -import java.io.IOException;
    5.51 -import java.io.OutputStreamWriter;
    5.52 -import java.io.PrintWriter;
    5.53 -import java.util.Arrays;
    5.54 -import java.util.Collection;
    5.55 -import java.util.Collections;
    5.56 -import java.util.EnumSet;
    5.57 -import java.util.HashMap;
    5.58 -import java.util.HashSet;
    5.59 -import java.util.LinkedList;
    5.60 -import java.util.List;
    5.61 -import java.util.Map;
    5.62 -import java.util.Map.Entry;
    5.63 -import java.util.Set;
    5.64 -import org.netbeans.api.java.source.ClasspathInfo;
    5.65 -import org.netbeans.api.java.source.CompilationController;
    5.66 -import org.netbeans.api.java.source.CompilationInfo;
    5.67 -import org.netbeans.api.java.source.JavaSource;
    5.68 -import org.netbeans.api.java.source.JavaSource.Phase;
    5.69 -import org.netbeans.api.java.source.Task;
    5.70 -import org.netbeans.modules.java.hints.spi.AbstractHint;
    5.71 -import org.netbeans.spi.editor.hints.ChangeInfo;
    5.72 -import org.netbeans.spi.editor.hints.ErrorDescription;
    5.73 -import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
    5.74 -import org.netbeans.spi.editor.hints.Fix;
    5.75 -import org.netbeans.spi.editor.hints.Severity;
    5.76 -import org.openide.awt.StatusDisplayer;
    5.77 -import org.openide.cookies.EditorCookie;
    5.78 -import org.openide.filesystems.FileObject;
    5.79 -import org.openide.filesystems.FileUtil;
    5.80 -import org.openide.loaders.DataObject;
    5.81 -
    5.82 -/**
    5.83 - *
    5.84 - * @author Jan Lahoda
    5.85 - */
    5.86 -public class TestsHint extends AbstractHint {
    5.87 -
    5.88 -    public TestsHint() {
    5.89 -        super(true, false, AbstractHint.HintSeverity.WARNING);
    5.90 -    }
    5.91 -
    5.92 -    @Override
    5.93 -    public String getDescription() {
    5.94 -        return "TestsHint";
    5.95 -    }
    5.96 -
    5.97 -    public Set<Kind> getTreeKinds() {
    5.98 -        return EnumSet.of(Kind.COMPILATION_UNIT);
    5.99 -    }
   5.100 -
   5.101 -    public List<ErrorDescription> run(CompilationInfo info, TreePath tp) {
   5.102 -        List<Fix> fixes = new LinkedList<Fix>();
   5.103 -        if (Utilities.getFolder().equals(info.getFileObject().getParent())) {
   5.104 -            fixes.add(new AddTest(info.getFileObject()));
   5.105 -            fixes.add(new RunTests(info.getFileObject()));
   5.106 -        }
   5.107 -        
   5.108 -        if (Utilities.getFolder().equals(info.getFileObject().getParent().getParent())) {
   5.109 -            fixes.add(new RecordCurrentResults(info.getFileObject()));
   5.110 -        }
   5.111 -
   5.112 -        if (!fixes.isEmpty()) {
   5.113 -            return Arrays.asList(ErrorDescriptionFactory.createErrorDescription(Severity.HINT, "Tests", fixes, info.getFileObject(), 0, 0));
   5.114 -        } else {
   5.115 -            return null;
   5.116 -        }
   5.117 -    }
   5.118 -
   5.119 -    public String getId() {
   5.120 -        return TestsHint.class.getName();
   5.121 -    }
   5.122 -
   5.123 -    public String getDisplayName() {
   5.124 -        return "TestsHint";
   5.125 -    }
   5.126 -
   5.127 -    public void cancel() {
   5.128 -    }
   5.129 -    
   5.130 -    private static Map<FileObject, List<? extends ErrorDescription>> computeResults(FileObject hint, Collection<FileObject> tests) throws IOException {
   5.131 -        if (tests.isEmpty()) {
   5.132 -            return Collections.emptyMap();
   5.133 -        }
   5.134 -        
   5.135 -        final HintsTask t = new HintsTask(UberHint.INSTANCE.hints);
   5.136 -        final Map<FileObject, List<? extends ErrorDescription>> result = new  HashMap<FileObject, List<? extends ErrorDescription>>();
   5.137 -        
   5.138 -        JavaSource.create(ClasspathInfo.create(tests.iterator().next()), tests).runUserActionTask(new  Task<CompilationController>() {
   5.139 -            public void run(CompilationController cc) throws Exception {
   5.140 -                if (Phase.RESOLVED.compareTo(cc.toPhase(Phase.RESOLVED)) > 0) {
   5.141 -                    return;
   5.142 -                }
   5.143 -                
   5.144 -                result.put(cc.getFileObject(), t.compute(cc));
   5.145 -            }
   5.146 -        }, true);
   5.147 -        
   5.148 -        return result;
   5.149 -    }
   5.150 -    
   5.151 -    private static List<FileObject> filterJava(FileObject... files) {
   5.152 -        List<FileObject> r = new  LinkedList<FileObject>();
   5.153 -        
   5.154 -        for (FileObject f : files) {
   5.155 -            if ("text/x-java".equals(FileUtil.getMIMEType(f))) {
   5.156 -                r.add(f);
   5.157 -            }
   5.158 -        }
   5.159 -        
   5.160 -        return r;
   5.161 -    }
   5.162 -
   5.163 -    private static final class AddTest implements Fix {
   5.164 -
   5.165 -        private FileObject forFile;
   5.166 -
   5.167 -        public AddTest(FileObject forFile) {
   5.168 -            this.forFile = forFile;
   5.169 -        }
   5.170 -        
   5.171 -        public String getText() {
   5.172 -            return "Add Test";
   5.173 -        }
   5.174 -
   5.175 -        public ChangeInfo implement() throws Exception {
   5.176 -            FileObject folder = FileUtil.createFolder(forFile.getParent(), forFile.getName());
   5.177 -            
   5.178 -            if (folder == null) {
   5.179 -                return null;
   5.180 -            }
   5.181 -            
   5.182 -            Set<String> names = new  HashSet<String>();
   5.183 -            
   5.184 -            for (FileObject f : folder.getChildren()) {
   5.185 -                names.add(f.getName());
   5.186 -            }
   5.187 -            
   5.188 -            int index = 1;
   5.189 -            
   5.190 -            while (names.contains("Test" + index))
   5.191 -                index++;
   5.192 -            
   5.193 -            FileObject file = FileUtil.createData(folder, "Test" + index + ".java");
   5.194 -            
   5.195 -            return new ChangeInfo(file, null, null);
   5.196 -        }
   5.197 -        
   5.198 -    }
   5.199 -    
   5.200 -    private static final class RecordCurrentResults implements Fix {
   5.201 -
   5.202 -        private FileObject forFile;
   5.203 -
   5.204 -        public RecordCurrentResults(FileObject forFile) {
   5.205 -            this.forFile = forFile;
   5.206 -        }
   5.207 -        
   5.208 -        public String getText() {
   5.209 -            return "Record Current Results";
   5.210 -        }
   5.211 -
   5.212 -        public ChangeInfo implement() throws Exception {
   5.213 -            String hintName = forFile.getParent().getName();
   5.214 -            FileObject hint = forFile.getParent().getParent().getFileObject(hintName + ".java");
   5.215 -            
   5.216 -            if (hint == null) {
   5.217 -                return null;
   5.218 -            }
   5.219 -
   5.220 -            Map<FileObject, List<? extends ErrorDescription>> computed = computeResults(hint, Collections.singleton(forFile));
   5.221 -            List<? extends ErrorDescription> eds;
   5.222 -            
   5.223 -            if (computed.get(forFile) == null) {
   5.224 -                eds = Collections.emptyList();
   5.225 -            } else {
   5.226 -                eds = computed.get(forFile);
   5.227 -            }
   5.228 -            
   5.229 -            FileObject pass = FileUtil.createData(forFile.getParent(), forFile.getName() + ".pass");
   5.230 -            PrintWriter pw = new PrintWriter(new OutputStreamWriter(pass.getOutputStream(), "UTF-8"));
   5.231 -            
   5.232 -            for (ErrorDescription ed : eds) {
   5.233 -                pw.println(ed.toString()); //XXX
   5.234 -            }
   5.235 -            
   5.236 -            pw.close(); //XXX
   5.237 -            
   5.238 -            return null;
   5.239 -        }
   5.240 -        
   5.241 -    }
   5.242 -    
   5.243 -    private static final class RunTests implements Fix {
   5.244 -
   5.245 -        private FileObject forFile;
   5.246 -
   5.247 -        public RunTests(FileObject forFile) {
   5.248 -            this.forFile = forFile;
   5.249 -        }
   5.250 -        
   5.251 -        public String getText() {
   5.252 -            return "Run Tests";
   5.253 -        }
   5.254 -
   5.255 -        public ChangeInfo implement() throws Exception {
   5.256 -            String hintName = forFile.getName();
   5.257 -            FileObject testFolder = forFile.getParent().getFileObject(hintName);
   5.258 -            
   5.259 -            if (testFolder == null) {
   5.260 -                StatusDisplayer.getDefault().setStatusText("No tests");
   5.261 -                return null;
   5.262 -            }
   5.263 -            
   5.264 -            List<FileObject> tests = filterJava(testFolder.getChildren());
   5.265 -            
   5.266 -            if (tests.isEmpty()) {
   5.267 -                StatusDisplayer.getDefault().setStatusText("No tests");
   5.268 -                return null;
   5.269 -            }
   5.270 -            
   5.271 -            Map<FileObject, List<? extends ErrorDescription>> computed = computeResults(forFile, tests);
   5.272 -            
   5.273 -            int testsCount = 0;
   5.274 -            int failedCount = 0;
   5.275 -            FileObject firstFail = null;
   5.276 -            
   5.277 -            for (Entry<FileObject, List<? extends ErrorDescription>> e : computed.entrySet()) {
   5.278 -                FileObject pass = e.getKey().getParent().getFileObject(e.getKey().getName() + ".pass");
   5.279 -                String passText = Utilities.copyFileToString(pass);
   5.280 -                
   5.281 -                StringBuilder out = new StringBuilder();
   5.282 -                
   5.283 -                for (ErrorDescription ed : e.getValue()) {
   5.284 -                    out.append(ed.toString());
   5.285 -                    out.append("\n");
   5.286 -                }
   5.287 -                
   5.288 -                if (!passText.equals(out.toString())) {
   5.289 -                    failedCount++;
   5.290 -                    if (firstFail == null) {
   5.291 -                        firstFail = e.getKey();
   5.292 -                    }
   5.293 -                }
   5.294 -                
   5.295 -                testsCount++;
   5.296 -            }
   5.297 -            
   5.298 -            StringBuilder hlaska = new StringBuilder();
   5.299 -            
   5.300 -            hlaska.append(testsCount);
   5.301 -            hlaska.append(" test(s) passed");
   5.302 -            
   5.303 -            if (failedCount > 0) {
   5.304 -                hlaska.append(", ");
   5.305 -                hlaska.append(failedCount);
   5.306 -                hlaska.append(" test(s) failed.");
   5.307 -            } else {
   5.308 -                hlaska.append(".");
   5.309 -            }
   5.310 -            
   5.311 -            StatusDisplayer.getDefault().setStatusText(hlaska.toString());
   5.312 -            
   5.313 -            return new ChangeInfo(firstFail, null, null);
   5.314 -        }
   5.315 -        
   5.316 -    }
   5.317 -    
   5.318 -}
     6.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/UberHint.java	Wed Mar 30 19:21:05 2016 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,238 +0,0 @@
     6.4 -/*
     6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.6 - * 
     6.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     6.8 - * 
     6.9 - * The contents of this file are subject to the terms of either the GNU
    6.10 - * General Public License Version 2 only ("GPL") or the Common
    6.11 - * Development and Distribution License("CDDL") (collectively, the
    6.12 - * "License"). You may not use this file except in compliance with the
    6.13 - * License. You can obtain a copy of the License at
    6.14 - * http://www.netbeans.org/cddl-gplv2.html
    6.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    6.16 - * specific language governing permissions and limitations under the
    6.17 - * License.  When distributing the software, include this License Header
    6.18 - * Notice in each file and include the License file at
    6.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    6.20 - * particular file as subject to the "Classpath" exception as provided
    6.21 - * by Sun in the GPL Version 2 section of the License file that
    6.22 - * accompanied this code. If applicable, add the following below the
    6.23 - * License Header, with the fields enclosed by brackets [] replaced by
    6.24 - * your own identifying information:
    6.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    6.26 - * 
    6.27 - * If you wish your version of this file to be governed by only the CDDL
    6.28 - * or only the GPL Version 2, indicate your decision by adding
    6.29 - * "[Contributor] elects to include this software in this distribution
    6.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    6.31 - * single choice of license, a recipient has the option to distribute
    6.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    6.33 - * to extend the choice of license to its licensees as provided above.
    6.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    6.35 - * Version 2 license, then the option applies only if the new code is
    6.36 - * made subject to such option by the copyright holder.
    6.37 - * 
    6.38 - * Contributor(s):
    6.39 - * 
    6.40 - * Portions Copyrighted 2008 Sun Microsystems, Inc.
    6.41 - */
    6.42 -
    6.43 -package org.netbeans.modules.java.hints.scripting;
    6.44 -
    6.45 -import com.sun.script.java.JavaCompiler;
    6.46 -import com.sun.script.java.MemoryClassLoader;
    6.47 -import com.sun.source.tree.Tree.Kind;
    6.48 -import com.sun.source.util.TreePath;
    6.49 -import java.io.File;
    6.50 -import java.io.IOException;
    6.51 -import java.io.OutputStreamWriter;
    6.52 -import java.net.URL;
    6.53 -import java.util.EnumMap;
    6.54 -import java.util.EnumSet;
    6.55 -import java.util.HashMap;
    6.56 -import java.util.LinkedList;
    6.57 -import java.util.List;
    6.58 -import java.util.Map;
    6.59 -import java.util.Set;
    6.60 -import java.util.logging.Level;
    6.61 -import java.util.logging.Logger;
    6.62 -import org.netbeans.api.java.source.CompilationInfo;
    6.63 -import org.netbeans.modules.java.hints.spi.AbstractHint;
    6.64 -import org.netbeans.modules.java.hints.spi.TreeRule;
    6.65 -import org.netbeans.spi.editor.hints.ErrorDescription;
    6.66 -import org.openide.filesystems.FileAttributeEvent;
    6.67 -import org.openide.filesystems.FileChangeListener;
    6.68 -import org.openide.filesystems.FileEvent;
    6.69 -import org.openide.filesystems.FileObject;
    6.70 -import org.openide.filesystems.FileRenameEvent;
    6.71 -import org.openide.filesystems.FileUtil;
    6.72 -import org.openide.util.Exceptions;
    6.73 -import org.openide.util.RequestProcessor;
    6.74 -
    6.75 -/**
    6.76 - *
    6.77 - * @author Jan Lahoda
    6.78 - */
    6.79 -public class UberHint extends AbstractHint {
    6.80 -
    6.81 -    static UberHint INSTANCE;
    6.82 -    
    6.83 -    public UberHint() {
    6.84 -        super(true, false, HintSeverity.WARNING);
    6.85 -        
    6.86 -        updateAllHints();
    6.87 -        INSTANCE = this;
    6.88 -    }
    6.89 -
    6.90 -    final Map<Kind, List<TreeRule>> hints = new  EnumMap<Kind, List<TreeRule>>(Kind.class);
    6.91 -    
    6.92 -    @Override
    6.93 -    public String getDescription() {
    6.94 -        return "Uber Hint";
    6.95 -    }
    6.96 -
    6.97 -    public Set<Kind> getTreeKinds() {
    6.98 -        return EnumSet.allOf(Kind.class);
    6.99 -    }
   6.100 -
   6.101 -    public List<ErrorDescription> run(CompilationInfo compilationInfo, TreePath treePath) {
   6.102 -        List<TreeRule> rules = hints.get(treePath.getLeaf().getKind());
   6.103 -        
   6.104 -        if (rules == null) {
   6.105 -            return null;
   6.106 -        }
   6.107 -        
   6.108 -        List<ErrorDescription> result = new  LinkedList<ErrorDescription>();
   6.109 -        
   6.110 -        for (TreeRule tr : rules) {
   6.111 -            List<ErrorDescription> r = tr.run(compilationInfo, treePath);
   6.112 -            
   6.113 -            if (r != null) {
   6.114 -                result.addAll(r);
   6.115 -            }
   6.116 -        }
   6.117 -        
   6.118 -        return result;
   6.119 -    }
   6.120 -
   6.121 -    public String getId() {
   6.122 -        return UberHint.class.getName();
   6.123 -    }
   6.124 -
   6.125 -    public String getDisplayName() {
   6.126 -        return "Uber Hint";
   6.127 -    }
   6.128 -
   6.129 -    public void cancel() {
   6.130 -    }
   6.131 -
   6.132 -    private FileChangeListener l = new FileChangeListener() {
   6.133 -        public void fileFolderCreated(FileEvent fe) {}
   6.134 -        public void fileDataCreated(FileEvent fe) {
   6.135 -            updateAllHints();
   6.136 -        }
   6.137 -        public void fileChanged(FileEvent fe) {
   6.138 -            updateAllHints();
   6.139 -        }
   6.140 -        public void fileDeleted(FileEvent fe) {
   6.141 -            updateAllHints();
   6.142 -        }
   6.143 -        public void fileRenamed(FileRenameEvent fe) {
   6.144 -            updateAllHints();
   6.145 -        }
   6.146 -        public void fileAttributeChanged(FileAttributeEvent fe) {}
   6.147 -    };
   6.148 -    
   6.149 -    private void updateAllHints() {
   6.150 -        worker.schedule(50);
   6.151 -    }
   6.152 -    
   6.153 -    private final RequestProcessor.Task worker = new RequestProcessor(UberHint.class.getName()).create(new Runnable() {
   6.154 -        public void run() {
   6.155 -            doUpdateAllHints();
   6.156 -        }
   6.157 -    });
   6.158 -    
   6.159 -    private void doUpdateAllHints() {
   6.160 -        synchronized (hints) {
   6.161 -            hints.clear();
   6.162 -            
   6.163 -            FileObject hintsFolder = Utilities.getFolder();
   6.164 -            
   6.165 -            hintsFolder.removeFileChangeListener(l);
   6.166 -            hintsFolder.addFileChangeListener(l);
   6.167 -            
   6.168 -            JavaCompiler compiler = new JavaCompiler();
   6.169 -            Map<String, byte[]> bytecode = new  HashMap<String, byte[]>();
   6.170 -            
   6.171 -            for (FileObject c : hintsFolder.getChildren()) {
   6.172 -                c.removeFileChangeListener(l);
   6.173 -                c.addFileChangeListener(l);
   6.174 -                
   6.175 -                if ("text/x-java".equals(FileUtil.getMIMEType(c))) {
   6.176 -                    try {
   6.177 -                        String data = Utilities.copyFileToString(c);
   6.178 -                        
   6.179 -                        Map<String, byte[]> compiled = compiler.compile(c.getNameExt(), data, new OutputStreamWriter(System.err), null, computeCPAsString());
   6.180 -                        
   6.181 -                        if (compiled != null) {
   6.182 -                            bytecode.putAll(compiled);
   6.183 -                        }
   6.184 -                    } catch (IOException ex) {
   6.185 -                        Exceptions.printStackTrace(ex);
   6.186 -                    }
   6.187 -                }
   6.188 -            }
   6.189 -            
   6.190 -            MemoryClassLoader mcl = new MemoryClassLoader(bytecode, null, UberHint.class.getClassLoader());
   6.191 -            
   6.192 -            Logger.getLogger("TIMER").log(Level.FINE, "UberHint.MemoryClassLoader", mcl);
   6.193 -            
   6.194 -            try {
   6.195 -                for (Class c : mcl.loadAll()) {
   6.196 -                    Logger.getLogger("TIMER").log(Level.FINE, "UberHint.Class", c);
   6.197 -                    if (TreeRule.class.isAssignableFrom(c)) {
   6.198 -                        try {
   6.199 -                            TreeRule rule = TreeRule.class.cast(c.newInstance());
   6.200 -                            
   6.201 -                            for (Kind k : rule.getTreeKinds()) {
   6.202 -                                List<TreeRule> rules = hints.get(k);
   6.203 -                                
   6.204 -                                if (rules == null) {
   6.205 -                                    hints.put(k, rules = new  LinkedList<TreeRule>());
   6.206 -                                }
   6.207 -                                
   6.208 -                                rules.add(rule);
   6.209 -                            }
   6.210 -                        } catch (InstantiationException ex) {
   6.211 -                            Exceptions.printStackTrace(ex);
   6.212 -                        } catch (IllegalAccessException ex) {
   6.213 -                            Exceptions.printStackTrace(ex);
   6.214 -                        }
   6.215 -                    }
   6.216 -                }
   6.217 -            } catch (ClassNotFoundException ex) {
   6.218 -                Exceptions.printStackTrace(ex);
   6.219 -            }
   6.220 -        }
   6.221 -    }
   6.222 -    
   6.223 -    private final static String computeCPAsString() {
   6.224 -        StringBuilder sb = new StringBuilder();
   6.225 -        boolean first = true;
   6.226 -        
   6.227 -        for (URL u : Utilities.computeCP()) {
   6.228 -            if (!first) {
   6.229 -                sb.append(':');
   6.230 -            }
   6.231 -            File f = FileUtil.archiveOrDirForURL(u);
   6.232 -
   6.233 -            if (f != null) {
   6.234 -                sb.append(f.getAbsolutePath());
   6.235 -                first = false;
   6.236 -            }
   6.237 -        }
   6.238 -        
   6.239 -        return sb.toString();
   6.240 -    }
   6.241 -}
     7.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/Utilities.java	Wed Mar 30 19:21:05 2016 +0200
     7.2 +++ b/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/Utilities.java	Sun Apr 24 22:23:36 2016 +0200
     7.3 @@ -41,19 +41,22 @@
     7.4  package org.netbeans.modules.java.hints.scripting;
     7.5  
     7.6  import com.sun.source.util.Trees;
     7.7 +
     7.8  import java.io.EOFException;
     7.9  import java.io.InputStream;
    7.10  import java.net.URL;
    7.11  import java.util.LinkedList;
    7.12  import java.util.List;
    7.13 +
    7.14  import org.netbeans.api.java.source.CompilationInfo;
    7.15 -import org.netbeans.modules.java.hints.spi.AbstractHint;
    7.16  import org.netbeans.spi.editor.hints.ErrorDescription;
    7.17 +import org.netbeans.spi.java.hints.Hint;
    7.18  import org.openide.filesystems.FileObject;
    7.19  import org.openide.filesystems.FileUtil;
    7.20  import org.openide.loaders.DataObject;
    7.21  import org.openide.nodes.Node;
    7.22  import org.openide.util.Lookup;
    7.23 +import org.openide.util.WeakSet;
    7.24  
    7.25  /**
    7.26   *
    7.27 @@ -62,24 +65,29 @@
    7.28  public class Utilities {
    7.29      
    7.30      public final static List<URL> computeCP() {
    7.31 -        List<URL> urls = new LinkedList<URL>();
    7.32 +        List<URL> urls = new LinkedList<>();
    7.33  
    7.34 -        urls.add(CompilationInfo.class.getProtectionDomain().getCodeSource().getLocation());
    7.35 -        urls.add(FileObject.class.getProtectionDomain().getCodeSource().getLocation());
    7.36 -        urls.add(DataObject.class.getProtectionDomain().getCodeSource().getLocation());
    7.37 -        urls.add(Node.class.getProtectionDomain().getCodeSource().getLocation());
    7.38 -        urls.add(Trees.class.getProtectionDomain().getCodeSource().getLocation());
    7.39 -        urls.add(ErrorDescription.class.getProtectionDomain().getCodeSource().getLocation());
    7.40 -        urls.add(AbstractHint.class.getProtectionDomain().getCodeSource().getLocation());
    7.41 -        urls.add(Lookup.class.getProtectionDomain().getCodeSource().getLocation());
    7.42 +        urls.add(urlForClass(CompilationInfo.class));
    7.43 +        urls.add(urlForClass(FileObject.class));
    7.44 +        urls.add(urlForClass(DataObject.class));
    7.45 +        urls.add(urlForClass(Node.class));
    7.46 +        urls.add(urlForClass(Trees.class));
    7.47 +        urls.add(urlForClass(ErrorDescription.class));
    7.48 +        urls.add(urlForClass(Hint.class));
    7.49 +        urls.add(urlForClass(Lookup.class));
    7.50 +        urls.add(urlForClass(WeakSet.class));
    7.51  
    7.52          return urls;
    7.53      }
    7.54  
    7.55 -    public static FileObject getFolder() {
    7.56 -        return FileUtil.getConfigFile("hints");
    7.57 +    private static URL urlForClass(Class c) {
    7.58 +        URL loc = c.getProtectionDomain().getCodeSource().getLocation();
    7.59 +
    7.60 +        if (FileUtil.isArchiveFile(loc))
    7.61 +            return FileUtil.getArchiveRoot(loc);
    7.62 +        return loc;
    7.63      }
    7.64 -    
    7.65 +
    7.66      public final static String copyFileToString (FileObject f) throws java.io.IOException {
    7.67          //XXX:
    7.68          int s = (int)f.getSize();
     8.1 --- a/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/layer.xml	Wed Mar 30 19:21:05 2016 +0200
     8.2 +++ b/java.hints.scripting/src/org/netbeans/modules/java/hints/scripting/layer.xml	Sun Apr 24 22:23:36 2016 +0200
     8.3 @@ -42,16 +42,4 @@
     8.4  -->
     8.5  <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
     8.6  <filesystem>
     8.7 -    <folder name="hints" />
     8.8 -    
     8.9 -    <folder name="org-netbeans-modules-java-hints">
    8.10 -        <folder name="rules">
    8.11 -            <folder name="hints">
    8.12 -                <folder name="general">
    8.13 -                    <file name="org-netbeans-modules-java-hints-scripting-UberHint.instance"/>
    8.14 -                    <file name="org-netbeans-modules-java-hints-scripting-TestsHint.instance"/>
    8.15 -                </folder>
    8.16 -            </folder>
    8.17 -        </folder>
    8.18 -    </folder>
    8.19  </filesystem>