Commits

Jan Lahoda committed cc82dea

Cleanup, tests.

Comments (0)

Files changed (80)

borrowedtests/build.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
+<!-- for some information on what you could do (e.g. targets to override). -->
+<!-- If you delete this file and reopen the project it will be recreated. -->
+<project name="org.netbeans.modules.jackpot30.test.borrowed" default="netbeans" basedir=".">
+    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.test.borrowed.</description>
+    <import file="nbproject/build-impl.xml"/>
+
+    <target name="test" />
+</project>

borrowedtests/manifest.mf

+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.modules.jackpot30.test.borrowed
+OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties
+OpenIDE-Module-Specification-Version: 1.0
+

borrowedtests/nbproject/build-impl.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
+***         EDIT ../build.xml INSTEAD         ***
+-->
+<project name="org.netbeans.modules.jackpot30.test.borrowed-impl" basedir="..">
+    <fail message="Please build using Ant 1.7.1 or higher.">
+        <condition>
+            <not>
+                <antversion atleast="1.7.1"/>
+            </not>
+        </condition>
+    </fail>
+    <property file="nbproject/private/suite-private.properties"/>
+    <property file="nbproject/suite.properties"/>
+    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
+    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
+    <property file="${suite.dir}/nbproject/platform.properties"/>
+    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
+        <attribute name="name"/>
+        <attribute name="value"/>
+        <sequential>
+            <property name="@{name}" value="${@{value}}"/>
+        </sequential>
+    </macrodef>
+    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
+        <attribute name="property"/>
+        <attribute name="value"/>
+        <sequential>
+            <property name="@{property}" value="@{value}"/>
+        </sequential>
+    </macrodef>
+    <property file="${user.properties.file}"/>
+    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+    <fail message="You must specify at least path to 'platform' cluster in $${cluster.path} property.">
+        <condition>
+            <not>
+                <contains string="${cluster.path.evaluated}" substring="platform"/>
+            </not>
+        </condition>
+    </fail>
+    <import file="${harness.dir}/build.xml"/>
+</project>

borrowedtests/nbproject/genfiles.properties

+build.xml.data.CRC32=a4393221
+build.xml.script.CRC32=3cb17d2d
+build.xml.stylesheet.CRC32=79c3b980@1.28.0.7
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=a4393221
+nbproject/build-impl.xml.script.CRC32=ae14414b
+nbproject/build-impl.xml.stylesheet.CRC32=3517ddf9@1.28.0.7

borrowedtests/nbproject/project.properties

+javac.source=1.5
+javac.compilerargs=-Xlint -Xlint:-serial

borrowedtests/nbproject/project.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.apisupport.project</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+            <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
+            <suite-component/>
+            <module-dependencies/>
+            <test-dependencies>
+                <test-type>
+                    <name>unit</name>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.api.java</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.api.java.classpath</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.libs.javacapi</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.libs.lucene</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.java.hints</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.java.source</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.lexer</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.queries</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openide.filesystems</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openide.loaders</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openide.nodes</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openide.text</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openide.util</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                </test-type>
+            </test-dependencies>
+            <public-packages/>
+        </data>
+    </configuration>
+</project>

borrowedtests/nbproject/suite.properties

+suite.dir=${basedir}/..

borrowedtests/src/org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties

+OpenIDE-Module-Name=Borrowed Test Infra

borrowedtests/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.api.java.source;
+
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyVetoException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.regex.Pattern;
+import javax.swing.event.ChangeListener;
+import junit.framework.Assert;
+import org.netbeans.api.editor.mimelookup.MimePath;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.SourceForBinaryQuery;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.java.JavaDataLoader;
+import org.netbeans.modules.java.source.parsing.JavacParser;
+import org.netbeans.modules.java.source.parsing.JavacParserFactory;
+import org.netbeans.modules.java.source.usages.IndexUtil;
+import org.netbeans.modules.parsing.api.indexing.IndexingManager;
+import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
+import org.openide.ErrorManager;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileStateInvalidException;
+import org.openide.filesystems.FileSystem;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.LocalFileSystem;
+import org.openide.filesystems.MIMEResolver;
+import org.openide.filesystems.MultiFileSystem;
+import org.openide.filesystems.Repository;
+import org.openide.filesystems.URLMapper;
+import org.openide.filesystems.XMLFileSystem;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.Lookups;
+import org.openide.util.lookup.ProxyLookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public final class SourceUtilsTestUtil extends ProxyLookup {
+    
+    private static SourceUtilsTestUtil DEFAULT_LOOKUP = null;
+    
+    public SourceUtilsTestUtil() {
+//        Assert.assertNull(DEFAULT_LOOKUP);
+        DEFAULT_LOOKUP = this;
+    }
+    
+    /**
+     * Set the global default lookup with some fixed instances including META-INF/services/*.
+     */
+    /**
+     * Set the global default lookup with some fixed instances including META-INF/services/*.
+     */
+    public static void setLookup(Object[] instances, ClassLoader cl) {
+        DEFAULT_LOOKUP.setLookups(new Lookup[] {
+            Lookups.fixed(instances),
+            Lookups.metaInfServices(cl),
+            Lookups.singleton(cl),
+        });
+    }
+    
+    private static Object[] extraLookupContent = null;
+    
+    public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
+        URL[] layers = new URL[additionalLayers.length];
+        
+        for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
+            layers[cntr] = Thread.currentThread().getContextClassLoader().getResource(additionalLayers[cntr]);
+        }
+        
+        XMLFileSystem xmlFS = new XMLFileSystem();
+        xmlFS.setXmlUrls(layers);
+        
+        FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});
+        
+        Repository repository = new Repository(system);
+        extraLookupContent = new Object[additionalLookupContent.length + 1];
+        
+        System.arraycopy(additionalLookupContent, 0, extraLookupContent, 1, additionalLookupContent.length);
+        
+        extraLookupContent[0] = repository;
+        
+        SourceUtilsTestUtil.setLookup(extraLookupContent, SourceUtilsTestUtil.class.getClassLoader());
+        
+        SourceUtilsTestUtil2.disableLocks();
+    }
+    
+    static {
+        SourceUtilsTestUtil.class.getClassLoader().setDefaultAssertionStatus(true);
+        System.setProperty("org.openide.util.Lookup", SourceUtilsTestUtil.class.getName());
+        Assert.assertEquals(SourceUtilsTestUtil.class, Lookup.getDefault().getClass());
+    }
+    
+    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache) throws Exception {
+        prepareTest(sourceRoot, buildRoot, cache, new FileObject[0]);
+    }
+    
+    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache, FileObject[] classPathElements) throws Exception {
+        if (extraLookupContent == null)
+            prepareTest(new String[0], new Object[0]);
+        
+        Object[] lookupContent = new Object[extraLookupContent.length + 4];
+        
+        System.arraycopy(extraLookupContent, 0, lookupContent, 4, extraLookupContent.length);
+        
+        lookupContent[0] = new TestProxyClassPathProvider(sourceRoot, buildRoot, classPathElements);
+        lookupContent[1] = new TestSourceForBinaryQuery(sourceRoot, classPathElements);
+        lookupContent[2] = new TestSourceLevelQueryImplementation();
+        lookupContent[3] = JavaDataLoader.findObject(JavaDataLoader.class, true);
+        
+        setLookup(lookupContent, SourceUtilsTestUtil.class.getClassLoader());
+
+        IndexUtil.setCacheFolder(FileUtil.toFile(cache));
+    }
+
+    private static Map<FileObject,  String> file2SourceLevel = new WeakHashMap<FileObject, String>();
+    
+    public static void setSourceLevel(FileObject file, String level) {
+        file2SourceLevel.put(file, level);
+    }
+
+    /**This method assures that all java classes under sourceRoot are compiled,
+     * and the caches are created for them.
+     */
+    public static void compileRecursively(FileObject sourceRoot) throws Exception {
+        IndexingManager.getDefault().refreshIndexAndWait(sourceRoot.getURL(), null);
+    }
+
+    private static List<URL> bootClassPath;
+
+    public static synchronized List<URL> getBootClassPath() {
+        if (bootClassPath == null) {
+            try {
+                String cp = System.getProperty("sun.boot.class.path");
+                List<URL> urls = new ArrayList<URL>();
+                String[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
+                
+                for (String path : paths) {
+                    File f = new File(path);
+                    
+                    if (!f.canRead())
+                        continue;
+                    
+                    FileObject fo = FileUtil.toFileObject(f);
+                    
+                    if (FileUtil.isArchiveFile(fo)) {
+                        fo = FileUtil.getArchiveRoot(fo);
+                    }
+                    
+                    if (fo != null) {
+                        urls.add(fo.getURL());
+                    }
+                }
+                
+                bootClassPath = urls;
+            } catch (FileStateInvalidException e) {
+                ErrorManager.getDefault().notify(e);
+            }
+        }
+
+        return bootClassPath;
+    }
+
+    private static class TestSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
+        
+        private FileObject sourceRoot;
+        private List<FileObject> classPathElements;
+        
+        public TestSourceForBinaryQuery(FileObject sourceRoot, FileObject[] classPathElements) {
+            this.sourceRoot = sourceRoot;
+            this.classPathElements = Arrays.asList(classPathElements);
+        }
+        
+        public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
+            if (getBootClassPath().contains(binaryRoot))
+                return null;
+
+            if (classPathElements.contains(URLMapper.findFileObject(binaryRoot)))
+                return null;
+
+            return new SourceForBinaryQuery.Result() {
+                public FileObject[] getRoots() {
+                    return new FileObject[] {
+                        sourceRoot,
+                    };
+                }
+                
+                public void addChangeListener(ChangeListener l) {
+                }
+                
+                public void removeChangeListener(ChangeListener l) {
+                }
+            };
+        }
+        
+    }
+    
+    private static class TestProxyClassPathProvider implements ClassPathProvider {
+        
+        private FileObject sourceRoot;
+        private FileObject buildRoot;
+        private FileObject[] classPathElements;
+        
+        public TestProxyClassPathProvider(FileObject sourceRoot, FileObject buildRoot, FileObject[] classPathElements) {
+            this.sourceRoot = sourceRoot;
+            this.buildRoot = buildRoot;
+            this.classPathElements = classPathElements;
+        }
+        
+        public ClassPath findClassPath(FileObject file, String type) {
+            try {
+            if (ClassPath.BOOT == type) {
+                return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
+            }
+            
+            if (ClassPath.SOURCE == type) {
+                return ClassPathSupport.createClassPath(new FileObject[] {
+                    sourceRoot
+                });
+            }
+            
+            if (ClassPath.COMPILE == type) {
+                return ClassPathSupport.createClassPath(classPathElements);
+            }
+            
+            if (ClassPath.EXECUTE == type) {
+                return ClassPathSupport.createClassPath(new FileObject[] {
+                    buildRoot
+                });
+            }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
+        
+    }
+
+    public static class TestSourceLevelQueryImplementation implements SourceLevelQueryImplementation {
+        
+        public String getSourceLevel(FileObject javaFile) {
+            String level = file2SourceLevel.get(javaFile);
+            
+            if (level == null) {
+                if (javaFile.isFolder()) {
+                    for (FileObject data : file2SourceLevel.keySet()) {
+                        if (FileUtil.isParentOf(javaFile, data)) {
+                            return file2SourceLevel.get(data);
+                        }
+                    }
+                }
+                return "1.5";
+            } else
+                return level;
+        }
+        
+    }
+
+    /**Copied from org.netbeans.api.project.
+     * Create a scratch directory for tests.
+     * Will be in /tmp or whatever, and will be empty.
+     * If you just need a java.io.File use clearWorkDir + getWorkDir.
+     */
+    public static FileObject makeScratchDir(NbTestCase test) throws IOException {
+        test.clearWorkDir();
+        File root = test.getWorkDir();
+        assert root.isDirectory() && root.list().length == 0;
+        FileObject fo = FileUtil.toFileObject(root);
+        if (fo != null) {
+            // Presumably using masterfs.
+            return fo;
+        } else {
+            // For the benefit of those not using masterfs.
+            LocalFileSystem lfs = new LocalFileSystem();
+            try {
+                lfs.setRootDirectory(root);
+            } catch (PropertyVetoException e) {
+                assert false : e;
+            }
+            Repository.getDefault().addFileSystem(lfs);
+            return lfs.getRoot();
+        }
+    }
+    
+    public static JavacTask getJavacTaskFor(CompilationInfo info) {
+        return info.impl.getJavacTask();
+    }
+    
+    /** Blocking call for CompilationInfo after given phase is reached.
+     *  @param phase to be reached
+     *  @return CompilationInfo or null
+     *  XXX: REMOVE ME!!!!!!!
+     */
+    public static CompilationInfo getCompilationInfo(JavaSource js, Phase phase ) throws IOException {        
+        if (phase == null || phase == Phase.MODIFIED) { 
+            throw new IllegalArgumentException (String.format("The %s is not a legal value of phase",phase));   //NOI18N
+        }
+        final DeadlockTask bt = new DeadlockTask(phase);
+        js.runUserActionTask(bt,true);
+        return bt.info;
+    }
+    
+    
+    private static class DeadlockTask implements Task<CompilationController> {
+        
+        private final Phase phase;
+        private CompilationInfo info;
+        
+        public DeadlockTask(Phase phase) {
+            assert phase != null;
+            this.phase = phase;
+        }
+        
+        public void run( CompilationController info ) {
+            try {
+                info.toPhase(this.phase);
+                this.info = info;
+            } catch (IOException ioe) {
+                ErrorManager.getDefault().notify(ioe);
+            }
+        }                
+        
+    }
+
+    @ServiceProvider(service=MimeDataProvider.class)
+    public static final class JavacParserProvider implements MimeDataProvider {
+
+        private Lookup javaLookup = Lookups.fixed(new JavacParserFactory());
+
+        public Lookup getLookup(MimePath mimePath) {
+            if (mimePath.getPath().endsWith(JavacParser.MIME_TYPE)) {
+                return javaLookup;
+            }
+
+            return Lookup.EMPTY;
+        }
+        
+    }
+
+    @ServiceProvider(service=MIMEResolver.class)
+    public static final class JavaMimeResolver extends MIMEResolver {
+
+        public JavaMimeResolver() {
+            super(JavacParser.MIME_TYPE);
+        }
+
+        @Override
+        public String findMIMEType(FileObject fo) {
+            if ("java".equals(fo.getExt())) {
+                return JavacParser.MIME_TYPE;
+            }
+
+            return null;
+        }
+
+    }
+    
+}

borrowedtests/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil2.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.netbeans.api.java.source;
+
+import com.sun.source.tree.Tree;
+import org.apache.lucene.store.FSDirectory;
+import org.netbeans.modules.java.source.transform.Transformer;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public final class SourceUtilsTestUtil2 {
+
+    private SourceUtilsTestUtil2() {
+    }
+
+    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t) {
+//        if (afterCommit)
+//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
+        t.init();
+        t.attach(wc.impl.getJavacTask().getContext(), wc);
+        t.apply(wc.getCompilationUnit());
+        t.release();
+        t.destroy();
+    }
+    
+    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t, Tree tree) {
+//        if (afterCommit)
+//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
+        t.init();
+        t.attach(wc.impl.getJavacTask().getContext(), wc);
+        t.apply(tree);
+        t.release();
+        t.destroy();
+    }
+    
+    public static void disableLocks() {
+        FSDirectory.setDisableLocks(true);
+    }
+    
+}

borrowedtests/test/unit/src/org/netbeans/api/java/source/TestUtilities.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+
+package org.netbeans.api.java.source;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.zip.GZIPInputStream;
+
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.modules.java.source.classpath.GlobalSourcePathTestUtil;
+import org.netbeans.modules.java.source.usages.BinaryAnalyser;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.java.source.usages.ClassIndexManager;
+import org.netbeans.modules.java.source.usages.IndexUtil;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+
+/**
+ * Utilities to aid unit testing java.source module.
+ *
+ * @author Jaroslav Tulach
+ * @author Tom Ball
+ * @author Tomas Zezula
+ */
+public final class TestUtilities {
+    
+    // do not instantiate
+    private TestUtilities() {}
+    
+    /**
+     * Waits for the end of the background scan, this helper method 
+     * is designed for tests which require to wait for the end of initial scan.
+     * The method can be used as a barrier but it is not guaranteed that the
+     * background scan will not start again after return from this method, the
+     * test is responsible for it itself. In general it's safer to use {@link JavaSource#runWhenScanFinished}
+     * method and do the critical action inside the run method.
+     * @param timeout the maximum time to wait
+     * @param unit the time unit of the timeout argument
+     * @return true if the scan finished, false when the timeout elapsed before the end of the scan.
+     * @throws InterruptedException is thrown when the waiting thread is interrupted.
+     */
+    public static boolean waitScanFinished (final long timeout, final TimeUnit unit) throws InterruptedException {
+        assert unit != null;
+        final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(new URL[0]),
+                ClassPathSupport.createClassPath(new URL[0]), null);
+        assert cpInfo != null;
+        final JavaSource js = JavaSource.create(cpInfo);
+        assert js != null;
+        try {
+            Future<Void> future = js.runWhenScanFinished(new Task<CompilationController>() {
+                public void run(CompilationController parameter) throws Exception {
+                }
+            }, true);
+            future.get(timeout,unit);
+            return true;
+        } catch (IOException ioe) {
+            //Actually never thrown
+        }
+        catch (ExecutionException ee) {
+            //Actually never thrown
+        }
+        catch (TimeoutException timeoutEx) {
+        }
+        return false;
+    }
+    
+    /**
+     * Disables use of {@link LibraryManager} in the {@link GlobalSourcePath}. The tests
+     * which don't register {@link LibraryProvider} or {@link LibraryTypeProvider} may
+     * use this method to disable use of {@link LibraryManager} in the {@link GlobalSourcePath}.
+     * @param use false value disables use of {@link LibraryManager}
+     */
+    public static void setUseLibraries (final boolean use) {
+        GlobalSourcePathTestUtil.setUseLibraries(use);
+    }
+    
+    /**
+     * Sets a root folder of the java source caches. This method may be used by tests
+     * which need to do an initial compilation, they require either {@link ClassIndex} or
+     * need to work with a group of related java files.
+     * @param cacheFolder the folder used by java infrastructure as a cache,
+     * has to exist and must be a folder.
+     */
+    public static void setCacheFolder (final File cacheFolder) {
+        IndexUtil.setCacheFolder(cacheFolder);
+    }
+    
+    /**
+     * Creates boot {@link ClassPath} for platform the test is running on,
+     * it uses the sun.boot.class.path property to find out the boot path roots.
+     * @return ClassPath
+     * @throws java.io.IOException when boot path property contains non valid path
+     */
+    public static ClassPath createBootClassPath () throws IOException {
+        String bootPath = System.getProperty ("sun.boot.class.path");
+        String[] paths = bootPath.split(File.pathSeparator);
+        List<URL>roots = new ArrayList<URL> (paths.length);
+        for (String path : paths) {
+            File f = new File (path);            
+            if (!f.exists()) {
+                continue;
+            }
+            URL url = f.toURI().toURL();
+            if (FileUtil.isArchiveFile(url)) {
+                url = FileUtil.getArchiveRoot(url);
+            }
+            roots.add (url);
+        }
+        return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
+    }
+    /**
+     * Returns a string which contains the contents of a file.
+     *
+     * @param f the file to be read
+     * @return the contents of the file(s).
+     */
+    public final static String copyFileToString (java.io.File f) throws java.io.IOException {
+        int s = (int)f.length ();
+        byte[] data = new byte[s];
+        int len = new FileInputStream (f).read (data);
+        if (len != s)
+            throw new EOFException("truncated file");
+        return new String (data);
+    }
+    
+    /**
+     * Returns a string which contains the contents of a GZIP compressed file.
+     *
+     * @param f the file to be read
+     * @return the contents of the file(s).
+     */
+    public final static String copyGZipFileToString (java.io.File f) throws java.io.IOException {
+        GZIPInputStream is = new GZIPInputStream(new FileInputStream(f));
+        byte[] arr = new byte[256 * 256];
+        int first = 0;
+        for(;;) {
+            int len = is.read(arr, first, arr.length - first);
+            if (first + len < arr.length) {
+                return new String(arr, 0, first + len);
+            }
+        }
+    }
+    
+    /**
+     * Copies a string to a specified file.
+     *
+     * @param f the file to use.
+     * @param content the contents of the returned file.
+     * @return the created file
+     */
+    public final static File copyStringToFile (File f, String content) throws Exception {
+        FileOutputStream os = new FileOutputStream(f);
+        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
+        FileUtil.copy(is, os);
+        os.close ();
+        is.close();
+            
+        return f;
+    }
+    
+    /**
+     * Copies a string to a specified file.
+     *
+     * @param f the {@link FilObject} to use.
+     * @param content the contents of the returned file.
+     * @return the created file
+     */
+    public final static FileObject copyStringToFile (FileObject f, String content) throws Exception {
+        OutputStream os = f.getOutputStream();
+        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
+        FileUtil.copy(is, os);
+        os.close ();
+        is.close();
+            
+        return f;
+    }   
+
+    private static final ClassPath EMPTY = ClassPathSupport.createClassPath(new URL[0]);
+    
+    /**
+     * Prepare Java caches for given binary roots.
+     * 
+     * @param urls to analyze
+     */
+    public final static void analyzeBinaries(final Collection<URL> urls) throws IOException {
+        final ClasspathInfo cpInfo = ClasspathInfo.create(EMPTY, EMPTY, EMPTY);
+        final ClassIndexManager mgr  = ClassIndexManager.getDefault();
+        final JavaSource js = JavaSource.create(cpInfo);
+        js.runUserActionTask(new Task<CompilationController>() {
+            public void run(CompilationController parameter) throws Exception {                
+                for (final URL url : urls) {
+                    final ClassIndexImpl cii = mgr.createUsagesQuery(url, false);            
+                    ClassIndexManager.getDefault().writeLock(new ClassIndexManager.ExceptionAction<Void>() {
+                        public Void run() throws IOException, InterruptedException {
+                            BinaryAnalyser ba = cii.getBinaryAnalyser();            
+                            ba.start(url, new AtomicBoolean(false), new AtomicBoolean(false));
+                            ba.finish();
+                            return null;
+                        }
+                    });            
+                }
+            }
+        }, true);
+    }
+    
+}

borrowedtests/test/unit/src/org/netbeans/modules/java/hints/introduce/CopyFinderTest.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2007 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.java.hints.introduce;
+
+import com.sun.source.util.TreePath;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.swing.text.Document;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtilsTestUtil;
+import org.netbeans.api.java.source.TestUtilities;
+import org.netbeans.api.java.source.TreePathHandle;
+import org.netbeans.api.lexer.Language;
+import org.netbeans.junit.NbTestCase;
+import org.openide.cookies.EditorCookie;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.loaders.DataObject;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public class CopyFinderTest extends NbTestCase {
+    
+    public CopyFinderTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
+        super.setUp();
+    }
+
+    public void testSimple1() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; y = i + i; y = i + i;}}", 90 - 22, 95 - 22, 101 - 22, 106 - 22);
+    }
+    
+//    public void testSimple2() throws Exception {
+//        performTest("package test; public class Test {public void test() {int i = 0; y = i + i; y = i + i + i;}}", 90 - 22, 95 - 22, 101 - 22, 106 - 22);
+//    }
+    
+    public void testSimple3() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = System.currentTimeMillis(); y = System.currentTimeMillis();}}", 83 - 22, 109 - 22, 115 - 22, 141 - 22);
+    }
+    
+    public void testSimple4() throws Exception {
+        performTest("package test; import java.util.ArrayList; public class Test {public void test() {Object o = new ArrayList<String>();o = new ArrayList<String>();}}", 114 - 22, 137- 22, 142 - 22, 165 - 22);
+    }
+    
+    public void testSimple5() throws Exception {
+        performTest("package test; public class Test {public void test() {Object o = null; String s = (String) o; s = (String) o; s = (String) null; o = (Object) o;}}", 103 - 22, 113 - 22, 119 - 22, 129 - 22);
+    }
+    
+    public void testSimple6() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; y = i + i; y = i + i;} public void test2() {int i = 0; y = i + i; y = i + i;}}", 90 - 22, 95 - 22, 101 - 22, 106 - 22);
+    }
+    
+    public void testSimple7() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; y = i != 0 ? i + i : i * i; y = i != 0 ? i + i : i * i; y = i != 1 ? i + i : i * i; y = i == 0 ? i + i : i * i; y = i != 0 ? i * i : i * i; y = i != 0 ? i + i : i + i; y = i != 0 ? i + i : i * 1;}}", 90 - 22, 112 - 22, 118 - 22, 140 - 22);
+    }
+    
+    public void testSimple8() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; int y = -i; y = -i; y = +i; y = +y;}}", 94 - 22, 96 - 22, 102 - 22, 104 - 22);
+    }
+    
+    public void testSimple9() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; int y = i *= 9; y = i *= 9; y = i /= 9; y = i *= 8; y = y *= 9;}}", 94 - 22, 100 - 22, 106 - 22, 112 - 22);
+    }
+    
+    public void testSimple10() throws Exception {
+        performTest("package test; public class Test {public void test() {int[] i = null; int y = i[1]; y = i[1]; y = i[y]; y = i[0];}}", 99 - 22, 103 - 22, 109 - 22, 113 - 22);
+    }
+    
+    public void testSimple11() throws Exception {
+        performTest("package test; public class Test {public void test() {int[] i = new int[0]; i = new int[0]; i = new int[1];}}", 85 - 22, 95 - 22, 101 - 22, 111 - 22);
+    }
+    
+    public void testSimple12() throws Exception {
+        performTest("package test; public class Test {public void test() {int[] i = new int[1]; i = new int[1]; i = new int[0];}}", 85 - 22, 95 - 22, 101 - 22, 111 - 22);
+    }
+    
+    public void testSimple13() throws Exception {
+        performTest("package test; public class Test {public void test() {int i = 0; int y = (i); y = (i); y = i;}}", 94 - 22, 97 - 22, 103 - 22, 106 - 22);
+    }
+    
+    public void testSimple14() throws Exception {
+        performTest("package test; public class Test {public void test() {Object o = null; boolean b = o instanceof String; b = o instanceof String; b = o instanceof Object;}}", 104 - 22, 123 - 22, 129 - 22, 148 - 22);
+    }
+    
+    public void testSimple15() throws Exception {
+        performTest("package test; public class Test {private int x = 1; private int y = 1; public void test() {int x = 1; int y = 1;}}", 90 - 22, 91 - 22, 71 - 22, 72 - 22, 121 - 22, 122 - 22, 132 - 22, 133 - 22);
+    }
+    
+    public void testSimple16() throws Exception {
+        performTest("package test; public class Test {public void test(int i) {int y = \"\".length(); test(\"\".length());} }", 88 - 22, 99 - 22, 106 - 22, 117 - 22);
+    }
+    
+    public void testSimple17() throws Exception {
+        performTest("package test; public class Test {public void test2() {int a = test(test(test(1))); a = test(test(test(1))); a = test(test(test(1)));} public int test(int i) {return 0;} }", 94 - 22, 101 - 22, 119 - 22, 126 - 22, 144 - 22, 151 - 22);
+    }
+    
+    protected void prepareTest(String code) throws Exception {
+        clearWorkDir();
+        
+        FileObject workFO = FileUtil.toFileObject(getWorkDir());
+        
+        assertNotNull(workFO);
+        
+        FileObject sourceRoot = workFO.createFolder("src");
+        FileObject buildRoot  = workFO.createFolder("build");
+        FileObject cache = workFO.createFolder("cache");
+        
+        FileObject data = FileUtil.createData(sourceRoot, "test/Test.java");
+        
+        TestUtilities.copyStringToFile(FileUtil.toFile(data), code);
+        
+        data.refresh();
+        
+        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache);
+        
+        DataObject od = DataObject.find(data);
+        EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
+        
+        assertNotNull(ec);
+        
+        doc = ec.openDocument();
+        
+        doc.putProperty(Language.class, JavaTokenId.language());
+        doc.putProperty("mimeType", "text/x-java");
+        
+        JavaSource js = JavaSource.forFileObject(data);
+        
+        assertNotNull(js);
+        
+        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
+        
+        assertNotNull(info);
+    }
+    
+    protected CompilationInfo info;
+    private Document doc;
+    
+    protected void performTest(String code, int start, int end, int... duplicates) throws Exception {
+        assertTrue(duplicates.length % 2 == 0);
+        
+        prepareTest(code);
+        
+        TreePath path = IntroduceHint.validateSelection(info, start, end);
+        
+        assertNotNull(path);
+
+        Collection<TreePath> result = computeDuplicates(path);
+
+        //        assertEquals(f.result.toString(), duplicates.length / 2, f.result.size());
+        
+        int[] dupes = new int[result.size() * 2];
+        int   index = 0;
+        
+        for (TreePath tp : result) {
+            dupes[index++] = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tp.getLeaf());
+            dupes[index++] = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), tp.getLeaf());
+        }
+        
+        assertTrue(Arrays.toString(dupes), Arrays.equals(duplicates, dupes));
+    }
+
+    protected Collection<TreePath> computeDuplicates(TreePath path) {
+        return CopyFinder.computeDuplicates(info, path, new TreePath(info.getCompilationUnit()), new AtomicBoolean());
+    }
+
+}

borrowedtests/test/unit/src/org/netbeans/modules/java/source/classpath/GlobalSourcePathTestUtil.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * 
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * 
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ * 
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ * 
+ * Contributor(s):
+ * 
+ * Portions Copyrighted 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.java.source.classpath;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public final class GlobalSourcePathTestUtil {
+    private GlobalSourcePathTestUtil () {}
+    
+    public static void setUseLibraries (final boolean use) {
+        GlobalSourcePath.getDefault().setUseLibraries(use);
+    }
+}

borrowedtests/test/unit/src/org/netbeans/modules/java/source/transform/Transformer.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+
+package org.netbeans.modules.java.source.transform;
+
+import org.netbeans.modules.java.source.query.CommentHandler;
+import org.openide.util.NbBundle;
+import com.sun.source.tree.*;
+import com.sun.source.util.TreeScanner;
+import com.sun.tools.javac.model.JavacTypes;
+import com.sun.tools.javac.util.Context;
+import java.util.List;
+import java.util.logging.*;
+import javax.lang.model.util.Types;
+import org.netbeans.api.java.source.WorkingCopy;
+import org.netbeans.modules.java.source.builder.ASTService;
+import org.netbeans.modules.java.source.builder.CommentHandlerService;
+import org.netbeans.modules.java.source.builder.TreeFactory;
+
+/**
+ * A Transformer is an Query that modifies the model.  Model transformation
+ * is done by a supplied ImmutableTreeTranslator implementation.  A new context
+ * is set upon successful completion of this Transformer.
+ */
+public abstract class Transformer<R, P> extends TreeScanner<R,P> {
+
+    CommentHandler commentHandler;
+    public TreeFactory make;
+    protected WorkingCopy copy;
+    protected String refactoringDescription;
+    protected Types types; // used by tests
+    private String failureMessage;
+    protected ASTService model;
+
+    static final Logger logger = Logger.getLogger("org.netbeans.modules.java.source");
+
+    public void init() {
+    }
+
+    /**
+     * Initialize and associate this Query instance with the
+     * specified QueryEnvironment.
+     */
+    public void attach(Context context, WorkingCopy copy) {
+        make = TreeFactory.instance(context);
+        types = JavacTypes.instance(context);
+        commentHandler = CommentHandlerService.instance(context);
+        model = ASTService.instance(context);
+        this.copy = copy;
+    }
+
+    /**
+     * Release any instance data created during attach() invocation.  This
+     * is necessary because the Java reflection support may cache created
+     * instances, preventing the session data from being garbage-collected.
+     */
+    public void release() {
+        //changes.release();  // enable when async results are supported
+        //result.release()
+        make = null;
+        types = null;
+        this.copy = null;
+    }
+
+    public void destroy() {}
+    
+    public String getRefactoringDescription() {
+        return refactoringDescription != null ? refactoringDescription : "Unnamed Refactoring";
+    }
+
+    public void setRefactoringDescription(String description) {
+        refactoringDescription = description;
+    }
+
+    public void apply(Tree t) {
+        t.accept(this, null);
+    }
+
+    String getString(String key) {
+        return NbBundle.getBundle(Transformer.class).getString(key); //NOI18N
+    }
+
+    /**
+     * True if no translation failures occurred.
+     */
+    protected boolean translationSuccessful() {
+        return failureMessage == null;
+    }
+
+    public final void copyCommentTo(Tree from, Tree to) {
+        if (from != null && to != null) {
+            commentHandler.copyComments(from, to);
+        }
+    }
+}

borrowedtests/test/unit/src/org/netbeans/modules/java/source/usages/IndexUtil.java

+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+
+package org.netbeans.modules.java.source.usages;
+
+import java.io.File;
+import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
+import org.openide.filesystems.FileUtil;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public class IndexUtil {
+
+    public static void setCacheFolder (final File cacheFolder) {
+        CacheFolder.setCacheFolder(FileUtil.toFileObject(cacheFolder));
+    }
+
+}

hints/nbproject/genfiles.properties

-build.xml.data.CRC32=ba63b3d5
+build.xml.data.CRC32=6b8aa402
 build.xml.script.CRC32=e5c1372f
 build.xml.stylesheet.CRC32=79c3b980@1.28.0.7
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=ba63b3d5
+nbproject/build-impl.xml.data.CRC32=6b8aa402
 nbproject/build-impl.xml.script.CRC32=c85c4c1c
 nbproject/build-impl.xml.stylesheet.CRC32=3517ddf9@1.28.0.7

hints/nbproject/project.xml

                     </run-dependency>
                 </dependency>
             </module-dependencies>
+            <test-dependencies>
+                <test-type>
+                    <name>unit</name>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.bootstrap</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.core.startup</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.classfile</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.defaults</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor.settings.storage</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.editor.util</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
+                        <recursive/>
+                        <compile-dependency/>
+                        <test/>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.progress.ui</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
+                    </test-dependency>
+                    <test-dependency>
+                        <code-name-base>org.openidex.util</code-name-base>
+                    </test-dependency>
+                </test-type>
+            </test-dependencies>
             <public-packages/>
         </data>
     </configuration>

hints/src/org/netbeans/modules/jackpot30/hints/Bundle.properties

-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-#
-# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
-#
-# The contents of this file are subject to the terms of either the GNU
-# General Public License Version 2 only ("GPL") or the Common
-# Development and Distribution License("CDDL") (collectively, the
-# "License"). You may not use this file except in compliance with the
-# License. You can obtain a copy of the License at
-# http://www.netbeans.org/cddl-gplv2.html
-# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
-# specific language governing permissions and limitations under the
-# License.  When distributing the software, include this License Header
-# Notice in each file and include the License file at
-# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the GPL Version 2 section of the License file that
-# accompanied this code. If applicable, add the following below the
-# License Header, with the fields enclosed by brackets [] replaced by
-# your own identifying information:
-# "Portions Copyrighted [year] [name of copyright owner]"
-#
-# Contributor(s):
-#
-#The Original Software is NetBeans. The Initial Developer of the Original
-# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
-#Microsystems, Inc. All Rights Reserved.
-#
-# If you wish your version of this file to be governed by only the CDDL
-# or only the GPL Version 2, indicate your decision by adding
-# "[Contributor] elects to include this software in this distribution
-# under the [CDDL or GPL Version 2] license." If you do not indicate a
-# single choice of license, a recipient has the option to distribute
-# your version of this file under either the CDDL, the GPL Version 2 or
-# to extend the choice of license to its licensees as provided above.
-# However, if you add GPL Version 2 code and therefore, elected the GPL
-# Version 2 license, then the option applies only if the new code is
-# made subject to such option by the copyright holder.
-
-
-#
-# This file contains localized strings used in this package.  The typical
-# NetBeans pattern is to use one bundle per-package, called Bundle.properties;
-# the openide class NbBundle supports this usage.
-#
-# Typically, fetch a resource as follows:
-# NbBundle.getMessage (MyClass.class, "SOME_Key");
-#
-# Don't bother caching strings or worse, static references to resource bundles -
-# this may seem like its faster, but it wastes memory and slows things down
-# in the long run.
-#
-
-Add_cast_to_X=Cast {0} to {1}
-
-Add_throws_clause_for_X=Add throws clause for {0}
-
-Add_import_for_X=Add import for {0}
-
-#actions in the Refactor menu:
-CTL_IntroduceVariableAction=Introduce Variable...
-CTL_IntroduceConstantAction=Introduce Constant...
-CTL_IntroduceFieldAction=Introduce Field...
-CTL_IntroduceMethodAction=Introduce Method...
-
-Implement_all_abstract_methods=Implement all abstract methods
-
-MSG_CreateField=Create field {0} in {1}
-MSG_CreateMethod=Create method {0} in {1}
-MSG_CreateLocalVariable=Create local variable {0}
-MSG_CreateParameter=Create parameter {0}
-MSG_MakeClassAbstract=Make the class {0} abstract
-
-
-# InitializeVariableHint
-MSG_InitializeVar=Initialize variable {0}
-LBL_surroundTryCatch=Surround with try-catch
-
-LBL_Error_Provider=Java Error Provider
-
-jCheckBox1.text=Replace All Occurrences
-
-jCheckBox2.text=Declare Final
-
-TL_InitializeIn=Initialize in
-IntroduceFieldPanel.name.text=
-LBL_Name=&Name\:
-
-LBL_DeclareFinal=Declare &Final
-
-LBL_ReplaceAll=Replace &All Occurrences
-LBL_public=&public
-LBL_Default=&default
-LBL_protected=pr&otected
-LBL_private=pri&vate
-LBL_CurrentMethod=Current &Method
-LBL_Field=F&ield
-LBL_Constructors=&Constructor(s)
-
-IntroduceFieldPanel.lblInitializeIn.text=Initialize in\:
-
-LBL_Access=Access\:
-
-HINT_Introduce=Introduce...
-#fixes in the editor:
-FIX_IntroduceConstant=Introduce Constant...
-FIX_IntroduceVariable=Introduce Variable...
-FIX_IntroduceField=Introduce Field...
-FIX_IntroduceMethod=Introduce Method...
-#captions of the dialogs:
-CAP_IntroduceConstant=Introduce Constant
-CAP_IntroduceVariable=Introduce Variable
-CAP_IntroduceField=Introduce Field
-CAP_IntroduceMethod=Introduce Method
-
-#error messages:
-ERR_Not_Selected=No supported file opened in the editor.
-ERR_Not_Supported=Not supported on this file.
-ERR_Invalid_Selection=Invalid Selection.
-ERR_Too_Many_Different_Exits=Too many different exits.
-ERR_Too_Many_Return_Values=Too many return values.
-ERR_Different_Return_Values=Different return values.
-ERR_Break_Mismatch=Break or Continue lead to different statements.
-
-
-#ConvertAnonymousToInner:
-HINT_ConvertAnonymousToInner=Convert Anonymous to Inner
-DN_ConvertAnonymousToInner=Convert Anonymous to Inner
-DESC_ConvertAnonymousToInner=Convert Anonymous to Inner
-FIX_ConvertAnonymousToInner=Convert Anonymous to Inner
-
-
-ERR_DereferencingNull=Dereferencing null
-ERR_PossiblyDereferencingNull=Possibly Dereferencing null
-ERR_AssigningNullToNotNull=Assigning Null to NotNull Variable
-ERR_PossibleAssigingNullToNotNull=Possibly Assigning Null to NotNull Variable
-ERR_NULL_TO_NON_NULL_ARG=Passing null to not-null argument
-ERR_POSSIBLENULL_TO_NON_NULL_ARG=Passing possible null to not-null argument
-
-
-DN_NegateCondition=Negate if condition
-DESC_NegateCondition=Negate if condition
-FIX_NegateCondition=Negate if condition
-
-
-DESC_ImageUtilities=Deprecation of image related methods in Utilities
-DN_ImageUtilities=Deprecation of image related methods in Utilities
-FIX_ImageUtilities=Replace with ImageUtilities
-
-CTL_OrganizeImportsAction=Organize Imports

hints/src/org/netbeans/modules/jackpot30/hints/ComparingSameExpressions.java

-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General