Starting to separate functionality into separate directories and other cleanup separate-by-function-cleanup
authorJan Lahoda <jlahoda@netbeans.org>
Sat, 11 Feb 2012 18:35:10 +0100
branchseparate-by-function-cleanup
changeset 7324633c6a7568f
parent 731 27f6e619f984
child 733 26159229c6a1
Starting to separate functionality into separate directories and other cleanup
.ant-targets-build.xml
api/nbproject/genfiles.properties
api/nbproject/project.xml
api/src/org/netbeans/modules/jackpot30/impl/batch/BatchUtilities.java
api/src/org/netbeans/modules/jackpot30/impl/batch/Bundle.properties
api/src/org/netbeans/modules/jackpot30/impl/batch/EnhancedScopes.java
api/src/org/netbeans/modules/jackpot30/impl/batch/OptionProcessorImpl.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties
api/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.form
api/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/GlobalFindDuplicates.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DeferredCustomIndexer.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndex.java
api/src/org/netbeans/modules/jackpot30/impl/examples/Bundle.properties
api/src/org/netbeans/modules/jackpot30/impl/examples/ExamplesList.form
api/src/org/netbeans/modules/jackpot30/impl/examples/ExamplesList.java
api/src/org/netbeans/modules/jackpot30/impl/hints/FindDuplicates.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/AbstractLuceneIndex.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/Cache.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImpl.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/FileBasedIndex.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/Index.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/IndexInfo.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/AbstractApplyHintsRefactoringPlugin.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/AddScopePanel.form
api/src/org/netbeans/modules/jackpot30/impl/refactoring/AddScopePanel.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/ApplyPatternAction.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties
api/src/org/netbeans/modules/jackpot30/impl/refactoring/ExamplesList.form
api/src/org/netbeans/modules/jackpot30/impl/refactoring/ExamplesList.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoring.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPanel.form
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPanel.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPlugin.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringUI.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindOccurrencesAction.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/RefactoringPluginFactoryImpl.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/RetoucheCommit.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/ScopesPanel.form
api/src/org/netbeans/modules/jackpot30/impl/refactoring/ScopesPanel.java
api/src/org/netbeans/modules/jackpot30/impl/refactoring/Utilities.java
api/src/org/netbeans/modules/jackpot30/spi/refactoring/JackpotBasedRefactoring.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicatesTest.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndexTest.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImplTest.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexTest.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexTestBase.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexingTestUtils.java
borrowedtests/build.xml
borrowedtests/manifest.mf
borrowedtests/nbproject/build-impl.xml
borrowedtests/nbproject/genfiles.properties
borrowedtests/nbproject/platform.properties
borrowedtests/nbproject/project.properties
borrowedtests/nbproject/project.xml
borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil2.java
borrowedtests/src/org/netbeans/api/java/source/TestUtilities.java
borrowedtests/src/org/netbeans/modules/jackpot30/impl/TestUtils.java
borrowedtests/src/org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties
borrowedtests/src/org/netbeans/modules/java/hints/TestUtilities.java
borrowedtests/src/org/netbeans/modules/java/hints/infrastructure/TreeRuleTestBase.java
borrowedtests/src/org/netbeans/modules/java/hints/jackpot/code/spi/TestBase.java
borrowedtests/src/org/netbeans/modules/java/hints/jackpot/impl/pm/BulkSearchTestPerformer.java
borrowedtests/src/org/netbeans/modules/java/source/transform/Transformer.java
borrowedtests/src/org/netbeans/modules/java/source/usages/IndexUtil.java
borrowedtests/src/org/netbeans/modules/parsing/impl/indexing/MimeTypes.java
borrowedtests/src/org/openide/util/test/AnnotationProcessorTestUtils.java
build.xml
duplicates/ide/build.xml
duplicates/ide/impl/build.xml
duplicates/ide/impl/manifest.mf
duplicates/ide/impl/nbproject/build-impl.xml
duplicates/ide/impl/nbproject/genfiles.properties
duplicates/ide/impl/nbproject/project.properties
duplicates/ide/impl/nbproject/project.xml
duplicates/ide/impl/nbproject/suite.properties
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/duplicates/impl/Bundle.properties
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.form
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/GlobalFindDuplicates.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/hints/FindDuplicates.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DeferredCustomIndexer.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java
duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndex.java
duplicates/ide/impl/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicatesTest.java
duplicates/ide/impl/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndexTest.java
duplicates/ide/nbproject/build-impl.xml
duplicates/ide/nbproject/genfiles.properties
duplicates/ide/nbproject/platform.properties
duplicates/ide/nbproject/platform.xml
duplicates/ide/nbproject/project.properties
duplicates/ide/nbproject/project.xml
language/ide/build.xml
language/ide/indexing/build.xml
language/ide/indexing/manifest.mf
language/ide/indexing/nbproject/build-impl.xml
language/ide/indexing/nbproject/genfiles.properties
language/ide/indexing/nbproject/project.properties
language/ide/indexing/nbproject/project.xml
language/ide/indexing/nbproject/suite.properties
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/Bundle.properties
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/BatchUtilities.java
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/Bundle.properties
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/EnhancedScopes.java
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/OptionProcessorImpl.java
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/index/IndexQuery.java
language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/index/Indexer.java
language/ide/indexing/test/unit/src/org/netbeans/modules/jackpot30/indexing/index/IndexerTest.java
language/ide/nbproject/build-impl.xml
language/ide/nbproject/genfiles.properties
language/ide/nbproject/platform.properties
language/ide/nbproject/platform.xml
language/ide/nbproject/project.properties
language/ide/nbproject/project.xml
nbproject/platform.properties
remoting/common/api/build.xml
remoting/common/api/manifest.mf
remoting/common/api/nbproject/build-impl.xml
remoting/common/api/nbproject/genfiles.properties
remoting/common/api/nbproject/project.properties
remoting/common/api/nbproject/project.xml
remoting/common/api/nbproject/suite.properties
remoting/common/api/src/org/netbeans/modules/jackpot30/common/Bundle.properties
remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/IndexAccess.java
remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/JavaUtils.java
remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/LuceneHelpers.java
remoting/common/borrowedtests/build.xml
remoting/common/borrowedtests/manifest.mf
remoting/common/borrowedtests/nbproject/build-impl.xml
remoting/common/borrowedtests/nbproject/genfiles.properties
remoting/common/borrowedtests/nbproject/platform.properties
remoting/common/borrowedtests/nbproject/project.properties
remoting/common/borrowedtests/nbproject/project.xml
remoting/common/borrowedtests/nbproject/suite.properties
remoting/common/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
remoting/common/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil2.java
remoting/common/borrowedtests/src/org/netbeans/api/java/source/TestUtilities.java
remoting/common/borrowedtests/src/org/netbeans/modules/jackpot30/impl/TestUtils.java
remoting/common/borrowedtests/src/org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties
remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/TestUtilities.java
remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/infrastructure/TreeRuleTestBase.java
remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/code/spi/TestBase.java
remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/impl/pm/BulkSearchTestPerformer.java
remoting/common/borrowedtests/src/org/netbeans/modules/java/source/transform/Transformer.java
remoting/common/borrowedtests/src/org/netbeans/modules/java/source/usages/IndexUtil.java
remoting/common/borrowedtests/src/org/netbeans/modules/parsing/impl/indexing/MimeTypes.java
remoting/common/borrowedtests/src/org/openide/util/test/AnnotationProcessorTestUtils.java
remoting/common/build.xml
remoting/common/nbproject/build-impl.xml
remoting/common/nbproject/genfiles.properties
remoting/common/nbproject/platform.properties
remoting/common/nbproject/platform.xml
remoting/common/nbproject/project.properties
remoting/common/nbproject/project.xml
remoting/common/test/build.xml
remoting/common/test/manifest.mf
remoting/common/test/nbproject/build-impl.xml
remoting/common/test/nbproject/genfiles.properties
remoting/common/test/nbproject/project.properties
remoting/common/test/nbproject/project.xml
remoting/common/test/nbproject/suite.properties
remoting/common/test/src/org/netbeans/modules/jackpot30/common/test/Bundle.properties
remoting/common/test/src/org/netbeans/modules/jackpot30/common/test/IndexTestBase.java
remoting/ide/build.xml
remoting/ide/nbproject/build-impl.xml
remoting/ide/nbproject/genfiles.properties
remoting/ide/nbproject/platform.properties
remoting/ide/nbproject/project.xml
remoting/ide/usages/nbproject/genfiles.properties
remoting/ide/usages/nbproject/project.xml
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Common.java
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java
remoting/server/web/web.main/build.xml
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.ant-targets-build.xml	Sat Feb 11 18:35:10 2012 +0100
     1.3 @@ -0,0 +1,26 @@
     1.4 +build-jnlp
     1.5 +build-mac
     1.6 +build-osgi
     1.7 +build-osgi-obr
     1.8 +build-zip
     1.9 +clusterize
    1.10 +copy-cluster
    1.11 +copy-nbexec
    1.12 +create-platform
    1.13 +debug
    1.14 +debug-jnlp
    1.15 +debug-osgi
    1.16 +display-coverage-report
    1.17 +nbms
    1.18 +profile
    1.19 +profile-osgi
    1.20 +run
    1.21 +run-jnlp
    1.22 +run-osgi
    1.23 +suite.build
    1.24 +suite.clean
    1.25 +suite.test
    1.26 +test-generate-html
    1.27 +test-view-html
    1.28 +testuserdir-delete
    1.29 +update
     2.1 --- a/api/nbproject/genfiles.properties	Fri Jan 27 13:35:56 2012 +0100
     2.2 +++ b/api/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
     2.3 @@ -3,6 +3,6 @@
     2.4  build.xml.stylesheet.CRC32=79c3b980@1.28.0.7
     2.5  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     2.6  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     2.7 -nbproject/build-impl.xml.data.CRC32=035c9b32
     2.8 +nbproject/build-impl.xml.data.CRC32=6500fcd0
     2.9  nbproject/build-impl.xml.script.CRC32=c4574e66
    2.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.47
    2.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
     3.1 --- a/api/nbproject/project.xml	Fri Jan 27 13:35:56 2012 +0100
     3.2 +++ b/api/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
     3.3 @@ -391,6 +391,10 @@
     3.4                          <code-name-base>org.netbeans.modules.editor.util</code-name-base>
     3.5                      </test-dependency>
     3.6                      <test-dependency>
     3.7 +                        <code-name-base>org.netbeans.modules.jackpot30.common.test</code-name-base>
     3.8 +                        <compile-dependency/>
     3.9 +                    </test-dependency>
    3.10 +                    <test-dependency>
    3.11                          <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
    3.12                          <recursive/>
    3.13                          <compile-dependency/>
     4.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/batch/BatchUtilities.java	Fri Jan 27 13:35:56 2012 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,121 +0,0 @@
     4.4 -/*
     4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 - *
     4.7 - * Copyright 2008-2010 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 - * If you wish your version of this file to be governed by only the CDDL
    4.28 - * or only the GPL Version 2, indicate your decision by adding
    4.29 - * "[Contributor] elects to include this software in this distribution
    4.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.31 - * single choice of license, a recipient has the option to distribute
    4.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    4.33 - * to extend the choice of license to its licensees as provided above.
    4.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.35 - * Version 2 license, then the option applies only if the new code is
    4.36 - * made subject to such option by the copyright holder.
    4.37 - *
    4.38 - * Contributor(s):
    4.39 - *
    4.40 - * Portions Copyrighted 2008-2010 Sun Microsystems, Inc.
    4.41 - */
    4.42 -
    4.43 -package org.netbeans.modules.jackpot30.impl.batch;
    4.44 -
    4.45 -import java.io.IOException;
    4.46 -import java.io.Reader;
    4.47 -import java.io.StringReader;
    4.48 -import java.io.Writer;
    4.49 -import java.nio.charset.Charset;
    4.50 -import org.netbeans.api.annotations.common.NullAllowed;
    4.51 -import org.netbeans.api.java.source.ModificationResult;
    4.52 -import org.netbeans.api.queries.FileEncodingQuery;
    4.53 -import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider;
    4.54 -import org.netbeans.modules.diff.builtin.visualizer.TextDiffVisualizer;
    4.55 -import org.netbeans.spi.diff.DiffProvider;
    4.56 -import org.openide.filesystems.FileObject;
    4.57 -import org.openide.filesystems.FileUtil;
    4.58 -
    4.59 -/**
    4.60 - *
    4.61 - * @author Jan Lahoda
    4.62 - */
    4.63 -public class BatchUtilities {
    4.64 -
    4.65 -    public static void exportDiff(ModificationResult result, @NullAllowed FileObject relativeTo, Writer out) throws IOException {
    4.66 -        for (FileObject f : result.getModifiedFileObjects()) {
    4.67 -            Charset c = FileEncodingQuery.getEncoding(f);
    4.68 -            String orig = new String(f.asBytes(), c);
    4.69 -            String nue = result.getResultingSource(f);
    4.70 -
    4.71 -            if (orig.equals(nue)) {
    4.72 -                continue;
    4.73 -            }
    4.74 -
    4.75 -            String name = relativeTo != null ? FileUtil.getRelativePath(relativeTo, f) : FileUtil.toFile(f).getAbsolutePath();
    4.76 -            
    4.77 -            doExportDiff(name, orig, nue, out);
    4.78 -        }
    4.79 -    }
    4.80 -
    4.81 -    //copied from the diff module:
    4.82 -    private static void doExportDiff(String name, String original, String modified, Writer out) throws IOException {
    4.83 -        DiffProvider diff = new BuiltInDiffProvider();//(DiffProvider) Lookup.getDefault().lookup(DiffProvider.class);
    4.84 -
    4.85 -        Reader r1 = null;
    4.86 -        Reader r2 = null;
    4.87 -        org.netbeans.api.diff.Difference[] differences;
    4.88 -
    4.89 -        try {
    4.90 -            r1 = new StringReader(original);
    4.91 -            r2 = new StringReader(modified);
    4.92 -            differences = diff.computeDiff(r1, r2);
    4.93 -        } finally {
    4.94 -            if (r1 != null) try { r1.close(); } catch (Exception e) {}
    4.95 -            if (r2 != null) try { r2.close(); } catch (Exception e) {}
    4.96 -        }
    4.97 -
    4.98 -        try {
    4.99 -            r1 = new StringReader(original);
   4.100 -            r2 = new StringReader(modified);
   4.101 -            TextDiffVisualizer.TextDiffInfo info = new TextDiffVisualizer.TextDiffInfo(
   4.102 -                name, // NOI18N
   4.103 -                name,  // NOI18N
   4.104 -                null,
   4.105 -                null,
   4.106 -                r1,
   4.107 -                r2,
   4.108 -                differences
   4.109 -            );
   4.110 -            info.setContextMode(true, 3);
   4.111 -            String diffText;
   4.112 -//            if (format == unifiedFilter) {
   4.113 -                diffText = TextDiffVisualizer.differenceToUnifiedDiffText(info);
   4.114 -//            } else {
   4.115 -//                diffText = TextDiffVisualizer.differenceToNormalDiffText(info);
   4.116 -//            }
   4.117 -            out.write(diffText);
   4.118 -        } finally {
   4.119 -            if (r1 != null) try { r1.close(); } catch (Exception e) {}
   4.120 -            if (r2 != null) try { r2.close(); } catch (Exception e) {}
   4.121 -        }
   4.122 -    }
   4.123 -
   4.124 -}
     5.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/batch/Bundle.properties	Fri Jan 27 13:35:56 2012 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,49 +0,0 @@
     5.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.5 -#
     5.6 -# Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
     5.7 -#
     5.8 -# The contents of this file are subject to the terms of either the GNU
     5.9 -# General Public License Version 2 only ("GPL") or the Common
    5.10 -# Development and Distribution License("CDDL") (collectively, the
    5.11 -# "License"). You may not use this file except in compliance with the
    5.12 -# License. You can obtain a copy of the License at
    5.13 -# http://www.netbeans.org/cddl-gplv2.html
    5.14 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.15 -# specific language governing permissions and limitations under the
    5.16 -# License.  When distributing the software, include this License Header
    5.17 -# Notice in each file and include the License file at
    5.18 -# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    5.19 -# particular file as subject to the "Classpath" exception as provided
    5.20 -# by Sun in the GPL Version 2 section of the License file that
    5.21 -# accompanied this code. If applicable, add the following below the
    5.22 -# License Header, with the fields enclosed by brackets [] replaced by
    5.23 -# your own identifying information:
    5.24 -# "Portions Copyrighted [year] [name of copyright owner]"
    5.25 -#
    5.26 -# Contributor(s):
    5.27 -#
    5.28 -#The Original Software is NetBeans. The Initial Developer of the Original
    5.29 -# Software is Sun Microsystems, Inc. Portions Copyright 2008-2009 Sun
    5.30 -#Microsystems, Inc. All Rights Reserved.
    5.31 -#
    5.32 -# If you wish your version of this file to be governed by only the CDDL
    5.33 -# or only the GPL Version 2, indicate your decision by adding
    5.34 -# "[Contributor] elects to include this software in this distribution
    5.35 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.36 -# single choice of license, a recipient has the option to distribute
    5.37 -# your version of this file under either the CDDL, the GPL Version 2 or
    5.38 -# to extend the choice of license to its licensees as provided above.
    5.39 -# However, if you add GPL Version 2 code and therefore, elected the GPL
    5.40 -# Version 2 license, then the option applies only if the new code is
    5.41 -# made subject to such option by the copyright holder.
    5.42 -
    5.43 -CTL_BatchApplyAction=Batch Apply Hint
    5.44 -SD_ApplyTransformations=applies specified transformation(s) on specified project or all opened projects
    5.45 -SD_ApplyTransformationsProject=projects on which the transformations should be applied
    5.46 -SelectHint.jLabel1.text=Select Hint:
    5.47 -SelectHint.addHint.text=>>
    5.48 -SelectHint.addAllHints.text=>>>
    5.49 -SelectHint.removeHint.text=<<
    5.50 -SelectHint.removeAllHints.text=<<<
    5.51 -SelectHint.selectedHintsLabel.text=Selected Hints
    5.52 -SelectHint.allHintsLabel.text_1=All Hints:
     6.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/batch/EnhancedScopes.java	Fri Jan 27 13:35:56 2012 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,458 +0,0 @@
     6.4 -/*
     6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.6 - *
     6.7 - * Copyright 2009-2011 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 2009-2011 Sun Microsystems, Inc.
    6.41 - */
    6.42 -
    6.43 -package org.netbeans.modules.jackpot30.impl.batch;
    6.44 -
    6.45 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Folder;
    6.46 -import org.netbeans.modules.java.hints.jackpot.spi.Trigger.PatternDescription;
    6.47 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Resource;
    6.48 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
    6.49 -import java.util.concurrent.Callable;
    6.50 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.IndexEnquirer;
    6.51 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.LocalIndexEnquirer;
    6.52 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.MapIndices;
    6.53 -import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
    6.54 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
    6.55 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
    6.56 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
    6.57 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
    6.58 -import org.netbeans.spi.editor.hints.Severity;
    6.59 -import java.util.Iterator;
    6.60 -import java.io.BufferedInputStream;
    6.61 -import java.io.BufferedOutputStream;
    6.62 -import java.io.File;
    6.63 -import java.io.FileInputStream;
    6.64 -import java.io.FileOutputStream;
    6.65 -import java.io.IOException;
    6.66 -import java.io.InputStream;
    6.67 -import java.io.OutputStream;
    6.68 -import java.net.URI;
    6.69 -import java.net.URISyntaxException;
    6.70 -import java.util.ArrayList;
    6.71 -import java.util.Collection;
    6.72 -import java.util.Collections;
    6.73 -import java.util.HashMap;
    6.74 -import java.util.HashSet;
    6.75 -import java.util.LinkedList;
    6.76 -import java.util.List;
    6.77 -import java.util.Map;
    6.78 -import java.util.Map.Entry;
    6.79 -import java.util.Properties;
    6.80 -import java.util.Set;
    6.81 -import java.util.concurrent.atomic.AtomicBoolean;
    6.82 -import java.util.logging.Level;
    6.83 -import java.util.logging.Logger;
    6.84 -import org.codeviation.pojson.Pojson;
    6.85 -import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
    6.86 -import org.netbeans.modules.jackpot30.impl.indexing.CustomIndexerImpl;
    6.87 -import org.netbeans.modules.jackpot30.impl.indexing.FileBasedIndex;
    6.88 -import org.netbeans.modules.jackpot30.impl.indexing.Index;
    6.89 -import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
    6.90 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
    6.91 -import org.netbeans.spi.editor.hints.ErrorDescription;
    6.92 -import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
    6.93 -import org.openide.filesystems.FileObject;
    6.94 -import org.openide.filesystems.FileStateInvalidException;
    6.95 -import org.openide.filesystems.FileUtil;
    6.96 -import org.openide.filesystems.URLMapper;
    6.97 -import org.openide.util.Exceptions;
    6.98 -import static org.netbeans.modules.jackpot30.remoting.api.WebUtilities.escapeForQuery;
    6.99 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.VerifiedSpansCallBack;
   6.100 -
   6.101 -/**
   6.102 - *
   6.103 - * @author lahvac
   6.104 - */
   6.105 -public class EnhancedScopes {
   6.106 -
   6.107 -    private static final Logger LOG = Logger.getLogger(EnhancedScopes.class.getName());
   6.108 -
   6.109 -    public static Scope allRemote() {
   6.110 -        return new RemoteIndexScope();
   6.111 -    }
   6.112 -
   6.113 -    public static final class GivenFolderScope extends Scope {
   6.114 -
   6.115 -        public final String folder;
   6.116 -        public final String indexURL;
   6.117 -        public final String subIndex;
   6.118 -        public final boolean update;
   6.119 -
   6.120 -        public GivenFolderScope(String folder, String indexURL, String subIndex, boolean update) {
   6.121 -            this.folder = folder;
   6.122 -            this.indexURL = indexURL;
   6.123 -            this.subIndex = subIndex;
   6.124 -            this.update = update;
   6.125 -        }
   6.126 -
   6.127 -        @Override
   6.128 -        public String getDisplayName() {
   6.129 -            return folder;
   6.130 -        }
   6.131 -
   6.132 -        @Override
   6.133 -        public Collection<? extends Folder> getTodo() {
   6.134 -            return Collections.singletonList(new Folder(FileUtil.toFileObject(new File(folder))));
   6.135 -        }
   6.136 -
   6.137 -        @Override
   6.138 -        public MapIndices getIndexMapper(Iterable<? extends HintDescription> patterns) {
   6.139 -            MapIndices mapper;
   6.140 -
   6.141 -            if (indexURL != null) {
   6.142 -                if (subIndex == null) {
   6.143 -                    mapper = new MapIndices() {
   6.144 -                        public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
   6.145 -                            return new SimpleIndexIndexEnquirer(root, createOrUpdateIndex(root, new File(indexURL), update, progress, recursive));
   6.146 -                        }
   6.147 -                    };
   6.148 -                } else {
   6.149 -                    mapper = new MapIndices() {
   6.150 -                        public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
   6.151 -                            progress.startNextPart(1);
   6.152 -                            try {
   6.153 -                                return new SimpleIndexIndexEnquirer(root, Index.createWithRemoteIndex(root.getURL(), indexURL, subIndex));
   6.154 -                            } catch (FileStateInvalidException ex) {
   6.155 -                                Exceptions.printStackTrace(ex);
   6.156 -                                return null;
   6.157 -                            }
   6.158 -                        }
   6.159 -                    };
   6.160 -                }
   6.161 -            } else {
   6.162 -                mapper = Scopes.getDefaultIndicesMapper();
   6.163 -            }
   6.164 -
   6.165 -            return mapper;
   6.166 -        }
   6.167 -
   6.168 -    }
   6.169 -
   6.170 -    private static final class RemoteIndexScope extends Scope {
   6.171 -        @Override
   6.172 -        public String getDisplayName() {
   6.173 -            return "All Remote Indices";
   6.174 -        }
   6.175 -
   6.176 -        @Override
   6.177 -        public Collection<? extends Folder> getTodo() {
   6.178 -            Collection<Folder> todo = new HashSet<Folder>();
   6.179 -
   6.180 -            for (RemoteIndex remoteIndex : RemoteIndex.loadIndices()) {
   6.181 -                FileObject localFolder = URLMapper.findFileObject(remoteIndex.getLocalFolder());
   6.182 -
   6.183 -                if (localFolder == null) continue;
   6.184 -                todo.add(new Folder(localFolder));
   6.185 -            }
   6.186 -
   6.187 -            return todo;
   6.188 -        }
   6.189 -
   6.190 -        @Override
   6.191 -        public MapIndices getIndexMapper(final Iterable<? extends HintDescription> patterns) {
   6.192 -            return new MapIndices() {
   6.193 -                public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
   6.194 -                    for (RemoteIndex remoteIndex : RemoteIndex.loadIndices()) {
   6.195 -                        FileObject localFolder = URLMapper.findFileObject(remoteIndex.getLocalFolder());
   6.196 -
   6.197 -                        if (localFolder == null) continue;
   6.198 -                        if (localFolder == root) {
   6.199 -                            return enquirerForRemoteIndex(root, remoteIndex, patterns);
   6.200 -                        }
   6.201 -                    }
   6.202 -                    throw new IllegalStateException();
   6.203 -                }
   6.204 -            };
   6.205 -        }
   6.206 -    }
   6.207 -
   6.208 -    private static Index createOrUpdateIndex(FileObject src, File indexRoot, boolean update, ProgressHandleWrapper progress, boolean recursive) {
   6.209 -        Index index;
   6.210 -
   6.211 -        try {
   6.212 -            index = FileBasedIndex.create(src.getURL(), indexRoot);
   6.213 -        } catch (FileStateInvalidException ex) {
   6.214 -            throw new IllegalStateException(ex);
   6.215 -        }
   6.216 -
   6.217 -        File timeStampsFile = new File(indexRoot, "timestamps.properties");
   6.218 -        Properties timeStamps = new Properties();
   6.219 -
   6.220 -        if (timeStampsFile.exists()) {
   6.221 -            if (!update) {
   6.222 -                progress.startNextPart(1);
   6.223 -                return index;
   6.224 -            }
   6.225 -
   6.226 -            InputStream in = null;
   6.227 -
   6.228 -            try {
   6.229 -                in = new BufferedInputStream(new FileInputStream(timeStampsFile));
   6.230 -                timeStamps.load(in);
   6.231 -            } catch (IOException ex) {
   6.232 -                Exceptions.printStackTrace(ex);
   6.233 -            } finally {
   6.234 -                try {
   6.235 -                    if (in != null)
   6.236 -                        in.close();
   6.237 -                } catch (IOException ex) {
   6.238 -                    Exceptions.printStackTrace(ex);
   6.239 -                }
   6.240 -            }
   6.241 -        }
   6.242 -
   6.243 -        Collection<FileObject> collected = new LinkedList<FileObject>();
   6.244 -        Set<String> removed = new HashSet<String>(timeStamps.stringPropertyNames());
   6.245 -
   6.246 -        org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities.recursive(src, src, collected, progress, 0, timeStamps, removed, recursive);
   6.247 -
   6.248 -        CustomIndexerImpl.doIndex(src, collected, removed, index);
   6.249 -
   6.250 -        OutputStream out = null;
   6.251 -
   6.252 -        try {
   6.253 -            out = new BufferedOutputStream(new FileOutputStream(timeStampsFile));
   6.254 -            timeStamps.store(out, null);
   6.255 -        } catch (IOException ex) {
   6.256 -            Exceptions.printStackTrace(ex);
   6.257 -        } finally {
   6.258 -            try {
   6.259 -                if (out != null) {
   6.260 -                    out.close();
   6.261 -                }
   6.262 -            } catch (IOException ex) {
   6.263 -                Exceptions.printStackTrace(ex);
   6.264 -            }
   6.265 -        }
   6.266 -
   6.267 -        return index;
   6.268 -    }
   6.269 -
   6.270 -    private static boolean isAttributedIndexWithSpans(RemoteIndex remoteIndex) {
   6.271 -        try {
   6.272 -            URI capabilitiesURI = new URI(remoteIndex.remote.toExternalForm() + "/capabilities");
   6.273 -            String capabilitiesString = WebUtilities.requestStringResponse(capabilitiesURI);
   6.274 -
   6.275 -            if (capabilitiesURI == null) return false;
   6.276 -
   6.277 -            @SuppressWarnings("unchecked")
   6.278 -            Map<String, Object> capabilities = Pojson.load(HashMap.class, capabilitiesString);
   6.279 -
   6.280 -            return capabilities.get("attributed") == Boolean.TRUE; //TODO: should also check "methods contains findWithSpans"
   6.281 -        } catch (URISyntaxException ex) {
   6.282 -            LOG.log(Level.FINE, null, ex);
   6.283 -            return false;
   6.284 -        }
   6.285 -    }
   6.286 -
   6.287 -    private static IndexEnquirer enquirerForRemoteIndex(FileObject src, RemoteIndex remoteIndex, Iterable<? extends HintDescription> hints) {
   6.288 -        boolean fullySupported = isAttributedIndexWithSpans(remoteIndex);
   6.289 -        StringBuilder textualRepresentation = new StringBuilder();
   6.290 -
   6.291 -        for (HintDescription hd : hints) {
   6.292 -            if (!(hd.getTrigger() instanceof PatternDescription)) {
   6.293 -                fullySupported = false;
   6.294 -                break;
   6.295 -            }
   6.296 -
   6.297 -            if (((PatternDescription) hd.getTrigger()).getImports().iterator().hasNext()) {
   6.298 -                fullySupported = false;
   6.299 -            }
   6.300 -
   6.301 -            if (!fullySupported) break;
   6.302 -
   6.303 -            String hintText = hd.getHintText();
   6.304 -
   6.305 -            if (hintText != null) {
   6.306 -                textualRepresentation.append(hintText);
   6.307 -            } else {
   6.308 -                textualRepresentation.append(defaultHintText(hd));
   6.309 -                fullySupported = false;
   6.310 -            }
   6.311 -
   6.312 -            textualRepresentation.append("\n");
   6.313 -        }
   6.314 -
   6.315 -        if (fullySupported) {
   6.316 -            return new RemoteFullyAttributedIndexEnquirer(src, remoteIndex, textualRepresentation.toString());
   6.317 -        } else {
   6.318 -            try {
   6.319 -                return new SimpleIndexIndexEnquirer(src, Index.createWithRemoteIndex(src.getURL(), remoteIndex.remote.toExternalForm(), remoteIndex.remoteSegment));
   6.320 -            } catch (FileStateInvalidException ex) {
   6.321 -                throw new IllegalStateException(ex);
   6.322 -            }
   6.323 -        }
   6.324 -    }
   6.325 -
   6.326 -    private static final class SimpleIndexIndexEnquirer extends LocalIndexEnquirer {
   6.327 -        private final Index idx;
   6.328 -        public SimpleIndexIndexEnquirer(FileObject src, Index idx) {
   6.329 -            super(src);
   6.330 -            this.idx = idx;
   6.331 -        }
   6.332 -        public Collection<? extends Resource> findResources(final Iterable<? extends HintDescription> hints, ProgressHandleWrapper progress, final Callable<BulkPattern> bulkPattern, final Collection<? super MessageImpl> problems) {
   6.333 -            final Collection<Resource> result = new ArrayList<Resource>();
   6.334 -
   6.335 -            progress.startNextPart(1);
   6.336 -
   6.337 -            try {
   6.338 -                BulkPattern bp = bulkPattern.call();
   6.339 -
   6.340 -                for (String candidate : idx.findCandidates(bp)) {
   6.341 -                    result.add(new Resource(this, candidate, hints, bp));
   6.342 -                }
   6.343 -            } catch (Exception ex) {
   6.344 -                Exceptions.printStackTrace(ex);
   6.345 -            }
   6.346 -
   6.347 -            return result;
   6.348 -        }
   6.349 -
   6.350 -    }
   6.351 -
   6.352 -    private static final class RemoteFullyAttributedIndexEnquirer extends IndexEnquirer {
   6.353 -        private final RemoteIndex remoteIndex;
   6.354 -        private final String textualHintRepresentation;
   6.355 -        public RemoteFullyAttributedIndexEnquirer(FileObject src, RemoteIndex remoteIndex, String textualHintRepresentation) {
   6.356 -            super(src);
   6.357 -            assert isAttributedIndexWithSpans(remoteIndex);
   6.358 -            this.remoteIndex = remoteIndex;
   6.359 -            this.textualHintRepresentation = textualHintRepresentation;
   6.360 -        }
   6.361 -        public Collection<? extends Resource> findResources(final Iterable<? extends HintDescription> hints, ProgressHandleWrapper progress, final Callable<BulkPattern> bulkPattern, final Collection<? super MessageImpl> problems) {
   6.362 -            final Collection<Resource> result = new ArrayList<Resource>();
   6.363 -
   6.364 -            progress.startNextPart(1);
   6.365 -
   6.366 -            try {
   6.367 -                URI u = new URI(remoteIndex.remote.toExternalForm() + "/find?path=" + escapeForQuery(remoteIndex.remoteSegment) + "&pattern=" + escapeForQuery(textualHintRepresentation));
   6.368 -
   6.369 -                for (String occurrence : new ArrayList<String>(WebUtilities.requestStringArrayResponse(u))) {
   6.370 -                    try {
   6.371 -                        BulkPattern bp = bulkPattern.call();
   6.372 -                        result.add(new Resource(this, occurrence, hints, bp));
   6.373 -                    } catch (Exception ex) {
   6.374 -                        //from bulkPattern.call()? should not happen.
   6.375 -                        Exceptions.printStackTrace(ex);
   6.376 -                    }
   6.377 -                }
   6.378 -
   6.379 -            } catch (URISyntaxException ex) {
   6.380 -                Exceptions.printStackTrace(ex);
   6.381 -            }
   6.382 -
   6.383 -            return result;
   6.384 -        }
   6.385 -
   6.386 -        @Override
   6.387 -        public void validateResource(Collection<? extends Resource> resources, ProgressHandleWrapper progress, VerifiedSpansCallBack callback, boolean doNotRegisterClassPath, Collection<? super MessageImpl> problems, AtomicBoolean cancel) {
   6.388 -            for (Resource r : resources) {
   6.389 -                try {
   6.390 -                    URI spanURI = new URI(remoteIndex.remote.toExternalForm() + "/findSpans?path=" + escapeForQuery(remoteIndex.remoteSegment) + "&relativePath=" + escapeForQuery(r.getRelativePath()) + "&pattern=" + escapeForQuery(textualHintRepresentation));
   6.391 -                    FileObject fo = r.getResolvedFile();
   6.392 -
   6.393 -                    if (fo == null) {
   6.394 -                        callback.cannotVerifySpan(r);
   6.395 -                    } else {
   6.396 -                        List<ErrorDescription> result = new ArrayList<ErrorDescription>();
   6.397 -
   6.398 -                        for (int[] span : parseSpans(WebUtilities.requestStringResponse(spanURI))) {
   6.399 -                            result.add(ErrorDescriptionFactory.createErrorDescription(Severity.WARNING, "Occurrence", fo, span[0], span[1]));
   6.400 -                        }
   6.401 -
   6.402 -                        callback.spansVerified(null, r, result);
   6.403 -                    }
   6.404 -                } catch (Exception ex) {
   6.405 -                    Exceptions.printStackTrace(ex);
   6.406 -                }
   6.407 -            }
   6.408 -        }
   6.409 -
   6.410 -    }
   6.411 -
   6.412 -    private static Iterable<int[]> parseSpans(String from) {
   6.413 -        if (from.isEmpty()) {
   6.414 -            return Collections.emptyList();
   6.415 -        }
   6.416 -        String[] split = from.split(":");
   6.417 -        List<int[]> result = new LinkedList<int[]>();
   6.418 -
   6.419 -        for (int i = 0; i < split.length; i += 2) {
   6.420 -            result.add(new int[] {
   6.421 -                Integer.parseInt(split[i + 0].trim()),
   6.422 -                Integer.parseInt(split[i + 1].trim())
   6.423 -            });
   6.424 -        }
   6.425 -
   6.426 -        return result;
   6.427 -    }
   6.428 -
   6.429 -    private static String defaultHintText(HintDescription hd) {
   6.430 -        StringBuilder result = new StringBuilder();
   6.431 -
   6.432 -        PatternDescription pd = (PatternDescription) hd.getTrigger();
   6.433 -
   6.434 -        if (pd == null) return null;
   6.435 -
   6.436 -        if (pd.getImports().iterator().hasNext()) {
   6.437 -            //cannot currently handle patterns with imports:
   6.438 -            return null;
   6.439 -        }
   6.440 -
   6.441 -        result.append(pd.getPattern());
   6.442 -
   6.443 -        if (!pd.getConstraints().isEmpty()) {
   6.444 -            result.append(" :: ");
   6.445 -
   6.446 -            for (Iterator<Entry<String, String>> it = pd.getConstraints().entrySet().iterator(); it.hasNext(); ) {
   6.447 -                Entry<String, String> e = it.next();
   6.448 -
   6.449 -                result.append(e.getKey()).append(" instanceof ").append(e.getValue());
   6.450 -
   6.451 -                if (it.hasNext()) {
   6.452 -                    result.append(" && ");
   6.453 -                }
   6.454 -            }
   6.455 -        }
   6.456 -
   6.457 -        result.append(";;\n");
   6.458 -
   6.459 -        return result.toString();
   6.460 -    }
   6.461 -}
     7.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/batch/OptionProcessorImpl.java	Fri Jan 27 13:35:56 2012 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,276 +0,0 @@
     7.4 -/*
     7.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 - *
     7.7 - * Copyright 2008-2010 Sun Microsystems, Inc. All rights reserved.
     7.8 - *
     7.9 - * The contents of this file are subject to the terms of either the GNU
    7.10 - * General Public License Version 2 only ("GPL") or the Common
    7.11 - * Development and Distribution License("CDDL") (collectively, the
    7.12 - * "License"). You may not use this file except in compliance with the
    7.13 - * License. You can obtain a copy of the License at
    7.14 - * http://www.netbeans.org/cddl-gplv2.html
    7.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.16 - * specific language governing permissions and limitations under the
    7.17 - * License.  When distributing the software, include this License Header
    7.18 - * Notice in each file and include the License file at
    7.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    7.20 - * particular file as subject to the "Classpath" exception as provided
    7.21 - * by Sun in the GPL Version 2 section of the License file that
    7.22 - * accompanied this code. If applicable, add the following below the
    7.23 - * License Header, with the fields enclosed by brackets [] replaced by
    7.24 - * your own identifying information:
    7.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    7.26 - *
    7.27 - * If you wish your version of this file to be governed by only the CDDL
    7.28 - * or only the GPL Version 2, indicate your decision by adding
    7.29 - * "[Contributor] elects to include this software in this distribution
    7.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    7.31 - * single choice of license, a recipient has the option to distribute
    7.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    7.33 - * to extend the choice of license to its licensees as provided above.
    7.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    7.35 - * Version 2 license, then the option applies only if the new code is
    7.36 - * made subject to such option by the copyright holder.
    7.37 - *
    7.38 - * Contributor(s):
    7.39 - *
    7.40 - * Portions Copyrighted 2008-2010 Sun Microsystems, Inc.
    7.41 - */
    7.42 -
    7.43 -package org.netbeans.modules.jackpot30.impl.batch;
    7.44 -
    7.45 -import java.io.File;
    7.46 -import java.io.IOException;
    7.47 -import java.util.ArrayList;
    7.48 -import java.util.Arrays;
    7.49 -import java.util.Collection;
    7.50 -import java.util.HashMap;
    7.51 -import java.util.HashSet;
    7.52 -import java.util.LinkedList;
    7.53 -import java.util.List;
    7.54 -import java.util.Map;
    7.55 -import java.util.Set;
    7.56 -import java.util.TreeMap;
    7.57 -import java.util.logging.Logger;
    7.58 -import org.netbeans.api.java.classpath.ClassPath;
    7.59 -import org.netbeans.api.java.source.ModificationResult;
    7.60 -import org.netbeans.api.project.Project;
    7.61 -import org.netbeans.api.project.ProjectManager;
    7.62 -import org.netbeans.api.project.ProjectUtils;
    7.63 -import org.netbeans.api.project.SourceGroup;
    7.64 -import org.netbeans.api.project.ui.OpenProjects;
    7.65 -import org.netbeans.api.sendopts.CommandException;
    7.66 -import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
    7.67 -import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
    7.68 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
    7.69 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
    7.70 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Folder;
    7.71 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities;
    7.72 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
    7.73 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
    7.74 -import org.netbeans.modules.java.hints.jackpot.spi.HintContext.MessageKind;
    7.75 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
    7.76 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
    7.77 -import org.netbeans.spi.sendopts.Env;
    7.78 -import org.netbeans.spi.sendopts.Option;
    7.79 -import org.netbeans.spi.sendopts.OptionProcessor;
    7.80 -import org.openide.filesystems.FileObject;
    7.81 -import org.openide.filesystems.FileUtil;
    7.82 -import org.openide.util.lookup.ServiceProvider;
    7.83 -
    7.84 -/**
    7.85 - *
    7.86 - * @author Jan Lahoda
    7.87 - */
    7.88 -@ServiceProvider(service=OptionProcessor.class)
    7.89 -public class OptionProcessorImpl extends OptionProcessor {
    7.90 -
    7.91 -    private static final Logger LOG = Logger.getLogger(OptionProcessorImpl.class.getName());
    7.92 -
    7.93 -    private static final String APPLY_TRANSFORMATIONS_PROJECT_OPTION = "apply-transformations-project";
    7.94 -
    7.95 -    private static final Option LIST = Option.withoutArgument(Option.NO_SHORT_NAME, "list-hints-transformation");
    7.96 -    private static final Option APPLY_TRANSFORMATIONS = Option.shortDescription(
    7.97 -                                                            Option.requiredArgument(Option.NO_SHORT_NAME, "apply-transformations"),
    7.98 -                                                            "org.netbeans.modules.jackpot30.impl.batch.Bundle",
    7.99 -                                                            "SD_ApplyTransformations");
   7.100 -    private static final Option APPLY_TRANSFORMATIONS_PROJECT = Option.shortDescription(
   7.101 -                                                            Option.additionalArguments(Option.NO_SHORT_NAME, APPLY_TRANSFORMATIONS_PROJECT_OPTION),
   7.102 -                                                            "org.netbeans.modules.jackpot30.impl.batch.Bundle",
   7.103 -                                                            "SD_ApplyTransformationsProject");
   7.104 -
   7.105 -    private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(LIST, APPLY_TRANSFORMATIONS, APPLY_TRANSFORMATIONS_PROJECT));
   7.106 -
   7.107 -    @Override
   7.108 -    protected Set<Option> getOptions() {
   7.109 -        return OPTIONS;
   7.110 -    }
   7.111 -
   7.112 -    @Override
   7.113 -    protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
   7.114 -        List<Project> projects = new LinkedList<Project>();
   7.115 -        Map<String, List<ClassPath>> classPaths = new HashMap<String, List<ClassPath>>();
   7.116 -
   7.117 -        if (optionValues.containsKey(APPLY_TRANSFORMATIONS_PROJECT)) {
   7.118 -            String[] projectNames = optionValues.get(APPLY_TRANSFORMATIONS_PROJECT);
   7.119 -
   7.120 -            if (projectNames.length == 0) {
   7.121 -                env.getErrorStream().println("At least one parameter needed for " + APPLY_TRANSFORMATIONS_PROJECT_OPTION);
   7.122 -                throw new CommandException(1);
   7.123 -            }
   7.124 -
   7.125 -            FileObject currentDirectory = FileUtil.toFileObject(env.getCurrentDirectory());
   7.126 -
   7.127 -            OUTER: for (String p : projectNames) {
   7.128 -                FileObject projectFile = currentDirectory.getFileObject(p);
   7.129 -
   7.130 -                if (projectFile == null) {
   7.131 -                    projectFile = FileUtil.toFileObject(new File(p));
   7.132 -                }
   7.133 -
   7.134 -                if (projectFile == null) {
   7.135 -                    env.getErrorStream().println("Ignoring file " + p + " - cannot be found.");
   7.136 -                    continue;
   7.137 -                }
   7.138 -
   7.139 -                if (!projectFile.isFolder()) {
   7.140 -                    env.getErrorStream().println("Ignoring file " + p + " - not a folder.");
   7.141 -                    continue;
   7.142 -                }
   7.143 -
   7.144 -                Project project = null;
   7.145 -                String  error   = null;
   7.146 -
   7.147 -                try {
   7.148 -                    project = ProjectManager.getDefault().findProject(projectFile);
   7.149 -                } catch (IOException ex) {
   7.150 -                    error = ex.getLocalizedMessage();
   7.151 -                } catch (IllegalArgumentException ex) {
   7.152 -                    error = ex.getLocalizedMessage();
   7.153 -                }
   7.154 -
   7.155 -                if (project == null) {
   7.156 -                    if (error == null) {
   7.157 -                        env.getErrorStream().println("Ignoring file " + p + " - not a project.");
   7.158 -                    } else {
   7.159 -                        env.getErrorStream().println("Ignoring file " + p + " - not a project (" + error + ").");
   7.160 -                    }
   7.161 -
   7.162 -                    continue;
   7.163 -                }
   7.164 -
   7.165 -                for (SourceGroup sg : ProjectUtils.getSources(project).getSourceGroups("java")) {
   7.166 -                    FileObject root = sg.getRootFolder();
   7.167 -
   7.168 -                    for (String type : Arrays.asList(ClassPath.BOOT, ClassPath.COMPILE, ClassPath.SOURCE)) {
   7.169 -                        if (!handleClassPath(root, type, env, p, classPaths)) {
   7.170 -                            continue OUTER;
   7.171 -                        }
   7.172 -                    }
   7.173 -                }
   7.174 -
   7.175 -                projects.add(project);
   7.176 -            }
   7.177 -        } else {
   7.178 -            projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
   7.179 -        }
   7.180 -
   7.181 -        if (optionValues.containsKey(LIST)) {
   7.182 -            env.getOutputStream().println("Supported Hints:");
   7.183 -
   7.184 -            Set<ClassPath> cps = new HashSet<ClassPath>();
   7.185 -
   7.186 -            for (List<ClassPath> c : classPaths.values()) {
   7.187 -                cps.addAll(c);
   7.188 -            }
   7.189 -
   7.190 -            Set<String> displayNames = Utilities.sortOutHints(Utilities.listAllHints(cps), new TreeMap<String, Collection<HintDescription>>()).keySet();
   7.191 -
   7.192 -            for (String displayName : displayNames) {
   7.193 -                env.getOutputStream().println(displayName);
   7.194 -            }
   7.195 -        }
   7.196 -
   7.197 -        if (optionValues.containsKey(APPLY_TRANSFORMATIONS)) {
   7.198 -            String hintsArg = optionValues.get(APPLY_TRANSFORMATIONS)[0];
   7.199 -            List<HintDescription> hintDescriptions = new LinkedList<HintDescription>();
   7.200 -            Set<ClassPath> cps = new HashSet<ClassPath>();
   7.201 -
   7.202 -            for (List<ClassPath> c : classPaths.values()) {
   7.203 -                cps.addAll(c);
   7.204 -            }
   7.205 -
   7.206 -            Map<String, Collection<HintDescription>> sorted = Utilities.sortOutHints(Utilities.listAllHints(cps), new TreeMap<String, Collection<HintDescription>>());
   7.207 -
   7.208 -            for (String hint : hintsArg.split(":")) {
   7.209 -                Collection<HintDescription> descs = sorted.get(hint);
   7.210 -
   7.211 -                if (descs == null) {
   7.212 -                    env.getErrorStream().println("Unknown hint: " + hint);
   7.213 -                    continue;
   7.214 -                }
   7.215 -
   7.216 -                hintDescriptions.addAll(descs);
   7.217 -            }
   7.218 -
   7.219 -            Collection<Folder> roots = new ArrayList<Folder>();
   7.220 -
   7.221 -            for (FileObject f : BatchUtilities.getSourceGroups(projects)) {
   7.222 -                roots.add(new Folder(f));
   7.223 -            }
   7.224 -
   7.225 -            BatchResult candidates = BatchSearch.findOccurrences(hintDescriptions, Scopes.specifiedFoldersScope(roots.toArray(new Folder[0])));
   7.226 -            List<MessageImpl> problems = new LinkedList<MessageImpl>(candidates.problems);
   7.227 -            Collection<? extends ModificationResult> res = BatchUtilities.applyFixes(candidates, new ProgressHandleWrapper(100), null, problems);
   7.228 -            Set<FileObject> modified = new HashSet<FileObject>();
   7.229 -
   7.230 -            for (ModificationResult mr : res) {
   7.231 -                try {
   7.232 -                    mr.commit();
   7.233 -                } catch (IOException ex) {
   7.234 -                    ex.printStackTrace(env.getErrorStream());
   7.235 -                    problems.add(new MessageImpl(MessageKind.ERROR, "Cannot apply changes: " + ex.getLocalizedMessage()));
   7.236 -                }
   7.237 -                modified.addAll(mr.getModifiedFileObjects());
   7.238 -            }
   7.239 -
   7.240 -            try {
   7.241 -                BatchUtilities.removeUnusedImports(modified);
   7.242 -            } catch (IOException ex) {
   7.243 -                ex.printStackTrace(env.getErrorStream());
   7.244 -                problems.add(new MessageImpl(MessageKind.ERROR, "Cannot remove unused imports: " + ex.getLocalizedMessage()));
   7.245 -            }
   7.246 -
   7.247 -            if (!problems.isEmpty()) {
   7.248 -                env.getErrorStream().println("Problem encountered while applying the transformations:");
   7.249 -
   7.250 -                for (MessageImpl problem : problems) {
   7.251 -                    env.getErrorStream().println(problem.text);
   7.252 -                }
   7.253 -            }
   7.254 -        }
   7.255 -
   7.256 -    }
   7.257 -
   7.258 -    private boolean handleClassPath(FileObject root, String type, Env env, String p, Map<String, List<ClassPath>> classPaths) {
   7.259 -        ClassPath cp = ClassPath.getClassPath(root, type);
   7.260 -
   7.261 -        if (cp == null) {
   7.262 -            env.getErrorStream().println("Ignoring file " + p + " - no " + type + " classpath for source group: " + FileUtil.getFileDisplayName(root));
   7.263 -            return false;
   7.264 -        }
   7.265 -
   7.266 -        List<ClassPath> cps = classPaths.get(type);
   7.267 -
   7.268 -        if (cps == null) {
   7.269 -            classPaths.put(type, cps = new LinkedList<ClassPath>());
   7.270 -        }
   7.271 -
   7.272 -        cp = ClassPathSupport.createProxyClassPath(cp);
   7.273 -
   7.274 -        cps.add(cp);
   7.275 -
   7.276 -        return true;
   7.277 -    }
   7.278 -
   7.279 -}
     8.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties	Fri Jan 27 13:35:56 2012 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,3 +0,0 @@
     8.4 -CTL_GlobalFindDuplicates=Global Find Duplicates
     8.5 -DuplicatesListPanel.findMore.text=<html><body><a href="">Look for More</a>
     8.6 -DuplicatesListPanel.progressLabel.text=
     9.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java	Fri Jan 27 13:35:56 2012 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,449 +0,0 @@
     9.4 -/*
     9.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     9.6 - *
     9.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
     9.8 - *
     9.9 - * The contents of this file are subject to the terms of either the GNU
    9.10 - * General Public License Version 2 only ("GPL") or the Common
    9.11 - * Development and Distribution License("CDDL") (collectively, the
    9.12 - * "License"). You may not use this file except in compliance with the
    9.13 - * License. You can obtain a copy of the License at
    9.14 - * http://www.netbeans.org/cddl-gplv2.html
    9.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    9.16 - * specific language governing permissions and limitations under the
    9.17 - * License.  When distributing the software, include this License Header
    9.18 - * Notice in each file and include the License file at
    9.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    9.20 - * particular file as subject to the "Classpath" exception as provided
    9.21 - * by Sun in the GPL Version 2 section of the License file that
    9.22 - * accompanied this code. If applicable, add the following below the
    9.23 - * License Header, with the fields enclosed by brackets [] replaced by
    9.24 - * your own identifying information:
    9.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    9.26 - *
    9.27 - * If you wish your version of this file to be governed by only the CDDL
    9.28 - * or only the GPL Version 2, indicate your decision by adding
    9.29 - * "[Contributor] elects to include this software in this distribution
    9.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    9.31 - * single choice of license, a recipient has the option to distribute
    9.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    9.33 - * to extend the choice of license to its licensees as provided above.
    9.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    9.35 - * Version 2 license, then the option applies only if the new code is
    9.36 - * made subject to such option by the copyright holder.
    9.37 - *
    9.38 - * Contributor(s):
    9.39 - *
    9.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
    9.41 - */
    9.42 -package org.netbeans.modules.jackpot30.impl.duplicates;
    9.43 -
    9.44 -import com.sun.source.tree.CompilationUnitTree;
    9.45 -import com.sun.source.tree.Tree;
    9.46 -import com.sun.source.util.SourcePositions;
    9.47 -import com.sun.source.util.TreePath;
    9.48 -import com.sun.source.util.TreePathScanner;
    9.49 -import com.sun.source.util.Trees;
    9.50 -import java.io.ByteArrayOutputStream;
    9.51 -import java.io.File;
    9.52 -import java.io.IOException;
    9.53 -import java.net.URL;
    9.54 -import java.security.DigestOutputStream;
    9.55 -import java.security.MessageDigest;
    9.56 -import java.security.NoSuchAlgorithmException;
    9.57 -import java.util.ArrayList;
    9.58 -import java.util.Arrays;
    9.59 -import java.util.BitSet;
    9.60 -import java.util.Collection;
    9.61 -import java.util.Collections;
    9.62 -import java.util.Comparator;
    9.63 -import java.util.HashMap;
    9.64 -import java.util.HashSet;
    9.65 -import java.util.Iterator;
    9.66 -import java.util.LinkedHashMap;
    9.67 -import java.util.LinkedList;
    9.68 -import java.util.List;
    9.69 -import java.util.Map;
    9.70 -import java.util.Map.Entry;
    9.71 -import java.util.NoSuchElementException;
    9.72 -import java.util.Set;
    9.73 -import java.util.TreeMap;
    9.74 -import java.util.concurrent.atomic.AtomicBoolean;
    9.75 -import javax.tools.JavaCompiler.CompilationTask;
    9.76 -import org.apache.lucene.document.Document;
    9.77 -import org.apache.lucene.index.IndexReader;
    9.78 -import org.apache.lucene.index.MultiReader;
    9.79 -import org.apache.lucene.index.Term;
    9.80 -import org.apache.lucene.index.TermEnum;
    9.81 -import org.apache.lucene.search.Collector;
    9.82 -import org.apache.lucene.search.IndexSearcher;
    9.83 -import org.apache.lucene.search.Query;
    9.84 -import org.apache.lucene.search.Searcher;
    9.85 -import org.apache.lucene.search.TermQuery;
    9.86 -import org.apache.lucene.store.FSDirectory;
    9.87 -import org.netbeans.api.annotations.common.CheckForNull;
    9.88 -import org.netbeans.api.java.classpath.ClassPath;
    9.89 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
    9.90 -import org.netbeans.api.java.source.CompilationInfo;
    9.91 -import org.netbeans.api.progress.ProgressHandle;
    9.92 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesCustomIndexerImpl;
    9.93 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesIndex;
    9.94 -import org.netbeans.modules.jackpot30.impl.indexing.AbstractLuceneIndex.BitSetCollector;
    9.95 -import org.netbeans.modules.jackpot30.impl.indexing.Cache;
    9.96 -import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
    9.97 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
    9.98 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
    9.99 -import org.netbeans.modules.java.source.JavaSourceAccessor;
   9.100 -import org.openide.filesystems.FileObject;
   9.101 -import org.openide.filesystems.URLMapper;
   9.102 -import org.openide.util.Exceptions;
   9.103 -
   9.104 -
   9.105 -/**
   9.106 - *
   9.107 - * @author lahvac
   9.108 - */
   9.109 -public class ComputeDuplicates {
   9.110 -
   9.111 -    public Iterator<? extends DuplicateDescription> computeDuplicatesForAllOpenedProjects(ProgressHandle progress, AtomicBoolean cancel) throws IOException {
   9.112 -        Set<URL> urls = new HashSet<URL>();
   9.113 -
   9.114 -        for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
   9.115 -            for (ClassPath.Entry e : cp.entries()) {
   9.116 -                urls.add(e.getURL());
   9.117 -            }
   9.118 -        }
   9.119 -
   9.120 -        long start = System.currentTimeMillis();
   9.121 -        try {
   9.122 -            return computeDuplicates(urls, progress, cancel);
   9.123 -        } finally {
   9.124 -            System.err.println("duplicates for all open projects: " + (System.currentTimeMillis() - start));
   9.125 -        }
   9.126 -    }
   9.127 -
   9.128 -    public Iterator<? extends DuplicateDescription> computeDuplicates(Set<URL> forURLs, ProgressHandle progress, AtomicBoolean cancel) throws IOException {
   9.129 -        Map<IndexReader, FileObject> readers2Roots = new LinkedHashMap<IndexReader, FileObject>();
   9.130 -
   9.131 -        progress.progress("Updating indices");
   9.132 -
   9.133 -        for (URL u : forURLs) {
   9.134 -            try {
   9.135 -                //TODO: needs to be removed for server mode
   9.136 -                new DuplicatesCustomIndexerImpl.FactoryImpl().updateIndex(u, cancel); //TODO: show updating progress to the user
   9.137 -                
   9.138 -                File cacheRoot = Cache.findCache(DuplicatesIndex.NAME, DuplicatesIndex.VERSION).findCacheRoot(u);
   9.139 -
   9.140 -                File dir = new File(cacheRoot, "fulltext");
   9.141 -
   9.142 -                if (dir.listFiles() != null && dir.listFiles().length > 0) {
   9.143 -                    IndexReader reader = IndexReader.open(FSDirectory.open(dir), true);
   9.144 -
   9.145 -                    readers2Roots.put(reader, URLMapper.findFileObject(u));
   9.146 -                }
   9.147 -            } catch (IOException ex) {
   9.148 -                Exceptions.printStackTrace(ex);
   9.149 -            }
   9.150 -        }
   9.151 -        
   9.152 -        progress.progress("Searching for duplicates");
   9.153 -
   9.154 -        MultiReader r = new MultiReader(readers2Roots.keySet().toArray(new IndexReader[0]));
   9.155 -
   9.156 -        List<String> dd = new ArrayList<String>(getDuplicatedValues(r, "generalized", cancel));
   9.157 -
   9.158 -        sortHashes(dd);
   9.159 -
   9.160 -        //TODO: only show valuable duplicates?:
   9.161 -//        dd = dd.subList(0, dd.size() / 10 + 1);
   9.162 -
   9.163 -        return new DuplicatesIterator(readers2Roots, dd, 2);
   9.164 -    }
   9.165 -
   9.166 -    public static Iterator<? extends DuplicateDescription> XXXduplicatesOf(Map<IndexReader, FileObject> readers2Roots, Collection<String> hashes) {
   9.167 -        List<String> hashesList = new ArrayList<String>(hashes);
   9.168 -        sortHashes(hashesList);
   9.169 -        return new DuplicatesIterator(readers2Roots, hashesList, 1);
   9.170 -    }
   9.171 -
   9.172 -    private static final class DuplicatesIterator implements Iterator<DuplicateDescription> {
   9.173 -        private final Map<IndexReader, FileObject> readers2Roots;
   9.174 -        private final Iterator<String> duplicateCandidates;
   9.175 -        private final int minDuplicates;
   9.176 -        private final List<DuplicateDescription> result = new LinkedList<DuplicateDescription>();
   9.177 -
   9.178 -        public DuplicatesIterator(Map<IndexReader, FileObject> readers2Roots, Iterable<String> duplicateCandidates, int minDuplicates) {
   9.179 -            this.readers2Roots = readers2Roots;
   9.180 -            this.duplicateCandidates = duplicateCandidates.iterator();
   9.181 -            this.minDuplicates = minDuplicates;
   9.182 -        }
   9.183 -
   9.184 -        private DuplicateDescription nextDescription() throws IOException {
   9.185 -        while (duplicateCandidates.hasNext()) {
   9.186 -            String longest = duplicateCandidates.next();
   9.187 -            List<Span> foundDuplicates = new LinkedList<Span>();
   9.188 -
   9.189 -            Query query = new TermQuery(new Term("generalized", longest));
   9.190 -
   9.191 -            for (Entry<IndexReader, FileObject> e : readers2Roots.entrySet()) {
   9.192 -                Searcher s = new IndexSearcher(e.getKey());
   9.193 -                BitSet matchingDocuments = new BitSet(e.getKey().maxDoc());
   9.194 -                Collector c = new BitSetCollector(matchingDocuments);
   9.195 -
   9.196 -                s.search(query, c);
   9.197 -
   9.198 -                for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum + 1)) {
   9.199 -                    final Document doc = e.getKey().document(docNum);
   9.200 -                    int pos = Arrays.binarySearch(doc.getValues("generalized"), longest);
   9.201 -
   9.202 -                    if (pos < 0) {
   9.203 -                        System.err.println("FOOBAR=" + pos);
   9.204 -                        continue;
   9.205 -                    }
   9.206 -                    
   9.207 -                    String spanSpec = doc.getValues("positions")[pos];
   9.208 -                    String relPath = doc.getField("path").stringValue();
   9.209 -
   9.210 -                    for (String spanPart : spanSpec.split(";")) {
   9.211 -                        Span span = Span.of(e.getValue().getFileObject(relPath), spanPart);
   9.212 -
   9.213 -                        if (span != null) {
   9.214 -                            foundDuplicates.add(span);
   9.215 -                        }
   9.216 -                    }
   9.217 -                }
   9.218 -            }
   9.219 -
   9.220 -            if (foundDuplicates.size() >= minDuplicates) {
   9.221 -                DuplicateDescription current = DuplicateDescription.of(foundDuplicates, getValue(longest), longest);
   9.222 -                boolean add = true;
   9.223 -
   9.224 -                for (Iterator<DuplicateDescription> it = result.iterator(); it.hasNext();) {
   9.225 -                    DuplicateDescription existing = it.next();
   9.226 -
   9.227 -                    if (subsumes(existing, current)) {
   9.228 -                        add = false;
   9.229 -                        break;
   9.230 -                    }
   9.231 -
   9.232 -                    if (subsumes(current, existing)) {
   9.233 -                        //can happen? (note that the duplicates are sorted by value)
   9.234 -                        it.remove();
   9.235 -                    }
   9.236 -                }
   9.237 -
   9.238 -                if (add) {
   9.239 -                    result.add(current);
   9.240 -                    return current;
   9.241 -                }
   9.242 -            }
   9.243 -
   9.244 -        }
   9.245 -        return null;
   9.246 -        }
   9.247 -
   9.248 -        private DuplicateDescription next;
   9.249 -
   9.250 -        public boolean hasNext() {
   9.251 -            if (next == null) {
   9.252 -                try {
   9.253 -                    next = nextDescription();
   9.254 -                } catch (IOException ex) {
   9.255 -                    Exceptions.printStackTrace(ex);
   9.256 -                }
   9.257 -            }
   9.258 -
   9.259 -            return next != null;
   9.260 -        }
   9.261 -
   9.262 -        public DuplicateDescription next() {
   9.263 -            if (!hasNext()) {
   9.264 -                throw new NoSuchElementException();
   9.265 -            }
   9.266 -
   9.267 -            DuplicateDescription r = next;
   9.268 -
   9.269 -            next = null;
   9.270 -            return r;
   9.271 -        }
   9.272 -
   9.273 -        public void remove() {
   9.274 -            throw new UnsupportedOperationException("Not supported.");
   9.275 -        }
   9.276 -
   9.277 -    }
   9.278 -
   9.279 -    private static List<String> getDuplicatedValues(IndexReader ir, String field, AtomicBoolean cancel) throws IOException {
   9.280 -        List<String> values = new ArrayList<String>();
   9.281 -        TermEnum terms = ir.terms( new Term(field));
   9.282 -        //while (terms.next()) {
   9.283 -        do {
   9.284 -            if (cancel.get()) return Collections.emptyList();
   9.285 -
   9.286 -            final Term term =  terms.term();
   9.287 -
   9.288 -            if ( !field.equals( term.field() ) ) {
   9.289 -                break;
   9.290 -            }
   9.291 -
   9.292 -            if (terms.docFreq() < 2) continue;
   9.293 -
   9.294 -            values.add(term.text());
   9.295 -        }
   9.296 -        while (terms.next());
   9.297 -        return values;
   9.298 -    }
   9.299 -
   9.300 -    private static long getValue(String encoded) {
   9.301 -        return Long.parseLong(encoded.substring(encoded.lastIndexOf(":") + 1));
   9.302 -    }
   9.303 -
   9.304 -    private static void sortHashes(List<String> hashes) {
   9.305 -        Collections.sort(hashes, new Comparator<String>() {
   9.306 -            public int compare(String arg0, String arg1) {
   9.307 -                return (int) Math.signum(getValue(arg1) - getValue(arg0));
   9.308 -            }
   9.309 -        });
   9.310 -    }
   9.311 -    
   9.312 -    private static boolean subsumes(DuplicateDescription bigger, DuplicateDescription smaller) {
   9.313 -        Set<FileObject> bFiles = new HashSet<FileObject>();
   9.314 -
   9.315 -        for (Span s : bigger.dupes) {
   9.316 -            bFiles.add(s.file);
   9.317 -        }
   9.318 -
   9.319 -        Set<FileObject> sFiles = new HashSet<FileObject>();
   9.320 -
   9.321 -        for (Span s : smaller.dupes) {
   9.322 -            sFiles.add(s.file);
   9.323 -        }
   9.324 -
   9.325 -        if (!bFiles.equals(sFiles)) return false;
   9.326 -
   9.327 -        Span testAgainst = bigger.dupes.get(0);
   9.328 -
   9.329 -        for (Span s : smaller.dupes) {
   9.330 -            if (s.file == testAgainst.file) {
   9.331 -                if (   (testAgainst.startOff <= s.startOff && testAgainst.endOff > s.endOff)
   9.332 -                    || (testAgainst.startOff < s.startOff && testAgainst.endOff >= s.endOff)) {
   9.333 -                    return true;
   9.334 -                }
   9.335 -            }
   9.336 -        }
   9.337 -
   9.338 -        return false;
   9.339 -    }
   9.340 -
   9.341 -    public static Map<String, long[]> encodeGeneralized(CompilationInfo info) {
   9.342 -        return encodeGeneralized(JavaSourceAccessor.getINSTANCE().getJavacTask(info), info.getCompilationUnit());
   9.343 -    }
   9.344 -
   9.345 -    public static Map<String, long[]> encodeGeneralized(final CompilationTask task, final CompilationUnitTree cut) {
   9.346 -        final SourcePositions sp = Trees.instance(task).getSourcePositions();
   9.347 -        final Map<String, Collection<Long>> positions = new HashMap<String, Collection<Long>>();
   9.348 -
   9.349 -        new TreePathScanner<Void, Void>() {
   9.350 -            @Override
   9.351 -            public Void scan(Tree tree, Void p) {
   9.352 -                if (tree == null) return null;
   9.353 -                if (getCurrentPath() != null) {
   9.354 -                    Tree generalizedPattern = Utilities.generalizePattern(task, new TreePath(getCurrentPath(), tree));
   9.355 -                    long value = Utilities.patternValue(generalizedPattern);
   9.356 -                    if (value >= MINIMAL_VALUE) {
   9.357 -                        {
   9.358 -                            DigestOutputStream baos = null;
   9.359 -                            try {
   9.360 -                                baos = new DigestOutputStream(new ByteArrayOutputStream(), MessageDigest.getInstance("MD5"));
   9.361 -                                final EncodingContext ec = new BulkSearch.EncodingContext(baos, true);
   9.362 -                                BulkSearch.getDefault().encode( generalizedPattern, ec);
   9.363 -                                StringBuilder text = new StringBuilder();
   9.364 -                                byte[] bytes = baos.getMessageDigest().digest();
   9.365 -                                for (int cntr = 0; cntr < 4; cntr++) {
   9.366 -                                    text.append(String.format("%02X", bytes[cntr]));
   9.367 -                                }
   9.368 -                                text.append(':').append(value);
   9.369 -                                String enc = text.toString();
   9.370 -                                Collection<Long> spanSpecs = positions.get(enc);
   9.371 -                                if (spanSpecs == null) {
   9.372 -                                    positions.put(enc, spanSpecs = new LinkedList<Long>());
   9.373 -//                                } else {
   9.374 -//                                    spanSpecs.append(";");
   9.375 -                                }
   9.376 -                                long start = sp.getStartPosition(cut, tree);
   9.377 -//                                spanSpecs.append(start).append(":").append(sp.getEndPosition(cut, tree) - start);
   9.378 -                                spanSpecs.add(start);
   9.379 -                                spanSpecs.add(sp.getEndPosition(cut, tree));
   9.380 -                            } catch (NoSuchAlgorithmException ex) {
   9.381 -                                Exceptions.printStackTrace(ex);
   9.382 -                           } finally {
   9.383 -                                try {
   9.384 -                                    baos.close();
   9.385 -                                } catch (IOException ex) {
   9.386 -                                    Exceptions.printStackTrace(ex);
   9.387 -                                }
   9.388 -                            }
   9.389 -                        }
   9.390 -                    }
   9.391 -                }
   9.392 -                return super.scan(tree, p);
   9.393 -            }
   9.394 -        }.scan(cut, null);
   9.395 -
   9.396 -        Map<String, long[]> result = new TreeMap<String, long[]>();
   9.397 -
   9.398 -        for (Entry<String, Collection<Long>> e : positions.entrySet()) {
   9.399 -            long[] spans = new long[e.getValue().size()];
   9.400 -            int idx = 0;
   9.401 -
   9.402 -            for (Long l : e.getValue()) {
   9.403 -                spans[idx++] = l;
   9.404 -            }
   9.405 -
   9.406 -            result.put(e.getKey(), spans);
   9.407 -        }
   9.408 -
   9.409 -        return result;
   9.410 -    }
   9.411 -
   9.412 -    private static final int MINIMAL_VALUE = 10;
   9.413 -
   9.414 -    public static final class DuplicateDescription {
   9.415 -
   9.416 -        public final List<Span> dupes;
   9.417 -        public final long value;
   9.418 -        public final String hash;
   9.419 -
   9.420 -        private DuplicateDescription(List<Span> dupes, long value, String hash) {
   9.421 -            this.dupes = dupes;
   9.422 -            this.value = value;
   9.423 -            this.hash = hash;
   9.424 -        }
   9.425 -
   9.426 -        public static DuplicateDescription of(List<Span> dupes, long value, String hash) {
   9.427 -            return new DuplicateDescription(dupes, value, hash);
   9.428 -        }
   9.429 -    }
   9.430 -
   9.431 -    public static final class Span {
   9.432 -        public final FileObject file;
   9.433 -        public final int startOff;
   9.434 -        public final int endOff;
   9.435 -
   9.436 -        public Span(FileObject file, int startOff, int endOff) {
   9.437 -            this.file = file;
   9.438 -            this.startOff = startOff;
   9.439 -            this.endOff = endOff;
   9.440 -        }
   9.441 -
   9.442 -        public static @CheckForNull Span of(FileObject file, String spanSpec) {
   9.443 -            String[] split = spanSpec.split(":");
   9.444 -            int start = Integer.valueOf(split[0]);
   9.445 -            int end = start + Integer.valueOf(split[1]);
   9.446 -            if (start < 0 || end < 0) return null; //XXX
   9.447 -
   9.448 -            return new Span(file, start, end);
   9.449 -        }
   9.450 -
   9.451 -    }
   9.452 -}
    10.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.form	Fri Jan 27 13:35:56 2012 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,189 +0,0 @@
    10.4 -<?xml version="1.1" encoding="UTF-8" ?>
    10.5 -
    10.6 -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    10.7 -  <AuxValues>
    10.8 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
    10.9 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   10.10 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   10.11 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
   10.12 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   10.13 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   10.14 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   10.15 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   10.16 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   10.17 -  </AuxValues>
   10.18 -
   10.19 -  <Layout>
   10.20 -    <DimensionLayout dim="0">
   10.21 -      <Group type="103" groupAlignment="0" attributes="0">
   10.22 -          <Group type="102" alignment="1" attributes="0">
   10.23 -              <EmptySpace max="-2" attributes="0"/>
   10.24 -              <Group type="103" groupAlignment="1" attributes="0">
   10.25 -                  <Component id="mainSplit2" alignment="0" pref="906" max="32767" attributes="0"/>
   10.26 -                  <Component id="jScrollPane1" alignment="0" pref="906" max="32767" attributes="0"/>
   10.27 -                  <Component id="jPanel1" alignment="1" min="-2" max="-2" attributes="0"/>
   10.28 -              </Group>
   10.29 -              <EmptySpace max="-2" attributes="0"/>
   10.30 -          </Group>
   10.31 -      </Group>
   10.32 -    </DimensionLayout>
   10.33 -    <DimensionLayout dim="1">
   10.34 -      <Group type="103" groupAlignment="0" attributes="0">
   10.35 -          <Group type="102" attributes="0">
   10.36 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   10.37 -              <Component id="jScrollPane1" min="-2" pref="67" max="-2" attributes="0"/>
   10.38 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   10.39 -              <Component id="mainSplit2" pref="467" max="32767" attributes="0"/>
   10.40 -              <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
   10.41 -              <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
   10.42 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   10.43 -          </Group>
   10.44 -      </Group>
   10.45 -    </DimensionLayout>
   10.46 -  </Layout>
   10.47 -  <SubComponents>
   10.48 -    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
   10.49 -
   10.50 -      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   10.51 -      <SubComponents>
   10.52 -        <Component class="javax.swing.JList" name="duplicatesList">
   10.53 -          <Properties>
   10.54 -            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
   10.55 -              <StringArray count="0"/>
   10.56 -            </Property>
   10.57 -            <Property name="prototypeCellValue" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   10.58 -              <Connection code="&quot;9999999999999999999999999999999999999999999999999999999999999999999999&quot;" type="code"/>
   10.59 -            </Property>
   10.60 -            <Property name="visibleRowCount" type="int" value="4"/>
   10.61 -          </Properties>
   10.62 -        </Component>
   10.63 -      </SubComponents>
   10.64 -    </Container>
   10.65 -    <Container class="javax.swing.JSplitPane" name="mainSplit2">
   10.66 -      <Properties>
   10.67 -        <Property name="dividerLocation" type="int" value="400"/>
   10.68 -      </Properties>
   10.69 -      <AuxValues>
   10.70 -        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new BalancedSplitPane()"/>
   10.71 -      </AuxValues>
   10.72 -
   10.73 -      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
   10.74 -      <SubComponents>
   10.75 -        <Container class="javax.swing.JPanel" name="rightPanel">
   10.76 -          <Constraints>
   10.77 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
   10.78 -              <JSplitPaneConstraints position="right"/>
   10.79 -            </Constraint>
   10.80 -          </Constraints>
   10.81 -
   10.82 -          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   10.83 -          <SubComponents>
   10.84 -            <Component class="javax.swing.JComboBox" name="rightFileList">
   10.85 -              <Properties>
   10.86 -                <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
   10.87 -                  <StringArray count="0"/>
   10.88 -                </Property>
   10.89 -              </Properties>
   10.90 -              <Constraints>
   10.91 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   10.92 -                  <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="324" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
   10.93 -                </Constraint>
   10.94 -              </Constraints>
   10.95 -            </Component>
   10.96 -            <Container class="javax.swing.JScrollPane" name="jScrollPane3">
   10.97 -              <AuxValues>
   10.98 -                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   10.99 -              </AuxValues>
  10.100 -              <Constraints>
  10.101 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  10.102 -                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  10.103 -                </Constraint>
  10.104 -              </Constraints>
  10.105 -
  10.106 -              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  10.107 -              <SubComponents>
  10.108 -                <Component class="javax.swing.JEditorPane" name="right">
  10.109 -                </Component>
  10.110 -              </SubComponents>
  10.111 -            </Container>
  10.112 -          </SubComponents>
  10.113 -        </Container>
  10.114 -        <Container class="javax.swing.JPanel" name="leftPanel">
  10.115 -          <Constraints>
  10.116 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
  10.117 -              <JSplitPaneConstraints position="left"/>
  10.118 -            </Constraint>
  10.119 -          </Constraints>
  10.120 -
  10.121 -          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  10.122 -          <SubComponents>
  10.123 -            <Container class="javax.swing.JScrollPane" name="jScrollPane2">
  10.124 -              <AuxValues>
  10.125 -                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
  10.126 -              </AuxValues>
  10.127 -              <Constraints>
  10.128 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  10.129 -                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  10.130 -                </Constraint>
  10.131 -              </Constraints>
  10.132 -
  10.133 -              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  10.134 -              <SubComponents>
  10.135 -                <Component class="javax.swing.JEditorPane" name="left">
  10.136 -                </Component>
  10.137 -              </SubComponents>
  10.138 -            </Container>
  10.139 -            <Component class="javax.swing.JComboBox" name="leftFileList">
  10.140 -              <Properties>
  10.141 -                <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
  10.142 -                  <StringArray count="0"/>
  10.143 -                </Property>
  10.144 -              </Properties>
  10.145 -              <Constraints>
  10.146 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  10.147 -                  <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  10.148 -                </Constraint>
  10.149 -              </Constraints>
  10.150 -            </Component>
  10.151 -          </SubComponents>
  10.152 -        </Container>
  10.153 -      </SubComponents>
  10.154 -    </Container>
  10.155 -    <Container class="javax.swing.JPanel" name="jPanel1">
  10.156 -
  10.157 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  10.158 -      <SubComponents>
  10.159 -        <Component class="javax.swing.JLabel" name="progressLabel">
  10.160 -          <Properties>
  10.161 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  10.162 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties" key="DuplicatesListPanel.progressLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  10.163 -            </Property>
  10.164 -          </Properties>
  10.165 -          <Constraints>
  10.166 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  10.167 -              <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  10.168 -            </Constraint>
  10.169 -          </Constraints>
  10.170 -        </Component>
  10.171 -        <Component class="javax.swing.JLabel" name="findMore">
  10.172 -          <Properties>
  10.173 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  10.174 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties" key="DuplicatesListPanel.findMore.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  10.175 -            </Property>
  10.176 -            <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
  10.177 -              <Color id="Hand Cursor"/>
  10.178 -            </Property>
  10.179 -          </Properties>
  10.180 -          <Events>
  10.181 -            <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="findMoreMouseClicked"/>
  10.182 -          </Events>
  10.183 -          <Constraints>
  10.184 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  10.185 -              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
  10.186 -            </Constraint>
  10.187 -          </Constraints>
  10.188 -        </Component>
  10.189 -      </SubComponents>
  10.190 -    </Container>
  10.191 -  </SubComponents>
  10.192 -</Form>
    11.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.java	Fri Jan 27 13:35:56 2012 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,464 +0,0 @@
    11.4 -/*
    11.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    11.6 - *
    11.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    11.8 - *
    11.9 - * The contents of this file are subject to the terms of either the GNU
   11.10 - * General Public License Version 2 only ("GPL") or the Common
   11.11 - * Development and Distribution License("CDDL") (collectively, the
   11.12 - * "License"). You may not use this file except in compliance with the
   11.13 - * License. You can obtain a copy of the License at
   11.14 - * http://www.netbeans.org/cddl-gplv2.html
   11.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   11.16 - * specific language governing permissions and limitations under the
   11.17 - * License.  When distributing the software, include this License Header
   11.18 - * Notice in each file and include the License file at
   11.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   11.20 - * particular file as subject to the "Classpath" exception as provided
   11.21 - * by Sun in the GPL Version 2 section of the License file that
   11.22 - * accompanied this code. If applicable, add the following below the
   11.23 - * License Header, with the fields enclosed by brackets [] replaced by
   11.24 - * your own identifying information:
   11.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   11.26 - *
   11.27 - * If you wish your version of this file to be governed by only the CDDL
   11.28 - * or only the GPL Version 2, indicate your decision by adding
   11.29 - * "[Contributor] elects to include this software in this distribution
   11.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   11.31 - * single choice of license, a recipient has the option to distribute
   11.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   11.33 - * to extend the choice of license to its licensees as provided above.
   11.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   11.35 - * Version 2 license, then the option applies only if the new code is
   11.36 - * made subject to such option by the copyright holder.
   11.37 - *
   11.38 - * Contributor(s):
   11.39 - *
   11.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   11.41 - */
   11.42 -package org.netbeans.modules.jackpot30.impl.duplicates;
   11.43 -
   11.44 -import java.awt.Color;
   11.45 -import java.awt.Component;
   11.46 -import java.awt.Rectangle;
   11.47 -import java.awt.event.ActionEvent;
   11.48 -import java.awt.event.ActionListener;
   11.49 -import java.io.IOException;
   11.50 -import java.util.Collection;
   11.51 -import java.util.Iterator;
   11.52 -import java.util.LinkedHashSet;
   11.53 -import java.util.Set;
   11.54 -import javax.swing.DefaultComboBoxModel;
   11.55 -import javax.swing.DefaultListCellRenderer;
   11.56 -import javax.swing.DefaultListModel;
   11.57 -import javax.swing.JEditorPane;
   11.58 -import javax.swing.JList;
   11.59 -import javax.swing.JSplitPane;
   11.60 -import javax.swing.SwingUtilities;
   11.61 -import javax.swing.event.ListSelectionEvent;
   11.62 -import javax.swing.event.ListSelectionListener;
   11.63 -import javax.swing.text.AttributeSet;
   11.64 -import javax.swing.text.BadLocationException;
   11.65 -import javax.swing.text.StyleConstants;
   11.66 -import org.netbeans.api.editor.mimelookup.MimePath;
   11.67 -import org.netbeans.api.editor.settings.AttributesUtilities;
   11.68 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   11.69 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   11.70 -import org.netbeans.spi.editor.highlighting.HighlightsLayer;
   11.71 -import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
   11.72 -import org.netbeans.spi.editor.highlighting.ZOrder;
   11.73 -import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
   11.74 -import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
   11.75 -import org.openide.filesystems.FileObject;
   11.76 -import org.openide.filesystems.FileUtil;
   11.77 -import org.openide.util.Exceptions;
   11.78 -import org.openide.util.Lookup;
   11.79 -import org.openide.util.RequestProcessor;
   11.80 -import org.openide.util.RequestProcessor.Task;
   11.81 -import org.openide.util.lookup.Lookups;
   11.82 -import org.openide.util.lookup.ServiceProvider;
   11.83 -
   11.84 -/**
   11.85 - *
   11.86 - * @author lahvac
   11.87 - */
   11.88 -public class DuplicatesListPanel extends javax.swing.JPanel {
   11.89 -    private final Collection<String> sourceRoots;
   11.90 -    private final Iterator<? extends DuplicateDescription> dupes;
   11.91 -
   11.92 -    private int targetCount;
   11.93 -
   11.94 -    public DuplicatesListPanel(Collection<String> sourceRoots, final Iterator<? extends DuplicateDescription> dupes) {
   11.95 -        this.sourceRoots = sourceRoots;
   11.96 -        this.dupes = dupes;
   11.97 -        
   11.98 -        initComponents();
   11.99 -
  11.100 -        left.setContentType("text/x-java");
  11.101 -        left.putClientProperty(DuplicatesListPanel.class, new OffsetsBag(left.getDocument()));
  11.102 -        
  11.103 -        right.setContentType("text/x-java");
  11.104 -        right.putClientProperty(DuplicatesListPanel.class, new OffsetsBag(right.getDocument()));
  11.105 -
  11.106 -        duplicatesList.setModel(new DefaultListModel());
  11.107 -        duplicatesList.setCellRenderer(new DuplicatesRendererImpl());
  11.108 -        duplicatesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
  11.109 -            public void valueChanged(ListSelectionEvent arg0) {
  11.110 -                DuplicateDescription dd = (DuplicateDescription) duplicatesList.getSelectedValue();
  11.111 -                DefaultComboBoxModel l = new DefaultComboBoxModel();
  11.112 -                DefaultComboBoxModel r = new DefaultComboBoxModel();
  11.113 -
  11.114 -                for (Span s : dd.dupes) {
  11.115 -                    l.addElement(s);
  11.116 -                    r.addElement(s);
  11.117 -                }
  11.118 -
  11.119 -                leftFileList.setModel(l);
  11.120 -                rightFileList.setModel(r);
  11.121 -
  11.122 -                leftFileList.setSelectedIndex(0);
  11.123 -                rightFileList.setSelectedIndex(1);
  11.124 -            }
  11.125 -        });
  11.126 -
  11.127 -        leftFileList.setRenderer(new SpanRendererImpl());
  11.128 -        leftFileList.addActionListener(new ActionListener() {
  11.129 -
  11.130 -            public void actionPerformed(ActionEvent e) {
  11.131 -                setSpan(left, (Span) leftFileList.getSelectedItem());
  11.132 -            }
  11.133 -        });
  11.134 -        rightFileList.setRenderer(new SpanRendererImpl());
  11.135 -        rightFileList.addActionListener(new ActionListener() {
  11.136 -            public void actionPerformed(ActionEvent e) {
  11.137 -                setSpan(right, (Span) rightFileList.getSelectedItem());
  11.138 -            }
  11.139 -        });
  11.140 -
  11.141 -        progressLabel.setText("Looking for duplicates...");
  11.142 -
  11.143 -        findMore();
  11.144 -    }
  11.145 -
  11.146 -    /** This method is called from within the constructor to
  11.147 -     * initialize the form.
  11.148 -     * WARNING: Do NOT modify this code. The content of this method is
  11.149 -     * always regenerated by the Form Editor.
  11.150 -     */
  11.151 -    @SuppressWarnings("unchecked")
  11.152 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  11.153 -    private void initComponents() {
  11.154 -        java.awt.GridBagConstraints gridBagConstraints;
  11.155 -
  11.156 -        jScrollPane1 = new javax.swing.JScrollPane();
  11.157 -        duplicatesList = new javax.swing.JList();
  11.158 -        mainSplit2 = new BalancedSplitPane();
  11.159 -        rightPanel = new javax.swing.JPanel();
  11.160 -        rightFileList = new javax.swing.JComboBox();
  11.161 -        jScrollPane3 = new javax.swing.JScrollPane();
  11.162 -        right = new javax.swing.JEditorPane();
  11.163 -        leftPanel = new javax.swing.JPanel();
  11.164 -        jScrollPane2 = new javax.swing.JScrollPane();
  11.165 -        left = new javax.swing.JEditorPane();
  11.166 -        leftFileList = new javax.swing.JComboBox();
  11.167 -        jPanel1 = new javax.swing.JPanel();
  11.168 -        progressLabel = new javax.swing.JLabel();
  11.169 -        findMore = new javax.swing.JLabel();
  11.170 -
  11.171 -        duplicatesList.setPrototypeCellValue("9999999999999999999999999999999999999999999999999999999999999999999999");
  11.172 -        duplicatesList.setVisibleRowCount(4);
  11.173 -        jScrollPane1.setViewportView(duplicatesList);
  11.174 -
  11.175 -        mainSplit2.setDividerLocation(400);
  11.176 -
  11.177 -        rightPanel.setLayout(new java.awt.GridBagLayout());
  11.178 -
  11.179 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.180 -        gridBagConstraints.gridx = 0;
  11.181 -        gridBagConstraints.gridy = 0;
  11.182 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  11.183 -        gridBagConstraints.ipadx = 324;
  11.184 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.185 -        gridBagConstraints.weightx = 1.0;
  11.186 -        rightPanel.add(rightFileList, gridBagConstraints);
  11.187 -
  11.188 -        jScrollPane3.setViewportView(right);
  11.189 -
  11.190 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.191 -        gridBagConstraints.gridx = 0;
  11.192 -        gridBagConstraints.gridy = 1;
  11.193 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  11.194 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.195 -        gridBagConstraints.weightx = 1.0;
  11.196 -        gridBagConstraints.weighty = 1.0;
  11.197 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  11.198 -        rightPanel.add(jScrollPane3, gridBagConstraints);
  11.199 -
  11.200 -        mainSplit2.setRightComponent(rightPanel);
  11.201 -
  11.202 -        leftPanel.setLayout(new java.awt.GridBagLayout());
  11.203 -
  11.204 -        jScrollPane2.setViewportView(left);
  11.205 -
  11.206 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.207 -        gridBagConstraints.gridx = 0;
  11.208 -        gridBagConstraints.gridy = 1;
  11.209 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  11.210 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.211 -        gridBagConstraints.weightx = 1.0;
  11.212 -        gridBagConstraints.weighty = 1.0;
  11.213 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  11.214 -        leftPanel.add(jScrollPane2, gridBagConstraints);
  11.215 -
  11.216 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.217 -        gridBagConstraints.gridx = 0;
  11.218 -        gridBagConstraints.gridy = 0;
  11.219 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  11.220 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.221 -        gridBagConstraints.weightx = 1.0;
  11.222 -        leftPanel.add(leftFileList, gridBagConstraints);
  11.223 -
  11.224 -        mainSplit2.setLeftComponent(leftPanel);
  11.225 -
  11.226 -        jPanel1.setLayout(new java.awt.GridBagLayout());
  11.227 -
  11.228 -        progressLabel.setText(org.openide.util.NbBundle.getMessage(DuplicatesListPanel.class, "DuplicatesListPanel.progressLabel.text")); // NOI18N
  11.229 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.230 -        gridBagConstraints.gridx = 0;
  11.231 -        gridBagConstraints.gridy = 0;
  11.232 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  11.233 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.234 -        gridBagConstraints.weightx = 1.0;
  11.235 -        jPanel1.add(progressLabel, gridBagConstraints);
  11.236 -
  11.237 -        findMore.setText(org.openide.util.NbBundle.getMessage(DuplicatesListPanel.class, "DuplicatesListPanel.findMore.text")); // NOI18N
  11.238 -        findMore.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  11.239 -        findMore.addMouseListener(new java.awt.event.MouseAdapter() {
  11.240 -            public void mouseClicked(java.awt.event.MouseEvent evt) {
  11.241 -                findMoreMouseClicked(evt);
  11.242 -            }
  11.243 -        });
  11.244 -        gridBagConstraints = new java.awt.GridBagConstraints();
  11.245 -        gridBagConstraints.gridx = 1;
  11.246 -        gridBagConstraints.gridy = 0;
  11.247 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  11.248 -        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
  11.249 -        jPanel1.add(findMore, gridBagConstraints);
  11.250 -
  11.251 -        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  11.252 -        this.setLayout(layout);
  11.253 -        layout.setHorizontalGroup(
  11.254 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  11.255 -            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  11.256 -                .addContainerGap()
  11.257 -                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  11.258 -                    .addComponent(mainSplit2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 906, Short.MAX_VALUE)
  11.259 -                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 906, Short.MAX_VALUE)
  11.260 -                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  11.261 -                .addContainerGap())
  11.262 -        );
  11.263 -        layout.setVerticalGroup(
  11.264 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  11.265 -            .addGroup(layout.createSequentialGroup()
  11.266 -                .addContainerGap()
  11.267 -                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
  11.268 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  11.269 -                .addComponent(mainSplit2, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
  11.270 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  11.271 -                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  11.272 -                .addContainerGap())
  11.273 -        );
  11.274 -    }// </editor-fold>//GEN-END:initComponents
  11.275 -
  11.276 -    private void findMoreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findMoreMouseClicked
  11.277 -        findMore();
  11.278 -    }//GEN-LAST:event_findMoreMouseClicked
  11.279 -
  11.280 -    private void findMore() {
  11.281 -        targetCount = duplicatesList.getModel().getSize() + 100;
  11.282 -        findMore.setVisible(false);
  11.283 -        WORKER.schedule(0);
  11.284 -    }
  11.285 -
  11.286 -    private static String computeCommonPrefix(String origCommonPrefix, FileObject file) {
  11.287 -        String name = FileUtil.getFileDisplayName(file);
  11.288 -
  11.289 -        if (origCommonPrefix == null) return name;
  11.290 -
  11.291 -        int len = Math.min(origCommonPrefix.length(), name.length());
  11.292 -
  11.293 -        for (int cntr = 0; cntr < len; cntr++) {
  11.294 -            if (origCommonPrefix.charAt(cntr) != name.charAt(cntr)) {
  11.295 -                return origCommonPrefix.substring(0, cntr);
  11.296 -            }
  11.297 -        }
  11.298 -
  11.299 -        return origCommonPrefix;
  11.300 -    }
  11.301 -    
  11.302 -    private static void setSpan(JEditorPane pane, Span s) {
  11.303 -        try {
  11.304 -            pane.setText(s.file.asText());
  11.305 -
  11.306 -            Rectangle top = pane.modelToView(0);
  11.307 -            Rectangle start = pane.modelToView(s.startOff);
  11.308 -            Rectangle end = pane.modelToView(s.endOff);
  11.309 -
  11.310 -            if (top != null && start != null && end != null) {
  11.311 -                Rectangle toScroll = start.union(end);
  11.312 -
  11.313 -                pane.scrollRectToVisible(top);
  11.314 -                pane.scrollRectToVisible(toScroll);
  11.315 -            }
  11.316 -
  11.317 -            OffsetsBag bag = (OffsetsBag) pane.getClientProperty(DuplicatesListPanel.class);
  11.318 -
  11.319 -            bag.clear();
  11.320 -            bag.addHighlight(s.startOff, s.endOff, HIGHLIGHT);
  11.321 -        } catch (IOException ex) {
  11.322 -            Exceptions.printStackTrace(ex);
  11.323 -        } catch (BadLocationException ex) {
  11.324 -            Exceptions.printStackTrace(ex);
  11.325 -        }
  11.326 -    }
  11.327 -
  11.328 -    private static final AttributeSet HIGHLIGHT = AttributesUtilities.createImmutable(StyleConstants.Background, new Color(0xDF, 0xDF, 0xDF, 0xff));
  11.329 -
  11.330 -    private final class DuplicatesRendererImpl extends DefaultListCellRenderer {
  11.331 -        @Override
  11.332 -        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  11.333 -            if (!(value instanceof DuplicateDescription)) return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  11.334 -            DuplicateDescription dd = (DuplicateDescription) value;
  11.335 -            Set<FileObject> files = new LinkedHashSet<FileObject>();
  11.336 -            String commonPrefix = null;
  11.337 -
  11.338 -            for (Span s : dd.dupes) {
  11.339 -                commonPrefix = computeCommonPrefix(commonPrefix, s.file);
  11.340 -                files.add(s.file);
  11.341 -            }
  11.342 -
  11.343 -            StringBuilder cap = new StringBuilder();
  11.344 -
  11.345 -            OUTER: for (FileObject file : files) {
  11.346 -                String name = FileUtil.getFileDisplayName(file);
  11.347 -
  11.348 -                if (cap.length() > 0) {
  11.349 -                    cap.append("    ");
  11.350 -                }
  11.351 -                
  11.352 -                for (String sr : sourceRoots) {
  11.353 -                    if (name.startsWith(sr)) {
  11.354 -                        cap.append(name.substring(Math.max(0, sr.lastIndexOf('/') + 1)));
  11.355 -                        continue OUTER;
  11.356 -                    }
  11.357 -                }
  11.358 -            }
  11.359 -
  11.360 -            return super.getListCellRendererComponent(list, cap.toString(), index, isSelected, cellHasFocus);
  11.361 -        }
  11.362 -    }
  11.363 -
  11.364 -    private final class SpanRendererImpl extends DefaultListCellRenderer {
  11.365 -        @Override
  11.366 -        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  11.367 -            if (!(value instanceof Span)) {
  11.368 -                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  11.369 -            }
  11.370 -            Span span = (Span) value;
  11.371 -
  11.372 -            return super.getListCellRendererComponent(list, FileUtil.getFileDisplayName(span.file), index, isSelected, cellHasFocus);
  11.373 -        }
  11.374 -    }
  11.375 -
  11.376 -    public static final class HighlightLayerFactoryImpl implements HighlightsLayerFactory {
  11.377 -        public HighlightsLayer[] createLayers(Context cntxt) {
  11.378 -            OffsetsBag bag = (OffsetsBag) cntxt.getComponent().getClientProperty(DuplicatesListPanel.class);
  11.379 -
  11.380 -            if (bag != null) {
  11.381 -                return new HighlightsLayer[] {
  11.382 -                    HighlightsLayer.create(DuplicatesListPanel.class.getName(), ZOrder.CARET_RACK, true, bag)
  11.383 -                };
  11.384 -            }
  11.385 -
  11.386 -            return new HighlightsLayer[0];
  11.387 -        }
  11.388 -    }
  11.389 -
  11.390 -    @ServiceProvider(service=MimeDataProvider.class)
  11.391 -    public static final class MDPI implements MimeDataProvider {
  11.392 -
  11.393 -        private static final Lookup L = Lookups.singleton(new HighlightLayerFactoryImpl());
  11.394 -
  11.395 -        public Lookup getLookup(MimePath mp) {
  11.396 -            if (mp.getPath().startsWith("text/x-java")) {
  11.397 -                return L;
  11.398 -            }
  11.399 -
  11.400 -            return null;
  11.401 -        }
  11.402 -        
  11.403 -    }
  11.404 -
  11.405 -    private static final class BalancedSplitPane extends JSplitPane {
  11.406 -
  11.407 -        @Override
  11.408 -        @SuppressWarnings("deprecation")
  11.409 -        public void reshape(int x, int y, int w, int h) {
  11.410 -            super.reshape(x, y, w, h);
  11.411 -            SwingUtilities.invokeLater(new Runnable() {
  11.412 -                public void run() {
  11.413 -                    setDividerLocation(0.5);
  11.414 -                }
  11.415 -            });
  11.416 -        }
  11.417 -
  11.418 -    }
  11.419 -
  11.420 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  11.421 -    private javax.swing.JList duplicatesList;
  11.422 -    private javax.swing.JLabel findMore;
  11.423 -    private javax.swing.JPanel jPanel1;
  11.424 -    private javax.swing.JScrollPane jScrollPane1;
  11.425 -    private javax.swing.JScrollPane jScrollPane2;
  11.426 -    private javax.swing.JScrollPane jScrollPane3;
  11.427 -    private javax.swing.JEditorPane left;
  11.428 -    private javax.swing.JComboBox leftFileList;
  11.429 -    private javax.swing.JPanel leftPanel;
  11.430 -    private javax.swing.JSplitPane mainSplit2;
  11.431 -    private javax.swing.JLabel progressLabel;
  11.432 -    private javax.swing.JEditorPane right;
  11.433 -    private javax.swing.JComboBox rightFileList;
  11.434 -    private javax.swing.JPanel rightPanel;
  11.435 -    // End of variables declaration//GEN-END:variables
  11.436 -
  11.437 -    private static final RequestProcessor DEFAULT_WORKER = new RequestProcessor(DuplicatesListPanel.class.getName(), 1, false, false);
  11.438 -    private final Task WORKER = DEFAULT_WORKER.create(new Runnable() {
  11.439 -        public void run() {
  11.440 -            if (dupes.hasNext()) {
  11.441 -                final DuplicateDescription dd = dupes.next();
  11.442 -
  11.443 -                SwingUtilities.invokeLater(new Runnable() {
  11.444 -
  11.445 -                    public void run() {
  11.446 -                        ((DefaultListModel)duplicatesList.getModel()).addElement(dd);
  11.447 -
  11.448 -                        int size = duplicatesList.getModel().getSize();
  11.449 -
  11.450 -                        if (size == 1) {
  11.451 -                            duplicatesList.setSelectedIndex(0);
  11.452 -                        }
  11.453 -                        
  11.454 -                        if (size >= targetCount) {
  11.455 -                            findMore.setVisible(true);
  11.456 -                            progressLabel.setText("Found " + size + " duplicated snippets.");
  11.457 -                        } else {
  11.458 -                            progressLabel.setText("Found " + size + " duplicated snippets and searching...");
  11.459 -                            WORKER.schedule(0);
  11.460 -                        }
  11.461 -                    }
  11.462 -                });
  11.463 -            }
  11.464 -        }
  11.465 -    });
  11.466 -
  11.467 -}
    12.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/GlobalFindDuplicates.java	Fri Jan 27 13:35:56 2012 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,179 +0,0 @@
    12.4 -/*
    12.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    12.6 - *
    12.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    12.8 - *
    12.9 - * The contents of this file are subject to the terms of either the GNU
   12.10 - * General Public License Version 2 only ("GPL") or the Common
   12.11 - * Development and Distribution License("CDDL") (collectively, the
   12.12 - * "License"). You may not use this file except in compliance with the
   12.13 - * License. You can obtain a copy of the License at
   12.14 - * http://www.netbeans.org/cddl-gplv2.html
   12.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   12.16 - * specific language governing permissions and limitations under the
   12.17 - * License.  When distributing the software, include this License Header
   12.18 - * Notice in each file and include the License file at
   12.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   12.20 - * particular file as subject to the "Classpath" exception as provided
   12.21 - * by Sun in the GPL Version 2 section of the License file that
   12.22 - * accompanied this code. If applicable, add the following below the
   12.23 - * License Header, with the fields enclosed by brackets [] replaced by
   12.24 - * your own identifying information:
   12.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   12.26 - *
   12.27 - * If you wish your version of this file to be governed by only the CDDL
   12.28 - * or only the GPL Version 2, indicate your decision by adding
   12.29 - * "[Contributor] elects to include this software in this distribution
   12.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   12.31 - * single choice of license, a recipient has the option to distribute
   12.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   12.33 - * to extend the choice of license to its licensees as provided above.
   12.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   12.35 - * Version 2 license, then the option applies only if the new code is
   12.36 - * made subject to such option by the copyright holder.
   12.37 - *
   12.38 - * Contributor(s):
   12.39 - *
   12.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   12.41 - */
   12.42 -package org.netbeans.modules.jackpot30.impl.duplicates;
   12.43 -
   12.44 -import java.awt.Dialog;
   12.45 -import java.awt.GridBagConstraints;
   12.46 -import java.awt.GridBagLayout;
   12.47 -import java.awt.Insets;
   12.48 -import java.awt.event.ActionEvent;
   12.49 -import java.awt.event.ActionListener;
   12.50 -import java.io.IOException;
   12.51 -import java.util.Collection;
   12.52 -import java.util.Iterator;
   12.53 -import java.util.LinkedList;
   12.54 -import java.util.concurrent.atomic.AtomicBoolean;
   12.55 -import javax.swing.JLabel;
   12.56 -import javax.swing.JPanel;
   12.57 -import javax.swing.SwingUtilities;
   12.58 -import org.netbeans.api.java.classpath.ClassPath;
   12.59 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
   12.60 -import org.netbeans.api.progress.ProgressHandle;
   12.61 -import org.netbeans.api.progress.ProgressHandleFactory;
   12.62 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   12.63 -import org.openide.DialogDescriptor;
   12.64 -import org.openide.DialogDisplayer;
   12.65 -import org.openide.NotifyDescriptor;
   12.66 -import org.openide.filesystems.FileObject;
   12.67 -import org.openide.filesystems.FileUtil;
   12.68 -import org.openide.util.Exceptions;
   12.69 -import org.openide.util.HelpCtx;
   12.70 -import org.openide.util.RequestProcessor;
   12.71 -
   12.72 -public final class GlobalFindDuplicates implements ActionListener {
   12.73 -
   12.74 -    public void actionPerformed(ActionEvent e) {
   12.75 -        final Iterator<? extends DuplicateDescription>[] dupes = new Iterator[1];
   12.76 -        final ProgressHandle handle = ProgressHandleFactory.createHandle("Compute Duplicates");
   12.77 -        JPanel panel = createPanel(handle);
   12.78 -        final AtomicBoolean cancel = new AtomicBoolean();
   12.79 -        DialogDescriptor w = new DialogDescriptor(panel, "Computing Duplicates", true, new Object[] {DialogDescriptor.CANCEL_OPTION}, DialogDescriptor.CANCEL_OPTION, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, new ActionListener() {
   12.80 -            public void actionPerformed(ActionEvent e) {
   12.81 -                cancel.set(true);
   12.82 -            }
   12.83 -        });
   12.84 -
   12.85 -        w.setClosingOptions(null);
   12.86 -
   12.87 -        final Dialog d = DialogDisplayer.getDefault().createDialog(w);
   12.88 -        final AtomicBoolean done = new AtomicBoolean();
   12.89 -        final Collection<String> sourceRoots = new LinkedList<String>();
   12.90 -
   12.91 -        WORKER.post(new Runnable() {
   12.92 -            public void run() {
   12.93 -                try {
   12.94 -                    for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
   12.95 -                        for (ClassPath.Entry e : cp.entries()) {
   12.96 -                            FileObject root = e.getRoot();
   12.97 -
   12.98 -                            if (root == null) continue;
   12.99 -
  12.100 -                            sourceRoots.add(FileUtil.getFileDisplayName(root));
  12.101 -                        }
  12.102 -                    }
  12.103 -
  12.104 -                    dupes[0] = new ComputeDuplicates().computeDuplicatesForAllOpenedProjects(handle, cancel);
  12.105 -                    done.set(true);
  12.106 -                } catch (IOException ex) {
  12.107 -                    Exceptions.printStackTrace(ex);
  12.108 -                } finally {
  12.109 -                    handle.finish();
  12.110 -
  12.111 -                    SwingUtilities.invokeLater(new Runnable() {
  12.112 -                        public void run() {
  12.113 -                            d.setVisible(false);
  12.114 -                        }
  12.115 -                    });
  12.116 -                }
  12.117 -            }
  12.118 -        });
  12.119 -
  12.120 -        handle.start();
  12.121 -        handle.progress(" ");
  12.122 -
  12.123 -        d.setVisible(true);
  12.124 -
  12.125 -        if (!done.get()) {
  12.126 -            cancel.set(true);
  12.127 -            return;
  12.128 -        }
  12.129 -        
  12.130 -        if (cancel.get()) return;
  12.131 -
  12.132 -        NotifyDescriptor nd = new NotifyDescriptor.Message(new DuplicatesListPanel(sourceRoots, dupes[0]));
  12.133 -
  12.134 -        DialogDisplayer.getDefault().notifyLater(nd);
  12.135 -    }
  12.136 -
  12.137 -    private JPanel createPanel(ProgressHandle handle) {
  12.138 -        JPanel panel = new JPanel(new GridBagLayout());
  12.139 -        GridBagConstraints gridBagConstraints;
  12.140 -
  12.141 -        gridBagConstraints = new GridBagConstraints();
  12.142 -        gridBagConstraints.gridx = 0;
  12.143 -        gridBagConstraints.gridy = 0;
  12.144 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  12.145 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  12.146 -        gridBagConstraints.weightx = 1.0;
  12.147 -        gridBagConstraints.insets = new Insets(6, 6, 0, 6);
  12.148 -        panel.add(new JLabel("Computing Duplicates - Please Wait"), gridBagConstraints);
  12.149 -
  12.150 -        gridBagConstraints = new GridBagConstraints();
  12.151 -        gridBagConstraints.gridx = 0;
  12.152 -        gridBagConstraints.gridy = 1;
  12.153 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  12.154 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  12.155 -        gridBagConstraints.weightx = 1.0;
  12.156 -        gridBagConstraints.insets = new Insets(6, 6, 0, 6);
  12.157 -        panel.add(ProgressHandleFactory.createProgressComponent(handle), gridBagConstraints);
  12.158 -
  12.159 -        gridBagConstraints = new GridBagConstraints();
  12.160 -        gridBagConstraints.gridx = 0;
  12.161 -        gridBagConstraints.gridy = 2;
  12.162 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  12.163 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  12.164 -        gridBagConstraints.weightx = 1.0;
  12.165 -        gridBagConstraints.insets = new Insets(6, 6, 6, 6);
  12.166 -        panel.add(ProgressHandleFactory.createDetailLabelComponent(handle), gridBagConstraints);
  12.167 -
  12.168 -        gridBagConstraints = new GridBagConstraints();
  12.169 -        gridBagConstraints.gridx = 0;
  12.170 -        gridBagConstraints.gridy = 3;
  12.171 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  12.172 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  12.173 -        gridBagConstraints.weightx = 1.0;
  12.174 -        gridBagConstraints.weighty = 1.0;
  12.175 -        panel.add(new JPanel(), gridBagConstraints);
  12.176 -
  12.177 -        return panel;
  12.178 -    }
  12.179 -
  12.180 -    private static final RequestProcessor WORKER = new RequestProcessor(GlobalFindDuplicates.class.getName(), 1);
  12.181 -    
  12.182 -}
    13.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DeferredCustomIndexer.java	Fri Jan 27 13:35:56 2012 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,494 +0,0 @@
    13.4 -/*
    13.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    13.6 - *
    13.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    13.8 - *
    13.9 - * The contents of this file are subject to the terms of either the GNU
   13.10 - * General Public License Version 2 only ("GPL") or the Common
   13.11 - * Development and Distribution License("CDDL") (collectively, the
   13.12 - * "License"). You may not use this file except in compliance with the
   13.13 - * License. You can obtain a copy of the License at
   13.14 - * http://www.netbeans.org/cddl-gplv2.html
   13.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   13.16 - * specific language governing permissions and limitations under the
   13.17 - * License.  When distributing the software, include this License Header
   13.18 - * Notice in each file and include the License file at
   13.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   13.20 - * particular file as subject to the "Classpath" exception as provided
   13.21 - * by Sun in the GPL Version 2 section of the License file that
   13.22 - * accompanied this code. If applicable, add the following below the
   13.23 - * License Header, with the fields enclosed by brackets [] replaced by
   13.24 - * your own identifying information:
   13.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   13.26 - *
   13.27 - * If you wish your version of this file to be governed by only the CDDL
   13.28 - * or only the GPL Version 2, indicate your decision by adding
   13.29 - * "[Contributor] elects to include this software in this distribution
   13.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   13.31 - * single choice of license, a recipient has the option to distribute
   13.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   13.33 - * to extend the choice of license to its licensees as provided above.
   13.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   13.35 - * Version 2 license, then the option applies only if the new code is
   13.36 - * made subject to such option by the copyright holder.
   13.37 - *
   13.38 - * Contributor(s):
   13.39 - *
   13.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   13.41 - */
   13.42 -
   13.43 -package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   13.44 -
   13.45 -import java.io.BufferedWriter;
   13.46 -import java.io.File;
   13.47 -import java.io.IOException;
   13.48 -import java.io.OutputStreamWriter;
   13.49 -import java.io.Writer;
   13.50 -import java.net.URL;
   13.51 -import java.util.Collection;
   13.52 -import java.util.Collections;
   13.53 -import java.util.HashMap;
   13.54 -import java.util.HashSet;
   13.55 -import java.util.Iterator;
   13.56 -import java.util.Map;
   13.57 -import java.util.Map.Entry;
   13.58 -import java.util.Set;
   13.59 -import java.util.concurrent.atomic.AtomicBoolean;
   13.60 -import java.util.logging.Level;
   13.61 -import java.util.logging.Logger;
   13.62 -import javax.swing.JButton;
   13.63 -import javax.swing.SwingUtilities;
   13.64 -import org.netbeans.api.annotations.common.NonNull;
   13.65 -import org.netbeans.api.java.classpath.ClassPath;
   13.66 -import org.netbeans.api.java.source.CancellableTask;
   13.67 -import org.netbeans.api.java.source.ClasspathInfo;
   13.68 -import org.netbeans.api.java.source.CompilationController;
   13.69 -import org.netbeans.api.java.source.CompilationInfo;
   13.70 -import org.netbeans.api.java.source.JavaSource;
   13.71 -import org.netbeans.api.java.source.JavaSource.Phase;
   13.72 -import org.netbeans.api.java.source.JavaSource.Priority;
   13.73 -import org.netbeans.api.java.source.JavaSourceTaskFactory;
   13.74 -import org.netbeans.api.java.source.Task;
   13.75 -import org.netbeans.api.progress.ProgressHandle;
   13.76 -import org.netbeans.api.progress.ProgressHandleFactory;
   13.77 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   13.78 -import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
   13.79 -import org.netbeans.modules.parsing.spi.indexing.Context;
   13.80 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
   13.81 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
   13.82 -import org.netbeans.modules.parsing.spi.indexing.Indexable;
   13.83 -import org.openide.DialogDescriptor;
   13.84 -import org.openide.DialogDisplayer;
   13.85 -import org.openide.filesystems.FileAlreadyLockedException;
   13.86 -import org.openide.filesystems.FileObject;
   13.87 -import org.openide.filesystems.FileUtil;
   13.88 -import org.openide.filesystems.URLMapper;
   13.89 -import org.openide.util.Cancellable;
   13.90 -import org.openide.util.Exceptions;
   13.91 -import org.openide.util.Lookup;
   13.92 -import org.openide.util.lookup.ServiceProvider;
   13.93 -
   13.94 -/**
   13.95 - *
   13.96 - * @author lahvac
   13.97 - */
   13.98 -public abstract class DeferredCustomIndexer extends CustomIndexer {
   13.99 -
  13.100 -    private static final Logger LOG = Logger.getLogger(DeferredCustomIndexer.class.getName());
  13.101 -    
  13.102 -    private final DeferredCustomIndexerFactory factory;
  13.103 -
  13.104 -    protected DeferredCustomIndexer(DeferredCustomIndexerFactory factory) {
  13.105 -        this.factory = factory;
  13.106 -    }
  13.107 -
  13.108 -    protected abstract void doIndex(DeferredContext ctx, Collection<? extends FileObject> modifiedAndAdded, Collection<? extends String> removed) throws IOException;
  13.109 -
  13.110 -    @Override
  13.111 -    protected final void index(Iterable<? extends Indexable> files, Context context) {
  13.112 -        update(factory, context.getRootURI(), files, Collections.<Indexable>emptyList());
  13.113 -    }
  13.114 -
  13.115 -    private static void dump(File where, Iterable<? extends String> lines) {
  13.116 -        Writer out = null;
  13.117 -
  13.118 -        try {
  13.119 -            out = new BufferedWriter(new OutputStreamWriter(FileUtil.createData(where).getOutputStream(), "UTF-8"));
  13.120 -            
  13.121 -            for (String line : lines) {
  13.122 -                out.write(line);
  13.123 -                out.write("\n");
  13.124 -            }
  13.125 -        } catch (FileAlreadyLockedException ex) {
  13.126 -            Exceptions.printStackTrace(ex);
  13.127 -        } catch (IOException ex) {
  13.128 -            Exceptions.printStackTrace(ex);
  13.129 -        } finally {
  13.130 -            if (out != null) {
  13.131 -                try {
  13.132 -                    out.close();
  13.133 -                } catch (IOException ex) {
  13.134 -                    Exceptions.printStackTrace(ex);
  13.135 -                }
  13.136 -            }
  13.137 -        }
  13.138 -    }
  13.139 -
  13.140 -    private static Set<String> gatherRelativePaths(Iterable<? extends Indexable> it) {
  13.141 -        Set<String> result = new HashSet<String>();
  13.142 -
  13.143 -        for (Indexable i : it) {
  13.144 -            result.add(i.getRelativePath());
  13.145 -        }
  13.146 -
  13.147 -        return result;
  13.148 -    }
  13.149 -
  13.150 -    private static void update(DeferredCustomIndexerFactory factory, URL root, Iterable<? extends Indexable> modified, Iterable<? extends Indexable> deleted) {
  13.151 -        try {
  13.152 -            Set<String> mod = gatherRelativePaths(modified);
  13.153 -            Set<String> del = gatherRelativePaths(deleted);
  13.154 -
  13.155 -            File cacheRoot = factory.cacheRoot(root);
  13.156 -            
  13.157 -            File modifiedFile = new File(cacheRoot, "modified");
  13.158 -            FileObject modifiedFileFO = FileUtil.toFileObject(modifiedFile);
  13.159 -            Set<String> modifiedFiles = modifiedFileFO != null ? new HashSet<String>(modifiedFileFO.asLines("UTF-8")) : new HashSet<String>();
  13.160 -            boolean modifiedFilesChanged = modifiedFiles.removeAll(del);
  13.161 -
  13.162 -            modifiedFilesChanged |= modifiedFiles.addAll(mod);
  13.163 -
  13.164 -            if (modifiedFilesChanged) {
  13.165 -                dump(modifiedFile, modifiedFiles);
  13.166 -            }
  13.167 -
  13.168 -            File deletedFile = new File(cacheRoot, "deleted");
  13.169 -            FileObject deletedFileFO = FileUtil.toFileObject(deletedFile);
  13.170 -            Set<String> deletedFiles = deletedFileFO != null ? new HashSet<String>(deletedFileFO.asLines("UTF-8")) : new HashSet<String>();
  13.171 -
  13.172 -            boolean deletedFilesChanged = deletedFiles.removeAll(mod);
  13.173 -
  13.174 -            deletedFilesChanged |= deletedFiles.addAll(del);
  13.175 -
  13.176 -            if (deletedFilesChanged) {
  13.177 -                dump(deletedFile, deletedFiles);
  13.178 -            }
  13.179 -
  13.180 -            if (!modifiedFiles.isEmpty() || !deletedFiles.isEmpty()) {
  13.181 -                add2TODO(root, factory);
  13.182 -            }
  13.183 -        } catch (IOException ex) {
  13.184 -            Exceptions.printStackTrace(ex);
  13.185 -        }
  13.186 -    }
  13.187 -    
  13.188 -    public static abstract class DeferredCustomIndexerFactory extends CustomIndexerFactory {
  13.189 -
  13.190 -        public abstract DeferredCustomIndexer createIndexer();
  13.191 -
  13.192 -        @Override
  13.193 -        public final void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
  13.194 -            update(this, context.getRootURI(), Collections.<Indexable>emptyList(), deleted);
  13.195 -        }
  13.196 -
  13.197 -        @Override
  13.198 -        public final void filesDirty(Iterable<? extends Indexable> dirty, Context context) {}
  13.199 -
  13.200 -        @Override
  13.201 -        public final boolean supportsEmbeddedIndexers() {
  13.202 -            return false;
  13.203 -        }
  13.204 -
  13.205 -        @Override
  13.206 -        public final void rootsRemoved(Iterable<? extends URL> removedRoots) {
  13.207 -            super.rootsRemoved(removedRoots);
  13.208 -        }
  13.209 -
  13.210 -        @Override
  13.211 -        public final void scanFinished(Context context) {
  13.212 -            super.scanFinished(context);
  13.213 -        }
  13.214 -
  13.215 -        @Override
  13.216 -        public final boolean scanStarted(Context context) {
  13.217 -            return super.scanStarted(context);
  13.218 -        }
  13.219 -
  13.220 -        protected File cacheRoot(URL root) throws IOException {
  13.221 -            FileObject indexBaseFolder = CacheFolder.getDataFolder(root);
  13.222 -            String path = SPIAccessor.getInstance().getIndexerPath(getIndexerName(), getIndexVersion());
  13.223 -            FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path);
  13.224 -            return FileUtil.toFile(indexFolder);
  13.225 -        }
  13.226 -
  13.227 -        public void updateIndex(final URL root, final AtomicBoolean cancel) throws IOException {
  13.228 -            final FileObject rootFO = URLMapper.findFileObject(root);
  13.229 -            final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY);
  13.230 -
  13.231 -            JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  13.232 -                public void run(CompilationController parameter) throws Exception {
  13.233 -                    if (cancel.get()) return ;
  13.234 -                    updateRoot(DeferredCustomIndexerFactory.this, root, rootFO, cancel);
  13.235 -                }
  13.236 -            }, true);
  13.237 -        }
  13.238 -
  13.239 -    }
  13.240 -
  13.241 -    public static final class DeferredContext {
  13.242 -        private final @NonNull URL root;
  13.243 -        private final @NonNull FileObject rootFileObject;
  13.244 -        private final @NonNull Set<? extends FileObject> modifiedAndAdded;
  13.245 -        private final @NonNull Set<? extends String> removed;
  13.246 -        private final @NonNull AtomicBoolean cancel;
  13.247 -
  13.248 -        public DeferredContext(@NonNull URL root, @NonNull FileObject rootFileObject, @NonNull Set<? extends FileObject> modifiedAndAdded, @NonNull Set<? extends String> removed, @NonNull AtomicBoolean cancel) {
  13.249 -            this.root = root;
  13.250 -            this.rootFileObject = rootFileObject;
  13.251 -            this.modifiedAndAdded = modifiedAndAdded;
  13.252 -            this.removed = removed;
  13.253 -            this.cancel = cancel;
  13.254 -        }
  13.255 -
  13.256 -        public @NonNull URL getRoot() {
  13.257 -            return root;
  13.258 -        }
  13.259 -
  13.260 -        public @NonNull FileObject getRootFileObject() {
  13.261 -            return rootFileObject;
  13.262 -        }
  13.263 -
  13.264 -        public boolean isCancelled() {
  13.265 -            return cancel.get();
  13.266 -        }
  13.267 -
  13.268 -        public void handledModifiedFile(FileObject file) {
  13.269 -            modifiedAndAdded.remove(file);
  13.270 -        }
  13.271 -
  13.272 -        public void handledRemovedFile(String relative) {
  13.273 -            removed.remove(relative);
  13.274 -        }
  13.275 -    }
  13.276 -
  13.277 -    /*return: true == done*/
  13.278 -    private static boolean updateRoot(DeferredCustomIndexerFactory factory, URL root, FileObject rootFO, AtomicBoolean cancel) throws IOException {
  13.279 -        LOG.log(Level.FINE, "updating: {0}, for indexer: {1}", new Object[] {root.toExternalForm(), factory.getIndexerName()});
  13.280 -         File cacheRoot = factory.cacheRoot(root);
  13.281 -         FileObject deletedFile = FileUtil.toFileObject(new File(cacheRoot, "deleted"));
  13.282 -         Set<String> deletedFiles = deletedFile != null ? new HashSet<String>(deletedFile.asLines("UTF-8")) : Collections.<String>emptySet();
  13.283 -
  13.284 -         FileObject modifiedFile = FileUtil.toFileObject(new File(cacheRoot, "modified"));
  13.285 -         Set<String> modifiedFiles = modifiedFile != null ? new HashSet<String>(modifiedFile.asLines("UTF-8")) : Collections.<String>emptySet();
  13.286 -
  13.287 -         Set<FileObject> toIndex = new HashSet<FileObject>();
  13.288 -
  13.289 -         for (String r : modifiedFiles) {
  13.290 -             FileObject f = rootFO.getFileObject(r);
  13.291 -
  13.292 -             if (f != null) {
  13.293 -                 toIndex.add(f);
  13.294 -             }
  13.295 -         }
  13.296 -
  13.297 -         if (!toIndex.isEmpty() || !modifiedFiles.isEmpty()) {
  13.298 -             factory.createIndexer().doIndex(new DeferredContext(root, rootFO, toIndex, deletedFiles, cancel), new HashSet<FileObject>(toIndex), new HashSet<String>(deletedFiles));
  13.299 -         }
  13.300 -
  13.301 -         boolean done = true;
  13.302 -
  13.303 -         if (deletedFile != null) {
  13.304 -             if (deletedFiles.isEmpty()) {
  13.305 -                 deletedFile.delete();
  13.306 -             } else {
  13.307 -                 dump(new File(cacheRoot, "deleted"), deletedFiles);
  13.308 -                 done = false;
  13.309 -             }
  13.310 -         }
  13.311 -         if (modifiedFile != null) {
  13.312 -             if (toIndex.isEmpty()) {
  13.313 -                 modifiedFile.delete();
  13.314 -             }  else {
  13.315 -                 modifiedFiles.clear();
  13.316 -
  13.317 -                 for (FileObject f : toIndex) {
  13.318 -                     modifiedFiles.add(FileUtil.getRelativePath(rootFO, f));
  13.319 -                 }
  13.320 -
  13.321 -                 dump(new File(cacheRoot, "modified"), modifiedFiles);
  13.322 -                 done = false;
  13.323 -             }
  13.324 -         }
  13.325 -
  13.326 -         return done;
  13.327 -    }
  13.328 -
  13.329 -    private static final Map<String, TODO> todo = new HashMap<String, TODO>(); //XXX: synchronization!!!
  13.330 -
  13.331 -    private static void add2TODO(URL root, DeferredCustomIndexerFactory factory) {
  13.332 -        if (DISABLED_INDEXERS.contains(factory.getIndexerName())) return;
  13.333 -        
  13.334 -        boolean wasEmpty = todo.isEmpty();
  13.335 -        TODO roots = todo.get(factory.getIndexerName());
  13.336 -
  13.337 -        if (roots == null) {
  13.338 -            todo.put(factory.getIndexerName(), roots = new TODO(factory));
  13.339 -        }
  13.340 -
  13.341 -        roots.roots.add(root);
  13.342 -
  13.343 -        LOG.log(Level.FINE, "add2TODO, root: {0}, for factory: {1}, wasEmpty: {2}, todo: {3}", new Object[] {root.toExternalForm(), factory.getIndexerName(), wasEmpty, todo.toString()});
  13.344 -        
  13.345 -        if (wasEmpty) RunAsNeededFactory.fileChanged();
  13.346 -        else RunAsNeededFactory.refresh();
  13.347 -    }
  13.348 -
  13.349 -    private static final Set<String> DISABLED_INDEXERS = Collections.synchronizedSet(new HashSet<String>());
  13.350 -
  13.351 -    private static class UpdateWorker implements CancellableTask<CompilationInfo> {
  13.352 -
  13.353 -        private static ProgressHandle progressForCurrentFactory;
  13.354 -        private static DeferredCustomIndexerFactory currentFactory;
  13.355 -        
  13.356 -        private final AtomicBoolean cancel = new AtomicBoolean();
  13.357 -
  13.358 -        public void run(CompilationInfo parameter) throws Exception {
  13.359 -            cancel.set(false);
  13.360 -
  13.361 -            for (Iterator<Entry<String, TODO>> it = todo.entrySet().iterator(); it.hasNext();) {
  13.362 -                if (cancel.get()) return;
  13.363 -
  13.364 -                final Entry<String, TODO> e = it.next();
  13.365 -
  13.366 -                if (DISABLED_INDEXERS.contains(e.getKey())) {
  13.367 -                    it.remove();
  13.368 -                    continue;
  13.369 -                }
  13.370 -                
  13.371 -                if (currentFactory != e.getValue().factory) {
  13.372 -                    if (progressForCurrentFactory != null) {
  13.373 -                        progressForCurrentFactory.finish();
  13.374 -                    }
  13.375 -
  13.376 -                    currentFactory = e.getValue().factory;
  13.377 -                    progressForCurrentFactory = ProgressHandleFactory.createSystemHandle("Background indexing for: " + currentFactory.getIndexerName(), new Cancellable() {
  13.378 -                        public boolean cancel() {
  13.379 -                            assert SwingUtilities.isEventDispatchThread();
  13.380 -
  13.381 -                            JButton disableInThisSession = new JButton("Disable in This Session");
  13.382 -                            JButton disablePermanently = new JButton("Disable Permanently");
  13.383 -
  13.384 -                            disablePermanently.setEnabled(false);
  13.385 -
  13.386 -                            Object[] buttons = new Object[]{disableInThisSession, disablePermanently, DialogDescriptor.CANCEL_OPTION};
  13.387 -                            DialogDescriptor dd = new DialogDescriptor("Disable background indexing for: " + e.getValue().factory.getIndexerName(), "Disable Background Indexing", true, buttons, disableInThisSession, DialogDescriptor.DEFAULT_ALIGN, null, null);
  13.388 -
  13.389 -                            dd.setClosingOptions(buttons);
  13.390 -
  13.391 -                            Object result = DialogDisplayer.getDefault().notify(dd);
  13.392 -
  13.393 -                            if (result == disableInThisSession) {
  13.394 -                                DISABLED_INDEXERS.add(e.getKey());
  13.395 -                                return true;
  13.396 -                            } else if (result == disablePermanently) {
  13.397 -                                throw new UnsupportedOperationException();
  13.398 -                            } else {
  13.399 -                                return false;
  13.400 -                            }
  13.401 -                        }
  13.402 -                    });
  13.403 -
  13.404 -                    progressForCurrentFactory.start();
  13.405 -                }
  13.406 -
  13.407 -                for (Iterator<URL> factIt = e.getValue().roots.iterator(); factIt.hasNext();) {
  13.408 -                    if (cancel.get()) return;
  13.409 -
  13.410 -                    URL root = factIt.next();
  13.411 -                    FileObject rootFO = URLMapper.findFileObject(root);
  13.412 -
  13.413 -                    if (rootFO == null) {
  13.414 -                        //already deleted
  13.415 -                        it.remove();
  13.416 -                        continue;
  13.417 -                    }
  13.418 -
  13.419 -                    if (updateRoot(e.getValue().factory, root, rootFO, cancel)) {
  13.420 -                        factIt.remove();
  13.421 -                    } else {
  13.422 -                        if (!cancel.get()) {
  13.423 -                            LOG.log(Level.WARNING, "indexer: {0} did not update all files even if the process was not cancelled", currentFactory.getIndexerName());
  13.424 -                        }
  13.425 -                    }
  13.426 -                }
  13.427 -
  13.428 -                if (e.getValue().roots.isEmpty())
  13.429 -                    it.remove();
  13.430 -
  13.431 -                progressForCurrentFactory.finish();
  13.432 -                progressForCurrentFactory = null;
  13.433 -                currentFactory = null;
  13.434 -            }
  13.435 -
  13.436 -            if (todo.isEmpty()) RunAsNeededFactory.fileChanged();
  13.437 -        }
  13.438 -
  13.439 -        public void cancel() {
  13.440 -            cancel.set(true);
  13.441 -        }
  13.442 -    }
  13.443 -
  13.444 -    private static final class TODO {
  13.445 -        final DeferredCustomIndexerFactory factory;
  13.446 -        final Collection<URL> roots = new HashSet<URL>();
  13.447 -        TODO(DeferredCustomIndexerFactory factory) {
  13.448 -            this.factory = factory;
  13.449 -        }
  13.450 -    }
  13.451 -
  13.452 -    private static final boolean DEFERRED_INDEXER_ENABLED = Boolean.getBoolean(DeferredCustomIndexerFactory.class.getName() + ".enable");
  13.453 -    
  13.454 -    private static final FileObject EMPTY_FILE;
  13.455 -
  13.456 -    static {
  13.457 -        try {
  13.458 -            EMPTY_FILE = FileUtil.createMemoryFileSystem().getRoot().createData("empty.java");
  13.459 -        } catch (IOException ex) {
  13.460 -            throw new IllegalStateException(ex);
  13.461 -        }
  13.462 -    }
  13.463 -
  13.464 -    @ServiceProvider(service=JavaSourceTaskFactory.class)
  13.465 -    public static final class RunAsNeededFactory extends JavaSourceTaskFactory {
  13.466 -
  13.467 -        public RunAsNeededFactory() {
  13.468 -            super(Phase.PARSED, Priority.MIN);
  13.469 -        }
  13.470 -
  13.471 -        @Override
  13.472 -        protected CancellableTask<CompilationInfo> createTask(FileObject file) {
  13.473 -            return new UpdateWorker();
  13.474 -        }
  13.475 -
  13.476 -        @Override
  13.477 -        protected Collection<FileObject> getFileObjects() {
  13.478 -            return DEFERRED_INDEXER_ENABLED && !todo.isEmpty() ? Collections.singletonList(EMPTY_FILE) : Collections.<FileObject>emptyList();
  13.479 -        }
  13.480 -
  13.481 -        public static void fileChanged() {
  13.482 -            for (JavaSourceTaskFactory f : Lookup.getDefault().lookupAll(JavaSourceTaskFactory.class)) {
  13.483 -                if (f instanceof RunAsNeededFactory) {
  13.484 -                    ((RunAsNeededFactory) f).fileObjectsChanged();
  13.485 -                }
  13.486 -            }
  13.487 -        }
  13.488 -
  13.489 -        public static void refresh() {
  13.490 -            for (JavaSourceTaskFactory f : Lookup.getDefault().lookupAll(JavaSourceTaskFactory.class)) {
  13.491 -                if (f instanceof RunAsNeededFactory) {
  13.492 -                    ((RunAsNeededFactory) f).reschedule(EMPTY_FILE);
  13.493 -                }
  13.494 -            }
  13.495 -        }
  13.496 -    }
  13.497 -}
    14.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java	Fri Jan 27 13:35:56 2012 +0100
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,126 +0,0 @@
    14.4 -/*
    14.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    14.6 - *
    14.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    14.8 - *
    14.9 - * The contents of this file are subject to the terms of either the GNU
   14.10 - * General Public License Version 2 only ("GPL") or the Common
   14.11 - * Development and Distribution License("CDDL") (collectively, the
   14.12 - * "License"). You may not use this file except in compliance with the
   14.13 - * License. You can obtain a copy of the License at
   14.14 - * http://www.netbeans.org/cddl-gplv2.html
   14.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   14.16 - * specific language governing permissions and limitations under the
   14.17 - * License.  When distributing the software, include this License Header
   14.18 - * Notice in each file and include the License file at
   14.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   14.20 - * particular file as subject to the "Classpath" exception as provided
   14.21 - * by Sun in the GPL Version 2 section of the License file that
   14.22 - * accompanied this code. If applicable, add the following below the
   14.23 - * License Header, with the fields enclosed by brackets [] replaced by
   14.24 - * your own identifying information:
   14.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   14.26 - *
   14.27 - * If you wish your version of this file to be governed by only the CDDL
   14.28 - * or only the GPL Version 2, indicate your decision by adding
   14.29 - * "[Contributor] elects to include this software in this distribution
   14.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   14.31 - * single choice of license, a recipient has the option to distribute
   14.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   14.33 - * to extend the choice of license to its licensees as provided above.
   14.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   14.35 - * Version 2 license, then the option applies only if the new code is
   14.36 - * made subject to such option by the copyright holder.
   14.37 - *
   14.38 - * Contributor(s):
   14.39 - *
   14.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   14.41 - */
   14.42 -
   14.43 -package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   14.44 -
   14.45 -import java.io.File;
   14.46 -import java.io.IOException;
   14.47 -import java.net.URL;
   14.48 -import java.util.Collection;
   14.49 -import org.netbeans.api.java.source.ClasspathInfo;
   14.50 -import org.netbeans.api.java.source.CompilationController;
   14.51 -import org.netbeans.api.java.source.JavaSource;
   14.52 -import org.netbeans.api.java.source.JavaSource.Phase;
   14.53 -import org.netbeans.api.java.source.Task;
   14.54 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesIndex.IndexWriter;
   14.55 -import org.netbeans.modules.jackpot30.impl.indexing.Cache;
   14.56 -import org.openide.filesystems.FileObject;
   14.57 -import org.openide.util.Exceptions;
   14.58 -
   14.59 -/**
   14.60 - *
   14.61 - * @author lahvac
   14.62 - */
   14.63 -public class DuplicatesCustomIndexerImpl extends DeferredCustomIndexer {
   14.64 -
   14.65 -    private static final String NAME = "";
   14.66 -    private static final int VERSION = 1;
   14.67 -    public DuplicatesCustomIndexerImpl(DeferredCustomIndexerFactory factory) {
   14.68 -        super(factory);
   14.69 -    }
   14.70 -
   14.71 -    protected void doIndex(final DeferredContext ctx, Collection<? extends FileObject> modifiedAndAdded, Collection<? extends String> removed) throws IOException {
   14.72 -        final IndexWriter[] w = new IndexWriter[1];
   14.73 -
   14.74 -        try {
   14.75 -            w[0] = DuplicatesIndex.get(ctx.getRoot()).openForWriting();
   14.76 -
   14.77 -            for (String r : removed) {
   14.78 -                w[0].remove(r);
   14.79 -                ctx.handledRemovedFile(r);
   14.80 -            }
   14.81 -
   14.82 -            final ClasspathInfo cpInfo = ClasspathInfo.create(ctx.getRootFileObject());
   14.83 -
   14.84 -            JavaSource.create(cpInfo, modifiedAndAdded).runUserActionTask(new Task<CompilationController>() {
   14.85 -                public void run(final CompilationController cc) throws Exception {
   14.86 -                    if (cc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0)
   14.87 -                        return ;
   14.88 -
   14.89 -                    w[0].record(cc, cc.getFileObject().getURL(), cc.getCompilationUnit());
   14.90 -
   14.91 -                    ctx.handledModifiedFile(cc.getFileObject());
   14.92 -                }
   14.93 -            }, true);
   14.94 -        } finally {
   14.95 -            if (w[0] != null) {
   14.96 -                try {
   14.97 -                    w[0].close();
   14.98 -                } catch (IOException ex) {
   14.99 -                    Exceptions.printStackTrace(ex);
  14.100 -                }
  14.101 -            }
  14.102 -        }
  14.103 -    }
  14.104 -    
  14.105 -    public static final class FactoryImpl extends DeferredCustomIndexerFactory {
  14.106 -
  14.107 -        @Override
  14.108 -        public DeferredCustomIndexer createIndexer() {
  14.109 -            return new DuplicatesCustomIndexerImpl(this);
  14.110 -        }
  14.111 -
  14.112 -        @Override
  14.113 -        public String getIndexerName() {
  14.114 -            return DuplicatesIndex.NAME;
  14.115 -        }
  14.116 -
  14.117 -        @Override
  14.118 -        public int getIndexVersion() {
  14.119 -            return DuplicatesIndex.VERSION;
  14.120 -        }
  14.121 -
  14.122 -        @Override
  14.123 -        protected File cacheRoot(URL root) throws IOException {
  14.124 -            return Cache.findCache(DuplicatesIndex.NAME, DuplicatesIndex.VERSION).findCacheRoot(root);
  14.125 -        }
  14.126 -
  14.127 -    }
  14.128 -
  14.129 -}
    15.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java	Fri Jan 27 13:35:56 2012 +0100
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,144 +0,0 @@
    15.4 -/*
    15.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    15.6 - *
    15.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    15.8 - *
    15.9 - * The contents of this file are subject to the terms of either the GNU
   15.10 - * General Public License Version 2 only ("GPL") or the Common
   15.11 - * Development and Distribution License("CDDL") (collectively, the
   15.12 - * "License"). You may not use this file except in compliance with the
   15.13 - * License. You can obtain a copy of the License at
   15.14 - * http://www.netbeans.org/cddl-gplv2.html
   15.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   15.16 - * specific language governing permissions and limitations under the
   15.17 - * License.  When distributing the software, include this License Header
   15.18 - * Notice in each file and include the License file at
   15.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   15.20 - * particular file as subject to the "Classpath" exception as provided
   15.21 - * by Sun in the GPL Version 2 section of the License file that
   15.22 - * accompanied this code. If applicable, add the following below the
   15.23 - * License Header, with the fields enclosed by brackets [] replaced by
   15.24 - * your own identifying information:
   15.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   15.26 - *
   15.27 - * If you wish your version of this file to be governed by only the CDDL
   15.28 - * or only the GPL Version 2, indicate your decision by adding
   15.29 - * "[Contributor] elects to include this software in this distribution
   15.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   15.31 - * single choice of license, a recipient has the option to distribute
   15.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   15.33 - * to extend the choice of license to its licensees as provided above.
   15.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   15.35 - * Version 2 license, then the option applies only if the new code is
   15.36 - * made subject to such option by the copyright holder.
   15.37 - *
   15.38 - * Contributor(s):
   15.39 - *
   15.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   15.41 - */
   15.42 -
   15.43 -package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   15.44 -
   15.45 -import com.sun.source.tree.CompilationUnitTree;
   15.46 -import java.io.File;
   15.47 -import java.io.IOException;
   15.48 -import java.net.URL;
   15.49 -import java.util.Map;
   15.50 -import java.util.Map.Entry;
   15.51 -import java.util.logging.Level;
   15.52 -import java.util.logging.Logger;
   15.53 -import javax.tools.JavaCompiler.CompilationTask;
   15.54 -import org.apache.lucene.document.Document;
   15.55 -import org.apache.lucene.document.Field;
   15.56 -import org.apache.lucene.document.Field.Index;
   15.57 -import org.apache.lucene.document.Field.Store;
   15.58 -import org.apache.lucene.index.IndexWriter.MaxFieldLength;
   15.59 -import org.apache.lucene.index.Term;
   15.60 -import org.apache.lucene.store.FSDirectory;
   15.61 -import org.netbeans.api.annotations.common.CheckForNull;
   15.62 -import org.netbeans.api.java.source.CompilationInfo;
   15.63 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates;
   15.64 -import org.netbeans.modules.jackpot30.impl.indexing.Cache;
   15.65 -import org.netbeans.modules.jackpot30.impl.indexing.FileBasedIndex.NoAnalyzer;
   15.66 -import org.netbeans.modules.java.source.JavaSourceAccessor;
   15.67 -
   15.68 -/**
   15.69 - *
   15.70 - * @author lahvac
   15.71 - */
   15.72 -public class DuplicatesIndex {
   15.73 -
   15.74 -    private final URL  sourceRoot;
   15.75 -    private final int  stripLength;
   15.76 -    private final File cacheRoot;
   15.77 -
   15.78 -    private DuplicatesIndex(URL sourceRoot, File cacheRoot) {
   15.79 -        this.sourceRoot = sourceRoot;
   15.80 -        this.stripLength = sourceRoot.getPath().length();
   15.81 -        this.cacheRoot = cacheRoot;
   15.82 -    }
   15.83 -
   15.84 -    public static @CheckForNull DuplicatesIndex get(URL sourceRoot) throws IOException {
   15.85 -        return new DuplicatesIndex(sourceRoot, Cache.findCache(NAME, VERSION).findCacheRoot(sourceRoot)); //XXX: new!
   15.86 -    }
   15.87 -
   15.88 -    public IndexWriter openForWriting() throws IOException {
   15.89 -        return new IndexWriter();
   15.90 -    }
   15.91 -
   15.92 -    public class IndexWriter {
   15.93 -
   15.94 -        private final org.apache.lucene.index.IndexWriter luceneWriter;
   15.95 -
   15.96 -        public IndexWriter() throws IOException {
   15.97 -            luceneWriter = new org.apache.lucene.index.IndexWriter(FSDirectory.open(new File(cacheRoot, "fulltext")), new NoAnalyzer(), MaxFieldLength.UNLIMITED);
   15.98 -        }
   15.99 -
  15.100 -        public void record(final CompilationInfo info, URL source, final CompilationUnitTree cut) throws IOException {
  15.101 -            record(JavaSourceAccessor.getINSTANCE().getJavacTask(info), source, cut);
  15.102 -        }
  15.103 -
  15.104 -        public void record(final CompilationTask task, URL source, final CompilationUnitTree cut) throws IOException {
  15.105 -            String relative = source.getPath().substring(stripLength);
  15.106 -
  15.107 -            try {
  15.108 -                final Document doc = new Document();
  15.109 -
  15.110 -                doc.add(new Field("path", relative, Field.Store.YES, Field.Index.NOT_ANALYZED));
  15.111 -
  15.112 -                final Map<String, long[]> positions = ComputeDuplicates.encodeGeneralized(task, cut);
  15.113 -
  15.114 -                for (Entry<String, long[]> e : positions.entrySet()) {
  15.115 -                    doc.add(new Field("generalized", e.getKey(), Store.YES, Index.NOT_ANALYZED));
  15.116 -
  15.117 -                    StringBuilder positionsSpec = new StringBuilder();
  15.118 -
  15.119 -                    for (int i = 0; i < e.getValue().length; i += 2) {
  15.120 -                        if (positionsSpec.length() > 0) positionsSpec.append(';');
  15.121 -                        positionsSpec.append(e.getValue()[i]).append(':').append(e.getValue()[i + 1] - e.getValue()[i]);
  15.122 -                    }
  15.123 -
  15.124 -                    doc.add(new Field("positions", positionsSpec.toString(), Store.YES, Index.NO));
  15.125 -                }
  15.126 -
  15.127 -                luceneWriter.addDocument(doc);
  15.128 -            } catch (ThreadDeath td) {
  15.129 -                throw td;
  15.130 -            } catch (Throwable t) {
  15.131 -                Logger.getLogger(DuplicatesIndex.class.getName()).log(Level.WARNING, null, t);
  15.132 -            }
  15.133 -        }
  15.134 -
  15.135 -        public void remove(String relativePath) throws IOException {
  15.136 -            luceneWriter.deleteDocuments(new Term("path", relativePath));
  15.137 -        }
  15.138 -        
  15.139 -        public void close() throws IOException {
  15.140 -            luceneWriter.optimize();
  15.141 -            luceneWriter.close();
  15.142 -        }
  15.143 -    }
  15.144 -
  15.145 -    public static final String NAME = "duplicates"; //NOI18N
  15.146 -    public static final int    VERSION = 1; //NOI18N
  15.147 -}
    16.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndex.java	Fri Jan 27 13:35:56 2012 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,413 +0,0 @@
    16.4 -/*
    16.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    16.6 - *
    16.7 - * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    16.8 - *
    16.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   16.10 - * Other names may be trademarks of their respective owners.
   16.11 - *
   16.12 - * The contents of this file are subject to the terms of either the GNU
   16.13 - * General Public License Version 2 only ("GPL") or the Common
   16.14 - * Development and Distribution License("CDDL") (collectively, the
   16.15 - * "License"). You may not use this file except in compliance with the
   16.16 - * License. You can obtain a copy of the License at
   16.17 - * http://www.netbeans.org/cddl-gplv2.html
   16.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   16.19 - * specific language governing permissions and limitations under the
   16.20 - * License.  When distributing the software, include this License Header
   16.21 - * Notice in each file and include the License file at
   16.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   16.23 - * particular file as subject to the "Classpath" exception as provided
   16.24 - * by Oracle in the GPL Version 2 section of the License file that
   16.25 - * accompanied this code. If applicable, add the following below the
   16.26 - * License Header, with the fields enclosed by brackets [] replaced by
   16.27 - * your own identifying information:
   16.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   16.29 - *
   16.30 - * If you wish your version of this file to be governed by only the CDDL
   16.31 - * or only the GPL Version 2, indicate your decision by adding
   16.32 - * "[Contributor] elects to include this software in this distribution
   16.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   16.34 - * single choice of license, a recipient has the option to distribute
   16.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   16.36 - * to extend the choice of license to its licensees as provided above.
   16.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   16.38 - * Version 2 license, then the option applies only if the new code is
   16.39 - * made subject to such option by the copyright holder.
   16.40 - *
   16.41 - * Contributor(s):
   16.42 - *
   16.43 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   16.44 - */
   16.45 -
   16.46 -package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   16.47 -
   16.48 -import java.io.File;
   16.49 -import java.io.IOException;
   16.50 -import java.net.URI;
   16.51 -import java.net.URISyntaxException;
   16.52 -import java.util.ArrayList;
   16.53 -import java.util.Arrays;
   16.54 -import java.util.BitSet;
   16.55 -import java.util.Collection;
   16.56 -import java.util.Collections;
   16.57 -import java.util.Comparator;
   16.58 -import java.util.HashSet;
   16.59 -import java.util.Iterator;
   16.60 -import java.util.LinkedHashMap;
   16.61 -import java.util.LinkedHashSet;
   16.62 -import java.util.LinkedList;
   16.63 -import java.util.List;
   16.64 -import java.util.Map;
   16.65 -import java.util.Map.Entry;
   16.66 -import java.util.Set;
   16.67 -import java.util.TreeMap;
   16.68 -import java.util.logging.Level;
   16.69 -import java.util.logging.Logger;
   16.70 -import org.apache.lucene.document.Document;
   16.71 -import org.apache.lucene.document.Field;
   16.72 -import org.apache.lucene.document.Field.Index;
   16.73 -import org.apache.lucene.document.Field.Store;
   16.74 -import org.apache.lucene.index.IndexReader;
   16.75 -import org.apache.lucene.index.IndexWriter;
   16.76 -import org.apache.lucene.index.IndexWriter.MaxFieldLength;
   16.77 -import org.apache.lucene.index.Term;
   16.78 -import org.apache.lucene.search.Collector;
   16.79 -import org.apache.lucene.search.IndexSearcher;
   16.80 -import org.apache.lucene.search.Query;
   16.81 -import org.apache.lucene.search.Searcher;
   16.82 -import org.apache.lucene.search.TermQuery;
   16.83 -import org.apache.lucene.store.FSDirectory;
   16.84 -import org.codeviation.pojson.Pojson;
   16.85 -import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
   16.86 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   16.87 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   16.88 -import org.netbeans.modules.jackpot30.impl.indexing.AbstractLuceneIndex.BitSetCollector;
   16.89 -import org.netbeans.modules.jackpot30.impl.indexing.Cache;
   16.90 -import org.netbeans.modules.jackpot30.impl.indexing.FileBasedIndex.NoAnalyzer;
   16.91 -import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   16.92 -import org.openide.filesystems.FileObject;
   16.93 -import org.openide.filesystems.FileUtil;
   16.94 -import org.openide.filesystems.URLMapper;
   16.95 -import org.openide.util.Exceptions;
   16.96 -
   16.97 -/**
   16.98 - *
   16.99 - * @author lahvac
  16.100 - */
  16.101 -public class RemoteDuplicatesIndex {
  16.102 -
  16.103 -    private static final Logger TIMER = Logger.getLogger("TIMER");
  16.104 -
  16.105 -    public static List<DuplicateDescription> findDuplicates(Map<String, long[]> hashes, FileObject currentFile) throws IOException {
  16.106 -        return translate(hashes, findHashOccurrences(hashes.keySet(), currentFile), currentFile);
  16.107 -    }
  16.108 -
  16.109 -    private static Map<String, Map<RemoteIndex, Collection<String>>> findHashOccurrences(Collection<? extends String> hashes, FileObject currentFile) throws IOException {
  16.110 -        Map<URI, Collection<RemoteIndex>> indices = new LinkedHashMap<URI, Collection<RemoteIndex>>();
  16.111 -
  16.112 -        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
  16.113 -            try {
  16.114 -                URI uri = ri.remote.toURI();
  16.115 -                Collection<RemoteIndex> list = indices.get(uri);
  16.116 -
  16.117 -                if (list == null) {
  16.118 -                    indices.put(uri, list = new ArrayList<RemoteIndex>());
  16.119 -                }
  16.120 -
  16.121 -                list.add(ri);
  16.122 -            } catch (URISyntaxException ex) {
  16.123 -                Exceptions.printStackTrace(ex);
  16.124 -            }
  16.125 -        }
  16.126 -
  16.127 -        Map<String, Map<RemoteIndex, Collection<String>>> result = new LinkedHashMap<String, Map<RemoteIndex, Collection<String>>>();
  16.128 -        long localTime = 0;
  16.129 -        long remoteTime = 0;
  16.130 -
  16.131 -        for (URI ri : indices.keySet()) {
  16.132 -            Set<String> toProcess = new LinkedHashSet<String>(hashes);
  16.133 -            Map<String, Map<String, Collection<? extends String>>> indexResult = new LinkedHashMap<String, Map<String, Collection<? extends String>>>();
  16.134 -
  16.135 -            long locS = System.currentTimeMillis();
  16.136 -            indexResult.putAll(findHashOccurrencesInLocalCache(ri, toProcess));
  16.137 -            localTime += System.currentTimeMillis() - locS;
  16.138 -
  16.139 -            toProcess.removeAll(result.keySet());
  16.140 -
  16.141 -            if (!toProcess.isEmpty()) {
  16.142 -                long remS = System.currentTimeMillis();
  16.143 -                Map<String, Map<String, Collection<? extends String>>> remoteResults = findHashOccurrencesRemote(ri, toProcess);
  16.144 -                remoteTime += System.currentTimeMillis() - remS;
  16.145 -
  16.146 -                Map<String, Map<String, Collection<? extends String>>> toSave = new LinkedHashMap<String, Map<String, Collection<? extends String>>>(remoteResults);
  16.147 -
  16.148 -                for (String hash : toProcess) {
  16.149 -                    if (!toSave.containsKey(hash)) {
  16.150 -                        toSave.put(hash, Collections.<String, Collection<? extends String>>emptyMap());
  16.151 -                    }
  16.152 -                }
  16.153 -
  16.154 -                saveToLocalCache(ri, toSave);
  16.155 -
  16.156 -                indexResult.putAll(remoteResults);
  16.157 -            }
  16.158 -
  16.159 -            for (Entry<String, Map<String, Collection<? extends String>>> e : indexResult.entrySet()) {
  16.160 -                Map<RemoteIndex, Collection<String>> hashResult = result.get(e.getKey());
  16.161 -
  16.162 -                if (hashResult == null) {
  16.163 -                    result.put(e.getKey(), hashResult = new LinkedHashMap<RemoteIndex, Collection<String>>());
  16.164 -                }
  16.165 -
  16.166 -                for (Entry<String, Collection<? extends String>> insideHash : e.getValue().entrySet()) {
  16.167 -                    RemoteIndex current = null;
  16.168 -
  16.169 -                    for (RemoteIndex r : indices.get(ri)) {
  16.170 -                        if (r.remoteSegment.equals(insideHash.getKey())) {
  16.171 -                            current = r;
  16.172 -                            break;
  16.173 -                        }
  16.174 -                    }
  16.175 -
  16.176 -                    if (current == null) {
  16.177 -                        continue;
  16.178 -                    }
  16.179 -
  16.180 -                    Collection<String> dupes = hashResult.get(current);
  16.181 -
  16.182 -                    if (dupes == null) {
  16.183 -                        hashResult.put(current, dupes = new HashSet<String>());
  16.184 -                    }
  16.185 -
  16.186 -                    dupes.addAll(insideHash.getValue());
  16.187 -                }
  16.188 -            }
  16.189 -        }
  16.190 -
  16.191 -        TIMER.log(Level.FINE, "local hash duplicates", new Object[] {currentFile, localTime});
  16.192 -        TIMER.log(Level.FINE, "remote hash duplicates", new Object[] {currentFile, remoteTime});
  16.193 -        return result;
  16.194 -    }
  16.195 -
  16.196 -    private static Map<String, Map<String, Collection<? extends String>>> findHashOccurrencesRemote(URI remoteIndex, Iterable<? extends String> hashes) {
  16.197 -        try {
  16.198 -            String indexURL = remoteIndex.toASCIIString();
  16.199 -            URI u = new URI(indexURL + "/findDuplicates?hashes=" + WebUtilities.escapeForQuery(Pojson.save(hashes)));
  16.200 -            String hashesMap = WebUtilities.requestStringResponse(u);
  16.201 -
  16.202 -            if (hashesMap == null) {
  16.203 -                //some kind of error while getting the duplicates (cannot access remote server)?
  16.204 -                //ignore:
  16.205 -                return Collections.emptyMap();
  16.206 -            }
  16.207 -            return Pojson.load(LinkedHashMap.class, hashesMap);
  16.208 -        } catch (URISyntaxException ex) {
  16.209 -            //XXX: better handling?
  16.210 -            Exceptions.printStackTrace(ex);
  16.211 -            return Collections.emptyMap();
  16.212 -        }
  16.213 -    }
  16.214 -
  16.215 -    private static volatile IndexReader readerCache;
  16.216 -
  16.217 -    private static File findLocalCacheDir(URI uri) throws IOException {
  16.218 -        return Cache.findCache("remote-duplicates", 0).findCacheRoot(uri.toURL());
  16.219 -    }
  16.220 -
  16.221 -    private static Map<String, Map<String, Collection<? extends String>>> findHashOccurrencesInLocalCache(URI uri, Iterable<? extends String> hashes) throws IOException {
  16.222 -        IndexReader reader = readerCache;
  16.223 -
  16.224 -        if (reader == null) {
  16.225 -            File dir = findLocalCacheDir(uri);
  16.226 -
  16.227 -            if (dir.listFiles() != null && dir.listFiles().length > 0) {
  16.228 -                readerCache = reader = IndexReader.open(FSDirectory.open(dir), true);
  16.229 -            }
  16.230 -        }
  16.231 -
  16.232 -        if (reader == null) {
  16.233 -            return Collections.emptyMap();
  16.234 -        }
  16.235 -
  16.236 -        Map<String, Map<String, Collection<String>>> result = new LinkedHashMap<String, Map<String, Collection<String>>>();
  16.237 -
  16.238 -        for (Entry<String, Collection<? extends String>> e : containsHash(reader, hashes).entrySet()) {
  16.239 -            Map<String, Collection<String>> forHash = result.get(e.getKey());
  16.240 -
  16.241 -            if (forHash == null) {
  16.242 -                result.put(e.getKey(), forHash = new LinkedHashMap<String, Collection<String>>());
  16.243 -            }
  16.244 -
  16.245 -            for (String path : e.getValue()) {
  16.246 -                String segment = path.substring(0, path.indexOf('/'));
  16.247 -
  16.248 -                path = path.substring(path.indexOf('/') + 1);
  16.249 -
  16.250 -                Collection<String> list = forHash.get(segment);
  16.251 -
  16.252 -                if (list == null) {
  16.253 -                    forHash.put(segment, list = new LinkedList<String>());
  16.254 -                }
  16.255 -
  16.256 -                list.add(path);
  16.257 -            }
  16.258 -        }
  16.259 -
  16.260 -        return (Map)result; //XXX
  16.261 -    }
  16.262 -
  16.263 -    private static void saveToLocalCache(URI uri, Map<String, Map<String, Collection<? extends String>>> what) throws IOException {
  16.264 -        IndexReader r = readerCache;
  16.265 -
  16.266 -        if (r != null) {
  16.267 -            r.close();
  16.268 -            readerCache = null;
  16.269 -        }
  16.270 -        
  16.271 -        IndexWriter w = new IndexWriter(FSDirectory.open(findLocalCacheDir(uri)), new NoAnalyzer(), MaxFieldLength.UNLIMITED);
  16.272 -
  16.273 -        for (Entry<String, Map<String, Collection<? extends String>>> e : what.entrySet()) {
  16.274 -            Document doc = new Document();
  16.275 -
  16.276 -            doc.add(new Field("hash", e.getKey(), Store.YES, Index.NOT_ANALYZED));
  16.277 -
  16.278 -            for (Entry<String, Collection<? extends String>> pe : e.getValue().entrySet()) {
  16.279 -                for (String path : pe.getValue()) {
  16.280 -                    doc.add(new Field("path", pe.getKey() + "/" + path, Store.YES, Index.NO));
  16.281 -                }
  16.282 -            }
  16.283 -
  16.284 -            w.addDocument(doc);
  16.285 -        }
  16.286 -
  16.287 -        w.optimize();
  16.288 -        w.close();
  16.289 -    }
  16.290 -    
  16.291 -    private static List<DuplicateDescription> translate(Map<String, long[]> hashes, Map<String, Map<RemoteIndex, Collection<String>>> occ, FileObject currentFile) {
  16.292 -        Map<String, Map<RemoteIndex, Collection<String>>> sorted = hashMap();
  16.293 -        Map<long[], DuplicateDescription> result = new LinkedHashMap<long[], DuplicateDescription>();
  16.294 -        List<long[]> seen = new LinkedList<long[]>();
  16.295 -
  16.296 -        sorted.putAll(occ);
  16.297 -
  16.298 -        OUTER: for (Entry<String, Map<RemoteIndex, Collection<String>>> e : occ.entrySet()) {
  16.299 -            long[] currentSpan = hashes.get(e.getKey());
  16.300 -
  16.301 -            for (Iterator<Entry<long[], DuplicateDescription>> it = result.entrySet().iterator(); it.hasNext();) {
  16.302 -                Entry<long[], DuplicateDescription> span = it.next();
  16.303 -
  16.304 -                if (span.getKey()[0] <= currentSpan[0] && span.getKey()[1] >= currentSpan[1]) {
  16.305 -                    continue OUTER;
  16.306 -                }
  16.307 -
  16.308 -                if (currentSpan[0] <= span.getKey()[0] && currentSpan[1] >= span.getKey()[1]) {
  16.309 -                    it.remove();
  16.310 -                }
  16.311 -            }
  16.312 -
  16.313 -            if (currentSpan[0] == (-1) || currentSpan[1] == (-1)) continue;
  16.314 -            
  16.315 -            seen.add(currentSpan);
  16.316 -            
  16.317 -            String longest = e.getKey();
  16.318 -            List<Span> foundDuplicates = new LinkedList<Span>();
  16.319 -
  16.320 -            for (Entry<RemoteIndex, Collection<String>> root2Occurrences : e.getValue().entrySet()) {
  16.321 -                FileObject localRoot = URLMapper.findFileObject(root2Occurrences.getKey().getLocalFolder());
  16.322 -
  16.323 -                for (String cand : root2Occurrences.getValue()) {
  16.324 -                    FileObject o = localRoot.getFileObject(cand);
  16.325 -
  16.326 -                    if (o == null) continue; //XXX log!
  16.327 -                    if (areEquivalent(currentFile, o)) continue;
  16.328 -                    
  16.329 -                    foundDuplicates.add(new Span(o, -1, -1));
  16.330 -                }
  16.331 -            }
  16.332 -
  16.333 -            if (foundDuplicates.isEmpty()) continue;
  16.334 -            
  16.335 -            DuplicateDescription current = DuplicateDescription.of(foundDuplicates, getValue(longest), longest);
  16.336 -
  16.337 -            result.put(currentSpan, current);
  16.338 -        }
  16.339 -
  16.340 -        return new LinkedList<DuplicateDescription>(result.values());
  16.341 -    }
  16.342 -
  16.343 -    private static boolean areEquivalent(FileObject f1, FileObject f2) {
  16.344 -        return f1.equals(f2);
  16.345 -    }
  16.346 -
  16.347 -    private static long getValue(String encoded) {
  16.348 -        return Long.parseLong(encoded.substring(encoded.lastIndexOf(":") + 1));
  16.349 -    }
  16.350 -
  16.351 -    private static <T> TreeMap<String, T> hashMap() {
  16.352 -        return new TreeMap<String, T>(new Comparator<String>() {
  16.353 -            public int compare(String arg0, String arg1) {
  16.354 -                return (int) Math.signum(getValue(arg1) - getValue(arg0));
  16.355 -            }
  16.356 -        });
  16.357 -    }
  16.358 -
  16.359 -    private static boolean subsumes(DuplicateDescription bigger, DuplicateDescription smaller) {
  16.360 -        Set<FileObject> bFiles = new HashSet<FileObject>();
  16.361 -
  16.362 -        for (Span s : bigger.dupes) {
  16.363 -            bFiles.add(s.file);
  16.364 -        }
  16.365 -
  16.366 -        Set<FileObject> sFiles = new HashSet<FileObject>();
  16.367 -
  16.368 -        for (Span s : smaller.dupes) {
  16.369 -            sFiles.add(s.file);
  16.370 -        }
  16.371 -
  16.372 -        if (!bFiles.equals(sFiles)) return false;
  16.373 -
  16.374 -        Span testAgainst = bigger.dupes.get(0);
  16.375 -
  16.376 -        for (Span s : smaller.dupes) {
  16.377 -            if (s.file == testAgainst.file) {
  16.378 -                if (   (testAgainst.startOff <= s.startOff && testAgainst.endOff > s.endOff)
  16.379 -                    || (testAgainst.startOff < s.startOff && testAgainst.endOff >= s.endOff)) {
  16.380 -                    return true;
  16.381 -                }
  16.382 -            }
  16.383 -        }
  16.384 -
  16.385 -        return false;
  16.386 -    }
  16.387 -
  16.388 -    public static Map<String, Collection<? extends String>> containsHash(IndexReader reader, Iterable<? extends String> hashes) throws IOException {
  16.389 -        Map<String, Collection<? extends String>> result = new LinkedHashMap<String, Collection<? extends String>>();
  16.390 -
  16.391 -        for (String hash : hashes) {
  16.392 -            Collection<String> found = new LinkedList<String>();
  16.393 -            Query query = new TermQuery(new Term("hash", hash));
  16.394 -            Searcher s = new IndexSearcher(reader);
  16.395 -            BitSet matchingDocuments = new BitSet(reader.maxDoc());
  16.396 -            Collector c = new BitSetCollector(matchingDocuments);
  16.397 -
  16.398 -            s.search(query, c);
  16.399 -
  16.400 -            boolean wasFound = false;
  16.401 -
  16.402 -            for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum + 1)) {
  16.403 -                final Document doc = reader.document(docNum);
  16.404 -
  16.405 -                found.addAll(Arrays.asList(doc.getValues("path")));
  16.406 -                wasFound = true;
  16.407 -            }
  16.408 -
  16.409 -            if (wasFound) {
  16.410 -                result.put(hash, found);
  16.411 -            }
  16.412 -        }
  16.413 -
  16.414 -        return result;
  16.415 -    }
  16.416 -}
    17.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/examples/Bundle.properties	Fri Jan 27 13:35:56 2012 +0100
    17.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/examples/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
    17.3 @@ -43,3 +43,4 @@
    17.4  double-checked-locking-fix=Double Checked Locking
    17.5  new-string=New String Creation
    17.6  lambda-candidate=Find candidates for Lambda expression
    17.7 +ExamplesList.pattern.contentType=text/x-javahints
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/examples/ExamplesList.form	Sat Feb 11 18:35:10 2012 +0100
    18.3 @@ -0,0 +1,95 @@
    18.4 +<?xml version="1.0" encoding="UTF-8" ?>
    18.5 +
    18.6 +<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    18.7 +  <AuxValues>
    18.8 +    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
    18.9 +    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   18.10 +    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   18.11 +    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
   18.12 +    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   18.13 +    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   18.14 +    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   18.15 +    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   18.16 +    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   18.17 +  </AuxValues>
   18.18 +
   18.19 +  <Layout>
   18.20 +    <DimensionLayout dim="0">
   18.21 +      <Group type="103" groupAlignment="0" attributes="0">
   18.22 +          <Group type="102" alignment="1" attributes="0">
   18.23 +              <EmptySpace max="-2" attributes="0"/>
   18.24 +              <Group type="103" groupAlignment="1" attributes="0">
   18.25 +                  <Component id="jScrollPane2" alignment="0" pref="376" max="32767" attributes="0"/>
   18.26 +                  <Component id="jScrollPane1" alignment="0" pref="376" max="32767" attributes="0"/>
   18.27 +                  <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
   18.28 +              </Group>
   18.29 +              <EmptySpace max="-2" attributes="0"/>
   18.30 +          </Group>
   18.31 +      </Group>
   18.32 +    </DimensionLayout>
   18.33 +    <DimensionLayout dim="1">
   18.34 +      <Group type="103" groupAlignment="0" attributes="0">
   18.35 +          <Group type="102" alignment="0" attributes="0">
   18.36 +              <EmptySpace max="-2" attributes="0"/>
   18.37 +              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
   18.38 +              <EmptySpace max="-2" attributes="0"/>
   18.39 +              <Component id="jScrollPane1" pref="130" max="32767" attributes="0"/>
   18.40 +              <EmptySpace max="-2" attributes="0"/>
   18.41 +              <Component id="jScrollPane2" min="-2" pref="119" max="-2" attributes="0"/>
   18.42 +              <EmptySpace max="-2" attributes="0"/>
   18.43 +          </Group>
   18.44 +      </Group>
   18.45 +    </DimensionLayout>
   18.46 +  </Layout>
   18.47 +  <SubComponents>
   18.48 +    <Component class="javax.swing.JLabel" name="jLabel1">
   18.49 +      <Properties>
   18.50 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   18.51 +          <Connection code="convertor.getHeader()" type="code"/>
   18.52 +        </Property>
   18.53 +      </Properties>
   18.54 +    </Component>
   18.55 +    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
   18.56 +      <AuxValues>
   18.57 +        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   18.58 +      </AuxValues>
   18.59 +
   18.60 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   18.61 +      <SubComponents>
   18.62 +        <Component class="javax.swing.JList" name="list">
   18.63 +          <Properties>
   18.64 +            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
   18.65 +              <StringArray count="5">
   18.66 +                <StringItem index="0" value="Item 1"/>
   18.67 +                <StringItem index="1" value="Item 2"/>
   18.68 +                <StringItem index="2" value="Item 3"/>
   18.69 +                <StringItem index="3" value="Item 4"/>
   18.70 +                <StringItem index="4" value="Item 5"/>
   18.71 +              </StringArray>
   18.72 +            </Property>
   18.73 +          </Properties>
   18.74 +          <Events>
   18.75 +            <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseClicked"/>
   18.76 +            <EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="listValueChanged"/>
   18.77 +          </Events>
   18.78 +        </Component>
   18.79 +      </SubComponents>
   18.80 +    </Container>
   18.81 +    <Container class="javax.swing.JScrollPane" name="jScrollPane2">
   18.82 +      <AuxValues>
   18.83 +        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   18.84 +      </AuxValues>
   18.85 +
   18.86 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   18.87 +      <SubComponents>
   18.88 +        <Component class="javax.swing.JEditorPane" name="pattern">
   18.89 +          <Properties>
   18.90 +            <Property name="contentType" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   18.91 +              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/examples/Bundle.properties" key="ExamplesList.pattern.contentType" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   18.92 +            </Property>
   18.93 +          </Properties>
   18.94 +        </Component>
   18.95 +      </SubComponents>
   18.96 +    </Container>
   18.97 +  </SubComponents>
   18.98 +</Form>
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/examples/ExamplesList.java	Sat Feb 11 18:35:10 2012 +0100
    19.3 @@ -0,0 +1,223 @@
    19.4 +/*
    19.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    19.6 + *
    19.7 + * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    19.8 + *
    19.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   19.10 + * Other names may be trademarks of their respective owners.
   19.11 + *
   19.12 + * The contents of this file are subject to the terms of either the GNU
   19.13 + * General Public License Version 2 only ("GPL") or the Common
   19.14 + * Development and Distribution License("CDDL") (collectively, the
   19.15 + * "License"). You may not use this file except in compliance with the
   19.16 + * License. You can obtain a copy of the License at
   19.17 + * http://www.netbeans.org/cddl-gplv2.html
   19.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   19.19 + * specific language governing permissions and limitations under the
   19.20 + * License.  When distributing the software, include this License Header
   19.21 + * Notice in each file and include the License file at
   19.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   19.23 + * particular file as subject to the "Classpath" exception as provided
   19.24 + * by Oracle in the GPL Version 2 section of the License file that
   19.25 + * accompanied this code. If applicable, add the following below the
   19.26 + * License Header, with the fields enclosed by brackets [] replaced by
   19.27 + * your own identifying information:
   19.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   19.29 + *
   19.30 + * If you wish your version of this file to be governed by only the CDDL
   19.31 + * or only the GPL Version 2, indicate your decision by adding
   19.32 + * "[Contributor] elects to include this software in this distribution
   19.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   19.34 + * single choice of license, a recipient has the option to distribute
   19.35 + * your version of this file under either the CDDL, the GPL Version 2 or
   19.36 + * to extend the choice of license to its licensees as provided above.
   19.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   19.38 + * Version 2 license, then the option applies only if the new code is
   19.39 + * made subject to such option by the copyright holder.
   19.40 + *
   19.41 + * Contributor(s):
   19.42 + *
   19.43 + * Portions Copyrighted 2010 Sun Microsystems, Inc.
   19.44 + */
   19.45 +package org.netbeans.modules.jackpot30.impl.examples;
   19.46 +
   19.47 +import java.awt.Component;
   19.48 +import java.awt.Dialog;
   19.49 +import java.awt.Rectangle;
   19.50 +import java.util.Collections;
   19.51 +import java.util.Set;
   19.52 +import javax.swing.DefaultListCellRenderer;
   19.53 +import javax.swing.DefaultListModel;
   19.54 +import javax.swing.JList;
   19.55 +import javax.swing.text.BadLocationException;
   19.56 +import org.netbeans.modules.jackpot30.impl.examples.Example.Option;
   19.57 +import org.openide.DialogDescriptor;
   19.58 +import org.openide.DialogDisplayer;
   19.59 +import org.openide.util.Exceptions;
   19.60 +
   19.61 +/**
   19.62 + *
   19.63 + * @author lahvac
   19.64 + */
   19.65 +public class ExamplesList<T> extends javax.swing.JPanel {
   19.66 +
   19.67 +    private final DialogDescription<T> convertor;
   19.68 +    private final Class<T> dataClass;
   19.69 +
   19.70 +    public ExamplesList(Iterable<? extends T> data, DialogDescription<T> convertor, Class<T> dataClass, Set<Option> require, Set<Option> forbidden) {
   19.71 +        this.convertor = convertor;
   19.72 +        this.dataClass = dataClass;
   19.73 +        
   19.74 +        initComponents();
   19.75 +
   19.76 +        DefaultListModel listModel = new DefaultListModel();
   19.77 +
   19.78 +        for (T t : data) {
   19.79 +            Set<Option> options = convertor.getOptions(t);
   19.80 +            if (!options.containsAll(require)) continue;
   19.81 +            if (!Collections.disjoint(options, forbidden)) continue;
   19.82 +            
   19.83 +            listModel.addElement(t);
   19.84 +        }
   19.85 +
   19.86 +        list.setModel(listModel);
   19.87 +        list.setCellRenderer(new ExamplesRenderer());
   19.88 +        list.setSelectedIndex(0);
   19.89 +    }
   19.90 +
   19.91 +    /** This method is called from within the constructor to
   19.92 +     * initialize the form.
   19.93 +     * WARNING: Do NOT modify this code. The content of this method is
   19.94 +     * always regenerated by the Form Editor.
   19.95 +     */
   19.96 +    @SuppressWarnings("unchecked")
   19.97 +    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   19.98 +    private void initComponents() {
   19.99 +
  19.100 +        jLabel1 = new javax.swing.JLabel();
  19.101 +        jScrollPane1 = new javax.swing.JScrollPane();
  19.102 +        list = new javax.swing.JList();
  19.103 +        jScrollPane2 = new javax.swing.JScrollPane();
  19.104 +        pattern = new javax.swing.JEditorPane();
  19.105 +
  19.106 +        jLabel1.setText(convertor.getHeader());
  19.107 +
  19.108 +        list.setModel(new javax.swing.AbstractListModel() {
  19.109 +            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  19.110 +            public int getSize() { return strings.length; }
  19.111 +            public Object getElementAt(int i) { return strings[i]; }
  19.112 +        });
  19.113 +        list.addMouseListener(new java.awt.event.MouseAdapter() {
  19.114 +            public void mouseClicked(java.awt.event.MouseEvent evt) {
  19.115 +                listMouseClicked(evt);
  19.116 +            }
  19.117 +        });
  19.118 +        list.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  19.119 +            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
  19.120 +                listValueChanged(evt);
  19.121 +            }
  19.122 +        });
  19.123 +        jScrollPane1.setViewportView(list);
  19.124 +
  19.125 +        pattern.setContentType(org.openide.util.NbBundle.getMessage(ExamplesList.class, "ExamplesList.pattern.contentType")); // NOI18N
  19.126 +        jScrollPane2.setViewportView(pattern);
  19.127 +
  19.128 +        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  19.129 +        this.setLayout(layout);
  19.130 +        layout.setHorizontalGroup(
  19.131 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  19.132 +            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  19.133 +                .addContainerGap()
  19.134 +                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  19.135 +                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
  19.136 +                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
  19.137 +                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
  19.138 +                .addContainerGap())
  19.139 +        );
  19.140 +        layout.setVerticalGroup(
  19.141 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  19.142 +            .addGroup(layout.createSequentialGroup()
  19.143 +                .addContainerGap()
  19.144 +                .addComponent(jLabel1)
  19.145 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  19.146 +                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
  19.147 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  19.148 +                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
  19.149 +                .addContainerGap())
  19.150 +        );
  19.151 +    }// </editor-fold>//GEN-END:initComponents
  19.152 +
  19.153 +    private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
  19.154 +        if (evt.getClickCount() > 1) {
  19.155 +            desc.setValue(DialogDescriptor.OK_OPTION);
  19.156 +            dialog.setVisible(false);
  19.157 +        }
  19.158 +    }//GEN-LAST:event_listMouseClicked
  19.159 +
  19.160 +    private void listValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listValueChanged
  19.161 +        T ex = dataClass.cast(list.getSelectedValue());
  19.162 +
  19.163 +        pattern.setText(convertor.getCode(ex));
  19.164 +        
  19.165 +        try {
  19.166 +            Rectangle rect = pattern.modelToView(0);
  19.167 +
  19.168 +            if (rect != null) {
  19.169 +                pattern.scrollRectToVisible(rect);
  19.170 +            }
  19.171 +        } catch (BadLocationException ex1) {
  19.172 +            Exceptions.printStackTrace(ex1);
  19.173 +        }
  19.174 +    }//GEN-LAST:event_listValueChanged
  19.175 +
  19.176 +    // Variables declaration - do not modify//GEN-BEGIN:variables
  19.177 +    private javax.swing.JLabel jLabel1;
  19.178 +    private javax.swing.JScrollPane jScrollPane1;
  19.179 +    private javax.swing.JScrollPane jScrollPane2;
  19.180 +    private javax.swing.JList list;
  19.181 +    private javax.swing.JEditorPane pattern;
  19.182 +    // End of variables declaration//GEN-END:variables
  19.183 +
  19.184 +    private DialogDescriptor desc;
  19.185 +    private Dialog           dialog;
  19.186 +
  19.187 +    public void setDialog(DialogDescriptor desc, Dialog dialog) {
  19.188 +        this.desc = desc;
  19.189 +        this.dialog = dialog;
  19.190 +    }
  19.191 +
  19.192 +    public T getSelectedExample() {
  19.193 +        return dataClass.cast(list.getSelectedValue());
  19.194 +    }
  19.195 +    
  19.196 +    private class ExamplesRenderer extends DefaultListCellRenderer {
  19.197 +        @Override
  19.198 +        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  19.199 +            value = convertor.getDisplayName(dataClass.cast(value));
  19.200 +            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  19.201 +        }
  19.202 +    }
  19.203 +
  19.204 +    public static <T> T chooseExample(Iterable<? extends T> examplesList, DialogDescription<T> convertor, Class<T> dataClass, Set<Option> require, Set<Option> forbidden) {
  19.205 +        ExamplesList<T> examples = new ExamplesList<T>(examplesList, convertor, dataClass, require, forbidden);
  19.206 +        DialogDescriptor dd = new DialogDescriptor(examples, convertor.getCaption(), true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, null);
  19.207 +        Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
  19.208 +
  19.209 +        examples.setDialog(dd, dialog);
  19.210 +        dialog.setVisible(true);
  19.211 +
  19.212 +        if (dd.getValue() == DialogDescriptor.OK_OPTION) {
  19.213 +            return examples.getSelectedExample();
  19.214 +        }
  19.215 +
  19.216 +        return null;
  19.217 +    }
  19.218 +
  19.219 +    public interface DialogDescription<T> {
  19.220 +        public String getCaption();
  19.221 +        public String getHeader();
  19.222 +        public String getDisplayName(T t);
  19.223 +        public String getCode(T t);
  19.224 +        public Set<Option> getOptions(T t);
  19.225 +    }
  19.226 +}
    20.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/hints/FindDuplicates.java	Fri Jan 27 13:35:56 2012 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,133 +0,0 @@
    20.4 -/*
    20.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    20.6 - *
    20.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    20.8 - *
    20.9 - * The contents of this file are subject to the terms of either the GNU
   20.10 - * General Public License Version 2 only ("GPL") or the Common
   20.11 - * Development and Distribution License("CDDL") (collectively, the
   20.12 - * "License"). You may not use this file except in compliance with the
   20.13 - * License. You can obtain a copy of the License at
   20.14 - * http://www.netbeans.org/cddl-gplv2.html
   20.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   20.16 - * specific language governing permissions and limitations under the
   20.17 - * License.  When distributing the software, include this License Header
   20.18 - * Notice in each file and include the License file at
   20.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   20.20 - * particular file as subject to the "Classpath" exception as provided
   20.21 - * by Sun in the GPL Version 2 section of the License file that
   20.22 - * accompanied this code. If applicable, add the following below the
   20.23 - * License Header, with the fields enclosed by brackets [] replaced by
   20.24 - * your own identifying information:
   20.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   20.26 - *
   20.27 - * If you wish your version of this file to be governed by only the CDDL
   20.28 - * or only the GPL Version 2, indicate your decision by adding
   20.29 - * "[Contributor] elects to include this software in this distribution
   20.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   20.31 - * single choice of license, a recipient has the option to distribute
   20.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   20.33 - * to extend the choice of license to its licensees as provided above.
   20.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   20.35 - * Version 2 license, then the option applies only if the new code is
   20.36 - * made subject to such option by the copyright holder.
   20.37 - *
   20.38 - * Contributor(s):
   20.39 - *
   20.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   20.41 - */
   20.42 -
   20.43 -package org.netbeans.modules.jackpot30.impl.hints;
   20.44 -
   20.45 -import java.util.Collection;
   20.46 -import java.util.Collections;
   20.47 -import java.util.Iterator;
   20.48 -import java.util.LinkedList;
   20.49 -import java.util.List;
   20.50 -import java.util.Map;
   20.51 -import java.util.concurrent.atomic.AtomicBoolean;
   20.52 -import java.util.logging.Level;
   20.53 -import java.util.logging.Logger;
   20.54 -import org.netbeans.api.java.source.CancellableTask;
   20.55 -import org.netbeans.api.java.source.CompilationInfo;
   20.56 -import org.netbeans.api.java.source.JavaSource.Phase;
   20.57 -import org.netbeans.api.java.source.JavaSource.Priority;
   20.58 -import org.netbeans.api.java.source.JavaSourceTaskFactory;
   20.59 -import org.netbeans.api.java.source.support.EditorAwareJavaSourceTaskFactory;
   20.60 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates;
   20.61 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   20.62 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.RemoteDuplicatesIndex;
   20.63 -import org.netbeans.spi.editor.hints.ErrorDescription;
   20.64 -import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
   20.65 -import org.netbeans.spi.editor.hints.HintsController;
   20.66 -import org.netbeans.spi.editor.hints.Severity;
   20.67 -import org.openide.filesystems.FileObject;
   20.68 -import org.openide.util.NbCollections;
   20.69 -import org.openide.util.lookup.ServiceProvider;
   20.70 -
   20.71 -/**
   20.72 - *
   20.73 - * @author lahvac
   20.74 - */
   20.75 -public class FindDuplicates implements CancellableTask<CompilationInfo> {
   20.76 -
   20.77 -    private final AtomicBoolean cancel = new AtomicBoolean();
   20.78 -    
   20.79 -    public void run(CompilationInfo info) throws Exception {
   20.80 -        cancel.set(false);
   20.81 -
   20.82 -        long start = System.currentTimeMillis();
   20.83 -        try {
   20.84 -            Collection<? extends ErrorDescription> eds = computeErrorDescription(info);
   20.85 -
   20.86 -            if (cancel.get()) return;
   20.87 -
   20.88 -            if (eds == null) {
   20.89 -                eds = Collections.emptyList();
   20.90 -            }
   20.91 -
   20.92 -            HintsController.setErrors(info.getFileObject(), FindDuplicates.class.getName(), eds);
   20.93 -        } finally {
   20.94 -            long end = System.currentTimeMillis();
   20.95 -
   20.96 -            Logger.getLogger("TIMER").log(Level.FINE, "Duplicates in editor", new Object[] {info.getFileObject(), end - start});
   20.97 -        }
   20.98 -    }
   20.99 -
  20.100 -    private Collection<? extends ErrorDescription> computeErrorDescription(CompilationInfo info) throws Exception {
  20.101 -        List<ErrorDescription> result = new LinkedList<ErrorDescription>();
  20.102 -
  20.103 -        Map<String, long[]> encoded = ComputeDuplicates.encodeGeneralized(info);
  20.104 -        Iterator<? extends DuplicateDescription> duplicates = RemoteDuplicatesIndex.findDuplicates(encoded, info.getFileObject()).iterator();
  20.105 -
  20.106 -        for (DuplicateDescription dd : NbCollections.iterable(duplicates)) {
  20.107 -            long[] spans = encoded.get(dd.hash);
  20.108 -
  20.109 -            for (int c = 0; c < spans.length; c += 2) {
  20.110 -                if (cancel.get()) return null;
  20.111 -                result.add(ErrorDescriptionFactory.createErrorDescription(Severity.WARNING, "Duplicate of code from " + dd.dupes.get(0).file, info.getFileObject(), (int) spans[c], (int) spans[c + 1]));
  20.112 -            }
  20.113 -        }
  20.114 -
  20.115 -        return result;
  20.116 -    }
  20.117 -    
  20.118 -    public void cancel() {
  20.119 -        cancel.set(true);
  20.120 -    }
  20.121 -
  20.122 -    @ServiceProvider(service=JavaSourceTaskFactory.class)
  20.123 -    public static final class FactoryImpl extends EditorAwareJavaSourceTaskFactory {
  20.124 -
  20.125 -        public FactoryImpl() {
  20.126 -            super(Phase.RESOLVED, Priority.LOW);
  20.127 -        }
  20.128 -
  20.129 -        @Override
  20.130 -        protected CancellableTask<CompilationInfo> createTask(FileObject file) {
  20.131 -            return new FindDuplicates();
  20.132 -        }
  20.133 -        
  20.134 -    }
  20.135 -
  20.136 -}
    21.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/AbstractLuceneIndex.java	Fri Jan 27 13:35:56 2012 +0100
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,430 +0,0 @@
    21.4 -/*
    21.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    21.6 - *
    21.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    21.8 - *
    21.9 - * The contents of this file are subject to the terms of either the GNU
   21.10 - * General Public License Version 2 only ("GPL") or the Common
   21.11 - * Development and Distribution License("CDDL") (collectively, the
   21.12 - * "License"). You may not use this file except in compliance with the
   21.13 - * License. You can obtain a copy of the License at
   21.14 - * http://www.netbeans.org/cddl-gplv2.html
   21.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   21.16 - * specific language governing permissions and limitations under the
   21.17 - * License.  When distributing the software, include this License Header
   21.18 - * Notice in each file and include the License file at
   21.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   21.20 - * particular file as subject to the "Classpath" exception as provided
   21.21 - * by Sun in the GPL Version 2 section of the License file that
   21.22 - * accompanied this code. If applicable, add the following below the
   21.23 - * License Header, with the fields enclosed by brackets [] replaced by
   21.24 - * your own identifying information:
   21.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   21.26 - *
   21.27 - * If you wish your version of this file to be governed by only the CDDL
   21.28 - * or only the GPL Version 2, indicate your decision by adding
   21.29 - * "[Contributor] elects to include this software in this distribution
   21.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   21.31 - * single choice of license, a recipient has the option to distribute
   21.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   21.33 - * to extend the choice of license to its licensees as provided above.
   21.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   21.35 - * Version 2 license, then the option applies only if the new code is
   21.36 - * made subject to such option by the copyright holder.
   21.37 - *
   21.38 - * Contributor(s):
   21.39 - *
   21.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   21.41 - */
   21.42 -
   21.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   21.44 -
   21.45 -import com.sun.source.tree.CompilationUnitTree;
   21.46 -import com.sun.source.tree.Tree;
   21.47 -import com.sun.source.util.TreePath;
   21.48 -import com.sun.source.util.TreePathScanner;
   21.49 -import java.io.ByteArrayInputStream;
   21.50 -import java.io.ByteArrayOutputStream;
   21.51 -import java.io.IOException;
   21.52 -import java.net.URL;
   21.53 -import java.util.BitSet;
   21.54 -import java.util.Collection;
   21.55 -import java.util.Collections;
   21.56 -import java.util.HashMap;
   21.57 -import java.util.HashSet;
   21.58 -import java.util.Iterator;
   21.59 -import java.util.List;
   21.60 -import java.util.Map;
   21.61 -import java.util.Set;
   21.62 -import java.util.logging.Level;
   21.63 -import java.util.logging.Logger;
   21.64 -import java.util.zip.DataFormatException;
   21.65 -import javax.lang.model.type.ArrayType;
   21.66 -import javax.lang.model.type.TypeKind;
   21.67 -import javax.lang.model.type.TypeMirror;
   21.68 -import org.apache.lucene.analysis.TokenStream;
   21.69 -import org.apache.lucene.analysis.tokenattributes.TermAttribute;
   21.70 -import org.apache.lucene.document.CompressionTools;
   21.71 -import org.apache.lucene.document.Document;
   21.72 -import org.apache.lucene.document.Field;
   21.73 -import org.apache.lucene.document.FieldSelector;
   21.74 -import org.apache.lucene.document.FieldSelectorResult;
   21.75 -import org.apache.lucene.index.IndexReader;
   21.76 -import org.apache.lucene.index.Term;
   21.77 -import org.apache.lucene.queryParser.ParseException;
   21.78 -import org.apache.lucene.search.BooleanClause;
   21.79 -import org.apache.lucene.search.BooleanQuery;
   21.80 -import org.apache.lucene.search.Collector;
   21.81 -import org.apache.lucene.search.IndexSearcher;
   21.82 -import org.apache.lucene.search.PhraseQuery;
   21.83 -import org.apache.lucene.search.Query;
   21.84 -import org.apache.lucene.search.Scorer;
   21.85 -import org.apache.lucene.search.Searcher;
   21.86 -import org.apache.lucene.search.TermQuery;
   21.87 -import org.apache.lucene.search.TopDocs;
   21.88 -import org.netbeans.api.annotations.common.NonNull;
   21.89 -import org.netbeans.api.annotations.common.NullAllowed;
   21.90 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
   21.91 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
   21.92 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
   21.93 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription.AdditionalQueryConstraints;
   21.94 -import org.openide.util.Exceptions;
   21.95 -
   21.96 -/**
   21.97 - *
   21.98 - * @author lahvac
   21.99 - */
  21.100 -public abstract class AbstractLuceneIndex extends Index {
  21.101 -
  21.102 -    public static final int MAJOR_VERSION = 1;
  21.103 -    //2: partial attribution added (erased types that occur in the file)
  21.104 -    public static final int MINOR_VERSION = 2;
  21.105 -    
  21.106 -    private final int  stripLength;
  21.107 -    private final boolean readOnly;
  21.108 -    private final boolean storeFullSourceCode;
  21.109 -
  21.110 -    protected AbstractLuceneIndex(int stripLength, boolean readOnly, boolean storeFullSourceCode) {
  21.111 -        this.stripLength = stripLength;
  21.112 -        this.readOnly = readOnly;
  21.113 -        this.storeFullSourceCode = storeFullSourceCode;
  21.114 -     }
  21.115 -
  21.116 -    public final IndexWriter openForWriting() throws IOException {
  21.117 -        if (readOnly) throw new UnsupportedOperationException();
  21.118 -         return new IndexWriterImpl();
  21.119 -     }
  21.120 -
  21.121 -    protected abstract IndexReader createReader() throws IOException;
  21.122 -    protected abstract org.apache.lucene.index.IndexWriter createWriter() throws IOException;
  21.123 -
  21.124 -    @Override
  21.125 -    public Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException {
  21.126 -        return findCandidates(pattern, false).keySet();
  21.127 -    }
  21.128 -
  21.129 -    @Override
  21.130 -    public Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException {
  21.131 -        return findCandidates(pattern, true);
  21.132 -    }
  21.133 -
  21.134 -    private Map<String, Map<String, Integer>> findCandidates(BulkPattern pattern, boolean withFrequencies) throws IOException {
  21.135 -        IndexReader reader = createReader();
  21.136 -
  21.137 -        if (reader == null) {
  21.138 -             return Collections.emptyMap();
  21.139 -        }
  21.140 -
  21.141 -        try {
  21.142 -        Searcher s = new IndexSearcher(reader);
  21.143 -        BitSet matchingDocuments = new BitSet(reader.maxDoc());
  21.144 -        Collector c = new BitSetCollector(matchingDocuments);
  21.145 -
  21.146 -        try {
  21.147 -            s.search(query(pattern), c);
  21.148 -        } catch (ParseException ex) {
  21.149 -            throw new IOException(ex);
  21.150 -        }
  21.151 -
  21.152 -        Map<String, Map<String, Integer>> result = new HashMap<String, Map<String, Integer>>();
  21.153 -
  21.154 -        for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum+1)) {
  21.155 -            try {
  21.156 -                final Document doc = reader.document(docNum, new FieldSelector() {
  21.157 -                    public FieldSelectorResult accept(String string) {
  21.158 -                        return "encoded".equals(string) || "path".equals(string) ? FieldSelectorResult.LOAD : FieldSelectorResult.NO_LOAD;
  21.159 -                    }
  21.160 -                });
  21.161 -                
  21.162 -                ByteArrayInputStream in = new ByteArrayInputStream(CompressionTools.decompress(doc.getField("encoded").getBinaryValue()));
  21.163 -
  21.164 -                try {
  21.165 -                    Map<String, Integer> freqs;
  21.166 -                    boolean matches;
  21.167 -
  21.168 -                    if (withFrequencies) {
  21.169 -                        freqs = BulkSearch.getDefault().matchesWithFrequencies(in, pattern);
  21.170 -                        matches = !freqs.isEmpty();
  21.171 -                    } else {
  21.172 -                        freqs = null;
  21.173 -                        matches = BulkSearch.getDefault().matches(in, pattern);
  21.174 -                    }
  21.175 -
  21.176 -                    if (matches) {
  21.177 -                        result.put(doc.getField("path").stringValue(), freqs);
  21.178 -                        continue;
  21.179 -                    }
  21.180 -                } finally {
  21.181 -                    in.close();
  21.182 -                }
  21.183 -            } catch (DataFormatException ex) {
  21.184 -                throw new IOException(ex);
  21.185 -            }
  21.186 -        }
  21.187 -
  21.188 -        return result;
  21.189 -        } finally {
  21.190 -            //TODO: might be better to cache the index/reader(s)
  21.191 -            reader.close();
  21.192 -        }
  21.193 -    }
  21.194 -
  21.195 -    private Query query(BulkPattern pattern) throws ParseException {
  21.196 -        BooleanQuery result = new BooleanQuery();
  21.197 -
  21.198 -        for (int cntr = 0; cntr < pattern.getIdentifiers().size(); cntr++) {
  21.199 -            assert !pattern.getRequiredContent().get(cntr).isEmpty();
  21.200 -            
  21.201 -            BooleanQuery emb = new BooleanQuery();
  21.202 -            
  21.203 -            for (List<String> c : pattern.getRequiredContent().get(cntr)) {
  21.204 -                if (c.isEmpty()) continue;
  21.205 -                
  21.206 -                PhraseQuery pq = new PhraseQuery();
  21.207 -                
  21.208 -                for (String s : c) {
  21.209 -                    pq.add(new Term("content", s));
  21.210 -                }
  21.211 -                
  21.212 -                emb.add(pq, BooleanClause.Occur.MUST);
  21.213 -            }
  21.214 -            
  21.215 -            AdditionalQueryConstraints additionalConstraints = pattern.getAdditionalConstraints().get(cntr);
  21.216 -
  21.217 -            if (additionalConstraints != null && !additionalConstraints.requiredErasedTypes.isEmpty()) {
  21.218 -                BooleanQuery constraintsQuery = new BooleanQuery();
  21.219 -
  21.220 -                constraintsQuery.add(new TermQuery(new Term("attributed", "false")), BooleanClause.Occur.SHOULD);
  21.221 -
  21.222 -                BooleanQuery constr = new BooleanQuery();
  21.223 -
  21.224 -                for (String tc : additionalConstraints.requiredErasedTypes) {
  21.225 -                    constr.add(new TermQuery(new Term("erasedTypes", tc)), BooleanClause.Occur.MUST);
  21.226 -                }
  21.227 -
  21.228 -                constraintsQuery.add(constr, BooleanClause.Occur.SHOULD);
  21.229 -                emb.add(constraintsQuery, BooleanClause.Occur.MUST);
  21.230 -            }
  21.231 -
  21.232 -            result.add(emb, BooleanClause.Occur.SHOULD);
  21.233 -        }
  21.234 -
  21.235 -        return result;
  21.236 -    }
  21.237 -
  21.238 -    public CharSequence getSourceCode(String relativePath) {
  21.239 -        try {
  21.240 -            IndexReader reader = createReader();
  21.241 -
  21.242 -            if (reader == null) {
  21.243 -                return "";
  21.244 -            }
  21.245 -
  21.246 -            Searcher s = new IndexSearcher(reader);
  21.247 -            TopDocs topDocs = s.search(new TermQuery(new Term("path", relativePath)), 1);
  21.248 -
  21.249 -            if (topDocs.totalHits < 1) return "";
  21.250 -
  21.251 -            Document doc = s.doc(topDocs.scoreDocs[0].doc, new FieldSelector() {
  21.252 -                public FieldSelectorResult accept(String string) {
  21.253 -                    return "sourceCode".equals(string) ? FieldSelectorResult.LOAD : FieldSelectorResult.NO_LOAD;
  21.254 -                }
  21.255 -            });
  21.256 -            
  21.257 -            return CompressionTools.decompressString(doc.getField("sourceCode").getBinaryValue()).replaceAll("\r\n", "\n")/*XXX*/;
  21.258 -        } catch (DataFormatException ex) {
  21.259 -            Exceptions.printStackTrace(ex);
  21.260 -            return "";
  21.261 -        } catch (IOException ex) {
  21.262 -            Exceptions.printStackTrace(ex);
  21.263 -            return "";
  21.264 -        }
  21.265 -    }
  21.266 -    
  21.267 -    public abstract @NonNull IndexInfo getIndexInfo();
  21.268 -    protected abstract void storeIndexInfo(@NonNull IndexInfo info) throws IOException;
  21.269 -
  21.270 -    private final class IndexWriterImpl extends IndexWriter {
  21.271 -
  21.272 -        private final org.apache.lucene.index.IndexWriter luceneWriter;
  21.273 -        private final IndexInfo info;
  21.274 -
  21.275 -        public IndexWriterImpl() throws IOException {
  21.276 -            luceneWriter = createWriter();
  21.277 -
  21.278 -            info = getIndexInfo();
  21.279 -        }
  21.280 -
  21.281 -        @Override
  21.282 -        public void record(URL source, final CompilationUnitTree cut, final @NullAllowed AttributionWrapper attributed) throws IOException {
  21.283 -            String relative = source.getPath().substring(stripLength);
  21.284 -            ByteArrayOutputStream out = null;
  21.285 -            EncodingContext ec = null;
  21.286 -            
  21.287 -            try {
  21.288 -                out = new ByteArrayOutputStream();
  21.289 -
  21.290 -                ec = new EncodingContext(out, false);
  21.291 -
  21.292 -                BulkSearch.getDefault().encode(cut, ec);
  21.293 -
  21.294 -                luceneWriter.deleteDocuments(new Term("path", relative));
  21.295 -            
  21.296 -                Document doc = new Document();
  21.297 -
  21.298 -                doc.add(new Field("content", new TokenStreamImpl(ec.getContent())));
  21.299 -                out.close();
  21.300 -                doc.add(new Field("encoded", CompressionTools.compress(out.toByteArray()), Field.Store.YES));
  21.301 -                if (storeFullSourceCode) {
  21.302 -                    doc.add(new Field("sourceCode", CompressionTools.compressString(cut.getSourceFile().getCharContent(false).toString()), Field.Store.YES));
  21.303 -                }
  21.304 -                doc.add(new Field("path", relative, Field.Store.YES, Field.Index.NOT_ANALYZED));
  21.305 -
  21.306 -                if (attributed != null) {
  21.307 -                    final Set<String> erased = new HashSet<String>();
  21.308 -
  21.309 -                    new TreePathScanner<Void, Void>() {
  21.310 -                        @Override
  21.311 -                        public Void scan(Tree tree, Void p) {
  21.312 -                            if (tree != null) {
  21.313 -                                TreePath tp = new TreePath(getCurrentPath(), tree);
  21.314 -                                TypeMirror type = attributed.trees.getTypeMirror(tp);
  21.315 -
  21.316 -                                if (type != null) {
  21.317 -                                    if (type.getKind() == TypeKind.ARRAY) {
  21.318 -                                        erased.add(attributed.types.erasure(type).toString());
  21.319 -                                        type = ((ArrayType) type).getComponentType();
  21.320 -                                    }
  21.321 -
  21.322 -                                    if (type.getKind().isPrimitive() || type.getKind() == TypeKind.DECLARED) {
  21.323 -                                        addErasedTypeAndSuperTypes(attributed, erased, type);
  21.324 -                                    }
  21.325 -                                }
  21.326 -
  21.327 -                                //bounds for type variables!!!
  21.328 -                            }
  21.329 -                            return super.scan(tree, p);
  21.330 -                        }
  21.331 -                    }.scan(cut, null);
  21.332 -
  21.333 -                    doc.add(new Field("attributed", "true", Field.Store.YES, Field.Index.NOT_ANALYZED));
  21.334 -                    doc.add(new Field("erasedTypes", new TokenStreamImpl(erased)));
  21.335 -                } else {
  21.336 -                    doc.add(new Field("attributed", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  21.337 -                }
  21.338 -                luceneWriter.addDocument(doc);
  21.339 -            } catch (ThreadDeath td) {
  21.340 -                throw td;
  21.341 -            } catch (Throwable t) {
  21.342 -                Logger.getLogger(FileBasedIndex.class.getName()).log(Level.WARNING, null, t);
  21.343 -            } finally {
  21.344 -                if (out != null) {
  21.345 -                    out.close();
  21.346 -                }
  21.347 -            }
  21.348 -        }
  21.349 -
  21.350 -        public void remove(String relativePath) throws IOException {
  21.351 -            luceneWriter.deleteDocuments(new Term("path", relativePath));
  21.352 -        }
  21.353 -
  21.354 -        public void clear() throws IOException {
  21.355 -            luceneWriter.deleteAll();
  21.356 -        }
  21.357 -
  21.358 -        public void close() throws IOException {
  21.359 -            info.majorVersion = MAJOR_VERSION;
  21.360 -            info.minorVersion = MINOR_VERSION;
  21.361 -            info.totalFiles = luceneWriter.numDocs();
  21.362 -            info.lastUpdate = System.currentTimeMillis();
  21.363 -            luceneWriter.optimize();
  21.364 -            luceneWriter.close();
  21.365 -            storeIndexInfo(info);
  21.366 -        }
  21.367 -    }
  21.368 -
  21.369 -    private static void addErasedTypeAndSuperTypes(AttributionWrapper attributed, Set<String> types, TypeMirror type) {
  21.370 -        if (type.getKind() == TypeKind.DECLARED) {
  21.371 -            if (types.add(attributed.types.erasure(type).toString())) {
  21.372 -                for (TypeMirror sup : attributed.types.directSupertypes(type)) {
  21.373 -                    addErasedTypeAndSuperTypes(attributed, types, sup);
  21.374 -                }
  21.375 -            }
  21.376 -        } else if (type.getKind().isPrimitive()) {
  21.377 -            types.add(type.toString());
  21.378 -        }
  21.379 -    }
  21.380 -
  21.381 -    public static final class TokenStreamImpl extends TokenStream {
  21.382 -
  21.383 -        private final Iterator<? extends String> tokens;
  21.384 -        private final TermAttribute termAtt;
  21.385 -
  21.386 -        public TokenStreamImpl(Iterable<? extends String> tokens) {
  21.387 -            this.tokens = tokens != null ? tokens.iterator() : /*???*/Collections.<String>emptyList().iterator();
  21.388 -            this.termAtt = addAttribute(TermAttribute.class);
  21.389 -        }
  21.390 -
  21.391 -        @Override
  21.392 -        public boolean incrementToken() throws IOException {
  21.393 -            if (!tokens.hasNext())
  21.394 -                return false;
  21.395 -
  21.396 -            String t = tokens.next();
  21.397 -
  21.398 -            termAtt.setTermBuffer(t);
  21.399 -            
  21.400 -            return true;
  21.401 -        }
  21.402 -    }
  21.403 -
  21.404 -    public static class BitSetCollector extends Collector {
  21.405 -
  21.406 -        private int docBase;
  21.407 -        public final BitSet bits;
  21.408 -
  21.409 -        public BitSetCollector(final BitSet bitSet) {
  21.410 -            assert bitSet != null;
  21.411 -            bits = bitSet;
  21.412 -        }
  21.413 -
  21.414 -        // ignore scorer
  21.415 -        public void setScorer(Scorer scorer) {
  21.416 -        }
  21.417 -
  21.418 -        // accept docs out of order (for a BitSet it doesn't matter)
  21.419 -        public boolean acceptsDocsOutOfOrder() {
  21.420 -          return true;
  21.421 -        }
  21.422 -
  21.423 -        public void collect(int doc) {
  21.424 -          bits.set(doc + docBase);
  21.425 -        }
  21.426 -
  21.427 -        public void setNextReader(IndexReader reader, int docBase) {
  21.428 -          this.docBase = docBase;
  21.429 -        }
  21.430 -
  21.431 -    }
  21.432 -
  21.433 -}
    22.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/Cache.java	Fri Jan 27 13:35:56 2012 +0100
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,217 +0,0 @@
    22.4 -/*
    22.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    22.6 - *
    22.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
    22.8 - *
    22.9 - * The contents of this file are subject to the terms of either the GNU
   22.10 - * General Public License Version 2 only ("GPL") or the Common
   22.11 - * Development and Distribution License("CDDL") (collectively, the
   22.12 - * "License"). You may not use this file except in compliance with the
   22.13 - * License. You can obtain a copy of the License at
   22.14 - * http://www.netbeans.org/cddl-gplv2.html
   22.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   22.16 - * specific language governing permissions and limitations under the
   22.17 - * License.  When distributing the software, include this License Header
   22.18 - * Notice in each file and include the License file at
   22.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   22.20 - * particular file as subject to the "Classpath" exception as provided
   22.21 - * by Sun in the GPL Version 2 section of the License file that
   22.22 - * accompanied this code. If applicable, add the following below the
   22.23 - * License Header, with the fields enclosed by brackets [] replaced by
   22.24 - * your own identifying information:
   22.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   22.26 - *
   22.27 - * If you wish your version of this file to be governed by only the CDDL
   22.28 - * or only the GPL Version 2, indicate your decision by adding
   22.29 - * "[Contributor] elects to include this software in this distribution
   22.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   22.31 - * single choice of license, a recipient has the option to distribute
   22.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   22.33 - * to extend the choice of license to its licensees as provided above.
   22.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   22.35 - * Version 2 license, then the option applies only if the new code is
   22.36 - * made subject to such option by the copyright holder.
   22.37 - *
   22.38 - * Contributor(s):
   22.39 - *
   22.40 - * Portions Copyrighted 1997-2009 Sun Microsystems, Inc.
   22.41 - */
   22.42 -package org.netbeans.modules.jackpot30.impl.indexing;
   22.43 -
   22.44 -import java.io.File;
   22.45 -import java.io.FileInputStream;
   22.46 -import java.io.FileOutputStream;
   22.47 -import java.io.IOException;
   22.48 -import java.io.InputStream;
   22.49 -import java.io.OutputStream;
   22.50 -import java.net.URI;
   22.51 -import java.net.URISyntaxException;
   22.52 -import java.net.URL;
   22.53 -import java.util.HashMap;
   22.54 -import java.util.LinkedList;
   22.55 -import java.util.List;
   22.56 -import java.util.Map;
   22.57 -import java.util.Map.Entry;
   22.58 -import java.util.Properties;
   22.59 -import java.util.logging.Level;
   22.60 -import java.util.logging.Logger;
   22.61 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   22.62 -import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
   22.63 -import org.openide.filesystems.FileObject;
   22.64 -import org.openide.filesystems.FileUtil;
   22.65 -
   22.66 -/**
   22.67 - *
   22.68 - * @author lahvac
   22.69 - */
   22.70 -public class Cache {
   22.71 -
   22.72 -    private static File standaloneCacheRoot;
   22.73 -    private static Map<String, Cache> name2Cache = new HashMap<String, Cache>();
   22.74 -
   22.75 -    public static Cache findCache(String indexName, int version) {
   22.76 -        Cache cache = name2Cache.get(indexName);
   22.77 -
   22.78 -        if (cache == null) {
   22.79 -            name2Cache.put(indexName, cache = new Cache(indexName, version));
   22.80 -        }
   22.81 -
   22.82 -        return cache;
   22.83 -    }
   22.84 -
   22.85 -    private final String name;
   22.86 -    private final int version;
   22.87 -
   22.88 -    private Cache(String name, int version) {
   22.89 -        this.name = name;
   22.90 -        this.version = version;
   22.91 -    }
   22.92 -    
   22.93 -    public File findCacheRoot(URL sourceRoot) throws IOException {
   22.94 -        try {
   22.95 -            sourceRoot = sourceRoot.toURI().normalize().toURL();
   22.96 -        } catch (URISyntaxException ex) {
   22.97 -            Logger.getLogger(Cache.class.getName()).log(Level.SEVERE, null, ex);
   22.98 -        }
   22.99 -        if (standaloneCacheRoot != null) {
  22.100 -            return getDataFolder(sourceRoot, name, version);
  22.101 -        } else {
  22.102 -            return findCacheRootNB(sourceRoot, version);
  22.103 -        }
  22.104 -    }
  22.105 -
  22.106 -    private File findCacheRootNB(URL sourceRoot, int version) throws IOException {
  22.107 -        FileObject indexBaseFolder = CacheFolder.getDataFolder(sourceRoot);
  22.108 -        String path = SPIAccessor.getInstance().getIndexerPath(name, version);
  22.109 -        FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path);
  22.110 -        return FileUtil.toFile(indexFolder);
  22.111 -    }
  22.112 -
  22.113 -    public static void setStandaloneCacheRoot(File standaloneCacheRoot) {
  22.114 -        Cache.standaloneCacheRoot = standaloneCacheRoot;
  22.115 -        segments = null;
  22.116 -        lastSegmentsTimeStamp = -1;
  22.117 -        invertedSegments = null;
  22.118 -        index = 0;
  22.119 -    }
  22.120 -
  22.121 -
  22.122 -    private static Properties segments;
  22.123 -    private static long lastSegmentsTimeStamp = -1;
  22.124 -    private static Map<String, String> invertedSegments;
  22.125 -    private static int index = 0;
  22.126 -
  22.127 -    private static final String SEGMENTS_FILE = "segments";      //NOI18N
  22.128 -    private static final String SLICE_PREFIX = "s";              //NOI18N
  22.129 -
  22.130 -    private static void loadSegments () throws IOException {
  22.131 -        final File folder = standaloneCacheRoot;
  22.132 -        assert folder != null;
  22.133 -        final File segmentsFile = new File(folder, SEGMENTS_FILE);
  22.134 -
  22.135 -        if (lastSegmentsTimeStamp != segmentsFile.lastModified()) {
  22.136 -            lastSegmentsTimeStamp = segmentsFile.lastModified();
  22.137 -            segments = null;
  22.138 -            lastSegmentsTimeStamp = -1;
  22.139 -            invertedSegments = null;
  22.140 -            index = 0;
  22.141 -        }
  22.142 -
  22.143 -        if (segments == null) {
  22.144 -            segments = new Properties ();
  22.145 -            invertedSegments = new HashMap<String,String> ();
  22.146 -            if (segmentsFile.canRead()) {
  22.147 -                final InputStream in = new FileInputStream(segmentsFile);
  22.148 -                try {
  22.149 -                    segments.load (in);
  22.150 -                } finally {
  22.151 -                    in.close();
  22.152 -                }
  22.153 -            }
  22.154 -            for (Entry<Object, Object> entry : segments.entrySet()) {
  22.155 -                String segment = (String) entry.getKey();
  22.156 -                String root = (String) entry.getValue();
  22.157 -                invertedSegments.put(root,segment);
  22.158 -                try {
  22.159 -                    index = Math.max (index,Integer.parseInt(segment.substring(SLICE_PREFIX.length())));
  22.160 -                } catch (NumberFormatException nfe) {
  22.161 -                    throw new IllegalStateException(nfe); //TODO: maybe just log the exception?
  22.162 -                }
  22.163 -            }
  22.164 -        }
  22.165 -    }
  22.166 -
  22.167 -    public static synchronized Iterable<? extends String> knownSourceRoots() throws IOException {
  22.168 -        loadSegments();
  22.169 -
  22.170 -        List<String> known = new LinkedList<String>();
  22.171 -        
  22.172 -        for (String segment : segments.stringPropertyNames()) {
  22.173 -            known.add(segment);
  22.174 -        }
  22.175 -
  22.176 -        return known;
  22.177 -    }
  22.178 -
  22.179 -    public static synchronized File sourceRootForKey(String segment) throws IOException {
  22.180 -        loadSegments();
  22.181 -
  22.182 -        try {
  22.183 -            return new File(new File(new URI(segments.getProperty(segment))).getAbsolutePath());
  22.184 -        } catch (URISyntaxException ex) {
  22.185 -            throw new IOException(ex);
  22.186 -        }
  22.187 -    }
  22.188 -
  22.189 -
  22.190 -    private static void storeSegments () throws IOException {
  22.191 -        final File folder = standaloneCacheRoot;
  22.192 -        assert folder != null;
  22.193 -        final File segmentsFile = new File(folder, SEGMENTS_FILE);
  22.194 -        segmentsFile.getParentFile().mkdirs();
  22.195 -        final OutputStream out = new FileOutputStream(segmentsFile);
  22.196 -        try {
  22.197 -            segments.store(out,null);
  22.198 -        } finally {
  22.199 -            out.close();
  22.200 -        }
  22.201 -    }
  22.202 -
  22.203 -    private static synchronized File getDataFolder (final URL root, String name, int version) throws IOException {
  22.204 -        loadSegments ();
  22.205 -        final String rootName = root.toExternalForm();
  22.206 -        String slice = invertedSegments.get (rootName);
  22.207 -        if ( slice == null) {
  22.208 -            slice = SLICE_PREFIX + (++index);
  22.209 -            while (segments.getProperty(slice) != null) {
  22.210 -                slice = SLICE_PREFIX + (++index);
  22.211 -            }
  22.212 -            segments.put (slice,rootName);
  22.213 -            invertedSegments.put(rootName, slice);
  22.214 -            storeSegments ();
  22.215 -        }
  22.216 -        final File folder = standaloneCacheRoot;
  22.217 -        return new File(new File(new File(folder, slice), name), Integer.toString(version));
  22.218 -    }
  22.219 -
  22.220 -}
    23.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImpl.java	Fri Jan 27 13:35:56 2012 +0100
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,177 +0,0 @@
    23.4 -/*
    23.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    23.6 - *
    23.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    23.8 - *
    23.9 - * The contents of this file are subject to the terms of either the GNU
   23.10 - * General Public License Version 2 only ("GPL") or the Common
   23.11 - * Development and Distribution License("CDDL") (collectively, the
   23.12 - * "License"). You may not use this file except in compliance with the
   23.13 - * License. You can obtain a copy of the License at
   23.14 - * http://www.netbeans.org/cddl-gplv2.html
   23.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   23.16 - * specific language governing permissions and limitations under the
   23.17 - * License.  When distributing the software, include this License Header
   23.18 - * Notice in each file and include the License file at
   23.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   23.20 - * particular file as subject to the "Classpath" exception as provided
   23.21 - * by Sun in the GPL Version 2 section of the License file that
   23.22 - * accompanied this code. If applicable, add the following below the
   23.23 - * License Header, with the fields enclosed by brackets [] replaced by
   23.24 - * your own identifying information:
   23.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   23.26 - *
   23.27 - * If you wish your version of this file to be governed by only the CDDL
   23.28 - * or only the GPL Version 2, indicate your decision by adding
   23.29 - * "[Contributor] elects to include this software in this distribution
   23.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   23.31 - * single choice of license, a recipient has the option to distribute
   23.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   23.33 - * to extend the choice of license to its licensees as provided above.
   23.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   23.35 - * Version 2 license, then the option applies only if the new code is
   23.36 - * made subject to such option by the copyright holder.
   23.37 - *
   23.38 - * Contributor(s):
   23.39 - *
   23.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   23.41 - */
   23.42 -
   23.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   23.44 -
   23.45 -import java.io.IOException;
   23.46 -import java.util.Collection;
   23.47 -import java.util.Collections;
   23.48 -import java.util.LinkedList;
   23.49 -import org.netbeans.api.java.source.ClasspathInfo;
   23.50 -import org.netbeans.api.java.source.CompilationController;
   23.51 -import org.netbeans.api.java.source.JavaSource;
   23.52 -import org.netbeans.api.java.source.JavaSource.Phase;
   23.53 -import org.netbeans.api.java.source.Task;
   23.54 -import org.netbeans.modules.jackpot30.impl.indexing.Index.AttributionWrapper;
   23.55 -import org.netbeans.modules.jackpot30.impl.indexing.Index.IndexWriter;
   23.56 -import org.netbeans.modules.parsing.spi.indexing.Context;
   23.57 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
   23.58 -import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
   23.59 -import org.netbeans.modules.parsing.spi.indexing.Indexable;
   23.60 -import org.openide.filesystems.FileObject;
   23.61 -import org.openide.filesystems.URLMapper;
   23.62 -import org.openide.util.Exceptions;
   23.63 -
   23.64 -/**
   23.65 - *
   23.66 - * @author lahvac
   23.67 - */
   23.68 -public class CustomIndexerImpl extends CustomIndexer {
   23.69 -
   23.70 -    @Override
   23.71 -    protected void index(Iterable<? extends Indexable> files, Context context) {
   23.72 -        Collection<FileObject> toIndex = new LinkedList<FileObject>(); //XXX: better would be to use File
   23.73 -
   23.74 -        for (Indexable i : files) {
   23.75 -            FileObject f = URLMapper.findFileObject(i.getURL());
   23.76 -
   23.77 -            if (f != null) {
   23.78 -                toIndex.add(f);
   23.79 -            }
   23.80 -        }
   23.81 -
   23.82 -        if (toIndex.isEmpty()) {
   23.83 -            return ;
   23.84 -        }
   23.85 -        
   23.86 -        try {
   23.87 -            doIndex(context.getRoot(), toIndex, Collections.<String>emptyList(), FileBasedIndex.get(context.getRootURI()));
   23.88 -        } catch (IOException ex) {
   23.89 -            Exceptions.printStackTrace(ex);
   23.90 -        }
   23.91 -    }
   23.92 -
   23.93 -    public static void doIndex(FileObject root, Collection<? extends FileObject> toIndex, Iterable<? extends String> deleted, Index index) {
   23.94 -        if (toIndex.isEmpty() && !deleted.iterator().hasNext()) {
   23.95 -            return ;
   23.96 -        }
   23.97 -
   23.98 -        final IndexWriter[] w = new IndexWriter[1];
   23.99 -
  23.100 -        try {
  23.101 -            ClasspathInfo cpInfo = ClasspathInfo.create(root);
  23.102 -            w[0] = index.openForWriting();
  23.103 -
  23.104 -            for (String path : deleted) {
  23.105 -                w[0].remove(path);
  23.106 -            }
  23.107 -
  23.108 -            final boolean attributed = Boolean.getBoolean(CustomIndexerImpl.class.getName() + "-attributed");
  23.109 -
  23.110 -            if (!toIndex.isEmpty()) {
  23.111 -                JavaSource.create(cpInfo, toIndex).runUserActionTask(new Task<CompilationController>() {
  23.112 -                    public void run(final CompilationController cc) throws Exception {
  23.113 -                        if (attributed) {
  23.114 -                            if (cc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0)
  23.115 -                                return ;
  23.116 -                        } else {
  23.117 -                        if (cc.toPhase(Phase.PARSED).compareTo(Phase.PARSED) < 0)
  23.118 -                            return ;
  23.119 -                        }
  23.120 -
  23.121 -                        w[0].record(cc.getFileObject().getURL(), cc.getCompilationUnit(), attributed ? new AttributionWrapper(cc) : null);
  23.122 -                    }
  23.123 -                }, true);
  23.124 -            }
  23.125 -        } catch (IOException ex) {
  23.126 -            Exceptions.printStackTrace(ex);
  23.127 -        } finally {
  23.128 -            if (w[0] != null) {
  23.129 -                try {
  23.130 -                    w[0].close();
  23.131 -                } catch (IOException ex) {
  23.132 -                    Exceptions.printStackTrace(ex);
  23.133 -                }
  23.134 -            }
  23.135 -        }
  23.136 -    }
  23.137 -
  23.138 -    public static final class CustomIndexerFactoryImpl extends CustomIndexerFactory {
  23.139 -
  23.140 -        @Override
  23.141 -        public CustomIndexer createIndexer() {
  23.142 -            return new CustomIndexerImpl();
  23.143 -        }
  23.144 -
  23.145 -        @Override
  23.146 -        public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
  23.147 -            Collection<String> deletedPaths = new LinkedList<String>();
  23.148 -
  23.149 -            for (Indexable i : deleted) {
  23.150 -                deletedPaths.add(i.getRelativePath());
  23.151 -
  23.152 -            }
  23.153 -            try {
  23.154 -                doIndex(context.getRoot(), Collections.<FileObject>emptyList(), deletedPaths, FileBasedIndex.get(context.getRootURI()));
  23.155 -            } catch (IOException ex) {
  23.156 -                Exceptions.printStackTrace(ex);
  23.157 -            }
  23.158 -        }
  23.159 -
  23.160 -        @Override
  23.161 -        public void filesDirty(Iterable<? extends Indexable> dirty, Context context) {}
  23.162 -
  23.163 -        @Override
  23.164 -        public String getIndexerName() {
  23.165 -            return FileBasedIndex.NAME;
  23.166 -        }
  23.167 -
  23.168 -        @Override
  23.169 -        public boolean supportsEmbeddedIndexers() {
  23.170 -            return false;
  23.171 -        }
  23.172 -
  23.173 -        @Override
  23.174 -        public int getIndexVersion() {
  23.175 -            return FileBasedIndex.VERSION;
  23.176 -        }
  23.177 -
  23.178 -    }
  23.179 -
  23.180 -}
    24.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/FileBasedIndex.java	Fri Jan 27 13:35:56 2012 +0100
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,176 +0,0 @@
    24.4 -/*
    24.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    24.6 - *
    24.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    24.8 - *
    24.9 - * The contents of this file are subject to the terms of either the GNU
   24.10 - * General Public License Version 2 only ("GPL") or the Common
   24.11 - * Development and Distribution License("CDDL") (collectively, the
   24.12 - * "License"). You may not use this file except in compliance with the
   24.13 - * License. You can obtain a copy of the License at
   24.14 - * http://www.netbeans.org/cddl-gplv2.html
   24.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   24.16 - * specific language governing permissions and limitations under the
   24.17 - * License.  When distributing the software, include this License Header
   24.18 - * Notice in each file and include the License file at
   24.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   24.20 - * particular file as subject to the "Classpath" exception as provided
   24.21 - * by Sun in the GPL Version 2 section of the License file that
   24.22 - * accompanied this code. If applicable, add the following below the
   24.23 - * License Header, with the fields enclosed by brackets [] replaced by
   24.24 - * your own identifying information:
   24.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   24.26 - *
   24.27 - * If you wish your version of this file to be governed by only the CDDL
   24.28 - * or only the GPL Version 2, indicate your decision by adding
   24.29 - * "[Contributor] elects to include this software in this distribution
   24.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   24.31 - * single choice of license, a recipient has the option to distribute
   24.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   24.33 - * to extend the choice of license to its licensees as provided above.
   24.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   24.35 - * Version 2 license, then the option applies only if the new code is
   24.36 - * made subject to such option by the copyright holder.
   24.37 - *
   24.38 - * Contributor(s):
   24.39 - *
   24.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   24.41 - */
   24.42 -
   24.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   24.44 -
   24.45 -import java.io.File;
   24.46 -import java.io.IOException;
   24.47 -import java.io.InputStream;
   24.48 -import java.io.InputStreamReader;
   24.49 -import java.io.Reader;
   24.50 -import java.net.URI;
   24.51 -import java.net.URISyntaxException;
   24.52 -import java.net.URL;
   24.53 -import org.apache.lucene.analysis.Analyzer;
   24.54 -import org.apache.lucene.analysis.TokenStream;
   24.55 -import org.apache.lucene.index.IndexReader;
   24.56 -import org.apache.lucene.index.IndexWriter.MaxFieldLength;
   24.57 -import org.apache.lucene.store.FSDirectory;
   24.58 -import org.codeviation.pojson.Pojson;
   24.59 -import org.netbeans.api.annotations.common.CheckForNull;
   24.60 -import org.netbeans.api.annotations.common.NonNull;
   24.61 -import org.openide.util.Exceptions;
   24.62 -
   24.63 -/**
   24.64 - *
   24.65 - * @author lahvac
   24.66 - */
   24.67 -public final class FileBasedIndex extends AbstractLuceneIndex {
   24.68 -
   24.69 -    public static Index create(URL sourceRoot, File indexRoot) {
   24.70 -        return new FileBasedIndex(sourceRoot, indexRoot, false);
   24.71 -    }
   24.72 -
   24.73 -    public static @CheckForNull Index get(URL sourceRoot) throws IOException {
   24.74 -        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME, FileBasedIndex.VERSION).findCacheRoot(sourceRoot), false); //XXX: new!
   24.75 -    }
   24.76 -
   24.77 -    public static @NonNull Index create(URL sourceRoot, boolean storeSources) throws IOException {
   24.78 -        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME, FileBasedIndex.VERSION).findCacheRoot(sourceRoot), storeSources);
   24.79 -    }
   24.80 -
   24.81 -    private final URL  sourceRoot;
   24.82 -    private final File cacheRoot;
   24.83 -
   24.84 -    private FileBasedIndex(URL sourceRoot, File cacheRoot, boolean storeSources) {
   24.85 -        super(sourceRoot.getPath().length(), false, storeSources);
   24.86 -        this.sourceRoot = sourceRoot;
   24.87 -        this.cacheRoot = cacheRoot;
   24.88 -    }
   24.89 -
   24.90 -    public CharSequence getSourceCode(String relativePath) {
   24.91 -        return getSourceCode(sourceRoot, relativePath);
   24.92 -    }
   24.93 -    
   24.94 -    static CharSequence getSourceCode(URL sourceRoot, String relativePath) {
   24.95 -        try {
   24.96 -            URI absolute = sourceRoot.toURI().resolve(relativePath);
   24.97 -            StringBuilder result = new StringBuilder();
   24.98 -            InputStream input = null;
   24.99 -            Reader reader = null;
  24.100 -
  24.101 -            try {
  24.102 -                input = absolute.toURL().openStream();
  24.103 -                reader = new InputStreamReader(input); //XXX encoding!!!
  24.104 -
  24.105 -                int read;
  24.106 -
  24.107 -                while ((read = reader.read()) != (-1)) {
  24.108 -                    result.append((char) read);
  24.109 -                }
  24.110 -
  24.111 -                return result;
  24.112 -            } finally {
  24.113 -                if (reader != null) {
  24.114 -                    reader.close();
  24.115 -                } else {
  24.116 -                    if (input != null) {
  24.117 -                        input.close();
  24.118 -                    }
  24.119 -                }
  24.120 -            }
  24.121 -        } catch (IOException ex) {
  24.122 -            Exceptions.printStackTrace(ex);
  24.123 -            return null;
  24.124 -        } catch (URISyntaxException ex) {
  24.125 -            Exceptions.printStackTrace(ex);
  24.126 -            return null;
  24.127 -        }
  24.128 -    }
  24.129 -
  24.130 -    public @NonNull IndexInfo getIndexInfo() {
  24.131 -        File infoFile = new File(cacheRoot, "info");
  24.132 -
  24.133 -        if (infoFile.exists()) {
  24.134 -            try {
  24.135 -                return Pojson.load(IndexInfo.class, infoFile);
  24.136 -            } catch (IOException ex) {
  24.137 -                Exceptions.printStackTrace(ex);
  24.138 -            }
  24.139 -        }
  24.140 -        
  24.141 -        return IndexInfo.empty();
  24.142 -    }
  24.143 -
  24.144 -    @Override
  24.145 -    protected IndexReader createReader() throws IOException {
  24.146 -        File dir = new File(cacheRoot, "fulltext");
  24.147 -
  24.148 -        if (dir.listFiles() == null || dir.listFiles().length == 0) {
  24.149 -            return null;
  24.150 -        }
  24.151 -
  24.152 -        return IndexReader.open(FSDirectory.open(dir), true);
  24.153 -    }
  24.154 -
  24.155 -    @Override
  24.156 -    protected org.apache.lucene.index.IndexWriter createWriter() throws IOException {
  24.157 -        return new org.apache.lucene.index.IndexWriter(FSDirectory.open(new File(cacheRoot, "fulltext")), new NoAnalyzer(), MaxFieldLength.UNLIMITED);
  24.158 -    }
  24.159 -
  24.160 -    @Override
  24.161 -    protected void storeIndexInfo(IndexInfo info) throws IOException {
  24.162 -        File infoFile = new File(cacheRoot, "info");
  24.163 -
  24.164 -        Pojson.save(info, infoFile);
  24.165 -    }
  24.166 -
  24.167 -    public static final class NoAnalyzer extends Analyzer {
  24.168 -
  24.169 -        @Override
  24.170 -        public TokenStream tokenStream(String string, Reader reader) {
  24.171 -            throw new UnsupportedOperationException("Should not be called");
  24.172 -        }
  24.173 -
  24.174 -    }
  24.175 -    
  24.176 -    public static final String NAME = "jackpot30"; //NOI18N
  24.177 -    public static final int VERSION = AbstractLuceneIndex.MAJOR_VERSION * 1000 + AbstractLuceneIndex.MINOR_VERSION;
  24.178 -
  24.179 -}
    25.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/Index.java	Fri Jan 27 13:35:56 2012 +0100
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,168 +0,0 @@
    25.4 -/*
    25.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    25.6 - *
    25.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    25.8 - *
    25.9 - * The contents of this file are subject to the terms of either the GNU
   25.10 - * General Public License Version 2 only ("GPL") or the Common
   25.11 - * Development and Distribution License("CDDL") (collectively, the
   25.12 - * "License"). You may not use this file except in compliance with the
   25.13 - * License. You can obtain a copy of the License at
   25.14 - * http://www.netbeans.org/cddl-gplv2.html
   25.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   25.16 - * specific language governing permissions and limitations under the
   25.17 - * License.  When distributing the software, include this License Header
   25.18 - * Notice in each file and include the License file at
   25.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   25.20 - * particular file as subject to the "Classpath" exception as provided
   25.21 - * by Sun in the GPL Version 2 section of the License file that
   25.22 - * accompanied this code. If applicable, add the following below the
   25.23 - * License Header, with the fields enclosed by brackets [] replaced by
   25.24 - * your own identifying information:
   25.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   25.26 - *
   25.27 - * If you wish your version of this file to be governed by only the CDDL
   25.28 - * or only the GPL Version 2, indicate your decision by adding
   25.29 - * "[Contributor] elects to include this software in this distribution
   25.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   25.31 - * single choice of license, a recipient has the option to distribute
   25.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   25.33 - * to extend the choice of license to its licensees as provided above.
   25.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   25.35 - * Version 2 license, then the option applies only if the new code is
   25.36 - * made subject to such option by the copyright holder.
   25.37 - *
   25.38 - * Contributor(s):
   25.39 - *
   25.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   25.41 - */
   25.42 -
   25.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   25.44 -
   25.45 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
   25.46 -import java.util.Map;
   25.47 -import com.sun.source.util.Trees;
   25.48 -import javax.lang.model.util.Types;
   25.49 -import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
   25.50 -import java.util.ArrayList;
   25.51 -import com.sun.source.tree.CompilationUnitTree;
   25.52 -import java.io.IOException;
   25.53 -import java.net.URI;
   25.54 -import java.net.URISyntaxException;
   25.55 -import java.net.URL;
   25.56 -import java.util.Collection;
   25.57 -import java.util.Collections;
   25.58 -import org.codeviation.pojson.Pojson;
   25.59 -import org.netbeans.api.annotations.common.NonNull;
   25.60 -import org.netbeans.api.annotations.common.NullAllowed;
   25.61 -import org.netbeans.api.java.source.CompilationInfo;
   25.62 -import org.openide.util.Exceptions;
   25.63 -import static org.netbeans.modules.jackpot30.remoting.api.WebUtilities.escapeForQuery;
   25.64 -
   25.65 -/**
   25.66 - *
   25.67 - * @author lahvac
   25.68 - */
   25.69 -public abstract class Index {
   25.70 -
   25.71 -    protected Index() {}
   25.72 -
   25.73 -    public static Index createWithRemoteIndex(final URL sourceRoot, final String indexURL, final String subIndex) {
   25.74 -        return new Index() {
   25.75 -            @Override
   25.76 -            public IndexWriter openForWriting() throws IOException {
   25.77 -                throw new UnsupportedOperationException();
   25.78 -            }
   25.79 -            @Override
   25.80 -            public Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException {
   25.81 -                try {
   25.82 -                    StringBuilder patterns = new StringBuilder();
   25.83 -
   25.84 -                    for (String p : pattern.getPatterns()) {
   25.85 -                        patterns.append(p);
   25.86 -                        patterns.append(";;");
   25.87 -                    }
   25.88 -
   25.89 -                    URI u = new URI(indexURL + "?path=" + escapeForQuery(subIndex) + "&pattern=" + escapeForQuery(patterns.toString()));
   25.90 -
   25.91 -                    return new ArrayList<String>(WebUtilities.requestStringArrayResponse(u));
   25.92 -                } catch (URISyntaxException ex) {
   25.93 -                    //XXX: better handling?
   25.94 -                    Exceptions.printStackTrace(ex);
   25.95 -                    return Collections.emptyList();
   25.96 -                }
   25.97 -            }
   25.98 -            @Override
   25.99 -            public Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException {
  25.100 -                throw new UnsupportedOperationException("Not supported yet.");
  25.101 -            }
  25.102 -            @Override
  25.103 -            public @NonNull IndexInfo getIndexInfo() {
  25.104 -                IndexInfo result = IndexInfo.empty();
  25.105 -
  25.106 -                try {
  25.107 -                    URI u = new URI(indexURL + "/info");
  25.108 -
  25.109 -                    Pojson.update(result, WebUtilities.requestStringResponse(u));
  25.110 -                } catch (URISyntaxException ex) {
  25.111 -                    //XXX: better handling?
  25.112 -                    Exceptions.printStackTrace(ex);
  25.113 -                }
  25.114 -                
  25.115 -                return result;
  25.116 -            }
  25.117 -            @Override
  25.118 -            public CharSequence getSourceCode(String relativePath) {
  25.119 -                try {
  25.120 -                    URI u = new URI(indexURL + "/cat?path=" + escapeForQuery(subIndex) + "&relative=" + escapeForQuery(relativePath));
  25.121 -
  25.122 -                    return WebUtilities.requestStringResponse(u);
  25.123 -                } catch (URISyntaxException ex) {
  25.124 -                    //XXX: better handling?
  25.125 -                    Exceptions.printStackTrace(ex);
  25.126 -                    return "";
  25.127 -                }
  25.128 -            }
  25.129 -        };
  25.130 -    }
  25.131 -
  25.132 -    public abstract IndexWriter openForWriting() throws IOException;
  25.133 -
  25.134 -    public abstract Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException;
  25.135 -    public abstract Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException;
  25.136 -
  25.137 -    public abstract CharSequence getSourceCode(String relativePath);
  25.138 -
  25.139 -    public abstract @NonNull IndexInfo getIndexInfo();
  25.140 -
  25.141 -    public abstract static class IndexWriter {
  25.142 -
  25.143 -        protected IndexWriter() throws IOException {}
  25.144 -
  25.145 -        public abstract void record(URL source, final CompilationUnitTree cut, @NullAllowed AttributionWrapper attributed) throws IOException;
  25.146 -
  25.147 -        public abstract void remove(String relativePath) throws IOException;
  25.148 -
  25.149 -        public abstract void clear() throws IOException;
  25.150 -        
  25.151 -        public abstract void close() throws IOException;
  25.152 -        
  25.153 -    }
  25.154 -
  25.155 -    public static final class AttributionWrapper {
  25.156 -        public final Trees trees;
  25.157 -        public final Types types;
  25.158 -
  25.159 -        public AttributionWrapper(CompilationInfo info) {
  25.160 -            trees = info.getTrees();
  25.161 -            types = info.getTypes();
  25.162 -        }
  25.163 -
  25.164 -        public AttributionWrapper(Trees trees, Types types) {
  25.165 -            this.trees = trees;
  25.166 -            this.types = types;
  25.167 -        }
  25.168 -
  25.169 -    }
  25.170 -
  25.171 -}
    26.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/IndexInfo.java	Fri Jan 27 13:35:56 2012 +0100
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,67 +0,0 @@
    26.4 -/*
    26.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    26.6 - *
    26.7 - * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
    26.8 - *
    26.9 - * The contents of this file are subject to the terms of either the GNU
   26.10 - * General Public License Version 2 only ("GPL") or the Common
   26.11 - * Development and Distribution License("CDDL") (collectively, the
   26.12 - * "License"). You may not use this file except in compliance with the
   26.13 - * License. You can obtain a copy of the License at
   26.14 - * http://www.netbeans.org/cddl-gplv2.html
   26.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   26.16 - * specific language governing permissions and limitations under the
   26.17 - * License.  When distributing the software, include this License Header
   26.18 - * Notice in each file and include the License file at
   26.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   26.20 - * particular file as subject to the "Classpath" exception as provided
   26.21 - * by Sun in the GPL Version 2 section of the License file that
   26.22 - * accompanied this code. If applicable, add the following below the
   26.23 - * License Header, with the fields enclosed by brackets [] replaced by
   26.24 - * your own identifying information:
   26.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   26.26 - *
   26.27 - * If you wish your version of this file to be governed by only the CDDL
   26.28 - * or only the GPL Version 2, indicate your decision by adding
   26.29 - * "[Contributor] elects to include this software in this distribution
   26.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   26.31 - * single choice of license, a recipient has the option to distribute
   26.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   26.33 - * to extend the choice of license to its licensees as provided above.
   26.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   26.35 - * Version 2 license, then the option applies only if the new code is
   26.36 - * made subject to such option by the copyright holder.
   26.37 - *
   26.38 - * Contributor(s):
   26.39 - *
   26.40 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   26.41 - */
   26.42 -
   26.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   26.44 -
   26.45 -/**
   26.46 - *
   26.47 - * @author lahvac
   26.48 - */
   26.49 -public class IndexInfo {
   26.50 -
   26.51 -    public int majorVersion;
   26.52 -    public int minorVersion;
   26.53 -    public int totalFiles;
   26.54 -    public long lastUpdate;
   26.55 -    public String sourceLocation;
   26.56 -    public String versionControlTip;
   26.57 -    public String displayName;
   26.58 -
   26.59 -    public static IndexInfo empty() {
   26.60 -        IndexInfo info = new IndexInfo();
   26.61 -
   26.62 -        info.majorVersion = 1;
   26.63 -        info.minorVersion = 0;
   26.64 -        info.totalFiles = -1;
   26.65 -        info.lastUpdate = -1;
   26.66 -
   26.67 -        return info;
   26.68 -    }
   26.69 -
   26.70 -}
    27.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/AbstractApplyHintsRefactoringPlugin.java	Fri Jan 27 13:35:56 2012 +0100
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,190 +0,0 @@
    27.4 -/*
    27.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    27.6 - *
    27.7 - * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    27.8 - *
    27.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   27.10 - * Other names may be trademarks of their respective owners.
   27.11 - *
   27.12 - * The contents of this file are subject to the terms of either the GNU
   27.13 - * General Public License Version 2 only ("GPL") or the Common
   27.14 - * Development and Distribution License("CDDL") (collectively, the
   27.15 - * "License"). You may not use this file except in compliance with the
   27.16 - * License. You can obtain a copy of the License at
   27.17 - * http://www.netbeans.org/cddl-gplv2.html
   27.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   27.19 - * specific language governing permissions and limitations under the
   27.20 - * License.  When distributing the software, include this License Header
   27.21 - * Notice in each file and include the License file at
   27.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   27.23 - * particular file as subject to the "Classpath" exception as provided
   27.24 - * by Oracle in the GPL Version 2 section of the License file that
   27.25 - * accompanied this code. If applicable, add the following below the
   27.26 - * License Header, with the fields enclosed by brackets [] replaced by
   27.27 - * your own identifying information:
   27.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   27.29 - *
   27.30 - * If you wish your version of this file to be governed by only the CDDL
   27.31 - * or only the GPL Version 2, indicate your decision by adding
   27.32 - * "[Contributor] elects to include this software in this distribution
   27.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   27.34 - * single choice of license, a recipient has the option to distribute
   27.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   27.36 - * to extend the choice of license to its licensees as provided above.
   27.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   27.38 - * Version 2 license, then the option applies only if the new code is
   27.39 - * made subject to such option by the copyright holder.
   27.40 - *
   27.41 - * Contributor(s):
   27.42 - *
   27.43 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   27.44 - */
   27.45 -
   27.46 -package org.netbeans.modules.jackpot30.impl.refactoring;
   27.47 -
   27.48 -import java.util.Collection;
   27.49 -import java.util.LinkedList;
   27.50 -import java.util.List;
   27.51 -import java.util.concurrent.atomic.AtomicBoolean;
   27.52 -import org.netbeans.api.java.source.CompilationController;
   27.53 -import org.netbeans.api.java.source.ModificationResult;
   27.54 -import org.netbeans.api.java.source.ModificationResult.Difference;
   27.55 -import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
   27.56 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
   27.57 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
   27.58 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Resource;
   27.59 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
   27.60 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities;
   27.61 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
   27.62 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper.ProgressHandleAbstraction;
   27.63 -import org.netbeans.modules.java.hints.jackpot.spi.HintContext.MessageKind;
   27.64 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   27.65 -import org.netbeans.modules.refactoring.api.AbstractRefactoring;
   27.66 -import org.netbeans.modules.refactoring.api.Problem;
   27.67 -import org.netbeans.modules.refactoring.java.spi.DiffElement;
   27.68 -import org.netbeans.modules.refactoring.spi.ProgressProviderAdapter;
   27.69 -import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
   27.70 -import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
   27.71 -import org.netbeans.spi.editor.hints.ErrorDescription;
   27.72 -import org.openide.filesystems.FileObject;
   27.73 -import org.openide.text.PositionBounds;
   27.74 -
   27.75 -/**
   27.76 - *
   27.77 - * @author lahvac
   27.78 - */
   27.79 -public abstract class AbstractApplyHintsRefactoringPlugin extends ProgressProviderAdapter implements RefactoringPlugin, ProgressHandleAbstraction {
   27.80 -
   27.81 -    private final AbstractRefactoring refactoring;
   27.82 -    protected final AtomicBoolean cancel = new AtomicBoolean();
   27.83 -
   27.84 -    protected AbstractApplyHintsRefactoringPlugin(AbstractRefactoring refactoring) {
   27.85 -        this.refactoring = refactoring;
   27.86 -    }
   27.87 -
   27.88 -    public void cancelRequest() {
   27.89 -        cancel.set(true);
   27.90 -    }
   27.91 -
   27.92 -    protected final Problem messagesToProblem(Collection<MessageImpl> problems) throws IllegalStateException {
   27.93 -        Problem current = null;
   27.94 -
   27.95 -        for (MessageImpl problem : problems) {
   27.96 -            Problem p = new Problem(problem.kind == MessageKind.ERROR, problem.text);
   27.97 -
   27.98 -            if (current != null)
   27.99 -                p.setNext(current);
  27.100 -            current = p;
  27.101 -        }
  27.102 -
  27.103 -        return current;
  27.104 -    }
  27.105 -
  27.106 -    protected Collection<MessageImpl> performApplyPattern(Iterable<? extends HintDescription> pattern, Scope scope, RefactoringElementsBag refactoringElements) {
  27.107 -        ProgressHandleWrapper w = new ProgressHandleWrapper(this, 30, 70);
  27.108 -        BatchResult candidates = BatchSearch.findOccurrences(pattern, scope, w);
  27.109 -        Collection<MessageImpl> problems = new LinkedList<MessageImpl>(candidates.problems);
  27.110 -        Collection<? extends ModificationResult> res = BatchUtilities.applyFixes(candidates, w, /*XXX*/new AtomicBoolean(), problems);
  27.111 -
  27.112 -        refactoringElements.registerTransaction(new RetoucheCommit(new LinkedList<ModificationResult>(res)));
  27.113 -
  27.114 -        for (ModificationResult mr : res) {
  27.115 -            for (FileObject file : mr.getModifiedFileObjects()) {
  27.116 -                for (Difference d : mr.getDifferences(file)) {
  27.117 -                    refactoringElements.add(refactoring, DiffElement.create(d, file, mr));
  27.118 -                }
  27.119 -            }
  27.120 -        }
  27.121 -
  27.122 -        w.finish();
  27.123 -
  27.124 -        return problems;
  27.125 -    }
  27.126 -
  27.127 -    protected final void prepareElements(BatchResult candidates, ProgressHandleWrapper w, final RefactoringElementsBag refactoringElements, final boolean verify, List<MessageImpl> problems) {
  27.128 -        if (verify) {
  27.129 -            BatchSearch.getVerifiedSpans(candidates, w, new BatchSearch.VerifiedSpansCallBack() {
  27.130 -                public void groupStarted() {}
  27.131 -                public boolean spansVerified(CompilationController wc, Resource r, Collection<? extends ErrorDescription> hints) throws Exception {
  27.132 -                    List<PositionBounds> spans = new LinkedList<PositionBounds>();
  27.133 -
  27.134 -                    for (ErrorDescription ed : hints) {
  27.135 -                        spans.add(ed.getRange());
  27.136 -                    }
  27.137 -
  27.138 -                    refactoringElements.addAll(refactoring, Utilities.createRefactoringElementImplementation(r.getResolvedFile(), spans, verify));
  27.139 -
  27.140 -                    return true;
  27.141 -                }
  27.142 -                public void groupFinished() {}
  27.143 -                public void cannotVerifySpan(Resource r) {
  27.144 -                    refactoringElements.addAll(refactoring, Utilities.createRefactoringElementImplementation(r.getResolvedFile(), prepareSpansFor(r), verify));
  27.145 -                }
  27.146 -            }, problems, cancel);
  27.147 -        } else {
  27.148 -            int[] parts = new int[candidates.getResources().size()];
  27.149 -            int   index = 0;
  27.150 -
  27.151 -            for (Collection<? extends Resource> resources : candidates.getResources()) {
  27.152 -                parts[index++] = resources.size();
  27.153 -            }
  27.154 -
  27.155 -            ProgressHandleWrapper inner = w.startNextPartWithEmbedding(parts);
  27.156 -
  27.157 -            for (Collection<? extends Resource> it :candidates.getResources()) {
  27.158 -                inner.startNextPart(it.size());
  27.159 -
  27.160 -                for (Resource r : it) {
  27.161 -                    refactoringElements.addAll(refactoring, Utilities.createRefactoringElementImplementation(r.getResolvedFile(), prepareSpansFor(r), verify));
  27.162 -                    inner.tick();
  27.163 -                }
  27.164 -            }
  27.165 -        }
  27.166 -    }
  27.167 -
  27.168 -    private static List<PositionBounds> prepareSpansFor(Resource r) {
  27.169 -        return Utilities.prepareSpansFor(r.getResolvedFile(), r.getCandidateSpans());
  27.170 -    }
  27.171 -
  27.172 -    public void start(int totalWork) {
  27.173 -        fireProgressListenerStart(-1, totalWork);
  27.174 -        lastWorkDone = 0;
  27.175 -    }
  27.176 -
  27.177 -    private int lastWorkDone;
  27.178 -    public void progress(int currentWorkDone) {
  27.179 -        while (lastWorkDone < currentWorkDone) {
  27.180 -            fireProgressListenerStep(currentWorkDone);
  27.181 -            lastWorkDone++;
  27.182 -        }
  27.183 -    }
  27.184 -
  27.185 -    public void progress(String message) {
  27.186 -        //ignored
  27.187 -    }
  27.188 -
  27.189 -    public void finish() {
  27.190 -        fireProgressListenerStop();
  27.191 -    }
  27.192 -
  27.193 -}
    28.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/AddScopePanel.form	Fri Jan 27 13:35:56 2012 +0100
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,373 +0,0 @@
    28.4 -<?xml version="1.1" encoding="UTF-8" ?>
    28.5 -
    28.6 -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    28.7 -  <NonVisualComponents>
    28.8 -    <Component class="javax.swing.ButtonGroup" name="buttonGroup1">
    28.9 -    </Component>
   28.10 -  </NonVisualComponents>
   28.11 -  <Properties>
   28.12 -    <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
   28.13 -      <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
   28.14 -        <EmptyBorder bottom="12" left="12" right="12" top="12"/>
   28.15 -      </Border>
   28.16 -    </Property>
   28.17 -  </Properties>
   28.18 -  <AuxValues>
   28.19 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
   28.20 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   28.21 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   28.22 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
   28.23 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   28.24 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   28.25 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   28.26 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   28.27 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   28.28 -    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,53,0,0,2,-66"/>
   28.29 -  </AuxValues>
   28.30 -
   28.31 -  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   28.32 -  <SubComponents>
   28.33 -    <Container class="javax.swing.JPanel" name="folderPanel">
   28.34 -      <Constraints>
   28.35 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   28.36 -          <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="1.0" weightY="0.0"/>
   28.37 -        </Constraint>
   28.38 -      </Constraints>
   28.39 -
   28.40 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   28.41 -      <SubComponents>
   28.42 -        <Component class="javax.swing.JLabel" name="folderLabel">
   28.43 -          <Properties>
   28.44 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   28.45 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.folderLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   28.46 -            </Property>
   28.47 -          </Properties>
   28.48 -          <Constraints>
   28.49 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   28.50 -              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="6" anchor="17" weightX="0.0" weightY="0.0"/>
   28.51 -            </Constraint>
   28.52 -          </Constraints>
   28.53 -        </Component>
   28.54 -        <Component class="javax.swing.JButton" name="folderChooser">
   28.55 -          <Properties>
   28.56 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   28.57 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.folderChooser.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   28.58 -            </Property>
   28.59 -          </Properties>
   28.60 -          <Events>
   28.61 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="folderChooserActionPerformed"/>
   28.62 -          </Events>
   28.63 -          <Constraints>
   28.64 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   28.65 -              <GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
   28.66 -            </Constraint>
   28.67 -          </Constraints>
   28.68 -        </Component>
   28.69 -        <Component class="javax.swing.JTextField" name="folder">
   28.70 -          <Properties>
   28.71 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   28.72 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.folder.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   28.73 -            </Property>
   28.74 -          </Properties>
   28.75 -          <Constraints>
   28.76 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   28.77 -              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
   28.78 -            </Constraint>
   28.79 -          </Constraints>
   28.80 -        </Component>
   28.81 -      </SubComponents>
   28.82 -    </Container>
   28.83 -    <Container class="javax.swing.JPanel" name="indexVariantsChooserPanel">
   28.84 -      <Constraints>
   28.85 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   28.86 -          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
   28.87 -        </Constraint>
   28.88 -      </Constraints>
   28.89 -
   28.90 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   28.91 -      <SubComponents>
   28.92 -        <Component class="javax.swing.JRadioButton" name="noIndexButton">
   28.93 -          <Properties>
   28.94 -            <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
   28.95 -              <ComponentRef name="buttonGroup1"/>
   28.96 -            </Property>
   28.97 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   28.98 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.noIndexButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   28.99 -            </Property>
  28.100 -          </Properties>
  28.101 -          <Events>
  28.102 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="noIndexButtonActionPerformed"/>
  28.103 -          </Events>
  28.104 -          <Constraints>
  28.105 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.106 -              <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
  28.107 -            </Constraint>
  28.108 -          </Constraints>
  28.109 -        </Component>
  28.110 -        <Component class="javax.swing.JRadioButton" name="localIndexButton">
  28.111 -          <Properties>
  28.112 -            <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
  28.113 -              <ComponentRef name="buttonGroup1"/>
  28.114 -            </Property>
  28.115 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.116 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.localIndexButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.117 -            </Property>
  28.118 -          </Properties>
  28.119 -          <Events>
  28.120 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="localIndexButtonActionPerformed"/>
  28.121 -          </Events>
  28.122 -          <Constraints>
  28.123 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.124 -              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="12" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
  28.125 -            </Constraint>
  28.126 -          </Constraints>
  28.127 -        </Component>
  28.128 -        <Component class="javax.swing.JRadioButton" name="removeIndexButton">
  28.129 -          <Properties>
  28.130 -            <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
  28.131 -              <ComponentRef name="buttonGroup1"/>
  28.132 -            </Property>
  28.133 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.134 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.removeIndexButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.135 -            </Property>
  28.136 -          </Properties>
  28.137 -          <Events>
  28.138 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeIndexButtonActionPerformed"/>
  28.139 -          </Events>
  28.140 -          <Constraints>
  28.141 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.142 -              <GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="12" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
  28.143 -            </Constraint>
  28.144 -          </Constraints>
  28.145 -        </Component>
  28.146 -        <Container class="javax.swing.JPanel" name="jPanel1">
  28.147 -          <Constraints>
  28.148 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.149 -              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="1.0" weightY="0.0"/>
  28.150 -            </Constraint>
  28.151 -          </Constraints>
  28.152 -
  28.153 -          <Layout>
  28.154 -            <DimensionLayout dim="0">
  28.155 -              <Group type="103" groupAlignment="0" attributes="0">
  28.156 -                  <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
  28.157 -              </Group>
  28.158 -            </DimensionLayout>
  28.159 -            <DimensionLayout dim="1">
  28.160 -              <Group type="103" groupAlignment="0" attributes="0">
  28.161 -                  <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
  28.162 -              </Group>
  28.163 -            </DimensionLayout>
  28.164 -          </Layout>
  28.165 -        </Container>
  28.166 -      </SubComponents>
  28.167 -    </Container>
  28.168 -    <Container class="javax.swing.JPanel" name="indexVariantsPanel">
  28.169 -      <Constraints>
  28.170 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.171 -          <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  28.172 -        </Constraint>
  28.173 -      </Constraints>
  28.174 -
  28.175 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/>
  28.176 -      <SubComponents>
  28.177 -        <Container class="javax.swing.JPanel" name="localIndexPanel">
  28.178 -          <Constraints>
  28.179 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
  28.180 -              <CardConstraints cardName="localIndex"/>
  28.181 -            </Constraint>
  28.182 -          </Constraints>
  28.183 -
  28.184 -          <Layout>
  28.185 -            <DimensionLayout dim="0">
  28.186 -              <Group type="103" groupAlignment="0" attributes="0">
  28.187 -                  <Group type="102" alignment="0" attributes="0">
  28.188 -                      <EmptySpace max="-2" attributes="0"/>
  28.189 -                      <Group type="103" groupAlignment="1" max="-2" attributes="0">
  28.190 -                          <Group type="102" attributes="1">
  28.191 -                              <EmptySpace min="12" pref="12" max="12" attributes="0"/>
  28.192 -                              <Component id="updateIndexCheckbox" max="32767" attributes="0"/>
  28.193 -                          </Group>
  28.194 -                          <Group type="102" alignment="0" attributes="0">
  28.195 -                              <Component id="indexFolderLabel" min="-2" max="-2" attributes="0"/>
  28.196 -                              <EmptySpace max="-2" attributes="0"/>
  28.197 -                              <Component id="indexFolder" min="-2" pref="482" max="-2" attributes="0"/>
  28.198 -                              <EmptySpace type="unrelated" max="-2" attributes="0"/>
  28.199 -                              <Component id="browse" min="-2" max="-2" attributes="0"/>
  28.200 -                          </Group>
  28.201 -                      </Group>
  28.202 -                      <EmptySpace max="-2" attributes="0"/>
  28.203 -                  </Group>
  28.204 -              </Group>
  28.205 -            </DimensionLayout>
  28.206 -            <DimensionLayout dim="1">
  28.207 -              <Group type="103" groupAlignment="0" attributes="0">
  28.208 -                  <Group type="102" alignment="0" attributes="0">
  28.209 -                      <EmptySpace max="-2" attributes="0"/>
  28.210 -                      <Group type="103" groupAlignment="3" attributes="0">
  28.211 -                          <Component id="indexFolderLabel" alignment="3" min="-2" max="-2" attributes="0"/>
  28.212 -                          <Component id="indexFolder" alignment="3" min="-2" max="-2" attributes="0"/>
  28.213 -                          <Component id="browse" alignment="3" min="-2" max="-2" attributes="0"/>
  28.214 -                      </Group>
  28.215 -                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
  28.216 -                      <Component id="updateIndexCheckbox" min="-2" max="-2" attributes="0"/>
  28.217 -                      <EmptySpace pref="11" max="32767" attributes="0"/>
  28.218 -                  </Group>
  28.219 -              </Group>
  28.220 -            </DimensionLayout>
  28.221 -          </Layout>
  28.222 -          <SubComponents>
  28.223 -            <Component class="javax.swing.JTextField" name="indexFolder">
  28.224 -              <Properties>
  28.225 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.226 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.indexFolder.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.227 -                </Property>
  28.228 -              </Properties>
  28.229 -            </Component>
  28.230 -            <Component class="javax.swing.JButton" name="browse">
  28.231 -              <Properties>
  28.232 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.233 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.browse.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.234 -                </Property>
  28.235 -              </Properties>
  28.236 -              <Events>
  28.237 -                <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="browseActionPerformed"/>
  28.238 -              </Events>
  28.239 -            </Component>
  28.240 -            <Component class="javax.swing.JLabel" name="indexFolderLabel">
  28.241 -              <Properties>
  28.242 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.243 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.indexFolderLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.244 -                </Property>
  28.245 -              </Properties>
  28.246 -            </Component>
  28.247 -            <Component class="javax.swing.JCheckBox" name="updateIndexCheckbox">
  28.248 -              <Properties>
  28.249 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.250 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.updateIndexCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.251 -                </Property>
  28.252 -              </Properties>
  28.253 -            </Component>
  28.254 -          </SubComponents>
  28.255 -        </Container>
  28.256 -        <Container class="javax.swing.JPanel" name="remoteIndexPanel">
  28.257 -          <Constraints>
  28.258 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
  28.259 -              <CardConstraints cardName="remoteIndex"/>
  28.260 -            </Constraint>
  28.261 -          </Constraints>
  28.262 -
  28.263 -          <Layout>
  28.264 -            <DimensionLayout dim="0">
  28.265 -              <Group type="103" groupAlignment="0" attributes="0">
  28.266 -                  <Group type="102" alignment="0" attributes="0">
  28.267 -                      <EmptySpace max="-2" attributes="0"/>
  28.268 -                      <Group type="103" groupAlignment="0" attributes="0">
  28.269 -                          <Group type="102" alignment="0" attributes="0">
  28.270 -                              <EmptySpace min="12" pref="12" max="12" attributes="0"/>
  28.271 -                              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
  28.272 -                              <EmptySpace max="-2" attributes="0"/>
  28.273 -                              <Component id="subIndex" pref="570" max="32767" attributes="0"/>
  28.274 -                          </Group>
  28.275 -                          <Group type="102" alignment="0" attributes="0">
  28.276 -                              <Component id="indexURLLabel" min="-2" max="-2" attributes="0"/>
  28.277 -                              <EmptySpace max="-2" attributes="0"/>
  28.278 -                              <Component id="indexURL" min="-2" max="-2" attributes="0"/>
  28.279 -                          </Group>
  28.280 -                      </Group>
  28.281 -                      <EmptySpace max="-2" attributes="0"/>
  28.282 -                  </Group>
  28.283 -              </Group>
  28.284 -            </DimensionLayout>
  28.285 -            <DimensionLayout dim="1">
  28.286 -              <Group type="103" groupAlignment="0" attributes="0">
  28.287 -                  <Group type="102" alignment="0" attributes="0">
  28.288 -                      <EmptySpace max="-2" attributes="0"/>
  28.289 -                      <Group type="103" groupAlignment="3" attributes="0">
  28.290 -                          <Component id="indexURLLabel" alignment="3" min="-2" max="-2" attributes="0"/>
  28.291 -                          <Component id="indexURL" alignment="3" min="-2" max="-2" attributes="0"/>
  28.292 -                      </Group>
  28.293 -                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
  28.294 -                      <Group type="103" groupAlignment="3" attributes="0">
  28.295 -                          <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
  28.296 -                          <Component id="subIndex" alignment="3" min="-2" max="-2" attributes="0"/>
  28.297 -                      </Group>
  28.298 -                      <EmptySpace max="32767" attributes="0"/>
  28.299 -                  </Group>
  28.300 -              </Group>
  28.301 -            </DimensionLayout>
  28.302 -          </Layout>
  28.303 -          <SubComponents>
  28.304 -            <Component class="javax.swing.JTextField" name="indexURL">
  28.305 -              <Properties>
  28.306 -                <Property name="columns" type="int" value="40"/>
  28.307 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.308 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.indexURL.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.309 -                </Property>
  28.310 -              </Properties>
  28.311 -            </Component>
  28.312 -            <Component class="javax.swing.JLabel" name="indexURLLabel">
  28.313 -              <Properties>
  28.314 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.315 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.indexURLLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.316 -                </Property>
  28.317 -              </Properties>
  28.318 -            </Component>
  28.319 -            <Component class="javax.swing.JComboBox" name="subIndex">
  28.320 -              <Properties>
  28.321 -                <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
  28.322 -                  <StringArray count="0"/>
  28.323 -                </Property>
  28.324 -              </Properties>
  28.325 -              <Events>
  28.326 -                <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="subIndexActionPerformed"/>
  28.327 -              </Events>
  28.328 -            </Component>
  28.329 -            <Component class="javax.swing.JLabel" name="jLabel1">
  28.330 -              <Properties>
  28.331 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  28.332 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="AddScopePanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  28.333 -                </Property>
  28.334 -              </Properties>
  28.335 -            </Component>
  28.336 -          </SubComponents>
  28.337 -        </Container>
  28.338 -        <Container class="javax.swing.JPanel" name="noIndexPanel">
  28.339 -          <Constraints>
  28.340 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
  28.341 -              <CardConstraints cardName="noIndex"/>
  28.342 -            </Constraint>
  28.343 -          </Constraints>
  28.344 -
  28.345 -          <Layout>
  28.346 -            <DimensionLayout dim="0">
  28.347 -              <Group type="103" groupAlignment="0" attributes="0">
  28.348 -                  <EmptySpace min="0" pref="678" max="32767" attributes="0"/>
  28.349 -              </Group>
  28.350 -            </DimensionLayout>
  28.351 -            <DimensionLayout dim="1">
  28.352 -              <Group type="103" groupAlignment="0" attributes="0">
  28.353 -                  <EmptySpace min="0" pref="79" max="32767" attributes="0"/>
  28.354 -              </Group>
  28.355 -            </DimensionLayout>
  28.356 -          </Layout>
  28.357 -        </Container>
  28.358 -      </SubComponents>
  28.359 -    </Container>
  28.360 -    <Component class="javax.swing.JTextArea" name="indexInfo">
  28.361 -      <Properties>
  28.362 -        <Property name="columns" type="int" value="20"/>
  28.363 -        <Property name="editable" type="boolean" value="false"/>
  28.364 -        <Property name="rows" type="int" value="5"/>
  28.365 -        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
  28.366 -          <Border info="null"/>
  28.367 -        </Property>
  28.368 -      </Properties>
  28.369 -      <Constraints>
  28.370 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  28.371 -          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  28.372 -        </Constraint>
  28.373 -      </Constraints>
  28.374 -    </Component>
  28.375 -  </SubComponents>
  28.376 -</Form>
    29.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/AddScopePanel.java	Fri Jan 27 13:35:56 2012 +0100
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,726 +0,0 @@
    29.4 -/*
    29.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    29.6 - *
    29.7 - * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
    29.8 - *
    29.9 - * The contents of this file are subject to the terms of either the GNU
   29.10 - * General Public License Version 2 only ("GPL") or the Common
   29.11 - * Development and Distribution License("CDDL") (collectively, the
   29.12 - * "License"). You may not use this file except in compliance with the
   29.13 - * License. You can obtain a copy of the License at
   29.14 - * http://www.netbeans.org/cddl-gplv2.html
   29.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   29.16 - * specific language governing permissions and limitations under the
   29.17 - * License.  When distributing the software, include this License Header
   29.18 - * Notice in each file and include the License file at
   29.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   29.20 - * particular file as subject to the "Classpath" exception as provided
   29.21 - * by Sun in the GPL Version 2 section of the License file that
   29.22 - * accompanied this code. If applicable, add the following below the
   29.23 - * License Header, with the fields enclosed by brackets [] replaced by
   29.24 - * your own identifying information:
   29.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   29.26 - *
   29.27 - * If you wish your version of this file to be governed by only the CDDL
   29.28 - * or only the GPL Version 2, indicate your decision by adding
   29.29 - * "[Contributor] elects to include this software in this distribution
   29.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   29.31 - * single choice of license, a recipient has the option to distribute
   29.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   29.33 - * to extend the choice of license to its licensees as provided above.
   29.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   29.35 - * Version 2 license, then the option applies only if the new code is
   29.36 - * made subject to such option by the copyright holder.
   29.37 - *
   29.38 - * Contributor(s):
   29.39 - *
   29.40 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   29.41 - */
   29.42 -package org.netbeans.modules.jackpot30.impl.refactoring;
   29.43 -
   29.44 -import java.awt.CardLayout;
   29.45 -import java.awt.Component;
   29.46 -import java.io.File;
   29.47 -import java.io.IOException;
   29.48 -import java.net.MalformedURLException;
   29.49 -import java.net.URISyntaxException;
   29.50 -import java.net.URL;
   29.51 -import java.text.DateFormat;
   29.52 -import java.util.Collection;
   29.53 -import java.util.Date;
   29.54 -import java.util.HashMap;
   29.55 -import java.util.Map;
   29.56 -import java.util.concurrent.atomic.AtomicBoolean;
   29.57 -import java.util.concurrent.atomic.AtomicReference;
   29.58 -import java.util.logging.Level;
   29.59 -import java.util.logging.Logger;
   29.60 -import javax.swing.DefaultComboBoxModel;
   29.61 -import javax.swing.DefaultListCellRenderer;
   29.62 -import javax.swing.JButton;
   29.63 -import javax.swing.JFileChooser;
   29.64 -import javax.swing.JList;
   29.65 -import javax.swing.JTextField;
   29.66 -import javax.swing.SwingUtilities;
   29.67 -import javax.swing.UIManager;
   29.68 -import javax.swing.event.DocumentEvent;
   29.69 -import javax.swing.event.DocumentListener;
   29.70 -import org.codeviation.pojson.Pojson;
   29.71 -import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
   29.72 -import org.netbeans.modules.jackpot30.impl.batch.EnhancedScopes.GivenFolderScope;
   29.73 -import org.netbeans.modules.jackpot30.impl.indexing.FileBasedIndex;
   29.74 -import org.netbeans.modules.jackpot30.impl.indexing.Index;
   29.75 -import org.netbeans.modules.jackpot30.impl.indexing.IndexInfo;
   29.76 -import org.openide.NotificationLineSupport;
   29.77 -import org.openide.util.Exceptions;
   29.78 -import org.openide.util.RequestProcessor;
   29.79 -
   29.80 -/**
   29.81 - *
   29.82 - * @author lahvac
   29.83 - */
   29.84 -public class AddScopePanel extends javax.swing.JPanel {
   29.85 -
   29.86 -    private final JButton okButton;
   29.87 -
   29.88 -    public AddScopePanel(JButton okButton) {
   29.89 -        this.okButton = okButton;
   29.90 -        initComponents();
   29.91 -        noIndexButton.setSelected(true);
   29.92 -        DocumentListener updateErrorsListener = new DocumentListener() {
   29.93 -            public void insertUpdate(DocumentEvent e) {
   29.94 -                updateErrors();
   29.95 -            }
   29.96 -            public void removeUpdate(DocumentEvent e) {
   29.97 -                updateErrors();
   29.98 -            }
   29.99 -            public void changedUpdate(DocumentEvent e) {}
  29.100 -        };
  29.101 -        folder.getDocument().addDocumentListener(updateErrorsListener);
  29.102 -        indexFolder.getDocument().addDocumentListener(updateErrorsListener);
  29.103 -        indexURL.getDocument().addDocumentListener(new DocumentListener() {
  29.104 -            public void insertUpdate(DocumentEvent e) {
  29.105 -                indexURLUpdated();
  29.106 -            }
  29.107 -            public void removeUpdate(DocumentEvent e) {
  29.108 -                indexURLUpdated();
  29.109 -            }
  29.110 -            public void changedUpdate(DocumentEvent e) {
  29.111 -            }
  29.112 -        });
  29.113 -        indexInfo.setFont(UIManager.getFont("Label.font"));
  29.114 -        indexInfo.setBackground(UIManager.getColor("Label.background"));
  29.115 -        indexInfo.setDisabledTextColor(UIManager.getColor("Label.foreground"));
  29.116 -    }
  29.117 -
  29.118 -    /** This method is called from within the constructor to
  29.119 -     * initialize the form.
  29.120 -     * WARNING: Do NOT modify this code. The content of this method is
  29.121 -     * always regenerated by the Form Editor.
  29.122 -     */
  29.123 -    @SuppressWarnings("unchecked")
  29.124 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  29.125 -    private void initComponents() {
  29.126 -        java.awt.GridBagConstraints gridBagConstraints;
  29.127 -
  29.128 -        buttonGroup1 = new javax.swing.ButtonGroup();
  29.129 -        folderPanel = new javax.swing.JPanel();
  29.130 -        folderLabel = new javax.swing.JLabel();
  29.131 -        folderChooser = new javax.swing.JButton();
  29.132 -        folder = new javax.swing.JTextField();
  29.133 -        indexVariantsChooserPanel = new javax.swing.JPanel();
  29.134 -        noIndexButton = new javax.swing.JRadioButton();
  29.135 -        localIndexButton = new javax.swing.JRadioButton();
  29.136 -        removeIndexButton = new javax.swing.JRadioButton();
  29.137 -        jPanel1 = new javax.swing.JPanel();
  29.138 -        indexVariantsPanel = new javax.swing.JPanel();
  29.139 -        localIndexPanel = new javax.swing.JPanel();
  29.140 -        indexFolder = new javax.swing.JTextField();
  29.141 -        browse = new javax.swing.JButton();
  29.142 -        indexFolderLabel = new javax.swing.JLabel();
  29.143 -        updateIndexCheckbox = new javax.swing.JCheckBox();
  29.144 -        remoteIndexPanel = new javax.swing.JPanel();
  29.145 -        indexURL = new javax.swing.JTextField();
  29.146 -        indexURLLabel = new javax.swing.JLabel();
  29.147 -        subIndex = new javax.swing.JComboBox();
  29.148 -        jLabel1 = new javax.swing.JLabel();
  29.149 -        noIndexPanel = new javax.swing.JPanel();
  29.150 -        indexInfo = new javax.swing.JTextArea();
  29.151 -
  29.152 -        setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
  29.153 -        setLayout(new java.awt.GridBagLayout());
  29.154 -
  29.155 -        folderPanel.setLayout(new java.awt.GridBagLayout());
  29.156 -
  29.157 -        org.openide.awt.Mnemonics.setLocalizedText(folderLabel, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.folderLabel.text")); // NOI18N
  29.158 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.159 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.160 -        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
  29.161 -        folderPanel.add(folderLabel, gridBagConstraints);
  29.162 -
  29.163 -        org.openide.awt.Mnemonics.setLocalizedText(folderChooser, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.folderChooser.text")); // NOI18N
  29.164 -        folderChooser.addActionListener(new java.awt.event.ActionListener() {
  29.165 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.166 -                folderChooserActionPerformed(evt);
  29.167 -            }
  29.168 -        });
  29.169 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.170 -        gridBagConstraints.gridx = 2;
  29.171 -        gridBagConstraints.gridy = 0;
  29.172 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.173 -        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
  29.174 -        folderPanel.add(folderChooser, gridBagConstraints);
  29.175 -
  29.176 -        folder.setText(org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.folder.text")); // NOI18N
  29.177 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.178 -        gridBagConstraints.gridx = 1;
  29.179 -        gridBagConstraints.gridy = 0;
  29.180 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  29.181 -        gridBagConstraints.weightx = 1.0;
  29.182 -        folderPanel.add(folder, gridBagConstraints);
  29.183 -
  29.184 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.185 -        gridBagConstraints.gridx = 0;
  29.186 -        gridBagConstraints.gridy = 0;
  29.187 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  29.188 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.189 -        gridBagConstraints.weightx = 1.0;
  29.190 -        add(folderPanel, gridBagConstraints);
  29.191 -
  29.192 -        indexVariantsChooserPanel.setLayout(new java.awt.GridBagLayout());
  29.193 -
  29.194 -        buttonGroup1.add(noIndexButton);
  29.195 -        org.openide.awt.Mnemonics.setLocalizedText(noIndexButton, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.noIndexButton.text")); // NOI18N
  29.196 -        noIndexButton.addActionListener(new java.awt.event.ActionListener() {
  29.197 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.198 -                noIndexButtonActionPerformed(evt);
  29.199 -            }
  29.200 -        });
  29.201 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.202 -        gridBagConstraints.gridx = 0;
  29.203 -        gridBagConstraints.gridy = 0;
  29.204 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.205 -        indexVariantsChooserPanel.add(noIndexButton, gridBagConstraints);
  29.206 -
  29.207 -        buttonGroup1.add(localIndexButton);
  29.208 -        org.openide.awt.Mnemonics.setLocalizedText(localIndexButton, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.localIndexButton.text")); // NOI18N
  29.209 -        localIndexButton.addActionListener(new java.awt.event.ActionListener() {
  29.210 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.211 -                localIndexButtonActionPerformed(evt);
  29.212 -            }
  29.213 -        });
  29.214 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.215 -        gridBagConstraints.gridx = 1;
  29.216 -        gridBagConstraints.gridy = 0;
  29.217 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.218 -        gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
  29.219 -        indexVariantsChooserPanel.add(localIndexButton, gridBagConstraints);
  29.220 -
  29.221 -        buttonGroup1.add(removeIndexButton);
  29.222 -        org.openide.awt.Mnemonics.setLocalizedText(removeIndexButton, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.removeIndexButton.text")); // NOI18N
  29.223 -        removeIndexButton.addActionListener(new java.awt.event.ActionListener() {
  29.224 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.225 -                removeIndexButtonActionPerformed(evt);
  29.226 -            }
  29.227 -        });
  29.228 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.229 -        gridBagConstraints.gridx = 2;
  29.230 -        gridBagConstraints.gridy = 0;
  29.231 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.232 -        gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
  29.233 -        indexVariantsChooserPanel.add(removeIndexButton, gridBagConstraints);
  29.234 -
  29.235 -        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  29.236 -        jPanel1.setLayout(jPanel1Layout);
  29.237 -        jPanel1Layout.setHorizontalGroup(
  29.238 -            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.239 -            .addGap(0, 0, Short.MAX_VALUE)
  29.240 -        );
  29.241 -        jPanel1Layout.setVerticalGroup(
  29.242 -            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.243 -            .addGap(0, 0, Short.MAX_VALUE)
  29.244 -        );
  29.245 -
  29.246 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.247 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  29.248 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.249 -        gridBagConstraints.weightx = 1.0;
  29.250 -        indexVariantsChooserPanel.add(jPanel1, gridBagConstraints);
  29.251 -
  29.252 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.253 -        gridBagConstraints.gridx = 0;
  29.254 -        gridBagConstraints.gridy = 1;
  29.255 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  29.256 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  29.257 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  29.258 -        add(indexVariantsChooserPanel, gridBagConstraints);
  29.259 -
  29.260 -        indexVariantsPanel.setLayout(new java.awt.CardLayout());
  29.261 -
  29.262 -        indexFolder.setText(org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.indexFolder.text")); // NOI18N
  29.263 -
  29.264 -        org.openide.awt.Mnemonics.setLocalizedText(browse, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.browse.text")); // NOI18N
  29.265 -        browse.addActionListener(new java.awt.event.ActionListener() {
  29.266 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.267 -                browseActionPerformed(evt);
  29.268 -            }
  29.269 -        });
  29.270 -
  29.271 -        org.openide.awt.Mnemonics.setLocalizedText(indexFolderLabel, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.indexFolderLabel.text")); // NOI18N
  29.272 -
  29.273 -        org.openide.awt.Mnemonics.setLocalizedText(updateIndexCheckbox, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.updateIndexCheckbox.text")); // NOI18N
  29.274 -
  29.275 -        javax.swing.GroupLayout localIndexPanelLayout = new javax.swing.GroupLayout(localIndexPanel);
  29.276 -        localIndexPanel.setLayout(localIndexPanelLayout);
  29.277 -        localIndexPanelLayout.setHorizontalGroup(
  29.278 -            localIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.279 -            .addGroup(localIndexPanelLayout.createSequentialGroup()
  29.280 -                .addContainerGap()
  29.281 -                .addGroup(localIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  29.282 -                    .addGroup(localIndexPanelLayout.createSequentialGroup()
  29.283 -                        .addGap(12, 12, 12)
  29.284 -                        .addComponent(updateIndexCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  29.285 -                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, localIndexPanelLayout.createSequentialGroup()
  29.286 -                        .addComponent(indexFolderLabel)
  29.287 -                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  29.288 -                        .addComponent(indexFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE)
  29.289 -                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  29.290 -                        .addComponent(browse)))
  29.291 -                .addContainerGap())
  29.292 -        );
  29.293 -        localIndexPanelLayout.setVerticalGroup(
  29.294 -            localIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.295 -            .addGroup(localIndexPanelLayout.createSequentialGroup()
  29.296 -                .addContainerGap()
  29.297 -                .addGroup(localIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  29.298 -                    .addComponent(indexFolderLabel)
  29.299 -                    .addComponent(indexFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  29.300 -                    .addComponent(browse))
  29.301 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  29.302 -                .addComponent(updateIndexCheckbox)
  29.303 -                .addContainerGap(11, Short.MAX_VALUE))
  29.304 -        );
  29.305 -
  29.306 -        indexVariantsPanel.add(localIndexPanel, "localIndex");
  29.307 -
  29.308 -        indexURL.setColumns(40);
  29.309 -        indexURL.setText(org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.indexURL.text")); // NOI18N
  29.310 -
  29.311 -        org.openide.awt.Mnemonics.setLocalizedText(indexURLLabel, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.indexURLLabel.text")); // NOI18N
  29.312 -
  29.313 -        subIndex.addActionListener(new java.awt.event.ActionListener() {
  29.314 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  29.315 -                subIndexActionPerformed(evt);
  29.316 -            }
  29.317 -        });
  29.318 -
  29.319 -        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddScopePanel.class, "AddScopePanel.jLabel1.text")); // NOI18N
  29.320 -
  29.321 -        javax.swing.GroupLayout remoteIndexPanelLayout = new javax.swing.GroupLayout(remoteIndexPanel);
  29.322 -        remoteIndexPanel.setLayout(remoteIndexPanelLayout);
  29.323 -        remoteIndexPanelLayout.setHorizontalGroup(
  29.324 -            remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.325 -            .addGroup(remoteIndexPanelLayout.createSequentialGroup()
  29.326 -                .addContainerGap()
  29.327 -                .addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.328 -                    .addGroup(remoteIndexPanelLayout.createSequentialGroup()
  29.329 -                        .addGap(12, 12, 12)
  29.330 -                        .addComponent(jLabel1)
  29.331 -                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  29.332 -                        .addComponent(subIndex, 0, 570, Short.MAX_VALUE))
  29.333 -                    .addGroup(remoteIndexPanelLayout.createSequentialGroup()
  29.334 -                        .addComponent(indexURLLabel)
  29.335 -                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  29.336 -                        .addComponent(indexURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  29.337 -                .addContainerGap())
  29.338 -        );
  29.339 -        remoteIndexPanelLayout.setVerticalGroup(
  29.340 -            remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.341 -            .addGroup(remoteIndexPanelLayout.createSequentialGroup()
  29.342 -                .addContainerGap()
  29.343 -                .addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  29.344 -                    .addComponent(indexURLLabel)
  29.345 -                    .addComponent(indexURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  29.346 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  29.347 -                .addGroup(remoteIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  29.348 -                    .addComponent(jLabel1)
  29.349 -                    .addComponent(subIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  29.350 -                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  29.351 -        );
  29.352 -
  29.353 -        indexVariantsPanel.add(remoteIndexPanel, "remoteIndex");
  29.354 -
  29.355 -        javax.swing.GroupLayout noIndexPanelLayout = new javax.swing.GroupLayout(noIndexPanel);
  29.356 -        noIndexPanel.setLayout(noIndexPanelLayout);
  29.357 -        noIndexPanelLayout.setHorizontalGroup(
  29.358 -            noIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.359 -            .addGap(0, 678, Short.MAX_VALUE)
  29.360 -        );
  29.361 -        noIndexPanelLayout.setVerticalGroup(
  29.362 -            noIndexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  29.363 -            .addGap(0, 79, Short.MAX_VALUE)
  29.364 -        );
  29.365 -
  29.366 -        indexVariantsPanel.add(noIndexPanel, "noIndex");
  29.367 -
  29.368 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.369 -        gridBagConstraints.gridx = 0;
  29.370 -        gridBagConstraints.gridy = 2;
  29.371 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  29.372 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  29.373 -        gridBagConstraints.weightx = 1.0;
  29.374 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  29.375 -        add(indexVariantsPanel, gridBagConstraints);
  29.376 -
  29.377 -        indexInfo.setColumns(20);
  29.378 -        indexInfo.setEditable(false);
  29.379 -        indexInfo.setRows(5);
  29.380 -        indexInfo.setBorder(null);
  29.381 -        gridBagConstraints = new java.awt.GridBagConstraints();
  29.382 -        gridBagConstraints.gridx = 0;
  29.383 -        gridBagConstraints.gridy = 3;
  29.384 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  29.385 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  29.386 -        gridBagConstraints.weightx = 1.0;
  29.387 -        gridBagConstraints.weighty = 1.0;
  29.388 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  29.389 -        add(indexInfo, gridBagConstraints);
  29.390 -    }// </editor-fold>//GEN-END:initComponents
  29.391 -
  29.392 -    private void folderChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folderChooserActionPerformed
  29.393 -        showFileChooser(folder);
  29.394 -}//GEN-LAST:event_folderChooserActionPerformed
  29.395 -
  29.396 -    private void noIndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noIndexButtonActionPerformed
  29.397 -        selectCorrectCard();
  29.398 -    }//GEN-LAST:event_noIndexButtonActionPerformed
  29.399 -
  29.400 -    private void localIndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localIndexButtonActionPerformed
  29.401 -        selectCorrectCard();
  29.402 -    }//GEN-LAST:event_localIndexButtonActionPerformed
  29.403 -
  29.404 -    private void removeIndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeIndexButtonActionPerformed
  29.405 -        selectCorrectCard();
  29.406 -    }//GEN-LAST:event_removeIndexButtonActionPerformed
  29.407 -
  29.408 -    private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
  29.409 -        showFileChooser(indexFolder);
  29.410 -    }//GEN-LAST:event_browseActionPerformed
  29.411 -
  29.412 -    private void subIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subIndexActionPerformed
  29.413 -        subindexSelectionUpdated();
  29.414 -    }//GEN-LAST:event_subIndexActionPerformed
  29.415 -
  29.416 -    private void selectCorrectCard() {
  29.417 -        String card;
  29.418 -
  29.419 -        indexInfo.setText("");
  29.420 -        
  29.421 -        if (noIndexButton.isSelected()) card = "noIndex";
  29.422 -        else if (localIndexButton.isSelected()) card = "localIndex";
  29.423 -        else {
  29.424 -            card = "remoteIndex";
  29.425 -            indexURLUpdated();
  29.426 -        }
  29.427 -
  29.428 -        ((CardLayout) indexVariantsPanel.getLayout()).show(indexVariantsPanel, card);
  29.429 -
  29.430 -        updateErrors();
  29.431 -    }
  29.432 -
  29.433 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  29.434 -    private javax.swing.JButton browse;
  29.435 -    private javax.swing.ButtonGroup buttonGroup1;
  29.436 -    private javax.swing.JTextField folder;
  29.437 -    private javax.swing.JButton folderChooser;
  29.438 -    private javax.swing.JLabel folderLabel;
  29.439 -    private javax.swing.JPanel folderPanel;
  29.440 -    private javax.swing.JTextField indexFolder;
  29.441 -    private javax.swing.JLabel indexFolderLabel;
  29.442 -    private javax.swing.JTextArea indexInfo;
  29.443 -    private javax.swing.JTextField indexURL;
  29.444 -    private javax.swing.JLabel indexURLLabel;
  29.445 -    private javax.swing.JPanel indexVariantsChooserPanel;
  29.446 -    private javax.swing.JPanel indexVariantsPanel;
  29.447 -    private javax.swing.JLabel jLabel1;
  29.448 -    private javax.swing.JPanel jPanel1;
  29.449 -    private javax.swing.JRadioButton localIndexButton;
  29.450 -    private javax.swing.JPanel localIndexPanel;
  29.451 -    private javax.swing.JRadioButton noIndexButton;
  29.452 -    private javax.swing.JPanel noIndexPanel;
  29.453 -    private javax.swing.JPanel remoteIndexPanel;
  29.454 -    private javax.swing.JRadioButton removeIndexButton;
  29.455 -    private javax.swing.JComboBox subIndex;
  29.456 -    private javax.swing.JCheckBox updateIndexCheckbox;
  29.457 -    // End of variables declaration//GEN-END:variables
  29.458 -
  29.459 -    private void showFileChooser(JTextField folder) {
  29.460 -        JFileChooser c = new JFileChooser();
  29.461 -
  29.462 -        c.setSelectedFile(new File(folder.getText()));
  29.463 -        c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  29.464 -        c.setMultiSelectionEnabled(false);
  29.465 -        c.setApproveButtonText("Select");
  29.466 -
  29.467 -        if (c.showDialog(this, null) == JFileChooser.APPROVE_OPTION) {
  29.468 -            folder.setText(c.getSelectedFile().getAbsolutePath());
  29.469 -        }
  29.470 -    }
  29.471 -
  29.472 -    public void setScope(GivenFolderScope scope) {
  29.473 -        folder.setText(scope.folder);
  29.474 -        if (scope.indexURL != null) {
  29.475 -            if (scope.subIndex != null) {
  29.476 -                removeIndexButton.setSelected(true);
  29.477 -                indexURL.setText(scope.indexURL);
  29.478 -                subIndex.setSelectedItem(scope.subIndex);
  29.479 -            } else {
  29.480 -                localIndexButton.setSelected(true);
  29.481 -                indexFolder.setText(scope.indexURL);
  29.482 -                updateIndexCheckbox.setSelected(scope.update);
  29.483 -            }
  29.484 -        } else {
  29.485 -            noIndexButton.setSelected(true);
  29.486 -        }
  29.487 -
  29.488 -        selectCorrectCard();
  29.489 -    }
  29.490 -
  29.491 -    public GivenFolderScope getScope() {
  29.492 -        if (noIndexButton.isSelected()) {
  29.493 -            return new GivenFolderScope(folder.getText(), null, null, false);
  29.494 -        }
  29.495 -        if (localIndexButton.isSelected()) {
  29.496 -            return new GivenFolderScope(folder.getText(), new File(indexFolder.getText()).getAbsolutePath(), null, updateIndexCheckbox.isSelected());
  29.497 -        }
  29.498 -        if (removeIndexButton.isSelected()) {
  29.499 -            return new GivenFolderScope(folder.getText(), indexURL.getText(), (String) subIndex.getSelectedItem(), false);
  29.500 -        }
  29.501 -
  29.502 -        throw new IllegalStateException();
  29.503 -    }
  29.504 -
  29.505 -    private NotificationLineSupport notificationSupport;
  29.506 -
  29.507 -    public void setNotificationSupport(NotificationLineSupport notificationSupport) {
  29.508 -        this.notificationSupport = notificationSupport;
  29.509 -        selectCorrectCard();
  29.510 -    }
  29.511 -
  29.512 -    private void updateErrors() {
  29.513 -        notificationSupport.clearMessages();
  29.514 -        
  29.515 -        File folderFile = new File(folder.getText());
  29.516 -
  29.517 -        if (!folderFile.exists()) {
  29.518 -            notificationSupport.setErrorMessage("Specified directory does not exist.");
  29.519 -            okButton.setEnabled(false);
  29.520 -            return;
  29.521 -        }
  29.522 -
  29.523 -        if (!folderFile.isDirectory()) {
  29.524 -            notificationSupport.setErrorMessage("Specified directory is not directory.");
  29.525 -            okButton.setEnabled(false);
  29.526 -            return ;
  29.527 -        }
  29.528 -
  29.529 -        if (localIndexButton.isSelected()) {
  29.530 -            File indexFile = new File(indexFolder.getText());
  29.531 -
  29.532 -            updateIndexCheckbox.setEnabled(indexFile.exists());
  29.533 -
  29.534 -            if (!indexFile.exists()) {
  29.535 -                notificationSupport.setInformationMessage("Index does not exist and will be created.");
  29.536 -                okButton.setEnabled(true);
  29.537 -                return;
  29.538 -            }
  29.539 -
  29.540 -            if (!indexFile.isDirectory()) {
  29.541 -               notificationSupport.setErrorMessage("Index is not a folder.");
  29.542 -                okButton.setEnabled(false);
  29.543 -               return;
  29.544 -            }
  29.545 -            try {
  29.546 -                Index idx = FileBasedIndex.create(folderFile.toURI().toURL(), indexFile);
  29.547 -                IndexInfo info = idx.getIndexInfo();
  29.548 -
  29.549 -                indexInfo.setText(toDisplayText(info));
  29.550 -            } catch (MalformedURLException ex) {
  29.551 -                Exceptions.printStackTrace(ex);
  29.552 -            } catch (IOException ex) {
  29.553 -                Exceptions.printStackTrace(ex);
  29.554 -            }
  29.555 -        }
  29.556 -
  29.557 -        if (removeIndexButton.isSelected()) {
  29.558 -            if (checkingIndexURL.get()) {
  29.559 -                notificationSupport.setInformationMessage("Checking index URL");
  29.560 -                okButton.setEnabled(false);
  29.561 -                return;
  29.562 -            }
  29.563 -
  29.564 -            String urlError = checkingIndexURLError.get();
  29.565 -
  29.566 -            if (urlError != null) {
  29.567 -                notificationSupport.setErrorMessage(urlError);
  29.568 -                okButton.setEnabled(false);
  29.569 -                return;
  29.570 -            }
  29.571 -        }
  29.572 -        
  29.573 -        okButton.setEnabled(true);
  29.574 -    }
  29.575 -
  29.576 -    private final AtomicBoolean checkingIndexURL = new AtomicBoolean();
  29.577 -    private final AtomicReference<String> checkingIndexURLContentCopy = new AtomicReference<String>();
  29.578 -    private final AtomicReference<String> checkingIndexURLError = new AtomicReference<String>();
  29.579 -
  29.580 -    private void indexURLUpdated() {
  29.581 -        checkingIndexURLContentCopy.set(indexURL.getText());
  29.582 -        urlCheckerTask.cancel();
  29.583 -        urlCheckerTask.schedule(50);
  29.584 -    }
  29.585 -
  29.586 -    private static final RequestProcessor WORKER = new RequestProcessor(AddScopePanel.class.getName(), 1, false, false);
  29.587 -    private final RequestProcessor.Task urlCheckerTask = WORKER.create(new Runnable() {
  29.588 -
  29.589 -        public void run() {
  29.590 -            checkingIndexURL.set(true);
  29.591 -            checkingIndexURLError.set(null);
  29.592 -
  29.593 -            SwingUtilities.invokeLater(new Runnable() {
  29.594 -                public void run() {
  29.595 -                    updateErrors();
  29.596 -                }
  29.597 -            });
  29.598 -
  29.599 -            String urlText = checkingIndexURLContentCopy.get();
  29.600 -            Collection<? extends String> subindices = null;
  29.601 -
  29.602 -            try {
  29.603 -                URL url = new URL(urlText);
  29.604 -
  29.605 -                if (!url.getPath().endsWith("/"))
  29.606 -                    url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/" + (url.getQuery() != null ? "?" + url.getQuery() : ""));
  29.607 -                
  29.608 -                subindices = WebUtilities.requestStringArrayResponse(url.toURI().resolve("list"));
  29.609 -
  29.610 -                if (subindices.isEmpty()) {
  29.611 -                   checkingIndexURLError.set("Not an index.");
  29.612 -                }
  29.613 -            } catch (URISyntaxException ex) {
  29.614 -                checkingIndexURLError.set(ex.getLocalizedMessage());
  29.615 -            } catch (MalformedURLException ex) {
  29.616 -                checkingIndexURLError.set(ex.getLocalizedMessage());
  29.617 -            }
  29.618 -            
  29.619 -            checkingIndexURL.set(false);
  29.620 -
  29.621 -            final Collection<? extends String> subindicesFinal = subindices;
  29.622 -
  29.623 -            SwingUtilities.invokeLater(new Runnable() {
  29.624 -                public void run() {
  29.625 -                    updateErrors();
  29.626 -
  29.627 -                    if (subindicesFinal == null) return;
  29.628 -
  29.629 -                    DefaultComboBoxModel model = (DefaultComboBoxModel) subIndex.getModel();
  29.630 -                    String selected = (String) model.getSelectedItem();
  29.631 -
  29.632 -                    model.removeAllElements();
  29.633 -
  29.634 -                    boolean containsSelection = false;
  29.635 -                    Map<String, String> displayNames = new HashMap<String, String>();
  29.636 -
  29.637 -                    for (String subindex : subindicesFinal) {
  29.638 -                        String[] subindexSplit = subindex.split(":", 2);
  29.639 -                        if (subindexSplit[0].equals(selected)) containsSelection = true;
  29.640 -                        model.addElement(subindexSplit[0]);
  29.641 -                        displayNames.put(subindexSplit[0], subindexSplit[1]);
  29.642 -                    }
  29.643 -
  29.644 -                    if (containsSelection) {
  29.645 -                        model.setSelectedItem(selected);
  29.646 -                    }
  29.647 -
  29.648 -                    subindexSelectionUpdated();
  29.649 -                    subIndex.setRenderer(new RendererImpl(displayNames));
  29.650 -                }
  29.651 -            });
  29.652 -        }
  29.653 -    });
  29.654 -
  29.655 -    private final AtomicReference<String> indexInfoURLContentCopy = new AtomicReference<String>();
  29.656 -    private final AtomicReference<String> indexInfoSubIndexCopy = new AtomicReference<String>();
  29.657 -    private void subindexSelectionUpdated() {
  29.658 -        indexInfoURLContentCopy.set(indexURL.getText());
  29.659 -        indexInfoSubIndexCopy.set((String) subIndex.getSelectedItem());
  29.660 -        indexInfoTask.cancel();
  29.661 -        indexInfoTask.schedule(50);
  29.662 -    }
  29.663 -
  29.664 -    private final RequestProcessor.Task indexInfoTask = WORKER.create(new Runnable() {
  29.665 -
  29.666 -        public void run() {
  29.667 -            String urlText = indexInfoURLContentCopy.get();
  29.668 -            String subIndex = indexInfoSubIndexCopy.get();
  29.669 -            IndexInfo info = null;
  29.670 -
  29.671 -            try {
  29.672 -                URL url = new URL(urlText);
  29.673 -
  29.674 -                if (!url.getPath().endsWith("/"))
  29.675 -                    url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/" + (url.getQuery() != null ? "?" + url.getQuery() : ""));
  29.676 -
  29.677 -                String indexInfoText = WebUtilities.requestStringResponse(url.toURI().resolve("info?path=" + WebUtilities.escapeForQuery(subIndex)));
  29.678 -                info = IndexInfo.empty();
  29.679 -
  29.680 -                Pojson.update(info, indexInfoText);
  29.681 -            } catch (URISyntaxException ex) {
  29.682 -                Logger.getLogger(AddScopePanel.class.getName()).log(Level.FINE, null, ex);
  29.683 -            } catch (MalformedURLException ex) {
  29.684 -                Logger.getLogger(AddScopePanel.class.getName()).log(Level.FINE, null, ex);
  29.685 -            }
  29.686 -
  29.687 -            final IndexInfo infoFinal = info;
  29.688 -
  29.689 -            SwingUtilities.invokeLater(new Runnable() {
  29.690 -                public void run() {
  29.691 -                    if (infoFinal != null) {
  29.692 -                        indexInfo.setText(toDisplayText(infoFinal));
  29.693 -                    } else {
  29.694 -                        indexInfo.setText("");
  29.695 -                    }
  29.696 -                }
  29.697 -            });
  29.698 -        }
  29.699 -    });
  29.700 -
  29.701 -    private static String toDisplayText(IndexInfo info) {
  29.702 -        StringBuilder sb = new StringBuilder();
  29.703 -
  29.704 -        if (info.sourceLocation != null) {
  29.705 -            sb.append("Source Location: ").append(info.sourceLocation).append("\n");
  29.706 -        }
  29.707 -        if (info.lastUpdate >= 0) {
  29.708 -            sb.append("Last Update:\t").append(DateFormat.getDateTimeInstance().format(new Date(info.lastUpdate))).append("\n");
  29.709 -        }
  29.710 -        if (info.totalFiles >= 0) {
  29.711 -            sb.append("Indexed Files:\t").append(info.totalFiles).append("\n");
  29.712 -        }
  29.713 -
  29.714 -        return sb.toString();
  29.715 -    }
  29.716 -
  29.717 -    private static final class RendererImpl extends DefaultListCellRenderer {
  29.718 -        private final Map<String, String> displayNames;
  29.719 -        public RendererImpl(Map<String, String> displayNames) {
  29.720 -            this.displayNames = displayNames;
  29.721 -        }
  29.722 -
  29.723 -        @Override
  29.724 -        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  29.725 -            return super.getListCellRendererComponent(list, displayNames.get(value), index, isSelected, cellHasFocus);
  29.726 -        }
  29.727 -
  29.728 -    }
  29.729 -}
    30.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/ApplyPatternAction.java	Fri Jan 27 13:35:56 2012 +0100
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,52 +0,0 @@
    30.4 -/*
    30.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    30.6 - *
    30.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    30.8 - *
    30.9 - * The contents of this file are subject to the terms of either the GNU
   30.10 - * General Public License Version 2 only ("GPL") or the Common
   30.11 - * Development and Distribution License("CDDL") (collectively, the
   30.12 - * "License"). You may not use this file except in compliance with the
   30.13 - * License. You can obtain a copy of the License at
   30.14 - * http://www.netbeans.org/cddl-gplv2.html
   30.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   30.16 - * specific language governing permissions and limitations under the
   30.17 - * License.  When distributing the software, include this License Header
   30.18 - * Notice in each file and include the License file at
   30.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   30.20 - * particular file as subject to the "Classpath" exception as provided
   30.21 - * by Sun in the GPL Version 2 section of the License file that
   30.22 - * accompanied this code. If applicable, add the following below the
   30.23 - * License Header, with the fields enclosed by brackets [] replaced by
   30.24 - * your own identifying information:
   30.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   30.26 - *
   30.27 - * If you wish your version of this file to be governed by only the CDDL
   30.28 - * or only the GPL Version 2, indicate your decision by adding
   30.29 - * "[Contributor] elects to include this software in this distribution
   30.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   30.31 - * single choice of license, a recipient has the option to distribute
   30.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   30.33 - * to extend the choice of license to its licensees as provided above.
   30.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   30.35 - * Version 2 license, then the option applies only if the new code is
   30.36 - * made subject to such option by the copyright holder.
   30.37 - *
   30.38 - * Contributor(s):
   30.39 - *
   30.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   30.41 - */
   30.42 -
   30.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   30.44 -
   30.45 -import java.awt.event.ActionEvent;
   30.46 -import java.awt.event.ActionListener;
   30.47 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
   30.48 -import org.netbeans.modules.refactoring.spi.ui.UI;
   30.49 -
   30.50 -public final class ApplyPatternAction implements ActionListener {
   30.51 -
   30.52 -    public void actionPerformed(ActionEvent e) {
   30.53 -        UI.openRefactoringUI(new FindDuplicatesRefactoringUI(null, Scopes.allOpenedProjectsScope(), true, false));
   30.54 -    }
   30.55 -}
    31.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties	Fri Jan 27 13:35:56 2012 +0100
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,74 +0,0 @@
    31.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    31.5 -#
    31.6 -# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    31.7 -#
    31.8 -# The contents of this file are subject to the terms of either the GNU
    31.9 -# General Public License Version 2 only ("GPL") or the Common
   31.10 -# Development and Distribution License("CDDL") (collectively, the
   31.11 -# "License"). You may not use this file except in compliance with the
   31.12 -# License. You can obtain a copy of the License at
   31.13 -# http://www.netbeans.org/cddl-gplv2.html
   31.14 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   31.15 -# specific language governing permissions and limitations under the
   31.16 -# License.  When distributing the software, include this License Header
   31.17 -# Notice in each file and include the License file at
   31.18 -# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   31.19 -# particular file as subject to the "Classpath" exception as provided
   31.20 -# by Sun in the GPL Version 2 section of the License file that
   31.21 -# accompanied this code. If applicable, add the following below the
   31.22 -# License Header, with the fields enclosed by brackets [] replaced by
   31.23 -# your own identifying information:
   31.24 -# "Portions Copyrighted [year] [name of copyright owner]"
   31.25 -#
   31.26 -# If you wish your version of this file to be governed by only the CDDL
   31.27 -# or only the GPL Version 2, indicate your decision by adding
   31.28 -# "[Contributor] elects to include this software in this distribution
   31.29 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
   31.30 -# single choice of license, a recipient has the option to distribute
   31.31 -# your version of this file under either the CDDL, the GPL Version 2 or
   31.32 -# to extend the choice of license to its licensees as provided above.
   31.33 -# However, if you add GPL Version 2 code and therefore, elected the GPL
   31.34 -# Version 2 license, then the option applies only if the new code is
   31.35 -# made subject to such option by the copyright holder.
   31.36 -#
   31.37 -# Contributor(s):
   31.38 -#
   31.39 -# Portions Copyrighted 2009 Sun Microsystems, Inc.
   31.40 -
   31.41 -CTL_ApplyPatternAction=Apply Pattern
   31.42 -CTL_FindOccurrencesAction=Find Pattern Occurrences
   31.43 -AdvancedOptions.externalIndex.text=Use &external index
   31.44 -AdvancedOptions.indexLocation.text=
   31.45 -AdvancedOptions.indexLocationLabel.text=&Location:
   31.46 -AdvancedOptions.indexProjectLabel.text=&Project:
   31.47 -AddScopePanel.indexFolder.text=
   31.48 -AddScopePanel.browse.text=Browse
   31.49 -AddScopePanel.indexFolderLabel.text=Index Path:
   31.50 -AddScopePanel.indexURLLabel.text=Index URL:
   31.51 -AddScopePanel.indexURL.text=
   31.52 -AddScopePanel.noIndexButton.text=&No External Index
   31.53 -AddScopePanel.localIndexButton.text=&Local Index
   31.54 -AddScopePanel.removeIndexButton.text=&Remote Index
   31.55 -AddScopePanel.folder.text=
   31.56 -AddScopePanel.folderChooser.text=Browse
   31.57 -AddScopePanel.folderLabel.text=&Folder:
   31.58 -AddScopePanel.updateIndexCheckbox.text=&Update Index
   31.59 -AddScopePanel.jLabel1.text=Subindex:
   31.60 -ScopesPanel.edit.text=Edit
   31.61 -ScopesPanel.removeButton.text=Remove
   31.62 -ScopesPanel.add.text=Add
   31.63 -ScopesPanel.jLabel2.text=&Scope:
   31.64 -FindDuplicatesRefactoringPanel.verify.text=Verify occurrences if possible (slower)
   31.65 -FindDuplicatesRefactoringPanel.removeAllHints.text=<<
   31.66 -FindDuplicatesRefactoringPanel.removeHint.text=<
   31.67 -FindDuplicatesRefactoringPanel.addAllHints.text=>>
   31.68 -FindDuplicatesRefactoringPanel.addHint.text=>
   31.69 -FindDuplicatesRefactoringPanel.selectedHintsLabel.text=Selected Hints
   31.70 -FindDuplicatesRefactoringPanel.allHintsLabel.text=All Hints:
   31.71 -FindDuplicatesRefactoringPanel.customPattern.text=&Custom Pattern
   31.72 -FindDuplicatesRefactoringPanel.knowPatterns.text=&Known patterns
   31.73 -FindDuplicatesRefactoringPanel.examplesButton.text=
   31.74 -BTN_Examples=Examples
   31.75 -FindDuplicatesRefactoringPanel.recentButton.toolTipText=Recent Rules
   31.76 -FindDuplicatesRefactoringPanel.recentButton.text=
   31.77 -ExamplesList.pattern.contentType=text/x-javahints
    32.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/ExamplesList.form	Fri Jan 27 13:35:56 2012 +0100
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,95 +0,0 @@
    32.4 -<?xml version="1.1" encoding="UTF-8" ?>
    32.5 -
    32.6 -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    32.7 -  <AuxValues>
    32.8 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
    32.9 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   32.10 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   32.11 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
   32.12 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   32.13 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   32.14 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   32.15 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   32.16 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   32.17 -  </AuxValues>
   32.18 -
   32.19 -  <Layout>
   32.20 -    <DimensionLayout dim="0">
   32.21 -      <Group type="103" groupAlignment="0" attributes="0">
   32.22 -          <Group type="102" alignment="1" attributes="0">
   32.23 -              <EmptySpace max="-2" attributes="0"/>
   32.24 -              <Group type="103" groupAlignment="1" attributes="0">
   32.25 -                  <Component id="jScrollPane2" alignment="0" pref="376" max="32767" attributes="0"/>
   32.26 -                  <Component id="jScrollPane1" alignment="0" pref="376" max="32767" attributes="0"/>
   32.27 -                  <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
   32.28 -              </Group>
   32.29 -              <EmptySpace max="-2" attributes="0"/>
   32.30 -          </Group>
   32.31 -      </Group>
   32.32 -    </DimensionLayout>
   32.33 -    <DimensionLayout dim="1">
   32.34 -      <Group type="103" groupAlignment="0" attributes="0">
   32.35 -          <Group type="102" alignment="0" attributes="0">
   32.36 -              <EmptySpace max="-2" attributes="0"/>
   32.37 -              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
   32.38 -              <EmptySpace max="-2" attributes="0"/>
   32.39 -              <Component id="jScrollPane1" pref="130" max="32767" attributes="0"/>
   32.40 -              <EmptySpace max="-2" attributes="0"/>
   32.41 -              <Component id="jScrollPane2" min="-2" pref="119" max="-2" attributes="0"/>
   32.42 -              <EmptySpace max="-2" attributes="0"/>
   32.43 -          </Group>
   32.44 -      </Group>
   32.45 -    </DimensionLayout>
   32.46 -  </Layout>
   32.47 -  <SubComponents>
   32.48 -    <Component class="javax.swing.JLabel" name="jLabel1">
   32.49 -      <Properties>
   32.50 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   32.51 -          <Connection code="convertor.getHeader()" type="code"/>
   32.52 -        </Property>
   32.53 -      </Properties>
   32.54 -    </Component>
   32.55 -    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
   32.56 -      <AuxValues>
   32.57 -        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   32.58 -      </AuxValues>
   32.59 -
   32.60 -      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   32.61 -      <SubComponents>
   32.62 -        <Component class="javax.swing.JList" name="list">
   32.63 -          <Properties>
   32.64 -            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
   32.65 -              <StringArray count="5">
   32.66 -                <StringItem index="0" value="Item 1"/>
   32.67 -                <StringItem index="1" value="Item 2"/>
   32.68 -                <StringItem index="2" value="Item 3"/>
   32.69 -                <StringItem index="3" value="Item 4"/>
   32.70 -                <StringItem index="4" value="Item 5"/>
   32.71 -              </StringArray>
   32.72 -            </Property>
   32.73 -          </Properties>
   32.74 -          <Events>
   32.75 -            <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseClicked"/>
   32.76 -            <EventHandler event="valueChanged" listener="javax.swing.event.ListSelectionListener" parameters="javax.swing.event.ListSelectionEvent" handler="listValueChanged"/>
   32.77 -          </Events>
   32.78 -        </Component>
   32.79 -      </SubComponents>
   32.80 -    </Container>
   32.81 -    <Container class="javax.swing.JScrollPane" name="jScrollPane2">
   32.82 -      <AuxValues>
   32.83 -        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   32.84 -      </AuxValues>
   32.85 -
   32.86 -      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   32.87 -      <SubComponents>
   32.88 -        <Component class="javax.swing.JEditorPane" name="pattern">
   32.89 -          <Properties>
   32.90 -            <Property name="contentType" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   32.91 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="ExamplesList.pattern.contentType" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   32.92 -            </Property>
   32.93 -          </Properties>
   32.94 -        </Component>
   32.95 -      </SubComponents>
   32.96 -    </Container>
   32.97 -  </SubComponents>
   32.98 -</Form>
    33.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/ExamplesList.java	Fri Jan 27 13:35:56 2012 +0100
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,223 +0,0 @@
    33.4 -/*
    33.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33.6 - *
    33.7 - * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    33.8 - *
    33.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   33.10 - * Other names may be trademarks of their respective owners.
   33.11 - *
   33.12 - * The contents of this file are subject to the terms of either the GNU
   33.13 - * General Public License Version 2 only ("GPL") or the Common
   33.14 - * Development and Distribution License("CDDL") (collectively, the
   33.15 - * "License"). You may not use this file except in compliance with the
   33.16 - * License. You can obtain a copy of the License at
   33.17 - * http://www.netbeans.org/cddl-gplv2.html
   33.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   33.19 - * specific language governing permissions and limitations under the
   33.20 - * License.  When distributing the software, include this License Header
   33.21 - * Notice in each file and include the License file at
   33.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   33.23 - * particular file as subject to the "Classpath" exception as provided
   33.24 - * by Oracle in the GPL Version 2 section of the License file that
   33.25 - * accompanied this code. If applicable, add the following below the
   33.26 - * License Header, with the fields enclosed by brackets [] replaced by
   33.27 - * your own identifying information:
   33.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   33.29 - *
   33.30 - * If you wish your version of this file to be governed by only the CDDL
   33.31 - * or only the GPL Version 2, indicate your decision by adding
   33.32 - * "[Contributor] elects to include this software in this distribution
   33.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   33.34 - * single choice of license, a recipient has the option to distribute
   33.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   33.36 - * to extend the choice of license to its licensees as provided above.
   33.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   33.38 - * Version 2 license, then the option applies only if the new code is
   33.39 - * made subject to such option by the copyright holder.
   33.40 - *
   33.41 - * Contributor(s):
   33.42 - *
   33.43 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   33.44 - */
   33.45 -package org.netbeans.modules.jackpot30.impl.refactoring;
   33.46 -
   33.47 -import java.awt.Component;
   33.48 -import java.awt.Dialog;
   33.49 -import java.awt.Rectangle;
   33.50 -import java.util.Collections;
   33.51 -import java.util.Set;
   33.52 -import javax.swing.DefaultListCellRenderer;
   33.53 -import javax.swing.DefaultListModel;
   33.54 -import javax.swing.JList;
   33.55 -import javax.swing.text.BadLocationException;
   33.56 -import org.netbeans.modules.jackpot30.impl.examples.Example.Option;
   33.57 -import org.openide.DialogDescriptor;
   33.58 -import org.openide.DialogDisplayer;
   33.59 -import org.openide.util.Exceptions;
   33.60 -
   33.61 -/**
   33.62 - *
   33.63 - * @author lahvac
   33.64 - */
   33.65 -public class ExamplesList<T> extends javax.swing.JPanel {
   33.66 -
   33.67 -    private final DialogDescription<T> convertor;
   33.68 -    private final Class<T> dataClass;
   33.69 -
   33.70 -    public ExamplesList(Iterable<? extends T> data, DialogDescription<T> convertor, Class<T> dataClass, Set<Option> require, Set<Option> forbidden) {
   33.71 -        this.convertor = convertor;
   33.72 -        this.dataClass = dataClass;
   33.73 -        
   33.74 -        initComponents();
   33.75 -
   33.76 -        DefaultListModel listModel = new DefaultListModel();
   33.77 -
   33.78 -        for (T t : data) {
   33.79 -            Set<Option> options = convertor.getOptions(t);
   33.80 -            if (!options.containsAll(require)) continue;
   33.81 -            if (!Collections.disjoint(options, forbidden)) continue;
   33.82 -            
   33.83 -            listModel.addElement(t);
   33.84 -        }
   33.85 -
   33.86 -        list.setModel(listModel);
   33.87 -        list.setCellRenderer(new ExamplesRenderer());
   33.88 -        list.setSelectedIndex(0);
   33.89 -    }
   33.90 -
   33.91 -    /** This method is called from within the constructor to
   33.92 -     * initialize the form.
   33.93 -     * WARNING: Do NOT modify this code. The content of this method is
   33.94 -     * always regenerated by the Form Editor.
   33.95 -     */
   33.96 -    @SuppressWarnings("unchecked")
   33.97 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   33.98 -    private void initComponents() {
   33.99 -
  33.100 -        jLabel1 = new javax.swing.JLabel();
  33.101 -        jScrollPane1 = new javax.swing.JScrollPane();
  33.102 -        list = new javax.swing.JList();
  33.103 -        jScrollPane2 = new javax.swing.JScrollPane();
  33.104 -        pattern = new javax.swing.JEditorPane();
  33.105 -
  33.106 -        jLabel1.setText(convertor.getHeader());
  33.107 -
  33.108 -        list.setModel(new javax.swing.AbstractListModel() {
  33.109 -            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  33.110 -            public int getSize() { return strings.length; }
  33.111 -            public Object getElementAt(int i) { return strings[i]; }
  33.112 -        });
  33.113 -        list.addMouseListener(new java.awt.event.MouseAdapter() {
  33.114 -            public void mouseClicked(java.awt.event.MouseEvent evt) {
  33.115 -                listMouseClicked(evt);
  33.116 -            }
  33.117 -        });
  33.118 -        list.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  33.119 -            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
  33.120 -                listValueChanged(evt);
  33.121 -            }
  33.122 -        });
  33.123 -        jScrollPane1.setViewportView(list);
  33.124 -
  33.125 -        pattern.setContentType(org.openide.util.NbBundle.getMessage(ExamplesList.class, "ExamplesList.pattern.contentType")); // NOI18N
  33.126 -        jScrollPane2.setViewportView(pattern);
  33.127 -
  33.128 -        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  33.129 -        this.setLayout(layout);
  33.130 -        layout.setHorizontalGroup(
  33.131 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  33.132 -            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  33.133 -                .addContainerGap()
  33.134 -                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  33.135 -                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
  33.136 -                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
  33.137 -                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
  33.138 -                .addContainerGap())
  33.139 -        );
  33.140 -        layout.setVerticalGroup(
  33.141 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  33.142 -            .addGroup(layout.createSequentialGroup()
  33.143 -                .addContainerGap()
  33.144 -                .addComponent(jLabel1)
  33.145 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  33.146 -                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
  33.147 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  33.148 -                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
  33.149 -                .addContainerGap())
  33.150 -        );
  33.151 -    }// </editor-fold>//GEN-END:initComponents
  33.152 -
  33.153 -    private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
  33.154 -        if (evt.getClickCount() > 1) {
  33.155 -            desc.setValue(DialogDescriptor.OK_OPTION);
  33.156 -            dialog.setVisible(false);
  33.157 -        }
  33.158 -    }//GEN-LAST:event_listMouseClicked
  33.159 -
  33.160 -    private void listValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listValueChanged
  33.161 -        T ex = dataClass.cast(list.getSelectedValue());
  33.162 -
  33.163 -        pattern.setText(convertor.getCode(ex));
  33.164 -        
  33.165 -        try {
  33.166 -            Rectangle rect = pattern.modelToView(0);
  33.167 -
  33.168 -            if (rect != null) {
  33.169 -                pattern.scrollRectToVisible(rect);
  33.170 -            }
  33.171 -        } catch (BadLocationException ex1) {
  33.172 -            Exceptions.printStackTrace(ex1);
  33.173 -        }
  33.174 -    }//GEN-LAST:event_listValueChanged
  33.175 -
  33.176 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  33.177 -    private javax.swing.JLabel jLabel1;
  33.178 -    private javax.swing.JScrollPane jScrollPane1;
  33.179 -    private javax.swing.JScrollPane jScrollPane2;
  33.180 -    private javax.swing.JList list;
  33.181 -    private javax.swing.JEditorPane pattern;
  33.182 -    // End of variables declaration//GEN-END:variables
  33.183 -
  33.184 -    private DialogDescriptor desc;
  33.185 -    private Dialog           dialog;
  33.186 -
  33.187 -    public void setDialog(DialogDescriptor desc, Dialog dialog) {
  33.188 -        this.desc = desc;
  33.189 -        this.dialog = dialog;
  33.190 -    }
  33.191 -
  33.192 -    public T getSelectedExample() {
  33.193 -        return dataClass.cast(list.getSelectedValue());
  33.194 -    }
  33.195 -    
  33.196 -    private class ExamplesRenderer extends DefaultListCellRenderer {
  33.197 -        @Override
  33.198 -        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  33.199 -            value = convertor.getDisplayName(dataClass.cast(value));
  33.200 -            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  33.201 -        }
  33.202 -    }
  33.203 -
  33.204 -    public static <T> T chooseExample(Iterable<? extends T> examplesList, DialogDescription<T> convertor, Class<T> dataClass, Set<Option> require, Set<Option> forbidden) {
  33.205 -        ExamplesList<T> examples = new ExamplesList<T>(examplesList, convertor, dataClass, require, forbidden);
  33.206 -        DialogDescriptor dd = new DialogDescriptor(examples, convertor.getCaption(), true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, null);
  33.207 -        Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
  33.208 -
  33.209 -        examples.setDialog(dd, dialog);
  33.210 -        dialog.setVisible(true);
  33.211 -
  33.212 -        if (dd.getValue() == DialogDescriptor.OK_OPTION) {
  33.213 -            return examples.getSelectedExample();
  33.214 -        }
  33.215 -
  33.216 -        return null;
  33.217 -    }
  33.218 -
  33.219 -    public interface DialogDescription<T> {
  33.220 -        public String getCaption();
  33.221 -        public String getHeader();
  33.222 -        public String getDisplayName(T t);
  33.223 -        public String getCode(T t);
  33.224 -        public Set<Option> getOptions(T t);
  33.225 -    }
  33.226 -}
    34.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoring.java	Fri Jan 27 13:35:56 2012 +0100
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,87 +0,0 @@
    34.4 -/*
    34.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    34.6 - *
    34.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    34.8 - *
    34.9 - * The contents of this file are subject to the terms of either the GNU
   34.10 - * General Public License Version 2 only ("GPL") or the Common
   34.11 - * Development and Distribution License("CDDL") (collectively, the
   34.12 - * "License"). You may not use this file except in compliance with the
   34.13 - * License. You can obtain a copy of the License at
   34.14 - * http://www.netbeans.org/cddl-gplv2.html
   34.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   34.16 - * specific language governing permissions and limitations under the
   34.17 - * License.  When distributing the software, include this License Header
   34.18 - * Notice in each file and include the License file at
   34.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   34.20 - * particular file as subject to the "Classpath" exception as provided
   34.21 - * by Sun in the GPL Version 2 section of the License file that
   34.22 - * accompanied this code. If applicable, add the following below the
   34.23 - * License Header, with the fields enclosed by brackets [] replaced by
   34.24 - * your own identifying information:
   34.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   34.26 - *
   34.27 - * If you wish your version of this file to be governed by only the CDDL
   34.28 - * or only the GPL Version 2, indicate your decision by adding
   34.29 - * "[Contributor] elects to include this software in this distribution
   34.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   34.31 - * single choice of license, a recipient has the option to distribute
   34.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   34.33 - * to extend the choice of license to its licensees as provided above.
   34.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   34.35 - * Version 2 license, then the option applies only if the new code is
   34.36 - * made subject to such option by the copyright holder.
   34.37 - *
   34.38 - * Contributor(s):
   34.39 - *
   34.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   34.41 - */
   34.42 -
   34.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   34.44 -
   34.45 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
   34.46 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   34.47 -import org.netbeans.modules.refactoring.api.AbstractRefactoring;
   34.48 -import org.openide.util.Lookup;
   34.49 -
   34.50 -public class FindDuplicatesRefactoring extends AbstractRefactoring {
   34.51 -
   34.52 -    private final boolean query;
   34.53 -    private Iterable<? extends HintDescription> patterns;
   34.54 -    private Scope scope;
   34.55 -    private boolean verify;
   34.56 -
   34.57 -    public FindDuplicatesRefactoring(boolean query) {
   34.58 -        super(Lookup.EMPTY);
   34.59 -        this.query = query;
   34.60 -    }
   34.61 -
   34.62 -    public boolean isQuery() {
   34.63 -        return query;
   34.64 -    }
   34.65 -
   34.66 -    public synchronized Iterable<? extends HintDescription> getPattern() {
   34.67 -        return patterns;
   34.68 -    }
   34.69 -
   34.70 -    public synchronized void setPattern(Iterable<? extends HintDescription> patterns) {
   34.71 -        this.patterns = patterns;
   34.72 -    }
   34.73 -
   34.74 -    public synchronized Scope getScope() {
   34.75 -        return scope;
   34.76 -    }
   34.77 -
   34.78 -    public synchronized void setScope(Scope scope) {
   34.79 -        this.scope = scope;
   34.80 -    }
   34.81 -
   34.82 -    public boolean isVerify() {
   34.83 -        return verify;
   34.84 -    }
   34.85 -
   34.86 -    public void setVerify(boolean verify) {
   34.87 -        this.verify = verify;
   34.88 -    }
   34.89 -
   34.90 -}
    35.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPanel.form	Fri Jan 27 13:35:56 2012 +0100
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,358 +0,0 @@
    35.4 -<?xml version="1.0" encoding="UTF-8" ?>
    35.5 -
    35.6 -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    35.7 -  <NonVisualComponents>
    35.8 -    <Component class="javax.swing.ButtonGroup" name="main">
    35.9 -    </Component>
   35.10 -  </NonVisualComponents>
   35.11 -  <AuxValues>
   35.12 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
   35.13 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   35.14 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   35.15 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
   35.16 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   35.17 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
   35.18 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   35.19 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   35.20 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   35.21 -    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,43,0,0,2,64"/>
   35.22 -  </AuxValues>
   35.23 -
   35.24 -  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   35.25 -  <SubComponents>
   35.26 -    <Component class="javax.swing.JCheckBox" name="verify">
   35.27 -      <Properties>
   35.28 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   35.29 -          <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.verify.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   35.30 -        </Property>
   35.31 -      </Properties>
   35.32 -      <Constraints>
   35.33 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   35.34 -          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="18" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
   35.35 -        </Constraint>
   35.36 -      </Constraints>
   35.37 -    </Component>
   35.38 -    <Container class="javax.swing.JPanel" name="patternSelection">
   35.39 -      <Constraints>
   35.40 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   35.41 -          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
   35.42 -        </Constraint>
   35.43 -      </Constraints>
   35.44 -
   35.45 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/>
   35.46 -      <SubComponents>
   35.47 -        <Container class="javax.swing.JPanel" name="knownPatternsPanel">
   35.48 -          <AuxValues>
   35.49 -            <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,2,8"/>
   35.50 -          </AuxValues>
   35.51 -          <Constraints>
   35.52 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
   35.53 -              <CardConstraints cardName="knownPatterns"/>
   35.54 -            </Constraint>
   35.55 -          </Constraints>
   35.56 -
   35.57 -          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   35.58 -          <SubComponents>
   35.59 -            <Component class="javax.swing.JLabel" name="allHintsLabel">
   35.60 -              <Properties>
   35.61 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   35.62 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.allHintsLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   35.63 -                </Property>
   35.64 -              </Properties>
   35.65 -              <Constraints>
   35.66 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   35.67 -                  <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="6" anchor="18" weightX="0.0" weightY="0.0"/>
   35.68 -                </Constraint>
   35.69 -              </Constraints>
   35.70 -            </Component>
   35.71 -            <Container class="javax.swing.JScrollPane" name="jScrollPane2">
   35.72 -              <AuxValues>
   35.73 -                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   35.74 -              </AuxValues>
   35.75 -              <Constraints>
   35.76 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   35.77 -                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="6" anchor="18" weightX="0.5" weightY="1.0"/>
   35.78 -                </Constraint>
   35.79 -              </Constraints>
   35.80 -
   35.81 -              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   35.82 -              <SubComponents>
   35.83 -                <Component class="javax.swing.JList" name="allHints">
   35.84 -                  <Properties>
   35.85 -                    <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
   35.86 -                      <StringArray count="5">
   35.87 -                        <StringItem index="0" value="Item 1"/>
   35.88 -                        <StringItem index="1" value="Item 2"/>
   35.89 -                        <StringItem index="2" value="Item 3"/>
   35.90 -                        <StringItem index="3" value="Item 4"/>
   35.91 -                        <StringItem index="4" value="Item 5"/>
   35.92 -                      </StringArray>
   35.93 -                    </Property>
   35.94 -                    <Property name="prototypeCellValue" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   35.95 -                      <Connection code="HINTS_LIST_PROTOTYPE" type="code"/>
   35.96 -                    </Property>
   35.97 -                    <Property name="visibleRowCount" type="int" value="24"/>
   35.98 -                  </Properties>
   35.99 -                </Component>
  35.100 -              </SubComponents>
  35.101 -            </Container>
  35.102 -            <Container class="javax.swing.JScrollPane" name="jScrollPane3">
  35.103 -              <AuxValues>
  35.104 -                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
  35.105 -              </AuxValues>
  35.106 -              <Constraints>
  35.107 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.108 -                  <GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.5" weightY="1.0"/>
  35.109 -                </Constraint>
  35.110 -              </Constraints>
  35.111 -
  35.112 -              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  35.113 -              <SubComponents>
  35.114 -                <Component class="javax.swing.JList" name="selectedHints">
  35.115 -                  <Properties>
  35.116 -                    <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
  35.117 -                      <StringArray count="5">
  35.118 -                        <StringItem index="0" value="Item 1"/>
  35.119 -                        <StringItem index="1" value="Item 2"/>
  35.120 -                        <StringItem index="2" value="Item 3"/>
  35.121 -                        <StringItem index="3" value="Item 4"/>
  35.122 -                        <StringItem index="4" value="Item 5"/>
  35.123 -                      </StringArray>
  35.124 -                    </Property>
  35.125 -                    <Property name="prototypeCellValue" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
  35.126 -                      <Connection code="HINTS_LIST_PROTOTYPE" type="code"/>
  35.127 -                    </Property>
  35.128 -                    <Property name="visibleRowCount" type="int" value="24"/>
  35.129 -                  </Properties>
  35.130 -                </Component>
  35.131 -              </SubComponents>
  35.132 -            </Container>
  35.133 -            <Component class="javax.swing.JLabel" name="selectedHintsLabel">
  35.134 -              <Properties>
  35.135 -                <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.136 -                  <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.selectedHintsLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.137 -                </Property>
  35.138 -              </Properties>
  35.139 -              <Constraints>
  35.140 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.141 -                  <GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
  35.142 -                </Constraint>
  35.143 -              </Constraints>
  35.144 -            </Component>
  35.145 -            <Container class="javax.swing.JPanel" name="jPanel2">
  35.146 -              <Constraints>
  35.147 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.148 -                  <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="5" anchor="10" weightX="0.0" weightY="1.0"/>
  35.149 -                </Constraint>
  35.150 -              </Constraints>
  35.151 -
  35.152 -              <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  35.153 -              <SubComponents>
  35.154 -                <Component class="javax.swing.JButton" name="addHint">
  35.155 -                  <Properties>
  35.156 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.157 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.addHint.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.158 -                    </Property>
  35.159 -                  </Properties>
  35.160 -                  <Events>
  35.161 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addHintActionPerformed"/>
  35.162 -                  </Events>
  35.163 -                  <Constraints>
  35.164 -                    <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.165 -                      <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="6" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
  35.166 -                    </Constraint>
  35.167 -                  </Constraints>
  35.168 -                </Component>
  35.169 -                <Component class="javax.swing.JButton" name="addAllHints">
  35.170 -                  <Properties>
  35.171 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.172 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.addAllHints.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.173 -                    </Property>
  35.174 -                  </Properties>
  35.175 -                  <Events>
  35.176 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addAllHintsActionPerformed"/>
  35.177 -                  </Events>
  35.178 -                  <Constraints>
  35.179 -                    <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.180 -                      <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="6" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
  35.181 -                    </Constraint>
  35.182 -                  </Constraints>
  35.183 -                </Component>
  35.184 -                <Component class="javax.swing.JButton" name="removeHint">
  35.185 -                  <Properties>
  35.186 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.187 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.removeHint.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.188 -                    </Property>
  35.189 -                  </Properties>
  35.190 -                  <Events>
  35.191 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeHintActionPerformed"/>
  35.192 -                  </Events>
  35.193 -                  <Constraints>
  35.194 -                    <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.195 -                      <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="6" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
  35.196 -                    </Constraint>
  35.197 -                  </Constraints>
  35.198 -                </Component>
  35.199 -                <Component class="javax.swing.JButton" name="removeAllHints">
  35.200 -                  <Properties>
  35.201 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.202 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.removeAllHints.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.203 -                    </Property>
  35.204 -                  </Properties>
  35.205 -                  <Events>
  35.206 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeAllHintsActionPerformed"/>
  35.207 -                  </Events>
  35.208 -                  <Constraints>
  35.209 -                    <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.210 -                      <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
  35.211 -                    </Constraint>
  35.212 -                  </Constraints>
  35.213 -                </Component>
  35.214 -              </SubComponents>
  35.215 -            </Container>
  35.216 -          </SubComponents>
  35.217 -        </Container>
  35.218 -        <Container class="javax.swing.JPanel" name="customPatternPanel">
  35.219 -          <Constraints>
  35.220 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
  35.221 -              <CardConstraints cardName="customPattern"/>
  35.222 -            </Constraint>
  35.223 -          </Constraints>
  35.224 -
  35.225 -          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  35.226 -          <SubComponents>
  35.227 -            <Container class="javax.swing.JPanel" name="jPanel3">
  35.228 -              <Constraints>
  35.229 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.230 -                  <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="3" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="13" weightX="0.0" weightY="0.0"/>
  35.231 -                </Constraint>
  35.232 -              </Constraints>
  35.233 -
  35.234 -              <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
  35.235 -                <Property name="horizontalGap" type="int" value="0"/>
  35.236 -              </Layout>
  35.237 -              <SubComponents>
  35.238 -                <Component class="javax.swing.JButton" name="recentButton">
  35.239 -                  <Properties>
  35.240 -                    <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
  35.241 -                      <Image iconType="3" name="/org/netbeans/modules/jackpot30/impl/resources/recent_icon.png"/>
  35.242 -                    </Property>
  35.243 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.244 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.recentButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.245 -                    </Property>
  35.246 -                    <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.247 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.recentButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.248 -                    </Property>
  35.249 -                    <Property name="borderPainted" type="boolean" value="false"/>
  35.250 -                    <Property name="contentAreaFilled" type="boolean" value="false"/>
  35.251 -                  </Properties>
  35.252 -                  <Events>
  35.253 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="recentButtonActionPerformed"/>
  35.254 -                  </Events>
  35.255 -                </Component>
  35.256 -                <Component class="javax.swing.JButton" name="examplesButton">
  35.257 -                  <Properties>
  35.258 -                    <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
  35.259 -                      <Image iconType="3" name="/org/netbeans/modules/jackpot30/impl/resources/examples_icon.png"/>
  35.260 -                    </Property>
  35.261 -                    <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.262 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.examplesButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.263 -                    </Property>
  35.264 -                    <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.265 -                      <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="BTN_Examples" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.266 -                    </Property>
  35.267 -                    <Property name="borderPainted" type="boolean" value="false"/>
  35.268 -                    <Property name="contentAreaFilled" type="boolean" value="false"/>
  35.269 -                  </Properties>
  35.270 -                  <Events>
  35.271 -                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="examplesButtonActionPerformed"/>
  35.272 -                  </Events>
  35.273 -                </Component>
  35.274 -              </SubComponents>
  35.275 -            </Container>
  35.276 -            <Container class="javax.swing.JScrollPane" name="jScrollPane4">
  35.277 -              <AuxValues>
  35.278 -                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
  35.279 -              </AuxValues>
  35.280 -              <Constraints>
  35.281 -                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.282 -                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  35.283 -                </Constraint>
  35.284 -              </Constraints>
  35.285 -
  35.286 -              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  35.287 -              <SubComponents>
  35.288 -                <Component class="javax.swing.JEditorPane" name="pattern">
  35.289 -                </Component>
  35.290 -              </SubComponents>
  35.291 -            </Container>
  35.292 -          </SubComponents>
  35.293 -        </Container>
  35.294 -      </SubComponents>
  35.295 -    </Container>
  35.296 -    <Container class="javax.swing.JPanel" name="patternTypeSelectionPanel">
  35.297 -      <Constraints>
  35.298 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.299 -          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  35.300 -        </Constraint>
  35.301 -      </Constraints>
  35.302 -
  35.303 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  35.304 -      <SubComponents>
  35.305 -        <Component class="javax.swing.JRadioButton" name="knowPatterns">
  35.306 -          <Properties>
  35.307 -            <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
  35.308 -              <ComponentRef name="main"/>
  35.309 -            </Property>
  35.310 -            <Property name="selected" type="boolean" value="true"/>
  35.311 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.312 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.knowPatterns.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.313 -            </Property>
  35.314 -          </Properties>
  35.315 -          <Events>
  35.316 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="knowPatternsActionPerformed"/>
  35.317 -          </Events>
  35.318 -          <Constraints>
  35.319 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.320 -              <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
  35.321 -            </Constraint>
  35.322 -          </Constraints>
  35.323 -        </Component>
  35.324 -        <Component class="javax.swing.JRadioButton" name="customPattern">
  35.325 -          <Properties>
  35.326 -            <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
  35.327 -              <ComponentRef name="main"/>
  35.328 -            </Property>
  35.329 -            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  35.330 -              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="FindDuplicatesRefactoringPanel.customPattern.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  35.331 -            </Property>
  35.332 -          </Properties>
  35.333 -          <Events>
  35.334 -            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="customPatternActionPerformed"/>
  35.335 -          </Events>
  35.336 -          <Constraints>
  35.337 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.338 -              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="24" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
  35.339 -            </Constraint>
  35.340 -          </Constraints>
  35.341 -        </Component>
  35.342 -        <Container class="javax.swing.JPanel" name="jPanel1">
  35.343 -          <Constraints>
  35.344 -            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.345 -              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  35.346 -            </Constraint>
  35.347 -          </Constraints>
  35.348 -
  35.349 -          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
  35.350 -        </Container>
  35.351 -      </SubComponents>
  35.352 -    </Container>
  35.353 -    <Component class="org.netbeans.modules.jackpot30.impl.refactoring.ScopesPanel" name="scopesPanel">
  35.354 -      <Constraints>
  35.355 -        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  35.356 -          <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="18" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  35.357 -        </Constraint>
  35.358 -      </Constraints>
  35.359 -    </Component>
  35.360 -  </SubComponents>
  35.361 -</Form>
    36.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPanel.java	Fri Jan 27 13:35:56 2012 +0100
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,723 +0,0 @@
    36.4 -/*
    36.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    36.6 - *
    36.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    36.8 - *
    36.9 - * The contents of this file are subject to the terms of either the GNU
   36.10 - * General Public License Version 2 only ("GPL") or the Common
   36.11 - * Development and Distribution License("CDDL") (collectively, the
   36.12 - * "License"). You may not use this file except in compliance with the
   36.13 - * License. You can obtain a copy of the License at
   36.14 - * http://www.netbeans.org/cddl-gplv2.html
   36.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   36.16 - * specific language governing permissions and limitations under the
   36.17 - * License.  When distributing the software, include this License Header
   36.18 - * Notice in each file and include the License file at
   36.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   36.20 - * particular file as subject to the "Classpath" exception as provided
   36.21 - * by Sun in the GPL Version 2 section of the License file that
   36.22 - * accompanied this code. If applicable, add the following below the
   36.23 - * License Header, with the fields enclosed by brackets [] replaced by
   36.24 - * your own identifying information:
   36.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   36.26 - *
   36.27 - * If you wish your version of this file to be governed by only the CDDL
   36.28 - * or only the GPL Version 2, indicate your decision by adding
   36.29 - * "[Contributor] elects to include this software in this distribution
   36.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   36.31 - * single choice of license, a recipient has the option to distribute
   36.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   36.33 - * to extend the choice of license to its licensees as provided above.
   36.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   36.35 - * Version 2 license, then the option applies only if the new code is
   36.36 - * made subject to such option by the copyright holder.
   36.37 - *
   36.38 - * Contributor(s):
   36.39 - *
   36.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   36.41 - */
   36.42 -
   36.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   36.44 -
   36.45 -import java.awt.CardLayout;
   36.46 -import java.awt.event.KeyEvent;
   36.47 -import java.awt.event.KeyListener;
   36.48 -import java.io.IOException;
   36.49 -import java.util.Collection;
   36.50 -import java.util.Collections;
   36.51 -import java.util.EnumSet;
   36.52 -import java.util.HashSet;
   36.53 -import java.util.LinkedList;
   36.54 -import java.util.List;
   36.55 -import java.util.Map;
   36.56 -import java.util.Set;
   36.57 -import java.util.TreeMap;
   36.58 -import java.util.logging.Level;
   36.59 -import java.util.logging.Logger;
   36.60 -import java.util.prefs.BackingStoreException;
   36.61 -import java.util.prefs.Preferences;
   36.62 -import javax.swing.DefaultListModel;
   36.63 -import javax.swing.SwingUtilities;
   36.64 -import javax.swing.event.ChangeEvent;
   36.65 -import javax.swing.event.ChangeListener;
   36.66 -import javax.swing.event.DocumentEvent;
   36.67 -import javax.swing.event.DocumentListener;
   36.68 -import javax.swing.text.Document;
   36.69 -import org.netbeans.api.java.classpath.ClassPath;
   36.70 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
   36.71 -import org.netbeans.modules.editor.NbEditorUtilities;
   36.72 -import org.netbeans.modules.jackpot30.impl.examples.Example;
   36.73 -import org.netbeans.modules.jackpot30.impl.examples.Example.Option;
   36.74 -import org.netbeans.modules.jackpot30.impl.examples.LoadExamples;
   36.75 -import org.netbeans.modules.jackpot30.impl.refactoring.ExamplesList.DialogDescription;
   36.76 -import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
   36.77 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
   36.78 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   36.79 -import org.openide.cookies.EditorCookie;
   36.80 -import org.openide.cookies.SaveCookie;
   36.81 -import org.openide.filesystems.FileObject;
   36.82 -import org.openide.filesystems.FileUtil;
   36.83 -import org.openide.loaders.DataObject;
   36.84 -import org.openide.util.Exceptions;
   36.85 -import org.openide.util.NbPreferences;
   36.86 -import org.openide.util.Union2;
   36.87 -
   36.88 -/**
   36.89 - *
   36.90 - * @author lahvac
   36.91 - */
   36.92 -public class FindDuplicatesRefactoringPanel extends javax.swing.JPanel {
   36.93 -
   36.94 -    private final Map<String, Collection<HintDescription>> displayName2Hints;
   36.95 -    private final ChangeListener changeListener;
   36.96 -    private final boolean query;
   36.97 -    
   36.98 -    public FindDuplicatesRefactoringPanel(final ChangeListener parent, boolean query) {
   36.99 -        this.changeListener = parent;
  36.100 -        this.query = query;
  36.101 -        
  36.102 -        Set<ClassPath> cps = new HashSet<ClassPath>();
  36.103 -
  36.104 -        cps.addAll(GlobalPathRegistry.getDefault().getPaths(ClassPath.BOOT));
  36.105 -        cps.addAll(GlobalPathRegistry.getDefault().getPaths(ClassPath.COMPILE));
  36.106 -        cps.addAll(GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE));
  36.107 -        
  36.108 -        Collection<? extends HintDescription> hints = Utilities.listAllHints(cps);
  36.109 -        
  36.110 -        displayName2Hints = Utilities.sortOutHints(hints, new TreeMap<String, Collection<HintDescription>>());
  36.111 -
  36.112 -        initComponents();
  36.113 -
  36.114 -        DefaultListModel all = new DefaultListModel();
  36.115 -        DefaultListModel selected = new DefaultListModel();
  36.116 -
  36.117 -        for (String dn : displayName2Hints.keySet()) {
  36.118 -            all.addElement(dn);
  36.119 -        }
  36.120 -
  36.121 -        allHints.setModel(all);
  36.122 -        selectedHints.setModel(selected);
  36.123 -        DocumentListener dl = new DocumentListener() {
  36.124 -            public void insertUpdate(DocumentEvent e) {
  36.125 -                stateChanged();
  36.126 -            }
  36.127 -            public void removeUpdate(DocumentEvent e) {
  36.128 -                stateChanged();
  36.129 -            }
  36.130 -            public void changedUpdate(DocumentEvent e) {}
  36.131 -        };
  36.132 -
  36.133 -        try {
  36.134 -            FileObject dummy = FileUtil.createMemoryFileSystem().getRoot().createData("dummy.hint");
  36.135 -            DataObject od = DataObject.find(dummy);
  36.136 -            EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
  36.137 -            Document doc = ec.openDocument();
  36.138 -            pattern.setContentType("text/x-javahints");
  36.139 -            pattern.setDocument(doc);
  36.140 -        } catch (Exception e) {
  36.141 -            Logger.getLogger(FindDuplicatesRefactoringPanel.class.getName()).log(Level.FINE, null, e);
  36.142 -        }
  36.143 -        
  36.144 -        pattern.getDocument().addDocumentListener(dl);
  36.145 -        //do not close the dialog on esc:
  36.146 -        pattern.addKeyListener(new KeyListener() {
  36.147 -            public void keyTyped(KeyEvent e) {}
  36.148 -            public void keyPressed(KeyEvent e) {
  36.149 -                keyReleased(e);
  36.150 -            }
  36.151 -            public void keyReleased(KeyEvent e) {
  36.152 -                if (e.getKeyCode() == KeyEvent.VK_ESCAPE && e.getModifiersEx() == 0) {
  36.153 -                    e.consume();
  36.154 -                }
  36.155 -            }
  36.156 -        });
  36.157 -
  36.158 -        if (!query) {
  36.159 -            verify.setVisible(false);
  36.160 -        }
  36.161 -
  36.162 -        scopesPanel.setChangeListener(changeListener);
  36.163 -        
  36.164 -        enableDisable();
  36.165 -    }
  36.166 -
  36.167 -    /** This method is called from within the constructor to
  36.168 -     * initialize the form.
  36.169 -     * WARNING: Do NOT modify this code. The content of this method is
  36.170 -     * always regenerated by the Form Editor.
  36.171 -     */
  36.172 -    @SuppressWarnings("unchecked")
  36.173 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  36.174 -    private void initComponents() {
  36.175 -        java.awt.GridBagConstraints gridBagConstraints;
  36.176 -
  36.177 -        main = new javax.swing.ButtonGroup();
  36.178 -        verify = new javax.swing.JCheckBox();
  36.179 -        patternSelection = new javax.swing.JPanel();
  36.180 -        knownPatternsPanel = new javax.swing.JPanel();
  36.181 -        allHintsLabel = new javax.swing.JLabel();
  36.182 -        jScrollPane2 = new javax.swing.JScrollPane();
  36.183 -        allHints = new javax.swing.JList();
  36.184 -        jScrollPane3 = new javax.swing.JScrollPane();
  36.185 -        selectedHints = new javax.swing.JList();
  36.186 -        selectedHintsLabel = new javax.swing.JLabel();
  36.187 -        jPanel2 = new javax.swing.JPanel();
  36.188 -        addHint = new javax.swing.JButton();
  36.189 -        addAllHints = new javax.swing.JButton();
  36.190 -        removeHint = new javax.swing.JButton();
  36.191 -        removeAllHints = new javax.swing.JButton();
  36.192 -        customPatternPanel = new javax.swing.JPanel();
  36.193 -        jPanel3 = new javax.swing.JPanel();
  36.194 -        recentButton = new javax.swing.JButton();
  36.195 -        examplesButton = new javax.swing.JButton();
  36.196 -        jScrollPane4 = new javax.swing.JScrollPane();
  36.197 -        pattern = new javax.swing.JEditorPane();
  36.198 -        patternTypeSelectionPanel = new javax.swing.JPanel();
  36.199 -        knowPatterns = new javax.swing.JRadioButton();
  36.200 -        customPattern = new javax.swing.JRadioButton();
  36.201 -        jPanel1 = new javax.swing.JPanel();
  36.202 -        scopesPanel = new org.netbeans.modules.jackpot30.impl.refactoring.ScopesPanel();
  36.203 -
  36.204 -        setLayout(new java.awt.GridBagLayout());
  36.205 -
  36.206 -        org.openide.awt.Mnemonics.setLocalizedText(verify, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.verify.text")); // NOI18N
  36.207 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.208 -        gridBagConstraints.gridx = 0;
  36.209 -        gridBagConstraints.gridy = 3;
  36.210 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.211 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.212 -        gridBagConstraints.weightx = 1.0;
  36.213 -        gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
  36.214 -        add(verify, gridBagConstraints);
  36.215 -
  36.216 -        patternSelection.setLayout(new java.awt.CardLayout());
  36.217 -
  36.218 -        knownPatternsPanel.setLayout(new java.awt.GridBagLayout());
  36.219 -
  36.220 -        org.openide.awt.Mnemonics.setLocalizedText(allHintsLabel, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.allHintsLabel.text")); // NOI18N
  36.221 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.222 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.223 -        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
  36.224 -        knownPatternsPanel.add(allHintsLabel, gridBagConstraints);
  36.225 -
  36.226 -        allHints.setModel(new javax.swing.AbstractListModel() {
  36.227 -            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  36.228 -            public int getSize() { return strings.length; }
  36.229 -            public Object getElementAt(int i) { return strings[i]; }
  36.230 -        });
  36.231 -        allHints.setPrototypeCellValue(HINTS_LIST_PROTOTYPE);
  36.232 -        allHints.setVisibleRowCount(24);
  36.233 -        jScrollPane2.setViewportView(allHints);
  36.234 -
  36.235 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.236 -        gridBagConstraints.gridx = 0;
  36.237 -        gridBagConstraints.gridy = 1;
  36.238 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  36.239 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.240 -        gridBagConstraints.weightx = 0.5;
  36.241 -        gridBagConstraints.weighty = 1.0;
  36.242 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 6);
  36.243 -        knownPatternsPanel.add(jScrollPane2, gridBagConstraints);
  36.244 -
  36.245 -        selectedHints.setModel(new javax.swing.AbstractListModel() {
  36.246 -            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  36.247 -            public int getSize() { return strings.length; }
  36.248 -            public Object getElementAt(int i) { return strings[i]; }
  36.249 -        });
  36.250 -        selectedHints.setPrototypeCellValue(HINTS_LIST_PROTOTYPE);
  36.251 -        selectedHints.setVisibleRowCount(24);
  36.252 -        jScrollPane3.setViewportView(selectedHints);
  36.253 -
  36.254 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.255 -        gridBagConstraints.gridx = 2;
  36.256 -        gridBagConstraints.gridy = 1;
  36.257 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  36.258 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.259 -        gridBagConstraints.weightx = 0.5;
  36.260 -        gridBagConstraints.weighty = 1.0;
  36.261 -        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  36.262 -        knownPatternsPanel.add(jScrollPane3, gridBagConstraints);
  36.263 -
  36.264 -        org.openide.awt.Mnemonics.setLocalizedText(selectedHintsLabel, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.selectedHintsLabel.text")); // NOI18N
  36.265 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.266 -        gridBagConstraints.gridx = 2;
  36.267 -        gridBagConstraints.gridy = 0;
  36.268 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.269 -        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
  36.270 -        knownPatternsPanel.add(selectedHintsLabel, gridBagConstraints);
  36.271 -
  36.272 -        jPanel2.setLayout(new java.awt.GridBagLayout());
  36.273 -
  36.274 -        org.openide.awt.Mnemonics.setLocalizedText(addHint, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.addHint.text")); // NOI18N
  36.275 -        addHint.addActionListener(new java.awt.event.ActionListener() {
  36.276 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.277 -                addHintActionPerformed(evt);
  36.278 -            }
  36.279 -        });
  36.280 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.281 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.282 -        gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
  36.283 -        jPanel2.add(addHint, gridBagConstraints);
  36.284 -
  36.285 -        org.openide.awt.Mnemonics.setLocalizedText(addAllHints, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.addAllHints.text")); // NOI18N
  36.286 -        addAllHints.addActionListener(new java.awt.event.ActionListener() {
  36.287 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.288 -                addAllHintsActionPerformed(evt);
  36.289 -            }
  36.290 -        });
  36.291 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.292 -        gridBagConstraints.gridx = 0;
  36.293 -        gridBagConstraints.gridy = 1;
  36.294 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.295 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
  36.296 -        jPanel2.add(addAllHints, gridBagConstraints);
  36.297 -
  36.298 -        org.openide.awt.Mnemonics.setLocalizedText(removeHint, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.removeHint.text")); // NOI18N
  36.299 -        removeHint.addActionListener(new java.awt.event.ActionListener() {
  36.300 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.301 -                removeHintActionPerformed(evt);
  36.302 -            }
  36.303 -        });
  36.304 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.305 -        gridBagConstraints.gridx = 0;
  36.306 -        gridBagConstraints.gridy = 2;
  36.307 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.308 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
  36.309 -        jPanel2.add(removeHint, gridBagConstraints);
  36.310 -
  36.311 -        org.openide.awt.Mnemonics.setLocalizedText(removeAllHints, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.removeAllHints.text")); // NOI18N
  36.312 -        removeAllHints.addActionListener(new java.awt.event.ActionListener() {
  36.313 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.314 -                removeAllHintsActionPerformed(evt);
  36.315 -            }
  36.316 -        });
  36.317 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.318 -        gridBagConstraints.gridx = 0;
  36.319 -        gridBagConstraints.gridy = 3;
  36.320 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.321 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  36.322 -        jPanel2.add(removeAllHints, gridBagConstraints);
  36.323 -
  36.324 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.325 -        gridBagConstraints.gridx = 1;
  36.326 -        gridBagConstraints.gridy = 1;
  36.327 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  36.328 -        gridBagConstraints.weighty = 1.0;
  36.329 -        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 5);
  36.330 -        knownPatternsPanel.add(jPanel2, gridBagConstraints);
  36.331 -
  36.332 -        patternSelection.add(knownPatternsPanel, "knownPatterns");
  36.333 -
  36.334 -        customPatternPanel.setLayout(new java.awt.GridBagLayout());
  36.335 -
  36.336 -        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 5));
  36.337 -
  36.338 -        recentButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/jackpot30/impl/resources/recent_icon.png"))); // NOI18N
  36.339 -        org.openide.awt.Mnemonics.setLocalizedText(recentButton, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.recentButton.text")); // NOI18N
  36.340 -        recentButton.setToolTipText(org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.recentButton.toolTipText")); // NOI18N
  36.341 -        recentButton.setBorderPainted(false);
  36.342 -        recentButton.setContentAreaFilled(false);
  36.343 -        recentButton.addActionListener(new java.awt.event.ActionListener() {
  36.344 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.345 -                recentButtonActionPerformed(evt);
  36.346 -            }
  36.347 -        });
  36.348 -        jPanel3.add(recentButton);
  36.349 -
  36.350 -        examplesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/jackpot30/impl/resources/examples_icon.png"))); // NOI18N
  36.351 -        org.openide.awt.Mnemonics.setLocalizedText(examplesButton, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.examplesButton.text")); // NOI18N
  36.352 -        examplesButton.setToolTipText(org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "BTN_Examples")); // NOI18N
  36.353 -        examplesButton.setBorderPainted(false);
  36.354 -        examplesButton.setContentAreaFilled(false);
  36.355 -        examplesButton.addActionListener(new java.awt.event.ActionListener() {
  36.356 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.357 -                examplesButtonActionPerformed(evt);
  36.358 -            }
  36.359 -        });
  36.360 -        jPanel3.add(examplesButton);
  36.361 -
  36.362 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.363 -        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
  36.364 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
  36.365 -        customPatternPanel.add(jPanel3, gridBagConstraints);
  36.366 -
  36.367 -        jScrollPane4.setViewportView(pattern);
  36.368 -
  36.369 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.370 -        gridBagConstraints.gridx = 0;
  36.371 -        gridBagConstraints.gridy = 1;
  36.372 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  36.373 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.374 -        gridBagConstraints.weightx = 1.0;
  36.375 -        gridBagConstraints.weighty = 1.0;
  36.376 -        customPatternPanel.add(jScrollPane4, gridBagConstraints);
  36.377 -
  36.378 -        patternSelection.add(customPatternPanel, "customPattern");
  36.379 -
  36.380 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.381 -        gridBagConstraints.gridx = 0;
  36.382 -        gridBagConstraints.gridy = 1;
  36.383 -        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  36.384 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.385 -        gridBagConstraints.weightx = 1.0;
  36.386 -        gridBagConstraints.weighty = 1.0;
  36.387 -        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  36.388 -        add(patternSelection, gridBagConstraints);
  36.389 -
  36.390 -        patternTypeSelectionPanel.setLayout(new java.awt.GridBagLayout());
  36.391 -
  36.392 -        main.add(knowPatterns);
  36.393 -        knowPatterns.setSelected(true);
  36.394 -        org.openide.awt.Mnemonics.setLocalizedText(knowPatterns, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.knowPatterns.text")); // NOI18N
  36.395 -        knowPatterns.addActionListener(new java.awt.event.ActionListener() {
  36.396 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.397 -                knowPatternsActionPerformed(evt);
  36.398 -            }
  36.399 -        });
  36.400 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.401 -        gridBagConstraints.gridx = 0;
  36.402 -        gridBagConstraints.gridy = 0;
  36.403 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.404 -        patternTypeSelectionPanel.add(knowPatterns, gridBagConstraints);
  36.405 -
  36.406 -        main.add(customPattern);
  36.407 -        org.openide.awt.Mnemonics.setLocalizedText(customPattern, org.openide.util.NbBundle.getMessage(FindDuplicatesRefactoringPanel.class, "FindDuplicatesRefactoringPanel.customPattern.text")); // NOI18N
  36.408 -        customPattern.addActionListener(new java.awt.event.ActionListener() {
  36.409 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  36.410 -                customPatternActionPerformed(evt);
  36.411 -            }
  36.412 -        });
  36.413 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.414 -        gridBagConstraints.gridx = 1;
  36.415 -        gridBagConstraints.gridy = 0;
  36.416 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.417 -        gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 0);
  36.418 -        patternTypeSelectionPanel.add(customPattern, gridBagConstraints);
  36.419 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.420 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.421 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.422 -        gridBagConstraints.weightx = 1.0;
  36.423 -        patternTypeSelectionPanel.add(jPanel1, gridBagConstraints);
  36.424 -
  36.425 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.426 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.427 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.428 -        gridBagConstraints.weightx = 1.0;
  36.429 -        add(patternTypeSelectionPanel, gridBagConstraints);
  36.430 -        gridBagConstraints = new java.awt.GridBagConstraints();
  36.431 -        gridBagConstraints.gridx = 0;
  36.432 -        gridBagConstraints.gridy = 2;
  36.433 -        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  36.434 -        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  36.435 -        gridBagConstraints.weightx = 1.0;
  36.436 -        gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
  36.437 -        add(scopesPanel, gridBagConstraints);
  36.438 -    }// </editor-fold>//GEN-END:initComponents
  36.439 -
  36.440 -    private void addHintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addHintActionPerformed
  36.441 -        for (Object selected : allHints.getSelectedValues()) {
  36.442 -            ((DefaultListModel) selectedHints.getModel()).addElement(selected);
  36.443 -            ((DefaultListModel) allHints.getModel()).removeElement(selected);
  36.444 -        }
  36.445 -        changeListener.stateChanged(new ChangeEvent(this));
  36.446 -}//GEN-LAST:event_addHintActionPerformed
  36.447 -
  36.448 -    private void addAllHintsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAllHintsActionPerformed
  36.449 -        for (Object o : ((DefaultListModel) allHints.getModel()).toArray()) {
  36.450 -            ((DefaultListModel) selectedHints.getModel()).addElement(o);
  36.451 -        }
  36.452 -        ((DefaultListModel) allHints.getModel()).removeAllElements();
  36.453 -        changeListener.stateChanged(new ChangeEvent(this));
  36.454 -}//GEN-LAST:event_addAllHintsActionPerformed
  36.455 -
  36.456 -    private void removeHintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeHintActionPerformed
  36.457 -        for (Object selected : selectedHints.getSelectedValues()) {
  36.458 -            ((DefaultListModel) allHints.getModel()).addElement(selected);
  36.459 -            ((DefaultListModel) selectedHints.getModel()).removeElement(selected);
  36.460 -        }
  36.461 -        changeListener.stateChanged(new ChangeEvent(this));
  36.462 -}//GEN-LAST:event_removeHintActionPerformed
  36.463 -
  36.464 -    private void removeAllHintsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAllHintsActionPerformed
  36.465 -        for (Object o : ((DefaultListModel) selectedHints.getModel()).toArray()) {
  36.466 -            ((DefaultListModel) allHints.getModel()).addElement(o);
  36.467 -        }
  36.468 -        ((DefaultListModel) selectedHints.getModel()).removeAllElements();
  36.469 -        changeListener.stateChanged(new ChangeEvent(this));
  36.470 -}//GEN-LAST:event_removeAllHintsActionPerformed
  36.471 -
  36.472 -    private void customPatternActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customPatternActionPerformed
  36.473 -        enableDisable();
  36.474 -    }//GEN-LAST:event_customPatternActionPerformed
  36.475 -
  36.476 -    private void knowPatternsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knowPatternsActionPerformed
  36.477 -        enableDisable();
  36.478 -    }//GEN-LAST:event_knowPatternsActionPerformed
  36.479 -
  36.480 -    private void examplesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_examplesButtonActionPerformed
  36.481 -        Example ex = ExamplesList.chooseExample(LoadExamples.loadExamples(), new ExamplesConvertor(), Example.class, query ? EnumSet.noneOf(Option.class) : EnumSet.of(Option.FIX), query ? EnumSet.of(Option.FIX) : EnumSet.noneOf(Option.class));
  36.482 -
  36.483 -        if (ex != null) {
  36.484 -            pattern.setText(ex.getCode());
  36.485 -        }
  36.486 -    }//GEN-LAST:event_examplesButtonActionPerformed
  36.487 -
  36.488 -    private void recentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recentButtonActionPerformed
  36.489 -        String cod = ExamplesList.chooseExample(loadRecent(),
  36.490 -                                                new DialogDescription<String>() {
  36.491 -                                                    public String getDisplayName(String t) {
  36.492 -                                                        return t;
  36.493 -                                                    }
  36.494 -                                                    public String getCode(String t) {
  36.495 -                                                        return t;
  36.496 -                                                    }
  36.497 -                                                    public Set<Option> getOptions(String t) {
  36.498 -                                                        return query ? EnumSet.noneOf(Option.class) : EnumSet.of(Option.FIX);
  36.499 -                                                    }
  36.500 -                                                    public String getCaption() {
  36.501 -                                                        return "Recent patterns";
  36.502 -                                                    }
  36.503 -                                                    public String getHeader() {
  36.504 -                                                        return "Patterns:";
  36.505 -                                                    }
  36.506 -                                                },
  36.507 -                                                String.class,
  36.508 -                                                query ? EnumSet.noneOf(Option.class) : EnumSet.of(Option.FIX), query ? EnumSet.of(Option.FIX) : EnumSet.noneOf(Option.class));
  36.509 -
  36.510 -        if (cod != null) {
  36.511 -            pattern.setText(cod);
  36.512 -        }
  36.513 -    }//GEN-LAST:event_recentButtonActionPerformed
  36.514 -
  36.515 -    private void stateChanged() {
  36.516 -        if (SwingUtilities.isEventDispatchThread()) {
  36.517 -            changeListener.stateChanged(new ChangeEvent(this));
  36.518 -        } else {
  36.519 -            SwingUtilities.invokeLater(new Runnable() {
  36.520 -                public void run() {
  36.521 -                    stateChanged();
  36.522 -                }
  36.523 -            });
  36.524 -        }
  36.525 -    }
  36.526 -
  36.527 -    private void enableDisable() {
  36.528 -        String toSelect = knowPatterns.isSelected() ? "knownPatterns" : "customPattern";
  36.529 -
  36.530 -        ((CardLayout) patternSelection.getLayout()).show(patternSelection, toSelect);
  36.531 -        stateChanged();
  36.532 -    }
  36.533 -
  36.534 -    public void setPattern(Union2<String, Iterable<? extends HintDescription>> pattern) {
  36.535 -        if (pattern.hasFirst()) {
  36.536 -            customPattern.setSelected(true);
  36.537 -            this.pattern.setText(pattern.first() != null ? pattern.first() : "");
  36.538 -        } else {
  36.539 -            knowPatterns.setSelected(true);
  36.540 -            
  36.541 -            Set<String> selected = new HashSet<String>();
  36.542 -
  36.543 -            for (HintDescription d : pattern.second()) {
  36.544 -                selected.add(d.getMetadata().displayName);
  36.545 -            }
  36.546 -
  36.547 -            DefaultListModel allModel = (DefaultListModel) allHints.getModel();
  36.548 -            DefaultListModel selectedModel = (DefaultListModel) selectedHints.getModel();
  36.549 -
  36.550 -            allModel.clear();
  36.551 -            selectedModel.clear();
  36.552 -            
  36.553 -            for (String dn : displayName2Hints.keySet()) {
  36.554 -                if (selected.contains(dn)) {
  36.555 -                    selectedModel.addElement(dn);
  36.556 -                } else {
  36.557 -                    allModel.addElement(dn);
  36.558 -                }
  36.559 -            }
  36.560 -        }
  36.561 -
  36.562 -        enableDisable();
  36.563 -    }
  36.564 -
  36.565 -    public Union2<String, Iterable<? extends HintDescription>> getPattern() {
  36.566 -        if (customPattern.isSelected()) {
  36.567 -            return Union2.createFirst(this.pattern.getText());
  36.568 -        } else {
  36.569 -            List<HintDescription> hints = new LinkedList<HintDescription>();
  36.570 -
  36.571 -            for (Object dn : ((DefaultListModel) selectedHints.getModel()).toArray()) {
  36.572 -                hints.addAll(displayName2Hints.get((String) dn));
  36.573 -            }
  36.574 -
  36.575 -            return Union2.<String, Iterable<? extends HintDescription>>createSecond(hints);
  36.576 -        }
  36.577 -    }
  36.578 -
  36.579 -    public void setScope(Scope scope) {
  36.580 -        scopesPanel.setScope(scope);
  36.581 -    }
  36.582 -
  36.583 -    public Scope getScope() {
  36.584 -        return scopesPanel.getScope();
  36.585 -    }
  36.586 -
  36.587 -    public boolean getVerify() {
  36.588 -        return verify.isSelected();
  36.589 -    }
  36.590 -
  36.591 -    public void setVerify(boolean verify) {
  36.592 -        this.verify.setSelected(verify);
  36.593 -    }
  36.594 -
  36.595 -    void fillInFromSettings() {
  36.596 -        scopesPanel.fillInFromSettings();
  36.597 -
  36.598 -        List<String> recent = loadRecent();
  36.599 -
  36.600 -        if (!recent.isEmpty()) {
  36.601 -            pattern.setText(recent.get(0));
  36.602 -        }
  36.603 -    }
  36.604 -
  36.605 -    void saveScopesCombo() {
  36.606 -        scopesPanel.saveScopesCombo();
  36.607 -
  36.608 -        String currentPattern = pattern.getText().trim();
  36.609 -        List<String> recent = loadRecent();
  36.610 -
  36.611 -        recent.remove(currentPattern);
  36.612 -        recent.add(0, currentPattern);
  36.613 -
  36.614 -        while (recent.size() > MAX_RECENT) {
  36.615 -            recent.remove(recent.size() - 1);
  36.616 -        }
  36.617 -
  36.618 -        Preferences prefs = NbPreferences.forModule(FindDuplicatesRefactoringPanel.class);
  36.619 -        Preferences recentPatterns = prefs.node(query ? RECENT_PATTERNS_QUERY : RECENT_PATTERNS_APPLY);
  36.620 -        int i = 0;
  36.621 -
  36.622 -        for (String r : recent) {
  36.623 -            recentPatterns.put("pattern_" + i++, r);
  36.624 -        }
  36.625 -    }
  36.626 -
  36.627 -    private static final int MAX_RECENT = 50;
  36.628 -    private static final String RECENT_PATTERNS_QUERY = "recentPatternsQuery";
  36.629 -    private static final String RECENT_PATTERNS_APPLY = "recentPatternsApply";
  36.630 -
  36.631 -    private List<String> loadRecent() {
  36.632 -        Preferences prefs = NbPreferences.forModule(FindDuplicatesRefactoringPanel.class);
  36.633 -
  36.634 -        if (prefs == null) return Collections.emptyList();
  36.635 -
  36.636 -        List<String> recent = new LinkedList<String>();
  36.637 -        Preferences recentPatterns = prefs.node(query ? RECENT_PATTERNS_QUERY : RECENT_PATTERNS_APPLY);
  36.638 -
  36.639 -        if (recentPatterns != null) {
  36.640 -            try {
  36.641 -                for (String k : recentPatterns.keys()) {
  36.642 -                    if (k.startsWith("pattern_")) {
  36.643 -                        recent.add(recentPatterns.get(k, null));
  36.644 -                    }
  36.645 -                }
  36.646 -            } catch (BackingStoreException ex) {
  36.647 -                Exceptions.printStackTrace(ex);
  36.648 -            }
  36.649 -        }
  36.650 -
  36.651 -        return recent;
  36.652 -    }
  36.653 -
  36.654 -    @Override
  36.655 -    public void removeNotify() {
  36.656 -        super.removeNotify();
  36.657 -        DataObject od = NbEditorUtilities.getDataObject(pattern.getDocument());
  36.658 -
  36.659 -        if (od != null) {
  36.660 -            SaveCookie sc = od.getLookup().lookup(SaveCookie.class);
  36.661 -
  36.662 -            if (sc != null) {
  36.663 -                try {
  36.664 -                    sc.save();
  36.665 -                } catch (IOException ex) {
  36.666 -                    Logger.getLogger(FindDuplicatesRefactoringPanel.class.getName()).log(Level.FINE, null, ex);
  36.667 -                }
  36.668 -            }
  36.669 -        }
  36.670 -    }
  36.671 -
  36.672 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  36.673 -    private javax.swing.JButton addAllHints;
  36.674 -    private javax.swing.JButton addHint;
  36.675 -    private javax.swing.JList allHints;
  36.676 -    private javax.swing.JLabel allHintsLabel;
  36.677 -    private javax.swing.JRadioButton customPattern;
  36.678 -    private javax.swing.JPanel customPatternPanel;
  36.679 -    private javax.swing.JButton examplesButton;
  36.680 -    private javax.swing.JPanel jPanel1;
  36.681 -    private javax.swing.JPanel jPanel2;
  36.682 -    private javax.swing.JPanel jPanel3;
  36.683 -    private javax.swing.JScrollPane jScrollPane2;
  36.684 -    private javax.swing.JScrollPane jScrollPane3;
  36.685 -    private javax.swing.JScrollPane jScrollPane4;
  36.686 -    private javax.swing.JRadioButton knowPatterns;
  36.687 -    private javax.swing.JPanel knownPatternsPanel;
  36.688 -    private javax.swing.ButtonGroup main;
  36.689 -    private javax.swing.JEditorPane pattern;
  36.690 -    private javax.swing.JPanel patternSelection;
  36.691 -    private javax.swing.JPanel patternTypeSelectionPanel;
  36.692 -    private javax.swing.JButton recentButton;
  36.693 -    private javax.swing.JButton removeAllHints;
  36.694 -    private javax.swing.JButton removeHint;
  36.695 -    private org.netbeans.modules.jackpot30.impl.refactoring.ScopesPanel scopesPanel;
  36.696 -    private javax.swing.JList selectedHints;
  36.697 -    private javax.swing.JLabel selectedHintsLabel;
  36.698 -    private javax.swing.JCheckBox verify;
  36.699 -    // End of variables declaration//GEN-END:variables
  36.700 -
  36.701 -    private static final String HINTS_LIST_PROTOTYPE  = "012345678901234567890123456789";
  36.702 -
  36.703 -    private static final class ExamplesConvertor implements DialogDescription<Example> {
  36.704 -
  36.705 -        public String getDisplayName(Example t) {
  36.706 -            return t.getDisplayName();
  36.707 -        }
  36.708 -
  36.709 -        public String getCode(Example t) {
  36.710 -            return t.getCode();
  36.711 -        }
  36.712 -
  36.713 -        public Set<Option> getOptions(Example t) {
  36.714 -            return t.getOptions();
  36.715 -        }
  36.716 -
  36.717 -        public String getCaption() {
  36.718 -            return "Choose Example";
  36.719 -        }
  36.720 -
  36.721 -        public String getHeader() {
  36.722 -            return "Examples:";
  36.723 -        }
  36.724 -
  36.725 -    }
  36.726 -}
    37.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringPlugin.java	Fri Jan 27 13:35:56 2012 +0100
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,107 +0,0 @@
    37.4 -/*
    37.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    37.6 - *
    37.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    37.8 - *
    37.9 - * The contents of this file are subject to the terms of either the GNU
   37.10 - * General Public License Version 2 only ("GPL") or the Common
   37.11 - * Development and Distribution License("CDDL") (collectively, the
   37.12 - * "License"). You may not use this file except in compliance with the
   37.13 - * License. You can obtain a copy of the License at
   37.14 - * http://www.netbeans.org/cddl-gplv2.html
   37.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   37.16 - * specific language governing permissions and limitations under the
   37.17 - * License.  When distributing the software, include this License Header
   37.18 - * Notice in each file and include the License file at
   37.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   37.20 - * particular file as subject to the "Classpath" exception as provided
   37.21 - * by Sun in the GPL Version 2 section of the License file that
   37.22 - * accompanied this code. If applicable, add the following below the
   37.23 - * License Header, with the fields enclosed by brackets [] replaced by
   37.24 - * your own identifying information:
   37.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   37.26 - *
   37.27 - * If you wish your version of this file to be governed by only the CDDL
   37.28 - * or only the GPL Version 2, indicate your decision by adding
   37.29 - * "[Contributor] elects to include this software in this distribution
   37.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   37.31 - * single choice of license, a recipient has the option to distribute
   37.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   37.33 - * to extend the choice of license to its licensees as provided above.
   37.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   37.35 - * Version 2 license, then the option applies only if the new code is
   37.36 - * made subject to such option by the copyright holder.
   37.37 - *
   37.38 - * Contributor(s):
   37.39 - *
   37.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   37.41 - */
   37.42 -
   37.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   37.44 -
   37.45 -import java.util.Collection;
   37.46 -import java.util.LinkedList;
   37.47 -import java.util.List;
   37.48 -import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
   37.49 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
   37.50 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
   37.51 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
   37.52 -import org.netbeans.modules.java.hints.jackpot.spi.HintContext.MessageKind;
   37.53 -import org.netbeans.modules.refactoring.api.Problem;
   37.54 -import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
   37.55 -
   37.56 -public class FindDuplicatesRefactoringPlugin extends AbstractApplyHintsRefactoringPlugin {
   37.57 -
   37.58 -    private final FindDuplicatesRefactoring refactoring;
   37.59 -
   37.60 -    public FindDuplicatesRefactoringPlugin(FindDuplicatesRefactoring refactoring) {
   37.61 -        super(refactoring);
   37.62 -        this.refactoring = refactoring;
   37.63 -    }
   37.64 -
   37.65 -    public Problem preCheck() {
   37.66 -        return null;
   37.67 -    }
   37.68 -
   37.69 -    public Problem checkParameters() {
   37.70 -        return null;
   37.71 -    }
   37.72 -
   37.73 -    public Problem fastCheckParameters() {
   37.74 -        return null;
   37.75 -    }
   37.76 -
   37.77 -     public Problem prepare(RefactoringElementsBag refactoringElements) {
   37.78 -        cancel.set(false);
   37.79 -
   37.80 -        Collection<MessageImpl> problems = refactoring.isQuery() ? performSearchForPattern(refactoringElements) : performApplyPattern(refactoringElements);
   37.81 -        Problem current = null;
   37.82 -
   37.83 -        for (MessageImpl problem : problems) {
   37.84 -            Problem p = new Problem(problem.kind == MessageKind.ERROR, problem.text);
   37.85 -
   37.86 -            if (current != null)
   37.87 -                p.setNext(current);
   37.88 -            current = p;
   37.89 -        }
   37.90 -
   37.91 -        return current;
   37.92 -    }
   37.93 -
   37.94 -    private List<MessageImpl> performSearchForPattern(final RefactoringElementsBag refactoringElements) {
   37.95 -        ProgressHandleWrapper w = new ProgressHandleWrapper(this, 50, 50);
   37.96 -        BatchResult candidates = BatchSearch.findOccurrences(refactoring.getPattern(), refactoring.getScope(), w);
   37.97 -        List<MessageImpl> problems = new LinkedList<MessageImpl>(candidates.problems);
   37.98 -
   37.99 -        prepareElements(candidates, w, refactoringElements, refactoring.isVerify(), problems);
  37.100 -
  37.101 -        w.finish();
  37.102 -
  37.103 -        return problems;
  37.104 -     }
  37.105 -
  37.106 -    private Collection<MessageImpl> performApplyPattern(RefactoringElementsBag refactoringElements) {
  37.107 -        return performApplyPattern(refactoring.getPattern(), refactoring.getScope(), refactoringElements);
  37.108 -    }
  37.109 -
  37.110 -}
  37.111 \ No newline at end of file
    38.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindDuplicatesRefactoringUI.java	Fri Jan 27 13:35:56 2012 +0100
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,193 +0,0 @@
    38.4 -/*
    38.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    38.6 - *
    38.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    38.8 - *
    38.9 - * The contents of this file are subject to the terms of either the GNU
   38.10 - * General Public License Version 2 only ("GPL") or the Common
   38.11 - * Development and Distribution License("CDDL") (collectively, the
   38.12 - * "License"). You may not use this file except in compliance with the
   38.13 - * License. You can obtain a copy of the License at
   38.14 - * http://www.netbeans.org/cddl-gplv2.html
   38.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   38.16 - * specific language governing permissions and limitations under the
   38.17 - * License.  When distributing the software, include this License Header
   38.18 - * Notice in each file and include the License file at
   38.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   38.20 - * particular file as subject to the "Classpath" exception as provided
   38.21 - * by Sun in the GPL Version 2 section of the License file that
   38.22 - * accompanied this code. If applicable, add the following below the
   38.23 - * License Header, with the fields enclosed by brackets [] replaced by
   38.24 - * your own identifying information:
   38.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   38.26 - *
   38.27 - * If you wish your version of this file to be governed by only the CDDL
   38.28 - * or only the GPL Version 2, indicate your decision by adding
   38.29 - * "[Contributor] elects to include this software in this distribution
   38.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   38.31 - * single choice of license, a recipient has the option to distribute
   38.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   38.33 - * to extend the choice of license to its licensees as provided above.
   38.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   38.35 - * Version 2 license, then the option applies only if the new code is
   38.36 - * made subject to such option by the copyright holder.
   38.37 - *
   38.38 - * Contributor(s):
   38.39 - *
   38.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   38.41 - */
   38.42 -
   38.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   38.44 -
   38.45 -import java.awt.Component;
   38.46 -import java.io.File;
   38.47 -import java.util.Collections;
   38.48 -import javax.swing.event.ChangeListener;
   38.49 -import org.netbeans.api.annotations.common.NonNull;
   38.50 -import org.netbeans.api.annotations.common.NullAllowed;
   38.51 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
   38.52 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   38.53 -import org.netbeans.modules.java.hints.jackpot.spi.PatternConvertor;
   38.54 -import org.netbeans.modules.refactoring.api.AbstractRefactoring;
   38.55 -import org.netbeans.modules.refactoring.api.Problem;
   38.56 -import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
   38.57 -import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
   38.58 -import org.openide.filesystems.FileObject;
   38.59 -import org.openide.filesystems.FileUtil;
   38.60 -import org.openide.util.HelpCtx;
   38.61 -import org.openide.util.Union2;
   38.62 -
   38.63 -public class FindDuplicatesRefactoringUI implements RefactoringUI {
   38.64 -
   38.65 -    private final boolean explicitPattern;
   38.66 -    private volatile @NonNull Union2<String, Iterable<? extends HintDescription>> pattern;
   38.67 -    private volatile @NonNull Scope scope;
   38.68 -    private volatile boolean verify;
   38.69 -
   38.70 -    private final boolean query;
   38.71 -    private final FindDuplicatesRefactoring refactoring;
   38.72 -
   38.73 -    public FindDuplicatesRefactoringUI(@NullAllowed String pattern, Scope scope) {
   38.74 -        this(pattern, scope, true);
   38.75 -    }
   38.76 -    
   38.77 -    public FindDuplicatesRefactoringUI(@NullAllowed String pattern, Scope scope, boolean verify) {
   38.78 -        this(pattern, scope, verify, true);
   38.79 -    }
   38.80 -
   38.81 -    public FindDuplicatesRefactoringUI(@NullAllowed String pattern, Scope scope, boolean verify, boolean query) {
   38.82 -        if (!query && !verify) {
   38.83 -            throw new UnsupportedOperationException();
   38.84 -        }
   38.85 -
   38.86 -        this.explicitPattern = pattern != null;
   38.87 -        this.pattern = pattern != null ? Union2.<String, Iterable<? extends HintDescription>>createFirst(pattern) : Union2.<String, Iterable<? extends HintDescription>>createSecond(Collections.<HintDescription>emptyList());
   38.88 -        this.scope = scope;
   38.89 -        this.verify = verify;
   38.90 -        this.query = query;
   38.91 -        this.refactoring = new FindDuplicatesRefactoring(query);
   38.92 -    }
   38.93 -
   38.94 -    public String getName() {
   38.95 -        return query ? "Find Pattern Occurrences" : "Apply Pattern";
   38.96 -    }
   38.97 -
   38.98 -    public String getDescription() {
   38.99 -        return query ? "Find Pattern Occurrences" : "Apply Pattern";
  38.100 -    }
  38.101 -
  38.102 -    public boolean isQuery() {
  38.103 -        return query;
  38.104 -    }
  38.105 -
  38.106 -    private FindDuplicatesRefactoringPanel panel;
  38.107 -
  38.108 -    public CustomRefactoringPanel getPanel(final ChangeListener parent) {
  38.109 -        return new CustomRefactoringPanel() {
  38.110 -            public void initialize() {
  38.111 -                panel.fillInFromSettings();
  38.112 -                panel.setPattern(FindDuplicatesRefactoringUI.this.pattern);
  38.113 -                panel.setScope(scope);
  38.114 -                panel.setVerify(verify);
  38.115 -            }
  38.116 -            public Component getComponent() {
  38.117 -                if (panel == null) {
  38.118 -                    panel = new FindDuplicatesRefactoringPanel(parent, query);
  38.119 -                }
  38.120 -
  38.121 -                return panel;
  38.122 -            }
  38.123 -        };
  38.124 -    }
  38.125 -
  38.126 -    public Problem setParameters() {
  38.127 -        pattern = panel.getPattern();
  38.128 -        scope   = panel.getScope();
  38.129 -        verify  = panel.getVerify();
  38.130 -        panel.saveScopesCombo();
  38.131 -        return null;
  38.132 -    }
  38.133 -
  38.134 -    public Problem checkParameters() {
  38.135 -        Union2<String, Iterable<? extends HintDescription>> pattern = panel != null ? panel.getPattern() : this.pattern;
  38.136 -        Scope scope = panel != null ? panel.getScope() : this.scope;
  38.137 -
  38.138 -        if (pattern.hasFirst()) {
  38.139 -            if (pattern.first() == null) {
  38.140 -                return new Problem(true, "No pattern specified");
  38.141 -            }
  38.142 -            if (PatternConvertor.create(pattern.first()) == null) {
  38.143 -                return new Problem(true, "The pattern cannot be parsed");
  38.144 -            }
  38.145 -        } else {
  38.146 -            if (!pattern.second().iterator().hasNext()) {
  38.147 -                return new Problem(true, "No pattern specified");
  38.148 -            }
  38.149 -        }
  38.150 -
  38.151 -//        if (scope.scopeType == ScopeType.GIVEN_FOLDER && findFolderFileObject(scope.folder) == null) {
  38.152 -//            return new Problem(true, "Specified folder not found");
  38.153 -//        }
  38.154 -        return null;
  38.155 -    }
  38.156 -
  38.157 -    public boolean hasParameters() {
  38.158 -        return true;
  38.159 -    }
  38.160 -
  38.161 -    public AbstractRefactoring getRefactoring() {
  38.162 -        Iterable<? extends HintDescription> hints;
  38.163 -        
  38.164 -        if (pattern.hasFirst()) {
  38.165 -            if (pattern.first() != null) {
  38.166 -                hints = PatternConvertor.create(pattern.first());
  38.167 -            } else {
  38.168 -                hints = Collections.<HintDescription>emptyList();
  38.169 -            }
  38.170 -        } else {
  38.171 -            hints = pattern.second();
  38.172 -        }
  38.173 -
  38.174 -        FindDuplicatesRefactoring r = refactoring;
  38.175 -        r.setPattern(hints);
  38.176 -        r.setScope(scope);
  38.177 -        r.setVerify(verify);
  38.178 -
  38.179 -        return r;
  38.180 -    }
  38.181 -
  38.182 -    public HelpCtx getHelpCtx() {
  38.183 -        return new HelpCtx("jackpot30.pattern.format");
  38.184 -    }
  38.185 -
  38.186 -    private FileObject findFolderFileObject(String folder) {
  38.187 -        if (folder == null) return null;
  38.188 -
  38.189 -        File file = new File(folder);
  38.190 -
  38.191 -        if (!file.exists()) return null;
  38.192 -
  38.193 -        return FileUtil.toFileObject(FileUtil.normalizeFile(file));
  38.194 -    }
  38.195 -
  38.196 -}
  38.197 \ No newline at end of file
    39.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/FindOccurrencesAction.java	Fri Jan 27 13:35:56 2012 +0100
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,52 +0,0 @@
    39.4 -/*
    39.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    39.6 - *
    39.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    39.8 - *
    39.9 - * The contents of this file are subject to the terms of either the GNU
   39.10 - * General Public License Version 2 only ("GPL") or the Common
   39.11 - * Development and Distribution License("CDDL") (collectively, the
   39.12 - * "License"). You may not use this file except in compliance with the
   39.13 - * License. You can obtain a copy of the License at
   39.14 - * http://www.netbeans.org/cddl-gplv2.html
   39.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   39.16 - * specific language governing permissions and limitations under the
   39.17 - * License.  When distributing the software, include this License Header
   39.18 - * Notice in each file and include the License file at
   39.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   39.20 - * particular file as subject to the "Classpath" exception as provided
   39.21 - * by Sun in the GPL Version 2 section of the License file that
   39.22 - * accompanied this code. If applicable, add the following below the
   39.23 - * License Header, with the fields enclosed by brackets [] replaced by
   39.24 - * your own identifying information:
   39.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   39.26 - *
   39.27 - * If you wish your version of this file to be governed by only the CDDL
   39.28 - * or only the GPL Version 2, indicate your decision by adding
   39.29 - * "[Contributor] elects to include this software in this distribution
   39.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   39.31 - * single choice of license, a recipient has the option to distribute
   39.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   39.33 - * to extend the choice of license to its licensees as provided above.
   39.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   39.35 - * Version 2 license, then the option applies only if the new code is
   39.36 - * made subject to such option by the copyright holder.
   39.37 - *
   39.38 - * Contributor(s):
   39.39 - *
   39.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   39.41 - */
   39.42 -
   39.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   39.44 -
   39.45 -import java.awt.event.ActionEvent;
   39.46 -import java.awt.event.ActionListener;
   39.47 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
   39.48 -import org.netbeans.modules.refactoring.spi.ui.UI;
   39.49 -
   39.50 -public final class FindOccurrencesAction implements ActionListener {
   39.51 -
   39.52 -    public void actionPerformed(ActionEvent e) {
   39.53 -        UI.openRefactoringUI(new FindDuplicatesRefactoringUI(null, Scopes.allOpenedProjectsScope()));
   39.54 -    }
   39.55 -}
    40.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/RefactoringPluginFactoryImpl.java	Fri Jan 27 13:35:56 2012 +0100
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,58 +0,0 @@
    40.4 -/*
    40.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    40.6 - *
    40.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    40.8 - *
    40.9 - * The contents of this file are subject to the terms of either the GNU
   40.10 - * General Public License Version 2 only ("GPL") or the Common
   40.11 - * Development and Distribution License("CDDL") (collectively, the
   40.12 - * "License"). You may not use this file except in compliance with the
   40.13 - * License. You can obtain a copy of the License at
   40.14 - * http://www.netbeans.org/cddl-gplv2.html
   40.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   40.16 - * specific language governing permissions and limitations under the
   40.17 - * License.  When distributing the software, include this License Header
   40.18 - * Notice in each file and include the License file at
   40.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   40.20 - * particular file as subject to the "Classpath" exception as provided
   40.21 - * by Sun in the GPL Version 2 section of the License file that
   40.22 - * accompanied this code. If applicable, add the following below the
   40.23 - * License Header, with the fields enclosed by brackets [] replaced by
   40.24 - * your own identifying information:
   40.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   40.26 - *
   40.27 - * If you wish your version of this file to be governed by only the CDDL
   40.28 - * or only the GPL Version 2, indicate your decision by adding
   40.29 - * "[Contributor] elects to include this software in this distribution
   40.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   40.31 - * single choice of license, a recipient has the option to distribute
   40.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   40.33 - * to extend the choice of license to its licensees as provided above.
   40.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   40.35 - * Version 2 license, then the option applies only if the new code is
   40.36 - * made subject to such option by the copyright holder.
   40.37 - *
   40.38 - * Contributor(s):
   40.39 - *
   40.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   40.41 - */
   40.42 -
   40.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   40.44 -
   40.45 -import org.netbeans.modules.refactoring.api.AbstractRefactoring;
   40.46 -import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
   40.47 -import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
   40.48 -import org.openide.util.lookup.ServiceProvider;
   40.49 -
   40.50 -@ServiceProvider(service=RefactoringPluginFactory.class)
   40.51 -public class RefactoringPluginFactoryImpl implements RefactoringPluginFactory {
   40.52 -
   40.53 -    public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {
   40.54 -        if (refactoring instanceof FindDuplicatesRefactoring) {
   40.55 -            return new FindDuplicatesRefactoringPlugin((FindDuplicatesRefactoring) refactoring);
   40.56 -        }
   40.57 -
   40.58 -        return null;
   40.59 -    }
   40.60 -    
   40.61 -}
    41.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/RetoucheCommit.java	Fri Jan 27 13:35:56 2012 +0100
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,128 +0,0 @@
    41.4 -/*
    41.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    41.6 - *
    41.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    41.8 - *
    41.9 - * The contents of this file are subject to the terms of either the GNU
   41.10 - * General Public License Version 2 only ("GPL") or the Common
   41.11 - * Development and Distribution License("CDDL") (collectively, the
   41.12 - * "License"). You may not use this file except in compliance with the
   41.13 - * License. You can obtain a copy of the License at
   41.14 - * http://www.netbeans.org/cddl-gplv2.html
   41.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   41.16 - * specific language governing permissions and limitations under the
   41.17 - * License.  When distributing the software, include this License Header
   41.18 - * Notice in each file and include the License file at
   41.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   41.20 - * particular file as subject to the "Classpath" exception as provided
   41.21 - * by Sun in the GPL Version 2 section of the License file that
   41.22 - * accompanied this code. If applicable, add the following below the
   41.23 - * License Header, with the fields enclosed by brackets [] replaced by
   41.24 - * your own identifying information:
   41.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   41.26 - *
   41.27 - * Contributor(s):
   41.28 - *
   41.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   41.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
   41.31 - * Microsystems, Inc. All Rights Reserved.
   41.32 - *
   41.33 - * If you wish your version of this file to be governed by only the CDDL
   41.34 - * or only the GPL Version 2, indicate your decision by adding
   41.35 - * "[Contributor] elects to include this software in this distribution
   41.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   41.37 - * single choice of license, a recipient has the option to distribute
   41.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   41.39 - * to extend the choice of license to its licensees as provided above.
   41.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   41.41 - * Version 2 license, then the option applies only if the new code is
   41.42 - * made subject to such option by the copyright holder.
   41.43 - */
   41.44 -package org.netbeans.modules.jackpot30.impl.refactoring;
   41.45 -
   41.46 -import java.io.File;
   41.47 -import java.io.IOException;
   41.48 -import java.util.ArrayList;
   41.49 -import java.util.Collection;
   41.50 -import java.util.LinkedList;
   41.51 -import java.util.Set;
   41.52 -import org.netbeans.api.java.source.ModificationResult;
   41.53 -import org.netbeans.modules.refactoring.spi.BackupFacility;
   41.54 -import org.netbeans.modules.refactoring.spi.Transaction;
   41.55 -import org.openide.filesystems.FileObject;
   41.56 -import org.openide.filesystems.FileUtil;
   41.57 -import org.openide.util.Exceptions;
   41.58 -
   41.59 -/**TODO: Copied from refactoring.java:
   41.60 - *
   41.61 - * @author Jan Becicka
   41.62 - */
   41.63 -
   41.64 -public class RetoucheCommit implements Transaction {
   41.65 -    ArrayList<BackupFacility.Handle> ids = new ArrayList<BackupFacility.Handle>();
   41.66 -    private boolean commited = false;
   41.67 -    Collection<ModificationResult> results;
   41.68 -    private Set<File> newFiles;
   41.69 -    
   41.70 -    public RetoucheCommit(Collection<ModificationResult> results) {
   41.71 -        this.results = results;
   41.72 -    }
   41.73 -    
   41.74 -    public void commit() {
   41.75 -        try {
   41.76 -            if (commited) {
   41.77 -                for (BackupFacility.Handle id:ids) {
   41.78 -                    try {
   41.79 -                        id.restore();
   41.80 -                    } catch (IOException ex) {
   41.81 -                        throw (RuntimeException) new RuntimeException().initCause(ex);
   41.82 -                    }
   41.83 -                }
   41.84 -            } else {
   41.85 -                commited = true;
   41.86 -                for (ModificationResult result:results) {
   41.87 -                    Collection<FileObject> toBackup = new LinkedList<FileObject>();
   41.88 -                    for (FileObject file : result.getModifiedFileObjects()) {
   41.89 -                        if (file != null && file.isData()) {
   41.90 -                            toBackup.add(file);
   41.91 -                        }
   41.92 -                    }
   41.93 -                    ids.add(BackupFacility.getDefault().backup(toBackup));
   41.94 -                    newFiles = result.getNewFiles();
   41.95 -                    result.commit();
   41.96 -                }
   41.97 -            }
   41.98 -            
   41.99 -        } catch (IOException ex) {
  41.100 -            throw (RuntimeException) new RuntimeException().initCause(ex);
  41.101 -        }
  41.102 -    }
  41.103 -    
  41.104 -    private boolean newFilesStored = false;
  41.105 -    public void rollback() {
  41.106 -        for (BackupFacility.Handle id:ids) {
  41.107 -            try {
  41.108 -                id.restore();
  41.109 -            } catch (IOException ex) {
  41.110 -                throw (RuntimeException) new RuntimeException().initCause(ex);
  41.111 -            }
  41.112 -        }
  41.113 -        boolean localStored = false;
  41.114 -        if (newFiles!=null) {
  41.115 -            for (File f:newFiles) {
  41.116 -                try {
  41.117 -                    FileObject fo = FileUtil.toFileObject(f);
  41.118 -                    if (!newFilesStored) {
  41.119 -                        ids.add(BackupFacility.getDefault().backup(fo));
  41.120 -                        localStored = true;
  41.121 -                    }
  41.122 -                    fo.delete();
  41.123 -                } catch (IOException ex) {
  41.124 -                    Exceptions.printStackTrace(ex);
  41.125 -                }
  41.126 -            }
  41.127 -            newFilesStored |= localStored;
  41.128 -        }
  41.129 -    }
  41.130 -}
  41.131 -            
  41.132 \ No newline at end of file
    42.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/ScopesPanel.form	Fri Jan 27 13:35:56 2012 +0100
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,115 +0,0 @@
    42.4 -<?xml version="1.1" encoding="UTF-8" ?>
    42.5 -
    42.6 -<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    42.7 -  <NonVisualComponents>
    42.8 -    <Component class="javax.swing.ButtonGroup" name="main">
    42.9 -    </Component>
   42.10 -  </NonVisualComponents>
   42.11 -  <AuxValues>
   42.12 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
   42.13 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   42.14 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   42.15 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
   42.16 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   42.17 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
   42.18 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   42.19 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   42.20 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   42.21 -  </AuxValues>
   42.22 -
   42.23 -  <Layout>
   42.24 -    <DimensionLayout dim="0">
   42.25 -      <Group type="103" groupAlignment="0" attributes="0">
   42.26 -          <Component id="scopePanel" min="-2" pref="576" max="-2" attributes="0"/>
   42.27 -          <Group type="102" alignment="0" attributes="0">
   42.28 -              <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
   42.29 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   42.30 -              <Component id="scope" pref="334" max="32767" attributes="0"/>
   42.31 -              <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
   42.32 -              <Component id="add" min="-2" max="-2" attributes="0"/>
   42.33 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   42.34 -              <Component id="edit" min="-2" max="-2" attributes="0"/>
   42.35 -              <EmptySpace min="-2" max="-2" attributes="0"/>
   42.36 -              <Component id="removeButton" min="-2" max="-2" attributes="0"/>
   42.37 -          </Group>
   42.38 -      </Group>
   42.39 -    </DimensionLayout>
   42.40 -    <DimensionLayout dim="1">
   42.41 -      <Group type="103" groupAlignment="0" attributes="0">
   42.42 -          <Group type="102" attributes="0">
   42.43 -              <EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
   42.44 -              <Group type="103" groupAlignment="3" attributes="0">
   42.45 -                  <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
   42.46 -                  <Component id="scope" alignment="3" min="-2" max="-2" attributes="0"/>
   42.47 -                  <Component id="add" alignment="3" min="-2" max="-2" attributes="0"/>
   42.48 -                  <Component id="edit" alignment="3" min="-2" max="-2" attributes="0"/>
   42.49 -                  <Component id="removeButton" alignment="3" min="-2" max="-2" attributes="0"/>
   42.50 -              </Group>
   42.51 -              <EmptySpace type="separate" max="-2" attributes="0"/>
   42.52 -              <Component id="scopePanel" min="-2" max="-2" attributes="0"/>
   42.53 -          </Group>
   42.54 -      </Group>
   42.55 -    </DimensionLayout>
   42.56 -  </Layout>
   42.57 -  <SubComponents>
   42.58 -    <Container class="javax.swing.JPanel" name="scopePanel">
   42.59 -
   42.60 -      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   42.61 -    </Container>
   42.62 -    <Component class="javax.swing.JLabel" name="jLabel2">
   42.63 -      <Properties>
   42.64 -        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
   42.65 -          <ComponentRef name="scope"/>
   42.66 -        </Property>
   42.67 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   42.68 -          <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="ScopesPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   42.69 -        </Property>
   42.70 -      </Properties>
   42.71 -    </Component>
   42.72 -    <Component class="javax.swing.JComboBox" name="scope">
   42.73 -      <Properties>
   42.74 -        <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
   42.75 -          <StringArray count="4">
   42.76 -            <StringItem index="0" value="Item 1"/>
   42.77 -            <StringItem index="1" value="Item 2"/>
   42.78 -            <StringItem index="2" value="Item 3"/>
   42.79 -            <StringItem index="3" value="Item 4"/>
   42.80 -          </StringArray>
   42.81 -        </Property>
   42.82 -        <Property name="prototypeDisplayValue" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   42.83 -          <Connection code="SCOPE_COMBO_PROTOTYPE" type="code"/>
   42.84 -        </Property>
   42.85 -      </Properties>
   42.86 -    </Component>
   42.87 -    <Component class="javax.swing.JButton" name="add">
   42.88 -      <Properties>
   42.89 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   42.90 -          <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="ScopesPanel.add.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
   42.91 -        </Property>
   42.92 -      </Properties>
   42.93 -      <Events>
   42.94 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addActionPerformed"/>
   42.95 -      </Events>
   42.96 -    </Component>
   42.97 -    <Component class="javax.swing.JButton" name="edit">
   42.98 -      <Properties>
   42.99 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  42.100 -          <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="ScopesPanel.edit.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  42.101 -        </Property>
  42.102 -      </Properties>
  42.103 -      <Events>
  42.104 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="editActionPerformed"/>
  42.105 -      </Events>
  42.106 -    </Component>
  42.107 -    <Component class="javax.swing.JButton" name="removeButton">
  42.108 -      <Properties>
  42.109 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  42.110 -          <ResourceString bundle="org/netbeans/modules/jackpot30/impl/refactoring/Bundle.properties" key="ScopesPanel.removeButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  42.111 -        </Property>
  42.112 -      </Properties>
  42.113 -      <Events>
  42.114 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeButtonActionPerformed"/>
  42.115 -      </Events>
  42.116 -    </Component>
  42.117 -  </SubComponents>
  42.118 -</Form>
    43.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/ScopesPanel.java	Fri Jan 27 13:35:56 2012 +0100
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,321 +0,0 @@
    43.4 -/*
    43.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    43.6 - *
    43.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    43.8 - *
    43.9 - * The contents of this file are subject to the terms of either the GNU
   43.10 - * General Public License Version 2 only ("GPL") or the Common
   43.11 - * Development and Distribution License("CDDL") (collectively, the
   43.12 - * "License"). You may not use this file except in compliance with the
   43.13 - * License. You can obtain a copy of the License at
   43.14 - * http://www.netbeans.org/cddl-gplv2.html
   43.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   43.16 - * specific language governing permissions and limitations under the
   43.17 - * License.  When distributing the software, include this License Header
   43.18 - * Notice in each file and include the License file at
   43.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   43.20 - * particular file as subject to the "Classpath" exception as provided
   43.21 - * by Sun in the GPL Version 2 section of the License file that
   43.22 - * accompanied this code. If applicable, add the following below the
   43.23 - * License Header, with the fields enclosed by brackets [] replaced by
   43.24 - * your own identifying information:
   43.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   43.26 - *
   43.27 - * If you wish your version of this file to be governed by only the CDDL
   43.28 - * or only the GPL Version 2, indicate your decision by adding
   43.29 - * "[Contributor] elects to include this software in this distribution
   43.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   43.31 - * single choice of license, a recipient has the option to distribute
   43.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   43.33 - * to extend the choice of license to its licensees as provided above.
   43.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   43.35 - * Version 2 license, then the option applies only if the new code is
   43.36 - * made subject to such option by the copyright holder.
   43.37 - *
   43.38 - * Contributor(s):
   43.39 - *
   43.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   43.41 - */
   43.42 -
   43.43 -package org.netbeans.modules.jackpot30.impl.refactoring;
   43.44 -
   43.45 -import java.awt.Component;
   43.46 -import java.awt.event.ItemEvent;
   43.47 -import java.awt.event.ItemListener;
   43.48 -import java.util.prefs.Preferences;
   43.49 -import javax.swing.DefaultComboBoxModel;
   43.50 -import javax.swing.DefaultListCellRenderer;
   43.51 -import javax.swing.JButton;
   43.52 -import javax.swing.JList;
   43.53 -import javax.swing.event.ChangeEvent;
   43.54 -import javax.swing.event.ChangeListener;
   43.55 -import org.netbeans.modules.jackpot30.impl.batch.EnhancedScopes.GivenFolderScope;
   43.56 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
   43.57 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
   43.58 -import org.openide.DialogDescriptor;
   43.59 -import org.openide.DialogDisplayer;
   43.60 -import org.openide.util.NbPreferences;
   43.61 -
   43.62 -/**
   43.63 - *
   43.64 - * @author lahvac
   43.65 - */
   43.66 -public class ScopesPanel extends javax.swing.JPanel {
   43.67 -
   43.68 -    private ChangeListener changeListener;
   43.69 -    
   43.70 -    public ScopesPanel() {
   43.71 -        initComponents();
   43.72 -
   43.73 -        ItemListener ilImpl = new ItemListener() {
   43.74 -            public void itemStateChanged(ItemEvent e) {
   43.75 -                stateChanged();
   43.76 -                enableDisableEditRemove();
   43.77 -            }
   43.78 -        };
   43.79 -
   43.80 -        scope.addItemListener(ilImpl);
   43.81 -
   43.82 -        scope.setModel(new DefaultComboBoxModel());//XXX
   43.83 -        scope.setRenderer(new RendererImpl());
   43.84 -    }
   43.85 -
   43.86 -    public void setChangeListener(ChangeListener changeListener) {
   43.87 -        this.changeListener = changeListener;
   43.88 -    }
   43.89 -
   43.90 -    /** This method is called from within the constructor to
   43.91 -     * initialize the form.
   43.92 -     * WARNING: Do NOT modify this code. The content of this method is
   43.93 -     * always regenerated by the Form Editor.
   43.94 -     */
   43.95 -    @SuppressWarnings("unchecked")
   43.96 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   43.97 -    private void initComponents() {
   43.98 -        java.awt.GridBagConstraints gridBagConstraints;
   43.99 -
  43.100 -        main = new javax.swing.ButtonGroup();
  43.101 -        scopePanel = new javax.swing.JPanel();
  43.102 -        jLabel2 = new javax.swing.JLabel();
  43.103 -        scope = new javax.swing.JComboBox();
  43.104 -        add = new javax.swing.JButton();
  43.105 -        edit = new javax.swing.JButton();
  43.106 -        removeButton = new javax.swing.JButton();
  43.107 -
  43.108 -        scopePanel.setLayout(new java.awt.GridBagLayout());
  43.109 -
  43.110 -        jLabel2.setLabelFor(scope);
  43.111 -        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ScopesPanel.class, "ScopesPanel.jLabel2.text")); // NOI18N
  43.112 -
  43.113 -        scope.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
  43.114 -        scope.setPrototypeDisplayValue(SCOPE_COMBO_PROTOTYPE);
  43.115 -
  43.116 -        org.openide.awt.Mnemonics.setLocalizedText(add, org.openide.util.NbBundle.getMessage(ScopesPanel.class, "ScopesPanel.add.text")); // NOI18N
  43.117 -        add.addActionListener(new java.awt.event.ActionListener() {
  43.118 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  43.119 -                addActionPerformed(evt);
  43.120 -            }
  43.121 -        });
  43.122 -
  43.123 -        org.openide.awt.Mnemonics.setLocalizedText(edit, org.openide.util.NbBundle.getMessage(ScopesPanel.class, "ScopesPanel.edit.text")); // NOI18N
  43.124 -        edit.addActionListener(new java.awt.event.ActionListener() {
  43.125 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  43.126 -                editActionPerformed(evt);
  43.127 -            }
  43.128 -        });
  43.129 -
  43.130 -        org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(ScopesPanel.class, "ScopesPanel.removeButton.text")); // NOI18N
  43.131 -        removeButton.addActionListener(new java.awt.event.ActionListener() {
  43.132 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  43.133 -                removeButtonActionPerformed(evt);
  43.134 -            }
  43.135 -        });
  43.136 -
  43.137 -        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
  43.138 -        this.setLayout(layout);
  43.139 -        layout.setHorizontalGroup(
  43.140 -            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  43.141 -            .add(scopePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 576, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  43.142 -            .add(layout.createSequentialGroup()
  43.143 -                .add(jLabel2)
  43.144 -                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  43.145 -                .add(scope, 0, 334, Short.MAX_VALUE)
  43.146 -                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
  43.147 -                .add(add)
  43.148 -                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  43.149 -                .add(edit)
  43.150 -                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  43.151 -                .add(removeButton))
  43.152 -        );
  43.153 -        layout.setVerticalGroup(
  43.154 -            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  43.155 -            .add(layout.createSequentialGroup()
  43.156 -                .add(11, 11, 11)
  43.157 -                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
  43.158 -                    .add(jLabel2)
  43.159 -                    .add(scope, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  43.160 -                    .add(add)
  43.161 -                    .add(edit)
  43.162 -                    .add(removeButton))
  43.163 -                .add(18, 18, 18)
  43.164 -                .add(scopePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
  43.165 -        );
  43.166 -    }// </editor-fold>//GEN-END:initComponents
  43.167 -
  43.168 -    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
  43.169 -        addEditScope(false);
  43.170 -    }//GEN-LAST:event_addActionPerformed
  43.171 -
  43.172 -    private void editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editActionPerformed
  43.173 -        addEditScope(true);
  43.174 -    }//GEN-LAST:event_editActionPerformed
  43.175 -
  43.176 -    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
  43.177 -        DefaultComboBoxModel model = (DefaultComboBoxModel) scope.getModel();
  43.178 -        int index = model.getIndexOf(model.getSelectedItem());
  43.179 -
  43.180 -        model.removeElementAt(index);
  43.181 -    }//GEN-LAST:event_removeButtonActionPerformed
  43.182 -
  43.183 -    private void stateChanged() {
  43.184 -        changeListener.stateChanged(new ChangeEvent(this));
  43.185 -    }
  43.186 -
  43.187 -    private void enableDisableEditRemove() {
  43.188 -        boolean enableEditRemove = scope.getSelectedItem() instanceof GivenFolderScope;
  43.189 -
  43.190 -        edit.setEnabled(enableEditRemove);
  43.191 -        removeButton.setEnabled(enableEditRemove);
  43.192 -    }
  43.193 -
  43.194 -    public void setScope(Scope scope) {
  43.195 -        this.scope.setSelectedItem(scope);
  43.196 -        stateChanged();
  43.197 -    }
  43.198 -
  43.199 -    public Scope getScope() {
  43.200 -        return (Scope) this.scope.getSelectedItem();
  43.201 -    }
  43.202 -
  43.203 -    private static final String SCOPES_KEY = ScopesPanel.class.getSimpleName() + "/scopes";
  43.204 -    private static final String LAST_SELECTED_SCOPE_KEY = "lastSelected";
  43.205 -
  43.206 -    public void fillInFromSettings() {
  43.207 -        Preferences prefs = NbPreferences.forModule(ScopesPanel.class).node(SCOPES_KEY);
  43.208 -        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
  43.209 -
  43.210 -        dcbm.addElement(Scopes.allOpenedProjectsScope());
  43.211 -
  43.212 -//        String lastSelectedFolder = prefs.get(LAST_SELECTED_SCOPE_KEY, null);
  43.213 -//        Scope lastSelectedScope = null;
  43.214 -//
  43.215 -//        if (prefs != null) {
  43.216 -//            try {
  43.217 -//                for (String key : prefs.keys()) {
  43.218 -//                    if (key.startsWith("scope")) {
  43.219 -//                        Scope scope = Scope.deserialize(prefs.get(key, null));
  43.220 -//
  43.221 -//                        if (scope.folder.equals(lastSelectedFolder)) {
  43.222 -//                            lastSelectedScope = scope;
  43.223 -//                        }
  43.224 -//
  43.225 -//                        dcbm.addElement(scope);
  43.226 -//                    }
  43.227 -//                }
  43.228 -//            } catch (BackingStoreException ex) {
  43.229 -//                Exceptions.printStackTrace(ex);
  43.230 -//            }
  43.231 -//        }
  43.232 -//
  43.233 -        scope.setModel(dcbm);
  43.234 -//        if (lastSelectedScope != null) {
  43.235 -//            scope.setSelectedItem(lastSelectedScope);
  43.236 -//        } else {
  43.237 -            scope.setSelectedIndex(0);
  43.238 -//        }
  43.239 -
  43.240 -        enableDisableEditRemove();
  43.241 -    }
  43.242 -
  43.243 -    public void saveScopesCombo() {
  43.244 -//        Preferences prefs = NbPreferences.forModule(ScopesPanel.class).node(SCOPES_KEY);
  43.245 -//
  43.246 -//        try {
  43.247 -//            prefs.clear();
  43.248 -//        } catch (BackingStoreException ex) {
  43.249 -//            Exceptions.printStackTrace(ex);
  43.250 -//        }
  43.251 -//
  43.252 -//        for (int i = 0; i < scope.getModel().getSize(); i++) {
  43.253 -//            Scope currentScope = (Scope) scope.getModel().getElementAt(i);
  43.254 -//
  43.255 -//            if (currentScope.scopeType == ScopeType.ALL_OPENED_PROJECTS) continue;
  43.256 -//
  43.257 -//            prefs.put("scope" + i, currentScope.serialize());
  43.258 -//        }
  43.259 -//
  43.260 -//        Scope selected = (Scope) scope.getModel().getSelectedItem();
  43.261 -//
  43.262 -//        if (selected.scopeType == ScopeType.GIVEN_FOLDER) {
  43.263 -//            prefs.put(LAST_SELECTED_SCOPE_KEY, selected.folder);
  43.264 -//        }
  43.265 -    }
  43.266 -
  43.267 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  43.268 -    private javax.swing.JButton add;
  43.269 -    private javax.swing.JButton edit;
  43.270 -    private javax.swing.JLabel jLabel2;
  43.271 -    private javax.swing.ButtonGroup main;
  43.272 -    private javax.swing.JButton removeButton;
  43.273 -    private javax.swing.JComboBox scope;
  43.274 -    private javax.swing.JPanel scopePanel;
  43.275 -    // End of variables declaration//GEN-END:variables
  43.276 -
  43.277 -    private static final class RendererImpl extends DefaultListCellRenderer {
  43.278 -
  43.279 -        @Override
  43.280 -        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  43.281 -            Object displayName;
  43.282 -
  43.283 -            if (value instanceof Scope) {
  43.284 -                displayName = ((Scope) value).getDisplayName();
  43.285 -            } else {
  43.286 -                displayName = value;
  43.287 -            }
  43.288 -            
  43.289 -            return super.getListCellRendererComponent(list, displayName, index, isSelected, cellHasFocus);
  43.290 -        }
  43.291 -
  43.292 -    }
  43.293 -
  43.294 -    private void addEditScope(boolean edit) {
  43.295 -        JButton okButton = new JButton("OK");
  43.296 -        AddScopePanel panel = new AddScopePanel(okButton);
  43.297 -        DialogDescriptor dd = new DialogDescriptor(panel, "Add Scope", true, new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}, okButton, DialogDescriptor.DEFAULT_ALIGN, null, null);
  43.298 -
  43.299 -        dd.setClosingOptions(null);
  43.300 -        panel.setNotificationSupport(dd.createNotificationLineSupport());
  43.301 -
  43.302 -        if (edit) {
  43.303 -            panel.setScope((GivenFolderScope) scope.getModel().getSelectedItem());
  43.304 -        }
  43.305 -
  43.306 -        if (DialogDisplayer.getDefault().notify(dd) == okButton) {
  43.307 -            DefaultComboBoxModel model = (DefaultComboBoxModel) scope.getModel();
  43.308 -            Scope scope = panel.getScope();
  43.309 -
  43.310 -            if (edit) {
  43.311 -                int index = model.getIndexOf(model.getSelectedItem());
  43.312 -
  43.313 -                model.removeElementAt(index);
  43.314 -                model.insertElementAt(scope, index);
  43.315 -            } else {
  43.316 -                model.addElement(scope);
  43.317 -            }
  43.318 -            
  43.319 -            model.setSelectedItem(scope);
  43.320 -        }
  43.321 -    }
  43.322 -
  43.323 -    private static final String SCOPE_COMBO_PROTOTYPE = "0123456789012345678901234567890123456789012345";
  43.324 -}
    44.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/refactoring/Utilities.java	Fri Jan 27 13:35:56 2012 +0100
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,185 +0,0 @@
    44.4 -/*
    44.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    44.6 - *
    44.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    44.8 - *
    44.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   44.10 - * Other names may be trademarks of their respective owners.
   44.11 - *
   44.12 - * The contents of this file are subject to the terms of either the GNU
   44.13 - * General Public License Version 2 only ("GPL") or the Common
   44.14 - * Development and Distribution License("CDDL") (collectively, the
   44.15 - * "License"). You may not use this file except in compliance with the
   44.16 - * License. You can obtain a copy of the License at
   44.17 - * http://www.netbeans.org/cddl-gplv2.html
   44.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   44.19 - * specific language governing permissions and limitations under the
   44.20 - * License.  When distributing the software, include this License Header
   44.21 - * Notice in each file and include the License file at
   44.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   44.23 - * particular file as subject to the "Classpath" exception as provided
   44.24 - * by Oracle in the GPL Version 2 section of the License file that
   44.25 - * accompanied this code. If applicable, add the following below the
   44.26 - * License Header, with the fields enclosed by brackets [] replaced by
   44.27 - * your own identifying information:
   44.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   44.29 - *
   44.30 - * If you wish your version of this file to be governed by only the CDDL
   44.31 - * or only the GPL Version 2, indicate your decision by adding
   44.32 - * "[Contributor] elects to include this software in this distribution
   44.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   44.34 - * single choice of license, a recipient has the option to distribute
   44.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   44.36 - * to extend the choice of license to its licensees as provided above.
   44.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   44.38 - * Version 2 license, then the option applies only if the new code is
   44.39 - * made subject to such option by the copyright holder.
   44.40 - *
   44.41 - * Contributor(s):
   44.42 - *
   44.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
   44.44 - */
   44.45 -
   44.46 -package org.netbeans.modules.jackpot30.impl.refactoring;
   44.47 -
   44.48 -import java.io.CharConversionException;
   44.49 -import java.io.IOException;
   44.50 -import java.util.ArrayList;
   44.51 -import java.util.Collection;
   44.52 -import java.util.LinkedList;
   44.53 -import java.util.List;
   44.54 -import javax.swing.text.Position.Bias;
   44.55 -import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
   44.56 -import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
   44.57 -import org.openide.cookies.EditorCookie;
   44.58 -import org.openide.cookies.LineCookie;
   44.59 -import org.openide.filesystems.FileObject;
   44.60 -import org.openide.loaders.DataObject;
   44.61 -import org.openide.loaders.DataObjectNotFoundException;
   44.62 -import org.openide.text.CloneableEditorSupport;
   44.63 -import org.openide.text.Line;
   44.64 -import org.openide.text.PositionBounds;
   44.65 -import org.openide.text.PositionRef;
   44.66 -import org.openide.util.Exceptions;
   44.67 -import org.openide.util.Lookup;
   44.68 -import org.openide.util.lookup.Lookups;
   44.69 -import org.openide.xml.XMLUtil;
   44.70 -
   44.71 -/**
   44.72 - *
   44.73 - * @author lahvac
   44.74 - */
   44.75 -public class Utilities {
   44.76 -    public static List<PositionBounds> prepareSpansFor(FileObject file, Iterable<? extends int[]> spans) {
   44.77 -        List<PositionBounds> result = new ArrayList<PositionBounds>();
   44.78 -
   44.79 -        try {
   44.80 -            DataObject d = DataObject.find(file);
   44.81 -            EditorCookie ec = d.getLookup().lookup(EditorCookie.class);
   44.82 -            CloneableEditorSupport ces = (CloneableEditorSupport) ec;
   44.83 -
   44.84 -            result = new LinkedList<PositionBounds>();
   44.85 -
   44.86 -            for (int[] span : spans) {
   44.87 -                PositionRef start = ces.createPositionRef(span[0], Bias.Forward);
   44.88 -                PositionRef end = ces.createPositionRef(span[1], Bias.Forward);
   44.89 -
   44.90 -                result.add(new PositionBounds(start, end));
   44.91 -            }
   44.92 -        } catch (DataObjectNotFoundException ex) {
   44.93 -            Exceptions.printStackTrace(ex);
   44.94 -        }
   44.95 -
   44.96 -        return result;
   44.97 -    }
   44.98 -
   44.99 -    public static Collection<RefactoringElementImplementation> createRefactoringElementImplementation(FileObject file, List<PositionBounds> spans, boolean verified) {
  44.100 -        List<RefactoringElementImplementation> result = new LinkedList<RefactoringElementImplementation>();
  44.101 -
  44.102 -        try {
  44.103 -            DataObject d = DataObject.find(file);
  44.104 -            LineCookie lc = d.getLookup().lookup(LineCookie.class);
  44.105 -
  44.106 -            for (PositionBounds bound : spans) {
  44.107 -                PositionRef start = bound.getBegin();
  44.108 -                PositionRef end = bound.getEnd();
  44.109 -                Line l = lc.getLineSet().getCurrent(start.getLine());
  44.110 -                String lineText = l.getText();
  44.111 -
  44.112 -                int boldStart = start.getColumn();
  44.113 -                int boldEnd   = end.getLine() == start.getLine() ? end.getColumn() : lineText.length();
  44.114 -
  44.115 -                StringBuilder displayName = new StringBuilder();
  44.116 -
  44.117 -                if (!verified) {
  44.118 -                    displayName.append("(not verified) ");
  44.119 -                }
  44.120 -
  44.121 -                displayName.append(escapedSubstring(lineText, 0, boldStart).replaceAll("^[ ]*", ""));
  44.122 -                displayName.append("<b>");
  44.123 -                displayName.append(escapedSubstring(lineText, boldStart, boldEnd));
  44.124 -                displayName.append("</b>");
  44.125 -                displayName.append(escapedSubstring(lineText, boldEnd, lineText.length()));
  44.126 -
  44.127 -                result.add(new RefactoringElementImpl(file, bound, displayName.toString()));
  44.128 -            }
  44.129 -        } catch (IOException ex) {
  44.130 -            Exceptions.printStackTrace(ex);
  44.131 -        }
  44.132 -
  44.133 -        return result;
  44.134 -    }
  44.135 -
  44.136 -    private static String escapedSubstring(String str, int start, int end) {
  44.137 -        String substring = str.substring(start, end);
  44.138 -
  44.139 -        try {
  44.140 -            return XMLUtil.toElementContent(substring);
  44.141 -        } catch (CharConversionException ex) {
  44.142 -            Exceptions.printStackTrace(ex);
  44.143 -            return substring;
  44.144 -        }
  44.145 -    }
  44.146 -
  44.147 -    private static final class RefactoringElementImpl extends SimpleRefactoringElementImplementation {
  44.148 -
  44.149 -        private final FileObject file;
  44.150 -        private final PositionBounds span;
  44.151 -        private final String displayName;
  44.152 -
  44.153 -        private final Lookup lookup;
  44.154 -
  44.155 -        public RefactoringElementImpl(FileObject file, PositionBounds span, String displayName) {
  44.156 -            this.file = file;
  44.157 -            this.span = span;
  44.158 -            this.lookup = Lookups.fixed(file);
  44.159 -            this.displayName = displayName;
  44.160 -        }
  44.161 -
  44.162 -        public String getText() {
  44.163 -            return getDisplayText();
  44.164 -        }
  44.165 -
  44.166 -        public String getDisplayText() {
  44.167 -            return displayName;
  44.168 -        }
  44.169 -
  44.170 -        public void performChange() {
  44.171 -            throw new IllegalStateException();
  44.172 -        }
  44.173 -
  44.174 -        public Lookup getLookup() {
  44.175 -            return lookup;
  44.176 -        }
  44.177 -
  44.178 -        public FileObject getParentFile() {
  44.179 -            return file;
  44.180 -        }
  44.181 -
  44.182 -        public PositionBounds getPosition() {
  44.183 -            return span;
  44.184 -        }
  44.185 -
  44.186 -    }
  44.187 -
  44.188 -}
    45.1 --- a/api/src/org/netbeans/modules/jackpot30/spi/refactoring/JackpotBasedRefactoring.java	Fri Jan 27 13:35:56 2012 +0100
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,210 +0,0 @@
    45.4 -/*
    45.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    45.6 - *
    45.7 - * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
    45.8 - *
    45.9 - * The contents of this file are subject to the terms of either the GNU
   45.10 - * General Public License Version 2 only ("GPL") or the Common
   45.11 - * Development and Distribution License("CDDL") (collectively, the
   45.12 - * "License"). You may not use this file except in compliance with the
   45.13 - * License. You can obtain a copy of the License at
   45.14 - * http://www.netbeans.org/cddl-gplv2.html
   45.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   45.16 - * specific language governing permissions and limitations under the
   45.17 - * License.  When distributing the software, include this License Header
   45.18 - * Notice in each file and include the License file at
   45.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   45.20 - * particular file as subject to the "Classpath" exception as provided
   45.21 - * by Sun in the GPL Version 2 section of the License file that
   45.22 - * accompanied this code. If applicable, add the following below the
   45.23 - * License Header, with the fields enclosed by brackets [] replaced by
   45.24 - * your own identifying information:
   45.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   45.26 - *
   45.27 - * If you wish your version of this file to be governed by only the CDDL
   45.28 - * or only the GPL Version 2, indicate your decision by adding
   45.29 - * "[Contributor] elects to include this software in this distribution
   45.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   45.31 - * single choice of license, a recipient has the option to distribute
   45.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   45.33 - * to extend the choice of license to its licensees as provided above.
   45.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   45.35 - * Version 2 license, then the option applies only if the new code is
   45.36 - * made subject to such option by the copyright holder.
   45.37 - *
   45.38 - * Contributor(s):
   45.39 - *
   45.40 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
   45.41 - */
   45.42 -
   45.43 -package org.netbeans.modules.jackpot30.spi.refactoring;
   45.44 -
   45.45 -import java.io.File;
   45.46 -import java.io.IOException;
   45.47 -import java.util.Arrays;
   45.48 -import java.util.Collection;
   45.49 -import java.util.Collections;
   45.50 -import java.util.EnumSet;
   45.51 -import java.util.HashMap;
   45.52 -import java.util.LinkedList;
   45.53 -import java.util.List;
   45.54 -import java.util.Map;
   45.55 -import java.util.Set;
   45.56 -import java.util.concurrent.atomic.AtomicBoolean;
   45.57 -import javax.swing.text.Document;
   45.58 -import javax.swing.text.Position.Bias;
   45.59 -import javax.tools.JavaFileObject;
   45.60 -import org.netbeans.api.java.classpath.ClassPath;
   45.61 -import org.netbeans.api.java.source.ModificationResult;
   45.62 -import org.netbeans.api.java.source.ModificationResult.Difference;
   45.63 -import org.netbeans.api.java.source.TreePathHandle;
   45.64 -import org.netbeans.api.queries.FileEncodingQuery;
   45.65 -import org.netbeans.modules.jackpot30.impl.refactoring.RetoucheCommit;
   45.66 -import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
   45.67 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
   45.68 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
   45.69 -import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities;
   45.70 -import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
   45.71 -import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
   45.72 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   45.73 -import org.netbeans.modules.java.hints.jackpot.spi.PatternConvertor;
   45.74 -import org.netbeans.modules.java.source.JavaSourceAccessor;
   45.75 -import org.netbeans.modules.java.source.parsing.FileObjects;
   45.76 -import org.netbeans.modules.refactoring.api.AbstractRefactoring;
   45.77 -import org.netbeans.modules.refactoring.api.Problem;
   45.78 -import org.netbeans.modules.refactoring.java.spi.DiffElement;
   45.79 -import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
   45.80 -import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
   45.81 -import org.openide.filesystems.FileObject;
   45.82 -import org.openide.filesystems.FileUtil;
   45.83 -import org.openide.loaders.DataObject;
   45.84 -import org.openide.text.CloneableEditorSupport;
   45.85 -import org.openide.text.PositionRef;
   45.86 -import org.openide.util.Exceptions;
   45.87 -
   45.88 -/**
   45.89 - *
   45.90 - * @author lahvac
   45.91 - */
   45.92 -public abstract class JackpotBasedRefactoring implements RefactoringPlugin {
   45.93 -
   45.94 -    protected final AtomicBoolean cancel = new AtomicBoolean();
   45.95 -
   45.96 -    private final AbstractRefactoring refactoring;
   45.97 -
   45.98 -    protected JackpotBasedRefactoring(AbstractRefactoring refactoring) {
   45.99 -        this.refactoring = refactoring;
  45.100 -    }
  45.101 -
  45.102 -    public final void cancelRequest() {
  45.103 -        cancel.set(true);
  45.104 -    }
  45.105 -
  45.106 -    public final Problem prepare(RefactoringElementsBag refactoringElements) {
  45.107 -        TreePathHandle tph = refactoring.getRefactoringSource().lookup(TreePathHandle.class);
  45.108 -        FileObject file = tph.getFileObject();
  45.109 -        ClassPath source = ClassPath.getClassPath(file, ClassPath.SOURCE);
  45.110 -        FileObject sourceRoot = source.findOwnerRoot(file);
  45.111 -        
  45.112 -        Collection<MessageImpl> problems = new LinkedList<MessageImpl>();
  45.113 -        Context result = new Context();
  45.114 -        prepareAndConstructRule(result);
  45.115 -        Collection<ModificationResult> modifications = new LinkedList<ModificationResult>(result.modifications);
  45.116 -        Collection<HintDescription> hints = new LinkedList<HintDescription>();
  45.117 -        Map<FileObject, List<Difference>> scriptDifferences = new HashMap<FileObject, List<Difference>>();
  45.118 -        for (ScriptDescription s : result.scripts) {
  45.119 -            if (s.options.contains(ScriptOptions.RUN)) {
  45.120 -                for (HintDescription c : PatternConvertor.create(s.code)) {
  45.121 -                    hints.add(c);
  45.122 -                }
  45.123 -            }
  45.124 -            if (s.options.contains(ScriptOptions.STORE)) {
  45.125 -                createDifference(sourceRoot, file, s, scriptDifferences);
  45.126 -            }
  45.127 -        }
  45.128 -        if (!scriptDifferences.isEmpty()) {
  45.129 -            modifications.add(JavaSourceAccessor.getINSTANCE().createModificationResult(scriptDifferences, Collections.<Object, int[]>emptyMap()));
  45.130 -        }
  45.131 -        BatchResult batchResult = BatchSearch.findOccurrences(hints, Scopes.allOpenedProjectsScope());
  45.132 -        modifications.addAll(BatchUtilities.applyFixes(batchResult, new ProgressHandleWrapper(1, 1), cancel, problems));
  45.133 -
  45.134 -        createAndAddElements(refactoringElements, modifications);
  45.135 -        
  45.136 -        return null;//XXX
  45.137 -    }
  45.138 -
  45.139 -    protected abstract void prepareAndConstructRule(Context result);
  45.140 -
  45.141 -    private void createAndAddElements(RefactoringElementsBag elements, Collection<ModificationResult> results) {
  45.142 -        elements.registerTransaction(new RetoucheCommit(results));
  45.143 -        for (ModificationResult result:results) {
  45.144 -            for (FileObject jfo : result.getModifiedFileObjects()) {
  45.145 -                for (Difference diff: result.getDifferences(jfo)) {
  45.146 -                    elements.add(refactoring,DiffElement.create(diff, jfo, result));
  45.147 -                }
  45.148 -            }
  45.149 -        }
  45.150 -    }
  45.151 -
  45.152 -    private static void createDifference(FileObject sourceRoot, FileObject origFile, ScriptDescription sd, Map<FileObject, List<Difference>> scriptDifferences) {
  45.153 -        String relPath = "META-INF/upgrade/" + sd.name + ".hint";
  45.154 -        FileObject hintFile = sourceRoot.getFileObject(relPath);
  45.155 -        List<Difference> diffs = scriptDifferences.get(hintFile != null ? hintFile : origFile);
  45.156 -
  45.157 -        if (diffs == null) {
  45.158 -            scriptDifferences.put(hintFile != null ? hintFile : origFile, diffs = new LinkedList<Difference>());
  45.159 -        }
  45.160 -
  45.161 -        if (hintFile != null) {
  45.162 -            //append:
  45.163 -            try {
  45.164 -                CloneableEditorSupport ces = DataObject.find(hintFile).getLookup().lookup(CloneableEditorSupport.class);
  45.165 -                Document doc = ces.openDocument();
  45.166 -                PositionRef pos = ces.createPositionRef(doc.getLength(), Bias.Forward);
  45.167 -
  45.168 -                diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(Difference.Kind.INSERT, pos, pos, "", sd.code, null));
  45.169 -            } catch (IOException ex) {
  45.170 -                //XXX:
  45.171 -                Exceptions.printStackTrace(ex);
  45.172 -            }
  45.173 -        } else {
  45.174 -            File root = FileUtil.toFile(sourceRoot);
  45.175 -            JavaFileObject jfo = FileObjects.fileFileObject(new File(root, relPath), root, null, FileEncodingQuery.getEncoding(sourceRoot));
  45.176 -            
  45.177 -            diffs.add(JavaSourceAccessor.getINSTANCE().createNewFileDifference(jfo, sd.code));
  45.178 -        }
  45.179 -    }
  45.180 -
  45.181 -    public static final class Context {
  45.182 -        private final Collection<ModificationResult> modifications = new LinkedList<ModificationResult>();
  45.183 -        private final Collection<ScriptDescription> scripts = new LinkedList<ScriptDescription>();
  45.184 -
  45.185 -        public void addModificationResult(ModificationResult r) {
  45.186 -            modifications.add(r);
  45.187 -        }
  45.188 -
  45.189 -        public void addScript(String name, String code, ScriptOptions... options) {
  45.190 -            Set<ScriptOptions> optionsSet = EnumSet.noneOf(ScriptOptions.class);
  45.191 -            optionsSet.addAll(Arrays.asList(options));
  45.192 -            scripts.add(new ScriptDescription(name, code, optionsSet));
  45.193 -        }
  45.194 -    }
  45.195 -
  45.196 -    private static final class ScriptDescription {
  45.197 -        private final String name;
  45.198 -        private final String code;
  45.199 -        private final Set<ScriptOptions> options;
  45.200 -
  45.201 -        public ScriptDescription(String name, String code, Set<ScriptOptions> run) {
  45.202 -            this.name = name;
  45.203 -            this.code = code;
  45.204 -            this.options = run;
  45.205 -        }
  45.206 -
  45.207 -    }
  45.208 -
  45.209 -    public enum ScriptOptions {
  45.210 -        STORE,
  45.211 -        RUN;
  45.212 -    }
  45.213 -}
    46.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicatesTest.java	Fri Jan 27 13:35:56 2012 +0100
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,118 +0,0 @@
    46.4 -/*
    46.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    46.6 - *
    46.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    46.8 - *
    46.9 - * The contents of this file are subject to the terms of either the GNU
   46.10 - * General Public License Version 2 only ("GPL") or the Common
   46.11 - * Development and Distribution License("CDDL") (collectively, the
   46.12 - * "License"). You may not use this file except in compliance with the
   46.13 - * License. You can obtain a copy of the License at
   46.14 - * http://www.netbeans.org/cddl-gplv2.html
   46.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   46.16 - * specific language governing permissions and limitations under the
   46.17 - * License.  When distributing the software, include this License Header
   46.18 - * Notice in each file and include the License file at
   46.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   46.20 - * particular file as subject to the "Classpath" exception as provided
   46.21 - * by Sun in the GPL Version 2 section of the License file that
   46.22 - * accompanied this code. If applicable, add the following below the
   46.23 - * License Header, with the fields enclosed by brackets [] replaced by
   46.24 - * your own identifying information:
   46.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   46.26 - *
   46.27 - * If you wish your version of this file to be governed by only the CDDL
   46.28 - * or only the GPL Version 2, indicate your decision by adding
   46.29 - * "[Contributor] elects to include this software in this distribution
   46.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   46.31 - * single choice of license, a recipient has the option to distribute
   46.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   46.33 - * to extend the choice of license to its licensees as provided above.
   46.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   46.35 - * Version 2 license, then the option applies only if the new code is
   46.36 - * made subject to such option by the copyright holder.
   46.37 - *
   46.38 - * Contributor(s):
   46.39 - *
   46.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   46.41 - */
   46.42 -
   46.43 -package org.netbeans.modules.jackpot30.impl.duplicates;
   46.44 -
   46.45 -import org.netbeans.api.progress.ProgressHandle;
   46.46 -import org.openide.filesystems.FileObject;
   46.47 -import java.util.HashMap;
   46.48 -import java.util.LinkedList;
   46.49 -import java.util.Map;
   46.50 -import java.util.concurrent.atomic.AtomicBoolean;
   46.51 -import org.netbeans.api.java.source.TestUtilities;
   46.52 -import org.netbeans.api.progress.ProgressHandleFactory;
   46.53 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   46.54 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   46.55 -import org.netbeans.modules.jackpot30.impl.indexing.IndexTestBase;
   46.56 -import org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.File;
   46.57 -import org.openide.filesystems.FileUtil;
   46.58 -import org.openide.util.NbCollections;
   46.59 -import static org.junit.Assert.*;
   46.60 -
   46.61 -import static org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.writeFilesAndWaitForScan;
   46.62 -
   46.63 -/**
   46.64 - *
   46.65 - * @author lahvac
   46.66 - */
   46.67 -public class ComputeDuplicatesTest extends IndexTestBase {
   46.68 -
   46.69 -    public ComputeDuplicatesTest(String name) {
   46.70 -        super(name);
   46.71 -    }
   46.72 -
   46.73 -    public void testDuplicateDuplicates() throws Exception {
   46.74 -        writeFilesAndWaitForScan(src,
   46.75 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
   46.76 -                                 new File("test/Test2.java", "package test; public class Test2 { private int a; private void test() { java.io.File f = null; f.isDirectory(); } }"));
   46.77 -
   46.78 -        verifyDuplicates("test/Test1.java",
   46.79 -                         "private void test() { java.io.File f = null; f.isDirectory(); }",
   46.80 -                         "test/Test2.java",
   46.81 -                         "private void test() { java.io.File f = null; f.isDirectory(); }");
   46.82 -    }
   46.83 -
   46.84 -    public void testCrossIndex() throws Exception {
   46.85 -        writeFilesAndWaitForScan(src,
   46.86 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"));
   46.87 -
   46.88 -        writeFilesAndWaitForScan(src2,
   46.89 -                                 new File("test/Test2.java", "package test; public class Test2 { private int a; private void test() { java.io.File f = null; f.isDirectory(); } }"));
   46.90 -
   46.91 -        verifyDuplicates("test/Test1.java",
   46.92 -                         "private void test() { java.io.File f = null; f.isDirectory(); }",
   46.93 -                         "test/Test2.java",
   46.94 -                         "private void test() { java.io.File f = null; f.isDirectory(); }");
   46.95 -    }
   46.96 -
   46.97 -    private void verifyDuplicates(String... fileAndDuplicateCode) throws Exception {
   46.98 -        Map<String, String> duplicatesGolden = new HashMap<String, String>();
   46.99 -
  46.100 -        for (int cntr = 0; cntr < fileAndDuplicateCode.length; cntr += 2) {
  46.101 -            duplicatesGolden.put(fileAndDuplicateCode[cntr], fileAndDuplicateCode[cntr + 1]);
  46.102 -        }
  46.103 -
  46.104 -        Map<String, String> duplicatesReal = new HashMap<String, String>();
  46.105 -        ProgressHandle handle = ProgressHandleFactory.createHandle("test");
  46.106 -
  46.107 -        handle.start();
  46.108 -        
  46.109 -        for (DuplicateDescription dd : NbCollections.iterable(new ComputeDuplicates().computeDuplicatesForAllOpenedProjects(handle, new AtomicBoolean()))) {
  46.110 -            for (Span s : dd.dupes) {
  46.111 -                duplicatesReal.put(relativePath(s.file), TestUtilities.copyFileToString(FileUtil.toFile(s.file)).substring(s.startOff, s.endOff));
  46.112 -            }
  46.113 -        }
  46.114 -
  46.115 -        assertEquals(duplicatesGolden, duplicatesReal);
  46.116 -    }
  46.117 -
  46.118 -    private String relativePath(FileObject file) {
  46.119 -        return FileUtil.isParentOf(src, file) ? FileUtil.getRelativePath(src, file) : FileUtil.getRelativePath(src2, file);
  46.120 -    }
  46.121 -}
  46.122 \ No newline at end of file
    47.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndexTest.java	Fri Jan 27 13:35:56 2012 +0100
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,133 +0,0 @@
    47.4 -/*
    47.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    47.6 - *
    47.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    47.8 - *
    47.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   47.10 - * Other names may be trademarks of their respective owners.
   47.11 - *
   47.12 - * The contents of this file are subject to the terms of either the GNU
   47.13 - * General Public License Version 2 only ("GPL") or the Common
   47.14 - * Development and Distribution License("CDDL") (collectively, the
   47.15 - * "License"). You may not use this file except in compliance with the
   47.16 - * License. You can obtain a copy of the License at
   47.17 - * http://www.netbeans.org/cddl-gplv2.html
   47.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   47.19 - * specific language governing permissions and limitations under the
   47.20 - * License.  When distributing the software, include this License Header
   47.21 - * Notice in each file and include the License file at
   47.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   47.23 - * particular file as subject to the "Classpath" exception as provided
   47.24 - * by Oracle in the GPL Version 2 section of the License file that
   47.25 - * accompanied this code. If applicable, add the following below the
   47.26 - * License Header, with the fields enclosed by brackets [] replaced by
   47.27 - * your own identifying information:
   47.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   47.29 - *
   47.30 - * If you wish your version of this file to be governed by only the CDDL
   47.31 - * or only the GPL Version 2, indicate your decision by adding
   47.32 - * "[Contributor] elects to include this software in this distribution
   47.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   47.34 - * single choice of license, a recipient has the option to distribute
   47.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   47.36 - * to extend the choice of license to its licensees as provided above.
   47.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   47.38 - * Version 2 license, then the option applies only if the new code is
   47.39 - * made subject to such option by the copyright holder.
   47.40 - *
   47.41 - * Contributor(s):
   47.42 - *
   47.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
   47.44 - */
   47.45 -package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   47.46 -
   47.47 -import java.io.File;
   47.48 -import java.net.URL;
   47.49 -import java.util.ArrayList;
   47.50 -import java.util.Arrays;
   47.51 -import java.util.HashMap;
   47.52 -import java.util.List;
   47.53 -import java.util.Map;
   47.54 -import org.netbeans.api.java.source.TestUtilities;
   47.55 -import static org.junit.Assert.*;
   47.56 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   47.57 -import org.netbeans.core.startup.Main;
   47.58 -import org.netbeans.junit.NbTestCase;
   47.59 -import org.netbeans.modules.jackpot30.impl.TestUtils;
   47.60 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   47.61 -import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   47.62 -import org.netbeans.modules.jackpot30.impl.indexing.Cache;
   47.63 -import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   47.64 -import org.openide.filesystems.FileObject;
   47.65 -import org.openide.filesystems.FileUtil;
   47.66 -
   47.67 -/**
   47.68 - *
   47.69 - * @author lahvac
   47.70 - */
   47.71 -public class RemoteDuplicatesIndexTest extends NbTestCase {
   47.72 -
   47.73 -    public RemoteDuplicatesIndexTest(String name) {
   47.74 -        super(name);
   47.75 -    }
   47.76 -
   47.77 -    public void setUp() throws Exception {
   47.78 -        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
   47.79 -        Main.initializeURLFactory();
   47.80 -        TestUtils.clearRemoteContent();
   47.81 -        super.setUp();
   47.82 -    }
   47.83 -
   47.84 -    public void testFindHashOccurrences() throws Exception {
   47.85 -        clearWorkDir();
   47.86 -        File cacheDir = new File(getWorkDir(), "cache");
   47.87 -        File dataDir = new File(getWorkDir(), "data");
   47.88 -
   47.89 -        Cache.setStandaloneCacheRoot(cacheDir);
   47.90 -
   47.91 -        FileObject data1 = FileUtil.createFolder(new File(dataDir, "data1"));
   47.92 -        FileObject data2 = FileUtil.createFolder(new File(dataDir, "data2"));
   47.93 -        FileObject source = FileUtil.createData(new File(dataDir, "src/Test.java"));
   47.94 -
   47.95 -        TestUtilities.copyStringToFile(data1.createData("T1.java"), "0123456789");
   47.96 -        TestUtilities.copyStringToFile(data1.createData("T2.java"), "0123456789");
   47.97 -        TestUtilities.copyStringToFile(data2.createData("T3.java"), "0123456789");
   47.98 -        TestUtilities.copyStringToFile(data2.createData("T4.java"), "0123456789");
   47.99 -        
  47.100 -        TestUtils.addRemoteContent(new URL("test://test/index/findDuplicates?hashes=[%0A%20%20%20%20%2200%22,%0A%20%20%20%20%2201%22,%0A%20%20%20%20%2202%22%0A]"), "{ \"00\": { \"foo1\": [ \"T1.java\", \"T2.java\" ], \"foo2\": [ \"T3.java\", \"T4.java\" ] } }");
  47.101 -        RemoteIndex.saveIndices(Arrays.asList(RemoteIndex.create(FileUtil.toFile(data1).toURI().toURL(), new URL("test://test/index"), "foo1"),
  47.102 -                                              RemoteIndex.create(FileUtil.toFile(data2).toURI().toURL(), new URL("test://test/index"), "foo2")));
  47.103 -
  47.104 -        TestUtilities.copyStringToFile(source, "01234567890123456789");
  47.105 -        
  47.106 -        Map<String, long[]> hashes = new HashMap<String, long[]>();
  47.107 -
  47.108 -        hashes.put("00", new long[] {1, 2, 5, 6});
  47.109 -        hashes.put("01", new long[] {8, 9});
  47.110 -        hashes.put("02", new long[] {3, 4});
  47.111 -        
  47.112 -        List<DuplicateDescription> duplicates = RemoteDuplicatesIndex.findDuplicates(hashes, source);
  47.113 -        List<String> duplicatesReal = new ArrayList<String>();
  47.114 -
  47.115 -        for (DuplicateDescription dd : duplicates) {
  47.116 -            for (Span s : dd.dupes) {
  47.117 -                duplicatesReal.add(s.file.getName());
  47.118 -            }
  47.119 -        }
  47.120 -
  47.121 -        assertEquals(Arrays.asList("T2", "T1", "T4", "T3"), duplicatesReal);
  47.122 -
  47.123 -        //check local cache:
  47.124 -        duplicates = RemoteDuplicatesIndex.findDuplicates(hashes, source);
  47.125 -        duplicatesReal = new ArrayList<String>();
  47.126 -
  47.127 -        for (DuplicateDescription dd : duplicates) {
  47.128 -            for (Span s : dd.dupes) {
  47.129 -                duplicatesReal.add(s.file.getName());
  47.130 -            }
  47.131 -        }
  47.132 -
  47.133 -        assertEquals(Arrays.asList("T2", "T1", "T4", "T3"), duplicatesReal);
  47.134 -    }
  47.135 -
  47.136 -}
    48.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImplTest.java	Fri Jan 27 13:35:56 2012 +0100
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,111 +0,0 @@
    48.4 -/*
    48.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    48.6 - *
    48.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    48.8 - *
    48.9 - * The contents of this file are subject to the terms of either the GNU
   48.10 - * General Public License Version 2 only ("GPL") or the Common
   48.11 - * Development and Distribution License("CDDL") (collectively, the
   48.12 - * "License"). You may not use this file except in compliance with the
   48.13 - * License. You can obtain a copy of the License at
   48.14 - * http://www.netbeans.org/cddl-gplv2.html
   48.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   48.16 - * specific language governing permissions and limitations under the
   48.17 - * License.  When distributing the software, include this License Header
   48.18 - * Notice in each file and include the License file at
   48.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   48.20 - * particular file as subject to the "Classpath" exception as provided
   48.21 - * by Sun in the GPL Version 2 section of the License file that
   48.22 - * accompanied this code. If applicable, add the following below the
   48.23 - * License Header, with the fields enclosed by brackets [] replaced by
   48.24 - * your own identifying information:
   48.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   48.26 - *
   48.27 - * If you wish your version of this file to be governed by only the CDDL
   48.28 - * or only the GPL Version 2, indicate your decision by adding
   48.29 - * "[Contributor] elects to include this software in this distribution
   48.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   48.31 - * single choice of license, a recipient has the option to distribute
   48.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   48.33 - * to extend the choice of license to its licensees as provided above.
   48.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   48.35 - * Version 2 license, then the option applies only if the new code is
   48.36 - * made subject to such option by the copyright holder.
   48.37 - *
   48.38 - * Contributor(s):
   48.39 - *
   48.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   48.41 - */
   48.42 -
   48.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   48.44 -
   48.45 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
   48.46 -import java.net.URL;
   48.47 -import java.util.Arrays;
   48.48 -import java.util.HashSet;
   48.49 -import java.util.Set;
   48.50 -import org.netbeans.api.java.classpath.ClassPath;
   48.51 -import org.netbeans.api.java.source.ClasspathInfo;
   48.52 -import org.netbeans.api.java.source.CompilationController;
   48.53 -import org.netbeans.api.java.source.JavaSource;
   48.54 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   48.55 -import org.netbeans.api.java.source.Task;
   48.56 -import org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.File;
   48.57 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
   48.58 -import org.openide.filesystems.FileObject;
   48.59 -
   48.60 -import static org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.writeFilesAndWaitForScan;
   48.61 -
   48.62 -/**
   48.63 - *
   48.64 - * @author lahvac
   48.65 - */
   48.66 -public class CustomIndexerImplTest extends IndexTestBase {
   48.67 -
   48.68 -    public CustomIndexerImplTest(String name) {
   48.69 -        super(name);
   48.70 -    }
   48.71 -
   48.72 -    public void testIndexing() throws Exception {
   48.73 -        writeFilesAndWaitForScan(src,
   48.74 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
   48.75 -                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
   48.76 -
   48.77 -        verifyIndex("$1.isDirectory()", "test/Test1.java");
   48.78 -        verifyIndex("new ImageIcon($1)", "test/Test2.java");
   48.79 -        
   48.80 -        writeFilesAndWaitForScan(src,
   48.81 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); new javax.swing.ImageIcon(null); } }"),
   48.82 -                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
   48.83 -
   48.84 -        verifyIndex("$1.isDirectory()", "test/Test1.java");
   48.85 -        verifyIndex("new ImageIcon($1)", "test/Test1.java", "test/Test2.java");
   48.86 -        
   48.87 -        writeFilesAndWaitForScan(src,
   48.88 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); new javax.swing.ImageIcon(null); } }"),
   48.89 -                                 new File("test/Test2.java", "package test; public class Test2 { }"));
   48.90 -
   48.91 -        verifyIndex("$1.isDirectory()", "test/Test1.java");
   48.92 -        verifyIndex("new ImageIcon($1)", "test/Test1.java");
   48.93 -    }
   48.94 -    
   48.95 -    private void verifyIndex(final String pattern, String... containedIn) throws Exception {
   48.96 -        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
   48.97 -        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
   48.98 -                                                    EMPTY,
   48.99 -                                                    EMPTY);
  48.100 -
  48.101 -        final Set<String> real = new HashSet<String>();
  48.102 -        
  48.103 -        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  48.104 -            public void run(CompilationController parameter) throws Exception {
  48.105 -                real.addAll(FileBasedIndex.get(src.getURL()).findCandidates(BulkSearch.getDefault().create(parameter, pattern)));
  48.106 -            }
  48.107 -        }, true);
  48.108 -
  48.109 -        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
  48.110 -
  48.111 -        assertEquals(golden, real);
  48.112 -    }
  48.113 -
  48.114 -}
  48.115 \ No newline at end of file
    49.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexTest.java	Fri Jan 27 13:35:56 2012 +0100
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,249 +0,0 @@
    49.4 -/*
    49.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    49.6 - *
    49.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    49.8 - *
    49.9 - * The contents of this file are subject to the terms of either the GNU
   49.10 - * General Public License Version 2 only ("GPL") or the Common
   49.11 - * Development and Distribution License("CDDL") (collectively, the
   49.12 - * "License"). You may not use this file except in compliance with the
   49.13 - * License. You can obtain a copy of the License at
   49.14 - * http://www.netbeans.org/cddl-gplv2.html
   49.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   49.16 - * specific language governing permissions and limitations under the
   49.17 - * License.  When distributing the software, include this License Header
   49.18 - * Notice in each file and include the License file at
   49.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   49.20 - * particular file as subject to the "Classpath" exception as provided
   49.21 - * by Sun in the GPL Version 2 section of the License file that
   49.22 - * accompanied this code. If applicable, add the following below the
   49.23 - * License Header, with the fields enclosed by brackets [] replaced by
   49.24 - * your own identifying information:
   49.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   49.26 - *
   49.27 - * If you wish your version of this file to be governed by only the CDDL
   49.28 - * or only the GPL Version 2, indicate your decision by adding
   49.29 - * "[Contributor] elects to include this software in this distribution
   49.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   49.31 - * single choice of license, a recipient has the option to distribute
   49.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   49.33 - * to extend the choice of license to its licensees as provided above.
   49.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   49.35 - * Version 2 license, then the option applies only if the new code is
   49.36 - * made subject to such option by the copyright holder.
   49.37 - *
   49.38 - * Contributor(s):
   49.39 - *
   49.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   49.41 - */
   49.42 -
   49.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   49.44 -
   49.45 -import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
   49.46 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
   49.47 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
   49.48 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription.AdditionalQueryConstraints;
   49.49 -import java.util.Map;
   49.50 -import java.util.Collections;
   49.51 -import java.net.URL;
   49.52 -import java.util.Arrays;
   49.53 -import java.util.HashMap;
   49.54 -import java.util.HashSet;
   49.55 -import java.util.Set;
   49.56 -import org.netbeans.api.java.classpath.ClassPath;
   49.57 -import org.netbeans.api.java.source.ClasspathInfo;
   49.58 -import org.netbeans.api.java.source.CompilationController;
   49.59 -import org.netbeans.api.java.source.JavaSource;
   49.60 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   49.61 -import org.netbeans.api.java.source.Task;
   49.62 -import org.netbeans.api.java.source.TestUtilities;
   49.63 -import org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.File;
   49.64 -import org.netbeans.modules.parsing.api.indexing.IndexingManager;
   49.65 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
   49.66 -import org.openide.filesystems.FileObject;
   49.67 -import org.openide.filesystems.FileUtil;
   49.68 -
   49.69 -import static org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.indexFiles;
   49.70 -import static org.netbeans.modules.jackpot30.impl.indexing.IndexingTestUtils.writeFilesAndWaitForScan;
   49.71 -
   49.72 -/**
   49.73 - *
   49.74 - * @author lahvac
   49.75 - */
   49.76 -public class IndexTest extends IndexTestBase {
   49.77 -
   49.78 -    public IndexTest(String name) {
   49.79 -        super(name);
   49.80 -    }
   49.81 -
   49.82 -    public void testMultiplePatternsIndexing() throws Exception {
   49.83 -        writeFilesAndWaitForScan(src,
   49.84 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
   49.85 -                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
   49.86 -
   49.87 -        String[] patterns = new String[] {
   49.88 -            "$1.isDirectory()",
   49.89 -            "new ImageIcon($1)"
   49.90 -        };
   49.91 -
   49.92 -        verifyIndex(patterns, "test/Test1.java", "test/Test2.java");
   49.93 -    }
   49.94 -
   49.95 -    public void testLambdaPattern() throws Exception {
   49.96 -        writeFilesAndWaitForScan(src,
   49.97 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { Runnable r = new Runnable() { public void run() { System.err.println(); } } } }"));
   49.98 -
   49.99 -        String[] patterns = new String[] {
  49.100 -            "new $type() {\n $mods$ $resultType $methodName($args$) {\n $statements$;\n }\n }\n",
  49.101 -        };
  49.102 -
  49.103 -        verifyIndex(patterns, "test/Test1.java");
  49.104 -    }
  49.105 -
  49.106 -    public void testUpdates() throws Exception {
  49.107 -        String[] patterns = new String[] {
  49.108 -            "$1.isDirectory()",
  49.109 -            "new ImageIcon($1)"
  49.110 -        };
  49.111 -
  49.112 -        writeFilesAndWaitForScan(src,
  49.113 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
  49.114 -                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
  49.115 -
  49.116 -        verifyIndex(patterns, "test/Test1.java", "test/Test2.java");
  49.117 -        assertEquals(2, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
  49.118 -
  49.119 -        src.getFileObject("test/Test1.java").delete();
  49.120 -
  49.121 -        assertNull(src.getFileObject("test/Test1.java"));
  49.122 -
  49.123 -        IndexingManager.getDefault().refreshIndexAndWait(src.getURL(), null, true);
  49.124 -
  49.125 -        verifyIndex(patterns, "test/Test2.java");
  49.126 -        assertEquals(1, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
  49.127 -
  49.128 -        FileObject test3 = FileUtil.createData(src, "test/Test3.java");
  49.129 -        TestUtilities.copyStringToFile(test3, "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }");
  49.130 -
  49.131 -        IndexingManager.getDefault().refreshIndexAndWait(src.getURL(), null, true);
  49.132 -
  49.133 -        verifyIndex(patterns, "test/Test2.java", "test/Test3.java");
  49.134 -        assertEquals(2, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
  49.135 -    }
  49.136 -
  49.137 -    public void testPartiallyAttributed1() throws Exception {
  49.138 -        Index index = FileBasedIndex.get(src.getURL());
  49.139 -        indexFiles(src.getURL().toURI(),
  49.140 -                   index,
  49.141 -                   new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }", true),
  49.142 -                   new File("test/Test2.java", "package test; public class Test2 { private void isDirectory() { this.isDirectory(); } }", true),
  49.143 -                   new File("test/Test3.java", "package test; public class Test3 { private void isDirectory() { this.isDirectory(); } }", false));
  49.144 -
  49.145 -        verifyIndex("$1.isDirectory()", new AdditionalQueryConstraints(Collections.singleton("java.io.File")), "test/Test1.java", "test/Test3.java");
  49.146 -    }
  49.147 -
  49.148 -    public void testPartiallyAttributed2() throws Exception {
  49.149 -        Index index = FileBasedIndex.get(src.getURL());
  49.150 -        indexFiles(src.getURL().toURI(),
  49.151 -                   index,
  49.152 -                   new File("test/Test1.java", "package test; public class Test1 { private void test() { String str = null; int l = str.length(); } }", true));
  49.153 -
  49.154 -        verifyIndex("$1.length()", new AdditionalQueryConstraints(Collections.singleton("java.lang.CharSequence")), "test/Test1.java");
  49.155 -    }
  49.156 -
  49.157 -    public void testFrequencies() throws Exception {
  49.158 -        writeFilesAndWaitForScan(src,
  49.159 -                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); f.isDirectory(); } }"),
  49.160 -                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); java.io.File f = null; f.isDirectory(); } }"),
  49.161 -                                 new File("test/Test3.java", "package test; public class Test3 { private void test() { new javax.swing.ImageIcon(null); new javax.swing.ImageIcon(null); } }")
  49.162 -                                );
  49.163 -
  49.164 -        String[] patterns = new String[] {
  49.165 -            "$1.isDirectory()",
  49.166 -            "new ImageIcon($1)"
  49.167 -        };
  49.168 -
  49.169 -        Map<String, Map<String, Integer>> golden = new HashMap<String, Map<String, Integer>>();
  49.170 -        
  49.171 -        golden.put("test/Test3.java", Collections.singletonMap("new ImageIcon($1)", 2));
  49.172 -        golden.put("test/Test1.java", Collections.singletonMap("$1.isDirectory()", 2));
  49.173 -        
  49.174 -        Map<String, Integer> freqsTest2 = new HashMap<String, Integer>();
  49.175 -        
  49.176 -        freqsTest2.put("$1.isDirectory()", 1);
  49.177 -        freqsTest2.put("new ImageIcon($1)", 1);
  49.178 -        
  49.179 -        golden.put("test/Test2.java", freqsTest2);
  49.180 -        
  49.181 -        verifyIndexWithFrequencies(patterns, golden);
  49.182 -    }
  49.183 -
  49.184 -    public void testInnerClass() throws Exception {
  49.185 -        Index index = FileBasedIndex.get(src.getURL());
  49.186 -        indexFiles(src.getURL().toURI(),
  49.187 -                   index,
  49.188 -                   new File("test/Test1.java", "package test; public class Test1 { private static final class O implements Iterable<String> { private String next; private String computeNext() { return null; } public String hasNext() { next = computeNext(); return next != null; } } }", true));
  49.189 -
  49.190 -        verifyIndex("$this.computeNext()", new AdditionalQueryConstraints(Collections.singleton("test.Test1.O")), "test/Test1.java");
  49.191 -    }
  49.192 -
  49.193 -    private void verifyIndex(final String[] patterns, String... containedIn) throws Exception {
  49.194 -        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
  49.195 -        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
  49.196 -                                                    EMPTY,
  49.197 -                                                    EMPTY);
  49.198 -
  49.199 -        final Set<String> real = new HashSet<String>();
  49.200 -        
  49.201 -        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  49.202 -            public void run(CompilationController parameter) throws Exception {
  49.203 -                real.addAll(FileBasedIndex.get(src.getURL()).findCandidates(BulkSearch.getDefault().create(parameter, patterns)));
  49.204 -            }
  49.205 -        }, true);
  49.206 -
  49.207 -        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
  49.208 -
  49.209 -        assertEquals(golden, real);
  49.210 -    }
  49.211 -
  49.212 -    private void verifyIndex(final String pattern, final AdditionalQueryConstraints additionalConstraints, String... containedIn) throws Exception {
  49.213 -        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
  49.214 -        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
  49.215 -                                                    EMPTY,
  49.216 -                                                    EMPTY);
  49.217 -
  49.218 -        final Set<String> real = new HashSet<String>();
  49.219 -
  49.220 -        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  49.221 -            public void run(CompilationController parameter) throws Exception {
  49.222 -                BulkPattern bulkPattern = BulkSearch.getDefault().create(Collections.singletonList(pattern),
  49.223 -                                                                          Collections.singletonList(Utilities.parseAndAttribute(parameter, pattern, null)),
  49.224 -                                                                          Collections.singletonList(additionalConstraints));
  49.225 -                
  49.226 -                real.addAll(FileBasedIndex.get(src.getURL()).findCandidates(bulkPattern));
  49.227 -            }
  49.228 -        }, true);
  49.229 -
  49.230 -        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
  49.231 -
  49.232 -        assertEquals(golden, real);
  49.233 -    }
  49.234 -
  49.235 -    private void verifyIndexWithFrequencies(final String[] patterns, Map<String, Map<String, Integer>> golden) throws Exception {
  49.236 -        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
  49.237 -        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
  49.238 -                                                    EMPTY,
  49.239 -                                                    EMPTY);
  49.240 -
  49.241 -        final Map<String, Map<String, Integer>> real = new HashMap<String, Map<String, Integer>>();
  49.242 -
  49.243 -        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  49.244 -            public void run(CompilationController parameter) throws Exception {
  49.245 -                real.putAll(FileBasedIndex.get(src.getURL()).findCandidatesWithFrequencies(BulkSearch.getDefault().create(parameter, patterns)));
  49.246 -            }
  49.247 -        }, true);
  49.248 -
  49.249 -        assertEquals(golden, real);
  49.250 -    }
  49.251 -
  49.252 -}
  49.253 \ No newline at end of file
    50.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexTestBase.java	Fri Jan 27 13:35:56 2012 +0100
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,103 +0,0 @@
    50.4 -/*
    50.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    50.6 - *
    50.7 - * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    50.8 - *
    50.9 - * The contents of this file are subject to the terms of either the GNU
   50.10 - * General Public License Version 2 only ("GPL") or the Common
   50.11 - * Development and Distribution License("CDDL") (collectively, the
   50.12 - * "License"). You may not use this file except in compliance with the
   50.13 - * License. You can obtain a copy of the License at
   50.14 - * http://www.netbeans.org/cddl-gplv2.html
   50.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   50.16 - * specific language governing permissions and limitations under the
   50.17 - * License.  When distributing the software, include this License Header
   50.18 - * Notice in each file and include the License file at
   50.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   50.20 - * particular file as subject to the "Classpath" exception as provided
   50.21 - * by Sun in the GPL Version 2 section of the License file that
   50.22 - * accompanied this code. If applicable, add the following below the
   50.23 - * License Header, with the fields enclosed by brackets [] replaced by
   50.24 - * your own identifying information:
   50.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   50.26 - *
   50.27 - * If you wish your version of this file to be governed by only the CDDL
   50.28 - * or only the GPL Version 2, indicate your decision by adding
   50.29 - * "[Contributor] elects to include this software in this distribution
   50.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   50.31 - * single choice of license, a recipient has the option to distribute
   50.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   50.33 - * to extend the choice of license to its licensees as provided above.
   50.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   50.35 - * Version 2 license, then the option applies only if the new code is
   50.36 - * made subject to such option by the copyright holder.
   50.37 - *
   50.38 - * Contributor(s):
   50.39 - *
   50.40 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   50.41 - */
   50.42 -
   50.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   50.44 -
   50.45 -import java.util.Collections;
   50.46 -import org.netbeans.api.java.classpath.ClassPath;
   50.47 -import org.netbeans.api.java.classpath.GlobalPathRegistry;
   50.48 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   50.49 -import org.netbeans.core.startup.Main;
   50.50 -import org.netbeans.junit.NbTestCase;
   50.51 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   50.52 -import org.netbeans.modules.parsing.impl.indexing.MimeTypes;
   50.53 -import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
   50.54 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
   50.55 -import org.openide.filesystems.FileObject;
   50.56 -import org.openide.filesystems.FileUtil;
   50.57 -
   50.58 -/**
   50.59 - *
   50.60 - * @author lahvac
   50.61 - */
   50.62 -public abstract class IndexTestBase extends NbTestCase {
   50.63 -
   50.64 -    public IndexTestBase(String name) {
   50.65 -        super(name);
   50.66 -    }
   50.67 -
   50.68 -    @Override
   50.69 -    protected void setUp() throws Exception {
   50.70 -        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
   50.71 -        Main.initializeURLFactory();
   50.72 -        org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
   50.73 -        prepareTest();
   50.74 -        MimeTypes.setAllMimeTypes(Collections.singleton("text/x-java"));
   50.75 -        GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {sourceCP});
   50.76 -        RepositoryUpdater.getDefault().start(true);
   50.77 -        super.setUp();
   50.78 -    }
   50.79 -
   50.80 -    @Override
   50.81 -    protected void tearDown() throws Exception {
   50.82 -        super.tearDown();
   50.83 -        GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, new ClassPath[] {sourceCP});
   50.84 -    }
   50.85 -
   50.86 -    protected FileObject sources;
   50.87 -    protected FileObject src;
   50.88 -    protected FileObject src2;
   50.89 -
   50.90 -    private ClassPath sourceCP;
   50.91 -
   50.92 -    private void prepareTest() throws Exception {
   50.93 -        FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);
   50.94 -
   50.95 -        sources = FileUtil.createFolder(workdir, "sources");
   50.96 -        src = FileUtil.createFolder(sources, "src");
   50.97 -        src2 = FileUtil.createFolder(sources, "src2");
   50.98 -
   50.99 -        FileObject cache = FileUtil.createFolder(workdir, "cache");
  50.100 -
  50.101 -        CacheFolder.setCacheFolder(cache);
  50.102 -
  50.103 -        sourceCP = ClassPathSupport.createClassPath(src, src2);
  50.104 -    }
  50.105 -
  50.106 -}
  50.107 \ No newline at end of file
    51.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/indexing/IndexingTestUtils.java	Fri Jan 27 13:35:56 2012 +0100
    51.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.3 @@ -1,171 +0,0 @@
    51.4 -/*
    51.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    51.6 - *
    51.7 - * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    51.8 - *
    51.9 - * The contents of this file are subject to the terms of either the GNU
   51.10 - * General Public License Version 2 only ("GPL") or the Common
   51.11 - * Development and Distribution License("CDDL") (collectively, the
   51.12 - * "License"). You may not use this file except in compliance with the
   51.13 - * License. You can obtain a copy of the License at
   51.14 - * http://www.netbeans.org/cddl-gplv2.html
   51.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   51.16 - * specific language governing permissions and limitations under the
   51.17 - * License.  When distributing the software, include this License Header
   51.18 - * Notice in each file and include the License file at
   51.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   51.20 - * particular file as subject to the "Classpath" exception as provided
   51.21 - * by Sun in the GPL Version 2 section of the License file that
   51.22 - * accompanied this content. If applicable, add the following below the
   51.23 - * License Header, with the fields enclosed by brackets [] replaced by
   51.24 - * your own identifying information:
   51.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   51.26 - *
   51.27 - * If you wish your version of this file to be governed by only the CDDL
   51.28 - * or only the GPL Version 2, indicate your decision by adding
   51.29 - * "[Contributor] elects to include this software in this distribution
   51.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   51.31 - * single choice of license, a recipient has the option to distribute
   51.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   51.33 - * to extend the choice of license to its licensees as provided above.
   51.34 - * However, if you add GPL Version 2 content and therefore, elected the GPL
   51.35 - * Version 2 license, then the option applies only if the new content is
   51.36 - * made subject to such option by the copyright holder.
   51.37 - *
   51.38 - * Contributor(s):
   51.39 - *
   51.40 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   51.41 - */
   51.42 -
   51.43 -package org.netbeans.modules.jackpot30.impl.indexing;
   51.44 -
   51.45 -import com.sun.source.tree.CompilationUnitTree;
   51.46 -import com.sun.source.util.Trees;
   51.47 -import com.sun.tools.javac.api.JavacTaskImpl;
   51.48 -import com.sun.tools.javac.model.JavacTypes;
   51.49 -import java.io.IOException;
   51.50 -import java.net.URI;
   51.51 -import java.net.URL;
   51.52 -import java.util.Arrays;
   51.53 -import java.util.Collections;
   51.54 -import javax.tools.Diagnostic;
   51.55 -import javax.tools.DiagnosticListener;
   51.56 -import javax.tools.JavaCompiler;
   51.57 -import javax.tools.JavaFileObject;
   51.58 -import javax.tools.SimpleJavaFileObject;
   51.59 -import javax.tools.StandardJavaFileManager;
   51.60 -import javax.tools.StandardLocation;
   51.61 -import javax.tools.ToolProvider;
   51.62 -import org.netbeans.api.editor.mimelookup.MimePath;
   51.63 -import org.netbeans.api.java.source.SourceUtils;
   51.64 -import org.netbeans.api.java.source.TestUtilities;
   51.65 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesCustomIndexerImpl.FactoryImpl;
   51.66 -import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesIndex;
   51.67 -import org.netbeans.modules.jackpot30.impl.indexing.CustomIndexerImpl.CustomIndexerFactoryImpl;
   51.68 -import org.netbeans.modules.jackpot30.impl.indexing.Index.IndexWriter;
   51.69 -import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
   51.70 -import org.openide.filesystems.FileObject;
   51.71 -import org.openide.filesystems.FileUtil;
   51.72 -import org.openide.util.Lookup;
   51.73 -import org.openide.util.lookup.Lookups;
   51.74 -import org.openide.util.lookup.ServiceProvider;
   51.75 -
   51.76 -public class IndexingTestUtils {
   51.77 -    
   51.78 -    public static void writeFiles(FileObject sourceRoot, File... files) throws Exception {
   51.79 -        for (FileObject c : sourceRoot.getChildren()) {
   51.80 -            c.delete();
   51.81 -        }
   51.82 -
   51.83 -        for (File f : files) {
   51.84 -            FileObject fo = FileUtil.createData(sourceRoot, f.filename);
   51.85 -            TestUtilities.copyStringToFile(fo, f.content);
   51.86 -        }
   51.87 -    }
   51.88 -
   51.89 -    public static void writeFilesAndWaitForScan(FileObject sourceRoot, File... files) throws Exception {
   51.90 -        writeFiles(sourceRoot, files);
   51.91 -        SourceUtils.waitScanFinished();
   51.92 -    }
   51.93 -
   51.94 -    public static void indexFiles(URI root, Index idx, File... files) throws Exception {
   51.95 -        IndexWriter iw = idx.openForWriting();
   51.96 -
   51.97 -        try {
   51.98 -            iw.clear();
   51.99 -
  51.100 -            for (File f : files) {
  51.101 -                indexFile(root, iw, null, f);
  51.102 -            }
  51.103 -        } finally {
  51.104 -            iw.close();
  51.105 -        }
  51.106 -    }
  51.107 -
  51.108 -    public static final class File {
  51.109 -        public final String filename;
  51.110 -        public final String content;
  51.111 -        public final boolean index;
  51.112 -
  51.113 -        public File(String filename, String content) {
  51.114 -            this(filename, content, true);
  51.115 -        }
  51.116 -
  51.117 -        public File(String filename, String content, boolean index) {
  51.118 -            this.filename = filename;
  51.119 -            this.content = content;
  51.120 -            this.index = index;
  51.121 -        }
  51.122 -    }
  51.123 -
  51.124 -    @ServiceProvider(service=MimeDataProvider.class)
  51.125 -    public static final class MimeDataProviderImpl implements MimeDataProvider {
  51.126 -
  51.127 -        private static final Lookup INDEXER = Lookups.fixed(new CustomIndexerFactoryImpl(), new FactoryImpl());
  51.128 -
  51.129 -        public Lookup getLookup(MimePath mimePath) {
  51.130 -            if ("text/x-java".equals(mimePath.getPath())) {
  51.131 -                return INDEXER;
  51.132 -            }
  51.133 -            return null;
  51.134 -        }
  51.135 -
  51.136 -    }
  51.137 -
  51.138 -    //copied from StandaloneIndexer:
  51.139 -    private static void indexFile(URI root, IndexWriter w, DuplicatesIndex.IndexWriter dw, File source) throws IOException {
  51.140 -        if (!source.filename.endsWith(".java"))
  51.141 -            return ;
  51.142 -
  51.143 -        final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
  51.144 -        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  51.145 -        assert tool != null;
  51.146 -
  51.147 -        DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
  51.148 -            public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
  51.149 -        };
  51.150 -        StandardJavaFileManager m = tool.getStandardFileManager(devNull, null, null);
  51.151 -
  51.152 -        m.setLocation(StandardLocation.CLASS_PATH, Collections.<java.io.File>emptyList());
  51.153 -        m.setLocation(StandardLocation.SOURCE_PATH, Collections.<java.io.File>emptyList());
  51.154 -
  51.155 -        JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, null, devNull, Arrays.asList("-bootclasspath",  bootPath), null, Collections.singleton(new JFOImpl(source.filename, source.content)));
  51.156 -        CompilationUnitTree cut = ct.parse().iterator().next();
  51.157 -
  51.158 -        ct.analyze(ct.enter(Collections.singletonList(cut)));
  51.159 -
  51.160 -        w.record(root.resolve(source.filename).toURL(), cut, source.index ? new Index.AttributionWrapper(Trees.instance(ct), JavacTypes.instance(ct.getContext())) : null);
  51.161 -    }
  51.162 -
  51.163 -    private static final class JFOImpl extends SimpleJavaFileObject {
  51.164 -        private final String content;
  51.165 -        public JFOImpl(String filename, String content) {
  51.166 -            super(URI.create("myfo:/" + filename), JavaFileObject.Kind.SOURCE);
  51.167 -            this.content = content;
  51.168 -        }
  51.169 -        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
  51.170 -            return content;
  51.171 -        }
  51.172 -    }
  51.173 -
  51.174 -}
  51.175 \ No newline at end of file
    52.1 --- a/borrowedtests/build.xml	Fri Jan 27 13:35:56 2012 +0100
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,13 +0,0 @@
    52.4 -<?xml version="1.0" encoding="UTF-8"?>
    52.5 -<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
    52.6 -<!-- for some information on what you could do (e.g. targets to override). -->
    52.7 -<!-- If you delete this file and reopen the project it will be recreated. -->
    52.8 -<project name="org.netbeans.modules.jackpot30.test.borrowed" default="netbeans" basedir=".">
    52.9 -    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.test.borrowed.</description>
   52.10 -    <import file="nbproject/build-impl.xml"/>
   52.11 -    <import file="../findbugs-import.xml"/>
   52.12 -
   52.13 -    <target name="test" />
   52.14 -    <target name="test-coverage" />
   52.15 -    <target name="coverage-report" />
   52.16 -</project>
    53.1 --- a/borrowedtests/manifest.mf	Fri Jan 27 13:35:56 2012 +0100
    53.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.3 @@ -1,6 +0,0 @@
    53.4 -Manifest-Version: 1.0
    53.5 -AutoUpdate-Show-In-Client: false
    53.6 -OpenIDE-Module: org.netbeans.modules.jackpot30.test.borrowed
    53.7 -OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties
    53.8 -OpenIDE-Module-Specification-Version: 1.16
    53.9 -
    54.1 --- a/borrowedtests/nbproject/build-impl.xml	Fri Jan 27 13:35:56 2012 +0100
    54.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.3 @@ -1,42 +0,0 @@
    54.4 -<?xml version="1.0" encoding="UTF-8"?>
    54.5 -<!--
    54.6 -*** GENERATED FROM project.xml - DO NOT EDIT  ***
    54.7 -***         EDIT ../build.xml INSTEAD         ***
    54.8 --->
    54.9 -<project name="org.netbeans.modules.jackpot30.test.borrowed-impl" basedir="..">
   54.10 -    <fail message="Please build using Ant 1.7.1 or higher.">
   54.11 -        <condition>
   54.12 -            <not>
   54.13 -                <antversion atleast="1.7.1"/>
   54.14 -            </not>
   54.15 -        </condition>
   54.16 -    </fail>
   54.17 -    <property file="nbproject/private/platform-private.properties"/>
   54.18 -    <property file="nbproject/platform.properties"/>
   54.19 -    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
   54.20 -        <attribute name="name"/>
   54.21 -        <attribute name="value"/>
   54.22 -        <sequential>
   54.23 -            <property name="@{name}" value="${@{value}}"/>
   54.24 -        </sequential>
   54.25 -    </macrodef>
   54.26 -    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
   54.27 -        <attribute name="property"/>
   54.28 -        <attribute name="value"/>
   54.29 -        <sequential>
   54.30 -            <property name="@{property}" value="@{value}"/>
   54.31 -        </sequential>
   54.32 -    </macrodef>
   54.33 -    <property file="${user.properties.file}"/>
   54.34 -    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   54.35 -    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   54.36 -    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   54.37 -    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
   54.38 -        <condition>
   54.39 -            <not>
   54.40 -                <contains string="${cluster.path.evaluated}" substring="platform"/>
   54.41 -            </not>
   54.42 -        </condition>
   54.43 -    </fail>
   54.44 -    <import file="${harness.dir}/build.xml"/>
   54.45 -</project>
    55.1 --- a/borrowedtests/nbproject/genfiles.properties	Fri Jan 27 13:35:56 2012 +0100
    55.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.3 @@ -1,8 +0,0 @@
    55.4 -build.xml.data.CRC32=a4393221
    55.5 -build.xml.script.CRC32=3cb17d2d
    55.6 -build.xml.stylesheet.CRC32=79c3b980@1.28.0.7
    55.7 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
    55.8 -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    55.9 -nbproject/build-impl.xml.data.CRC32=c00f7099
   55.10 -nbproject/build-impl.xml.script.CRC32=c6833bcb
   55.11 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
    56.1 --- a/borrowedtests/nbproject/platform.properties	Fri Jan 27 13:35:56 2012 +0100
    56.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.3 @@ -1,21 +0,0 @@
    56.4 -cluster.path=\
    56.5 -    ${nbplatform.active.dir}/identity:\
    56.6 -    ${nbplatform.active.dir}/enterprise:\
    56.7 -    ${nbplatform.active.dir}/webcommon:\
    56.8 -    ${nbplatform.active.dir}/mobility:\
    56.9 -    ${nbplatform.active.dir}/php:\
   56.10 -    ${nbplatform.active.dir}/harness:\
   56.11 -    ${nbplatform.active.dir}/dlight:\
   56.12 -    ${nbplatform.active.dir}/profiler:\
   56.13 -    ${nbplatform.active.dir}/platform:\
   56.14 -    ${nbplatform.active.dir}/websvccommon:\
   56.15 -    ${nbplatform.active.dir}/nb:\
   56.16 -    ${nbplatform.active.dir}/apisupport:\
   56.17 -    ${nbplatform.active.dir}/cnd:\
   56.18 -    ${nbplatform.active.dir}/ergonomics:\
   56.19 -    ${nbplatform.active.dir}/java:\
   56.20 -    ${nbplatform.active.dir}/groovy:\
   56.21 -    ${nbplatform.active.dir}/ruby:\
   56.22 -    ${nbplatform.active.dir}/extra:\
   56.23 -    ${nbplatform.active.dir}/ide
   56.24 -nbplatform.active=default
    57.1 --- a/borrowedtests/nbproject/project.properties	Fri Jan 27 13:35:56 2012 +0100
    57.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.3 @@ -1,2 +0,0 @@
    57.4 -javac.source=1.5
    57.5 -javac.compilerargs=-Xlint -Xlint:-serial
    58.1 --- a/borrowedtests/nbproject/project.xml	Fri Jan 27 13:35:56 2012 +0100
    58.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.3 @@ -1,328 +0,0 @@
    58.4 -<?xml version="1.0" encoding="UTF-8"?>
    58.5 -<project xmlns="http://www.netbeans.org/ns/project/1">
    58.6 -    <type>org.netbeans.modules.apisupport.project</type>
    58.7 -    <configuration>
    58.8 -        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
    58.9 -            <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
   58.10 -            <standalone/>
   58.11 -            <module-dependencies>
   58.12 -                <dependency>
   58.13 -                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
   58.14 -                    <build-prerequisite/>
   58.15 -                    <compile-dependency/>
   58.16 -                    <run-dependency>
   58.17 -                        <release-version>1</release-version>
   58.18 -                        <specification-version>1.13</specification-version>
   58.19 -                    </run-dependency>
   58.20 -                </dependency>
   58.21 -                <dependency>
   58.22 -                    <code-name-base>org.netbeans.api.java</code-name-base>
   58.23 -                    <build-prerequisite/>
   58.24 -                    <compile-dependency/>
   58.25 -                    <run-dependency>
   58.26 -                        <release-version>1</release-version>
   58.27 -                        <specification-version>1.31</specification-version>
   58.28 -                    </run-dependency>
   58.29 -                </dependency>
   58.30 -                <dependency>
   58.31 -                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
   58.32 -                    <build-prerequisite/>
   58.33 -                    <compile-dependency/>
   58.34 -                    <run-dependency>
   58.35 -                        <release-version>1</release-version>
   58.36 -                        <specification-version>1.27</specification-version>
   58.37 -                    </run-dependency>
   58.38 -                </dependency>
   58.39 -                <dependency>
   58.40 -                    <code-name-base>org.netbeans.api.progress</code-name-base>
   58.41 -                    <build-prerequisite/>
   58.42 -                    <compile-dependency/>
   58.43 -                    <run-dependency>
   58.44 -                        <release-version>1</release-version>
   58.45 -                        <specification-version>1.22</specification-version>
   58.46 -                    </run-dependency>
   58.47 -                </dependency>
   58.48 -                <dependency>
   58.49 -                    <code-name-base>org.netbeans.insane</code-name-base>
   58.50 -                    <build-prerequisite/>
   58.51 -                    <compile-dependency/>
   58.52 -                    <run-dependency>
   58.53 -                        <release-version>1</release-version>
   58.54 -                        <implementation-version/>
   58.55 -                    </run-dependency>
   58.56 -                </dependency>
   58.57 -                <dependency>
   58.58 -                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
   58.59 -                    <build-prerequisite/>
   58.60 -                    <compile-dependency/>
   58.61 -                    <run-dependency>
   58.62 -                        <specification-version>7.1.0.2</specification-version>
   58.63 -                    </run-dependency>
   58.64 -                </dependency>
   58.65 -                <dependency>
   58.66 -                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
   58.67 -                    <build-prerequisite/>
   58.68 -                    <compile-dependency/>
   58.69 -                    <run-dependency>
   58.70 -                        <release-version>1</release-version>
   58.71 -                        <implementation-version/>
   58.72 -                    </run-dependency>
   58.73 -                </dependency>
   58.74 -                <dependency>
   58.75 -                    <code-name-base>org.netbeans.libs.junit4</code-name-base>
   58.76 -                    <build-prerequisite/>
   58.77 -                    <compile-dependency/>
   58.78 -                    <run-dependency>
   58.79 -                        <specification-version>1.12</specification-version>
   58.80 -                    </run-dependency>
   58.81 -                </dependency>
   58.82 -                <dependency>
   58.83 -                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
   58.84 -                    <build-prerequisite/>
   58.85 -                    <compile-dependency/>
   58.86 -                    <run-dependency>
   58.87 -                        <release-version>1-3</release-version>
   58.88 -                        <specification-version>2.13</specification-version>
   58.89 -                    </run-dependency>
   58.90 -                </dependency>
   58.91 -                <dependency>
   58.92 -                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
   58.93 -                    <build-prerequisite/>
   58.94 -                    <compile-dependency/>
   58.95 -                    <run-dependency>
   58.96 -                        <release-version>1</release-version>
   58.97 -                        <specification-version>1.35.0.5</specification-version>
   58.98 -                    </run-dependency>
   58.99 -                </dependency>
  58.100 -                <dependency>
  58.101 -                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
  58.102 -                    <build-prerequisite/>
  58.103 -                    <compile-dependency/>
  58.104 -                    <run-dependency>
  58.105 -                        <release-version>1</release-version>
  58.106 -                        <specification-version>1.20</specification-version>
  58.107 -                    </run-dependency>
  58.108 -                </dependency>
  58.109 -                <dependency>
  58.110 -                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
  58.111 -                    <build-prerequisite/>
  58.112 -                    <compile-dependency/>
  58.113 -                    <run-dependency>
  58.114 -                        <release-version>1</release-version>
  58.115 -                        <specification-version>1.39</specification-version>
  58.116 -                    </run-dependency>
  58.117 -                </dependency>
  58.118 -                <dependency>
  58.119 -                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
  58.120 -                    <build-prerequisite/>
  58.121 -                    <compile-dependency/>
  58.122 -                    <run-dependency>
  58.123 -                        <release-version>1</release-version>
  58.124 -                        <implementation-version/>
  58.125 -                    </run-dependency>
  58.126 -                </dependency>
  58.127 -                <dependency>
  58.128 -                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
  58.129 -                    <build-prerequisite/>
  58.130 -                    <compile-dependency/>
  58.131 -                    <run-dependency>
  58.132 -                        <release-version>1</release-version>
  58.133 -                        <specification-version>1.12</specification-version>
  58.134 -                    </run-dependency>
  58.135 -                </dependency>
  58.136 -                <dependency>
  58.137 -                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
  58.138 -                    <build-prerequisite/>
  58.139 -                    <compile-dependency/>
  58.140 -                    <run-dependency>
  58.141 -                        <implementation-version/>
  58.142 -                    </run-dependency>
  58.143 -                </dependency>
  58.144 -                <dependency>
  58.145 -                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
  58.146 -                    <build-prerequisite/>
  58.147 -                    <compile-dependency/>
  58.148 -                    <run-dependency>
  58.149 -                        <release-version>2</release-version>
  58.150 -                        <specification-version>1.37.0.1</specification-version>
  58.151 -                    </run-dependency>
  58.152 -                </dependency>
  58.153 -                <dependency>
  58.154 -                    <code-name-base>org.netbeans.modules.masterfs</code-name-base>
  58.155 -                    <build-prerequisite/>
  58.156 -                    <compile-dependency/>
  58.157 -                    <run-dependency>
  58.158 -                        <release-version>2</release-version>
  58.159 -                        <implementation-version/>
  58.160 -                    </run-dependency>
  58.161 -                </dependency>
  58.162 -                <dependency>
  58.163 -                    <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
  58.164 -                    <build-prerequisite/>
  58.165 -                    <compile-dependency/>
  58.166 -                    <run-dependency>
  58.167 -                        <release-version>1</release-version>
  58.168 -                        <specification-version>1.65</specification-version>
  58.169 -                    </run-dependency>
  58.170 -                </dependency>
  58.171 -                <dependency>
  58.172 -                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
  58.173 -                    <build-prerequisite/>
  58.174 -                    <compile-dependency/>
  58.175 -                    <run-dependency>
  58.176 -                        <release-version>1</release-version>
  58.177 -                        <implementation-version/>
  58.178 -                    </run-dependency>
  58.179 -                </dependency>
  58.180 -                <dependency>
  58.181 -                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
  58.182 -                    <build-prerequisite/>
  58.183 -                    <compile-dependency/>
  58.184 -                    <run-dependency>
  58.185 -                        <release-version>1</release-version>
  58.186 -                        <specification-version>1.34</specification-version>
  58.187 -                    </run-dependency>
  58.188 -                </dependency>
  58.189 -                <dependency>
  58.190 -                    <code-name-base>org.netbeans.modules.projectui</code-name-base>
  58.191 -                    <build-prerequisite/>
  58.192 -                    <compile-dependency/>
  58.193 -                    <run-dependency>
  58.194 -                        <implementation-version/>
  58.195 -                    </run-dependency>
  58.196 -                </dependency>
  58.197 -                <dependency>
  58.198 -                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
  58.199 -                    <build-prerequisite/>
  58.200 -                    <compile-dependency/>
  58.201 -                    <run-dependency>
  58.202 -                        <release-version>1</release-version>
  58.203 -                        <specification-version>1.49.0.8</specification-version>
  58.204 -                    </run-dependency>
  58.205 -                </dependency>
  58.206 -                <dependency>
  58.207 -                    <code-name-base>org.netbeans.modules.queries</code-name-base>
  58.208 -                    <build-prerequisite/>
  58.209 -                    <compile-dependency/>
  58.210 -                    <run-dependency>
  58.211 -                        <release-version>1</release-version>
  58.212 -                        <specification-version>1.21</specification-version>
  58.213 -                    </run-dependency>
  58.214 -                </dependency>
  58.215 -                <dependency>
  58.216 -                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
  58.217 -                    <build-prerequisite/>
  58.218 -                    <compile-dependency/>
  58.219 -                    <run-dependency>
  58.220 -                        <release-version>0-1</release-version>
  58.221 -                        <specification-version>1.16.0.7.5</specification-version>
  58.222 -                    </run-dependency>
  58.223 -                </dependency>
  58.224 -                <dependency>
  58.225 -                    <code-name-base>org.openide.actions</code-name-base>
  58.226 -                    <build-prerequisite/>
  58.227 -                    <compile-dependency/>
  58.228 -                    <run-dependency>
  58.229 -                        <specification-version>6.19</specification-version>
  58.230 -                    </run-dependency>
  58.231 -                </dependency>
  58.232 -                <dependency>
  58.233 -                    <code-name-base>org.openide.awt</code-name-base>
  58.234 -                    <build-prerequisite/>
  58.235 -                    <compile-dependency/>
  58.236 -                    <run-dependency>
  58.237 -                        <specification-version>7.29</specification-version>
  58.238 -                    </run-dependency>
  58.239 -                </dependency>
  58.240 -                <dependency>
  58.241 -                    <code-name-base>org.openide.dialogs</code-name-base>
  58.242 -                    <build-prerequisite/>
  58.243 -                    <compile-dependency/>
  58.244 -                    <run-dependency>
  58.245 -                        <specification-version>7.17</specification-version>
  58.246 -                    </run-dependency>
  58.247 -                </dependency>
  58.248 -                <dependency>
  58.249 -                    <code-name-base>org.openide.filesystems</code-name-base>
  58.250 -                    <build-prerequisite/>
  58.251 -                    <compile-dependency/>
  58.252 -                    <run-dependency>
  58.253 -                        <specification-version>7.43</specification-version>
  58.254 -                    </run-dependency>
  58.255 -                </dependency>
  58.256 -                <dependency>
  58.257 -                    <code-name-base>org.openide.loaders</code-name-base>
  58.258 -                    <build-prerequisite/>
  58.259 -                    <compile-dependency/>
  58.260 -                    <run-dependency>
  58.261 -                        <specification-version>7.19</specification-version>
  58.262 -                    </run-dependency>
  58.263 -                </dependency>
  58.264 -                <dependency>
  58.265 -                    <code-name-base>org.openide.nodes</code-name-base>
  58.266 -                    <build-prerequisite/>
  58.267 -                    <compile-dependency/>
  58.268 -                    <run-dependency>
  58.269 -                        <specification-version>7.19</specification-version>
  58.270 -                    </run-dependency>
  58.271 -                </dependency>
  58.272 -                <dependency>
  58.273 -                    <code-name-base>org.openide.text</code-name-base>
  58.274 -                    <build-prerequisite/>
  58.275 -                    <compile-dependency/>
  58.276 -                    <run-dependency>
  58.277 -                        <specification-version>6.34</specification-version>
  58.278 -                    </run-dependency>
  58.279 -                </dependency>
  58.280 -                <dependency>
  58.281 -                    <code-name-base>org.openide.util</code-name-base>
  58.282 -                    <build-prerequisite/>
  58.283 -                    <compile-dependency/>
  58.284 -                    <run-dependency>
  58.285 -                        <specification-version>8.9</specification-version>
  58.286 -                    </run-dependency>
  58.287 -                </dependency>
  58.288 -                <dependency>
  58.289 -                    <code-name-base>org.openide.util.lookup</code-name-base>
  58.290 -                    <build-prerequisite/>
  58.291 -                    <compile-dependency/>
  58.292 -                    <run-dependency>
  58.293 -                        <specification-version>8.5</specification-version>
  58.294 -                    </run-dependency>
  58.295 -                </dependency>
  58.296 -                <dependency>
  58.297 -                    <code-name-base>org.openide.windows</code-name-base>
  58.298 -                    <build-prerequisite/>
  58.299 -                    <compile-dependency/>
  58.300 -                    <run-dependency>
  58.301 -                        <specification-version>6.37</specification-version>
  58.302 -                    </run-dependency>
  58.303 -                </dependency>
  58.304 -                <dependency>
  58.305 -                    <code-name-base>org.openidex.util</code-name-base>
  58.306 -                    <build-prerequisite/>
  58.307 -                    <compile-dependency/>
  58.308 -                    <run-dependency>
  58.309 -                        <release-version>3</release-version>
  58.310 -                        <specification-version>3.27</specification-version>
  58.311 -                    </run-dependency>
  58.312 -                </dependency>
  58.313 -            </module-dependencies>
  58.314 -            <test-dependencies>
  58.315 -                <test-type>
  58.316 -                    <name>unit</name>
  58.317 -                    <test-dependency>
  58.318 -                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
  58.319 -                        <compile-dependency/>
  58.320 -                    </test-dependency>
  58.321 -                    <test-dependency>
  58.322 -                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
  58.323 -                        <recursive/>
  58.324 -                        <compile-dependency/>
  58.325 -                    </test-dependency>
  58.326 -                </test-type>
  58.327 -            </test-dependencies>
  58.328 -            <public-packages/>
  58.329 -        </data>
  58.330 -    </configuration>
  58.331 -</project>
    59.1 --- a/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java	Fri Jan 27 13:35:56 2012 +0100
    59.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.3 @@ -1,441 +0,0 @@
    59.4 -/*
    59.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    59.6 - *
    59.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
    59.8 - *
    59.9 - * The contents of this file are subject to the terms of either the GNU
   59.10 - * General Public License Version 2 only ("GPL") or the Common
   59.11 - * Development and Distribution License("CDDL") (collectively, the
   59.12 - * "License"). You may not use this file except in compliance with the
   59.13 - * License. You can obtain a copy of the License at
   59.14 - * http://www.netbeans.org/cddl-gplv2.html
   59.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   59.16 - * specific language governing permissions and limitations under the
   59.17 - * License.  When distributing the software, include this License Header
   59.18 - * Notice in each file and include the License file at
   59.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   59.20 - * particular file as subject to the "Classpath" exception as provided
   59.21 - * by Sun in the GPL Version 2 section of the License file that
   59.22 - * accompanied this code. If applicable, add the following below the
   59.23 - * License Header, with the fields enclosed by brackets [] replaced by
   59.24 - * your own identifying information:
   59.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   59.26 - *
   59.27 - * Contributor(s):
   59.28 - *
   59.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   59.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
   59.31 - * Microsystems, Inc. All Rights Reserved.
   59.32 - *
   59.33 - * If you wish your version of this file to be governed by only the CDDL
   59.34 - * or only the GPL Version 2, indicate your decision by adding
   59.35 - * "[Contributor] elects to include this software in this distribution
   59.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   59.37 - * single choice of license, a recipient has the option to distribute
   59.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   59.39 - * to extend the choice of license to its licensees as provided above.
   59.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   59.41 - * Version 2 license, then the option applies only if the new code is
   59.42 - * made subject to such option by the copyright holder.
   59.43 - */
   59.44 -package org.netbeans.api.java.source;
   59.45 -
   59.46 -import com.sun.source.util.JavacTask;
   59.47 -import java.beans.PropertyVetoException;
   59.48 -import java.io.File;
   59.49 -import java.io.IOException;
   59.50 -import java.net.URL;
   59.51 -import java.util.ArrayList;
   59.52 -import java.util.Enumeration;
   59.53 -import java.util.HashSet;
   59.54 -import java.util.LinkedList;
   59.55 -import java.util.List;
   59.56 -import java.util.Map;
   59.57 -import java.util.Set;
   59.58 -import java.util.WeakHashMap;
   59.59 -import java.util.logging.Logger;
   59.60 -import java.util.logging.Level;
   59.61 -import java.util.regex.Pattern;
   59.62 -import javax.swing.event.ChangeListener;
   59.63 -import junit.framework.Assert;
   59.64 -import org.netbeans.api.editor.mimelookup.MimePath;
   59.65 -import org.netbeans.api.java.classpath.ClassPath;
   59.66 -import org.netbeans.api.java.queries.SourceForBinaryQuery;
   59.67 -import org.netbeans.api.java.source.JavaSource.Phase;
   59.68 -import org.netbeans.junit.NbTestCase;
   59.69 -import org.netbeans.modules.java.JavaDataLoader;
   59.70 -import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
   59.71 -import org.netbeans.modules.java.source.parsing.JavacParser;
   59.72 -import org.netbeans.modules.java.source.parsing.JavacParserFactory;
   59.73 -import org.netbeans.modules.java.source.usages.IndexUtil;
   59.74 -import org.netbeans.modules.parsing.api.indexing.IndexingManager;
   59.75 -import org.netbeans.modules.parsing.impl.indexing.MimeTypes;
   59.76 -import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
   59.77 -import org.netbeans.spi.java.classpath.ClassPathProvider;
   59.78 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
   59.79 -import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
   59.80 -import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
   59.81 -import org.openide.filesystems.FileObject;
   59.82 -import org.openide.filesystems.FileStateInvalidException;
   59.83 -import org.openide.filesystems.FileSystem;
   59.84 -import org.openide.filesystems.FileUtil;
   59.85 -import org.openide.filesystems.LocalFileSystem;
   59.86 -import org.openide.filesystems.MIMEResolver;
   59.87 -import org.openide.filesystems.MultiFileSystem;
   59.88 -import org.openide.filesystems.Repository;
   59.89 -import org.openide.filesystems.URLMapper;
   59.90 -import org.openide.filesystems.XMLFileSystem;
   59.91 -import org.openide.util.Lookup;
   59.92 -import org.openide.util.lookup.Lookups;
   59.93 -import org.openide.util.lookup.ProxyLookup;
   59.94 -import org.openide.util.lookup.ServiceProvider;
   59.95 -import org.xml.sax.SAXException;
   59.96 -
   59.97 -/**
   59.98 - *
   59.99 - * @author Jan Lahoda
  59.100 - */
  59.101 -public final class SourceUtilsTestUtil extends ProxyLookup {
  59.102 -    
  59.103 -    private static SourceUtilsTestUtil DEFAULT_LOOKUP = null;
  59.104 -    
  59.105 -    public SourceUtilsTestUtil() {
  59.106 -//        Assert.assertNull(DEFAULT_LOOKUP);
  59.107 -        DEFAULT_LOOKUP = this;
  59.108 -    }
  59.109 -    
  59.110 -    /**
  59.111 -     * Set the global default lookup with some fixed instances including META-INF/services/*.
  59.112 -     */
  59.113 -    /**
  59.114 -     * Set the global default lookup with some fixed instances including META-INF/services/*.
  59.115 -     */
  59.116 -    public static void setLookup(Object[] instances, ClassLoader cl) {
  59.117 -        DEFAULT_LOOKUP.setLookups(new Lookup[] {
  59.118 -            Lookups.fixed(instances),
  59.119 -            Lookups.metaInfServices(cl),
  59.120 -            Lookups.singleton(cl),
  59.121 -        });
  59.122 -    }
  59.123 -    
  59.124 -    private static Object[] extraLookupContent = null;
  59.125 -    
  59.126 -    public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
  59.127 -        List<URL> layers = new LinkedList<URL>();
  59.128 -        
  59.129 -        for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
  59.130 -            boolean found = false;
  59.131 -
  59.132 -            for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(additionalLayers[cntr]); en.hasMoreElements(); ) {
  59.133 -                found = true;
  59.134 -                layers.add(en.nextElement());
  59.135 -            }
  59.136 -
  59.137 -            Assert.assertTrue(additionalLayers[cntr], found);
  59.138 -        }
  59.139 -        
  59.140 -        XMLFileSystem xmlFS = new XMLFileSystem();
  59.141 -        xmlFS.setXmlUrls(layers.toArray(new URL[0]));
  59.142 -        
  59.143 -        FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});
  59.144 -        
  59.145 -        Repository repository = new Repository(system);
  59.146 -        extraLookupContent = new Object[additionalLookupContent.length + 1];
  59.147 -        
  59.148 -        System.arraycopy(additionalLookupContent, 0, extraLookupContent, 1, additionalLookupContent.length);
  59.149 -        
  59.150 -        extraLookupContent[0] = repository;
  59.151 -        
  59.152 -        SourceUtilsTestUtil.setLookup(extraLookupContent, SourceUtilsTestUtil.class.getClassLoader());
  59.153 -        
  59.154 -        SourceUtilsTestUtil2.disableLocks();
  59.155 -
  59.156 -        Set<String> mimeTypes = MimeTypes.getAllMimeTypes();
  59.157 -
  59.158 -        if (mimeTypes == null) {
  59.159 -            mimeTypes = new HashSet<String>();
  59.160 -        } else {
  59.161 -            mimeTypes = new HashSet<String>(mimeTypes);
  59.162 -        }
  59.163 -
  59.164 -        mimeTypes.add("text/x-java");
  59.165 -
  59.166 -        MimeTypes.setAllMimeTypes(mimeTypes);
  59.167 -        org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
  59.168 -    }
  59.169 -    
  59.170 -    static {
  59.171 -        SourceUtilsTestUtil.class.getClassLoader().setDefaultAssertionStatus(true);
  59.172 -        System.setProperty("org.openide.util.Lookup", SourceUtilsTestUtil.class.getName());
  59.173 -        Assert.assertEquals(SourceUtilsTestUtil.class, Lookup.getDefault().getClass());
  59.174 -    }
  59.175 -    
  59.176 -    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache) throws Exception {
  59.177 -        prepareTest(sourceRoot, buildRoot, cache, new FileObject[0]);
  59.178 -    }
  59.179 -    
  59.180 -    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache, FileObject[] classPathElements) throws Exception {
  59.181 -        if (extraLookupContent == null)
  59.182 -            prepareTest(new String[0], new Object[0]);
  59.183 -        
  59.184 -        Object[] lookupContent = new Object[extraLookupContent.length + 4];
  59.185 -        
  59.186 -        System.arraycopy(extraLookupContent, 0, lookupContent, 4, extraLookupContent.length);
  59.187 -        
  59.188 -        lookupContent[0] = new TestProxyClassPathProvider(sourceRoot, buildRoot, classPathElements);
  59.189 -        lookupContent[1] = new TestSourceForBinaryQuery(sourceRoot, buildRoot);
  59.190 -        lookupContent[2] = new TestSourceLevelQueryImplementation();
  59.191 -        lookupContent[3] = JavaDataLoader.findObject(JavaDataLoader.class, true);
  59.192 -        
  59.193 -        setLookup(lookupContent, SourceUtilsTestUtil.class.getClassLoader());
  59.194 -
  59.195 -        IndexUtil.setCacheFolder(FileUtil.toFile(cache));
  59.196 -    }
  59.197 -
  59.198 -    private static Map<FileObject,  String> file2SourceLevel = new WeakHashMap<FileObject, String>();
  59.199 -    
  59.200 -    public static void setSourceLevel(FileObject file, String level) {
  59.201 -        file2SourceLevel.put(file, level);
  59.202 -    }
  59.203 -
  59.204 -    /**This method assures that all java classes under sourceRoot are compiled,
  59.205 -     * and the caches are created for them.
  59.206 -     */
  59.207 -    public static void compileRecursively(FileObject sourceRoot) throws Exception {
  59.208 -        IndexingManager.getDefault().refreshIndexAndWait(sourceRoot.getURL(), null);
  59.209 -    }
  59.210 -
  59.211 -    private static List<URL> bootClassPath;
  59.212 -
  59.213 -    private static Logger log = Logger.getLogger(SourceUtilsTestUtil.class.getName());
  59.214 -    
  59.215 -    public static synchronized List<URL> getBootClassPath() {
  59.216 -        if (bootClassPath == null) {
  59.217 -            try {
  59.218 -                String cp = System.getProperty("sun.boot.class.path");
  59.219 -                List<URL> urls = new ArrayList<URL>();
  59.220 -                String[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
  59.221 -                
  59.222 -                for (String path : paths) {
  59.223 -                    File f = new File(path);
  59.224 -                    
  59.225 -                    if (!f.canRead())
  59.226 -                        continue;
  59.227 -                    
  59.228 -                    FileObject fo = FileUtil.toFileObject(f);
  59.229 -                    
  59.230 -                    if (FileUtil.isArchiveFile(fo)) {
  59.231 -                        fo = FileUtil.getArchiveRoot(fo);
  59.232 -                    }
  59.233 -                    
  59.234 -                    if (fo != null) {
  59.235 -                        urls.add(fo.getURL());
  59.236 -                    }
  59.237 -                }
  59.238 -                
  59.239 -                bootClassPath = urls;
  59.240 -            } catch (FileStateInvalidException e) {
  59.241 -                if (log.isLoggable(Level.SEVERE))
  59.242 -                    log.log(Level.SEVERE, e.getMessage(), e);
  59.243 -            }
  59.244 -        }
  59.245 -
  59.246 -        return bootClassPath;
  59.247 -    }
  59.248 -
  59.249 -    private static class TestSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
  59.250 -        
  59.251 -        private final FileObject sourceRoot;
  59.252 -        private final FileObject buildRoot;
  59.253 -        
  59.254 -        public TestSourceForBinaryQuery(FileObject sourceRoot, FileObject buildRoot) {
  59.255 -            this.sourceRoot = sourceRoot;
  59.256 -            this.buildRoot = buildRoot;
  59.257 -        }
  59.258 -        
  59.259 -        public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
  59.260 -            FileObject f = URLMapper.findFileObject(binaryRoot);
  59.261 -
  59.262 -            if (buildRoot.equals(f)) {
  59.263 -                return new SourceForBinaryQuery.Result() {
  59.264 -                    public FileObject[] getRoots() {
  59.265 -                        return new FileObject[] {
  59.266 -                            sourceRoot,
  59.267 -                        };
  59.268 -                    }
  59.269 -
  59.270 -                    public void addChangeListener(ChangeListener l) {
  59.271 -                    }
  59.272 -
  59.273 -                    public void removeChangeListener(ChangeListener l) {
  59.274 -                    }
  59.275 -                };
  59.276 -            }
  59.277 -
  59.278 -            return null;
  59.279 -        }
  59.280 -        
  59.281 -    }
  59.282 -    
  59.283 -    private static class TestProxyClassPathProvider implements ClassPathProvider {
  59.284 -        
  59.285 -        private FileObject sourceRoot;
  59.286 -        private FileObject buildRoot;
  59.287 -        private FileObject[] classPathElements;
  59.288 -        
  59.289 -        public TestProxyClassPathProvider(FileObject sourceRoot, FileObject buildRoot, FileObject[] classPathElements) {
  59.290 -            this.sourceRoot = sourceRoot;
  59.291 -            this.buildRoot = buildRoot;
  59.292 -            this.classPathElements = classPathElements;
  59.293 -        }
  59.294 -        
  59.295 -        public ClassPath findClassPath(FileObject file, String type) {
  59.296 -            try {
  59.297 -            if (ClassPath.BOOT == type) {
  59.298 -                return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
  59.299 -            }
  59.300 -            
  59.301 -            if (ClassPath.SOURCE == type) {
  59.302 -                return ClassPathSupport.createClassPath(new FileObject[] {
  59.303 -                    sourceRoot
  59.304 -                });
  59.305 -            }
  59.306 -            
  59.307 -            if (ClassPath.COMPILE == type) {
  59.308 -                return ClassPathSupport.createClassPath(classPathElements);
  59.309 -            }
  59.310 -            
  59.311 -            if (ClassPath.EXECUTE == type) {
  59.312 -                return ClassPathSupport.createClassPath(new FileObject[] {
  59.313 -                    buildRoot
  59.314 -                });
  59.315 -            }
  59.316 -            } catch (Exception e) {
  59.317 -                e.printStackTrace();
  59.318 -            }
  59.319 -            return null;
  59.320 -        }
  59.321 -        
  59.322 -    }
  59.323 -
  59.324 -    public static class TestSourceLevelQueryImplementation implements SourceLevelQueryImplementation {
  59.325 -        
  59.326 -        public String getSourceLevel(FileObject javaFile) {
  59.327 -            String level = file2SourceLevel.get(javaFile);
  59.328 -            
  59.329 -            if (level == null) {
  59.330 -                if (javaFile.isFolder()) {
  59.331 -                    for (FileObject data : file2SourceLevel.keySet()) {
  59.332 -                        if (FileUtil.isParentOf(javaFile, data)) {
  59.333 -                            return file2SourceLevel.get(data);
  59.334 -                        }
  59.335 -                    }
  59.336 -                }
  59.337 -                return "1.5";
  59.338 -            } else
  59.339 -                return level;
  59.340 -        }
  59.341 -        
  59.342 -    }
  59.343 -
  59.344 -    /**Copied from org.netbeans.api.project.
  59.345 -     * Create a scratch directory for tests.
  59.346 -     * Will be in /tmp or whatever, and will be empty.
  59.347 -     * If you just need a java.io.File use clearWorkDir + getWorkDir.
  59.348 -     */
  59.349 -    public static FileObject makeScratchDir(NbTestCase test) throws IOException {
  59.350 -        test.clearWorkDir();
  59.351 -        File root = test.getWorkDir();
  59.352 -        assert root.isDirectory() && root.list().length == 0;
  59.353 -        FileObject fo = FileUtil.toFileObject(root);
  59.354 -        if (fo != null) {
  59.355 -            // Presumably using masterfs.
  59.356 -            return fo;
  59.357 -        } else {
  59.358 -            // For the benefit of those not using masterfs.
  59.359 -            LocalFileSystem lfs = new LocalFileSystem();
  59.360 -            try {
  59.361 -                lfs.setRootDirectory(root);
  59.362 -            } catch (PropertyVetoException e) {
  59.363 -                assert false : e;
  59.364 -            }
  59.365 -            Repository.getDefault().addFileSystem(lfs);
  59.366 -            return lfs.getRoot();
  59.367 -        }
  59.368 -    }
  59.369 -    
  59.370 -    public static JavacTask getJavacTaskFor(CompilationInfo info) {
  59.371 -        return info.impl.getJavacTask();
  59.372 -    }
  59.373 -    
  59.374 -    /** Blocking call for CompilationInfo after given phase is reached.
  59.375 -     *  @param phase to be reached
  59.376 -     *  @return CompilationInfo or null
  59.377 -     *  XXX: REMOVE ME!!!!!!!
  59.378 -     */
  59.379 -    public static CompilationInfo getCompilationInfo(JavaSource js, Phase phase ) throws IOException {        
  59.380 -        if (phase == null || phase == Phase.MODIFIED) { 
  59.381 -            throw new IllegalArgumentException (String.format("The %s is not a legal value of phase",phase));   //NOI18N
  59.382 -        }
  59.383 -        final DeadlockTask bt = new DeadlockTask(phase);
  59.384 -        js.runUserActionTask(bt,true);
  59.385 -        return bt.info;
  59.386 -    }
  59.387 -    
  59.388 -    
  59.389 -    private static class DeadlockTask implements Task<CompilationController> {
  59.390 -        
  59.391 -        private final Phase phase;
  59.392 -        private CompilationInfo info;
  59.393 -        
  59.394 -        public DeadlockTask(Phase phase) {
  59.395 -            assert phase != null;
  59.396 -            this.phase = phase;
  59.397 -        }
  59.398 -        
  59.399 -        public void run( CompilationController info ) {
  59.400 -            try {
  59.401 -                info.toPhase(this.phase);
  59.402 -                this.info = info;
  59.403 -            } catch (IOException ioe) {
  59.404 -                if (log.isLoggable(Level.SEVERE))
  59.405 -                    log.log(Level.SEVERE, ioe.getMessage(), ioe);
  59.406 -            }
  59.407 -        }                
  59.408 -        
  59.409 -    }
  59.410 -
  59.411 -    @ServiceProvider(service=MimeDataProvider.class)
  59.412 -    public static final class JavacParserProvider implements MimeDataProvider {
  59.413 -
  59.414 -        private Lookup javaLookup = Lookups.fixed(new JavacParserFactory(), new JavaCustomIndexer.Factory());
  59.415 -
  59.416 -        public Lookup getLookup(MimePath mimePath) {
  59.417 -            if (mimePath.getPath().endsWith(JavacParser.MIME_TYPE)) {
  59.418 -                return javaLookup;
  59.419 -            }
  59.420 -
  59.421 -            return Lookup.EMPTY;
  59.422 -        }
  59.423 -        
  59.424 -    }
  59.425 -
  59.426 -    @ServiceProvider(service=MIMEResolver.class)
  59.427 -    public static final class JavaMimeResolver extends MIMEResolver {
  59.428 -
  59.429 -        public JavaMimeResolver() {
  59.430 -            super(JavacParser.MIME_TYPE);
  59.431 -        }
  59.432 -
  59.433 -        @Override
  59.434 -        public String findMIMEType(FileObject fo) {
  59.435 -            if ("java".equals(fo.getExt())) {
  59.436 -                return JavacParser.MIME_TYPE;
  59.437 -            }
  59.438 -
  59.439 -            return null;
  59.440 -        }
  59.441 -
  59.442 -    }
  59.443 -    
  59.444 -}
    60.1 --- a/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil2.java	Fri Jan 27 13:35:56 2012 +0100
    60.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.3 @@ -1,80 +0,0 @@
    60.4 -/*
    60.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    60.6 - *
    60.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
    60.8 - *
    60.9 - * The contents of this file are subject to the terms of either the GNU
   60.10 - * General Public License Version 2 only ("GPL") or the Common
   60.11 - * Development and Distribution License("CDDL") (collectively, the
   60.12 - * "License"). You may not use this file except in compliance with the
   60.13 - * License. You can obtain a copy of the License at
   60.14 - * http://www.netbeans.org/cddl-gplv2.html
   60.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   60.16 - * specific language governing permissions and limitations under the
   60.17 - * License.  When distributing the software, include this License Header
   60.18 - * Notice in each file and include the License file at
   60.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   60.20 - * particular file as subject to the "Classpath" exception as provided
   60.21 - * by Sun in the GPL Version 2 section of the License file that
   60.22 - * accompanied this code. If applicable, add the following below the
   60.23 - * License Header, with the fields enclosed by brackets [] replaced by
   60.24 - * your own identifying information:
   60.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   60.26 - *
   60.27 - * Contributor(s):
   60.28 - *
   60.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   60.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
   60.31 - * Microsystems, Inc. All Rights Reserved.
   60.32 - *
   60.33 - * If you wish your version of this file to be governed by only the CDDL
   60.34 - * or only the GPL Version 2, indicate your decision by adding
   60.35 - * "[Contributor] elects to include this software in this distribution
   60.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   60.37 - * single choice of license, a recipient has the option to distribute
   60.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   60.39 - * to extend the choice of license to its licensees as provided above.
   60.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   60.41 - * Version 2 license, then the option applies only if the new code is
   60.42 - * made subject to such option by the copyright holder.
   60.43 - */
   60.44 -package org.netbeans.api.java.source;
   60.45 -
   60.46 -import com.sun.source.tree.Tree;
   60.47 -import org.apache.lucene.store.FSDirectory;
   60.48 -import org.netbeans.modules.java.source.transform.Transformer;
   60.49 -
   60.50 -/**
   60.51 - *
   60.52 - * @author Jan Lahoda
   60.53 - */
   60.54 -public final class SourceUtilsTestUtil2 {
   60.55 -
   60.56 -    private SourceUtilsTestUtil2() {
   60.57 -    }
   60.58 -
   60.59 -    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t) {
   60.60 -//        if (afterCommit)
   60.61 -//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
   60.62 -        t.init();
   60.63 -        t.attach(wc.impl.getJavacTask().getContext(), wc);
   60.64 -        t.apply(wc.getCompilationUnit());
   60.65 -        t.release();
   60.66 -        t.destroy();
   60.67 -    }
   60.68 -    
   60.69 -    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t, Tree tree) {
   60.70 -//        if (afterCommit)
   60.71 -//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
   60.72 -        t.init();
   60.73 -        t.attach(wc.impl.getJavacTask().getContext(), wc);
   60.74 -        t.apply(tree);
   60.75 -        t.release();
   60.76 -        t.destroy();
   60.77 -    }
   60.78 -    
   60.79 -    public static void disableLocks() {
   60.80 -//        FSDirectory.setDisableLocks(true);
   60.81 -    }
   60.82 -    
   60.83 -}
    61.1 --- a/borrowedtests/src/org/netbeans/api/java/source/TestUtilities.java	Fri Jan 27 13:35:56 2012 +0100
    61.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.3 @@ -1,263 +0,0 @@
    61.4 -/*
    61.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    61.6 - *
    61.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
    61.8 - *
    61.9 - * The contents of this file are subject to the terms of either the GNU
   61.10 - * General Public License Version 2 only ("GPL") or the Common
   61.11 - * Development and Distribution License("CDDL") (collectively, the
   61.12 - * "License"). You may not use this file except in compliance with the
   61.13 - * License. You can obtain a copy of the License at
   61.14 - * http://www.netbeans.org/cddl-gplv2.html
   61.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   61.16 - * specific language governing permissions and limitations under the
   61.17 - * License.  When distributing the software, include this License Header
   61.18 - * Notice in each file and include the License file at
   61.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   61.20 - * particular file as subject to the "Classpath" exception as provided
   61.21 - * by Sun in the GPL Version 2 section of the License file that
   61.22 - * accompanied this code. If applicable, add the following below the
   61.23 - * License Header, with the fields enclosed by brackets [] replaced by
   61.24 - * your own identifying information:
   61.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   61.26 - *
   61.27 - * Contributor(s):
   61.28 - *
   61.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   61.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
   61.31 - * Microsystems, Inc. All Rights Reserved.
   61.32 - *
   61.33 - * If you wish your version of this file to be governed by only the CDDL
   61.34 - * or only the GPL Version 2, indicate your decision by adding
   61.35 - * "[Contributor] elects to include this software in this distribution
   61.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   61.37 - * single choice of license, a recipient has the option to distribute
   61.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   61.39 - * to extend the choice of license to its licensees as provided above.
   61.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   61.41 - * Version 2 license, then the option applies only if the new code is
   61.42 - * made subject to such option by the copyright holder.
   61.43 - */
   61.44 -
   61.45 -package org.netbeans.api.java.source;
   61.46 -
   61.47 -import java.io.ByteArrayInputStream;
   61.48 -import java.io.EOFException;
   61.49 -import java.io.File;
   61.50 -import java.io.FileInputStream;
   61.51 -import java.io.FileOutputStream;
   61.52 -import java.io.IOException;
   61.53 -import java.io.InputStream;
   61.54 -import java.io.OutputStream;
   61.55 -import java.net.URL;
   61.56 -import java.util.ArrayList;
   61.57 -import java.util.Collection;
   61.58 -import java.util.List;
   61.59 -import java.util.concurrent.ExecutionException;
   61.60 -import java.util.concurrent.Future;
   61.61 -import java.util.concurrent.TimeUnit;
   61.62 -import java.util.concurrent.TimeoutException;
   61.63 -import java.util.concurrent.atomic.AtomicBoolean;
   61.64 -import java.util.zip.GZIPInputStream;
   61.65 -
   61.66 -import org.netbeans.api.java.classpath.ClassPath;
   61.67 -import org.netbeans.modules.java.source.usages.BinaryAnalyser;
   61.68 -import org.netbeans.modules.java.source.usages.ClassIndexImpl;
   61.69 -import org.netbeans.modules.java.source.usages.ClassIndexManager;
   61.70 -import org.netbeans.modules.java.source.usages.IndexUtil;
   61.71 -//import org.netbeans.modules.parsing.lucene.support.IndexManager.Action;
   61.72 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
   61.73 -import org.openide.filesystems.FileObject;
   61.74 -import org.openide.filesystems.FileUtil;
   61.75 -
   61.76 -/**
   61.77 - * Utilities to aid unit testing java.source module.
   61.78 - *
   61.79 - * @author Jaroslav Tulach
   61.80 - * @author Tom Ball
   61.81 - * @author Tomas Zezula
   61.82 - */
   61.83 -public final class TestUtilities {
   61.84 -    
   61.85 -    // do not instantiate
   61.86 -    private TestUtilities() {}
   61.87 -    
   61.88 -    /**
   61.89 -     * Waits for the end of the background scan, this helper method 
   61.90 -     * is designed for tests which require to wait for the end of initial scan.
   61.91 -     * The method can be used as a barrier but it is not guaranteed that the
   61.92 -     * background scan will not start again after return from this method, the
   61.93 -     * test is responsible for it itself. In general it's safer to use {@link JavaSource#runWhenScanFinished}
   61.94 -     * method and do the critical action inside the run method.
   61.95 -     * @param timeout the maximum time to wait
   61.96 -     * @param unit the time unit of the timeout argument
   61.97 -     * @return true if the scan finished, false when the timeout elapsed before the end of the scan.
   61.98 -     * @throws InterruptedException is thrown when the waiting thread is interrupted.
   61.99 -     */
  61.100 -    public static boolean waitScanFinished (final long timeout, final TimeUnit unit) throws InterruptedException {
  61.101 -        assert unit != null;
  61.102 -        final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(new URL[0]),
  61.103 -                ClassPathSupport.createClassPath(new URL[0]), null);
  61.104 -        assert cpInfo != null;
  61.105 -        final JavaSource js = JavaSource.create(cpInfo);
  61.106 -        assert js != null;
  61.107 -        try {
  61.108 -            Future<Void> future = js.runWhenScanFinished(new Task<CompilationController>() {
  61.109 -                public void run(CompilationController parameter) throws Exception {
  61.110 -                }
  61.111 -            }, true);
  61.112 -            future.get(timeout,unit);
  61.113 -            return true;
  61.114 -        } catch (IOException ioe) {
  61.115 -            //Actually never thrown
  61.116 -        }
  61.117 -        catch (ExecutionException ee) {
  61.118 -            //Actually never thrown
  61.119 -        }
  61.120 -        catch (TimeoutException timeoutEx) {
  61.121 -        }
  61.122 -        return false;
  61.123 -    }
  61.124 -    
  61.125 -//    /**
  61.126 -//     * Disables use of {@link LibraryManager} in the {@link GlobalSourcePath}. The tests
  61.127 -//     * which don't register {@link LibraryProvider} or {@link LibraryTypeProvider} may
  61.128 -//     * use this method to disable use of {@link LibraryManager} in the {@link GlobalSourcePath}.
  61.129 -//     * @param use false value disables use of {@link LibraryManager}
  61.130 -//     */
  61.131 -//    public static void setUseLibraries (final boolean use) {
  61.132 -//        //GlobalSourcePathTestUtil.setUseLibraries(use);
  61.133 -//        // IMO this in fact did nothing... If your tests are failing due to this
  61.134 -//        // please file a defect on editor/parsing & indexing and we will try to help.
  61.135 -//    }
  61.136 -    
  61.137 -    /**
  61.138 -     * Sets a root folder of the java source caches. This method may be used by tests
  61.139 -     * which need to do an initial compilation, they require either {@link ClassIndex} or
  61.140 -     * need to work with a group of related java files.
  61.141 -     * @param cacheFolder the folder used by java infrastructure as a cache,
  61.142 -     * has to exist and must be a folder.
  61.143 -     */
  61.144 -    public static void setCacheFolder (final File cacheFolder) {
  61.145 -        IndexUtil.setCacheFolder(cacheFolder);
  61.146 -    }
  61.147 -    
  61.148 -    /**
  61.149 -     * Creates boot {@link ClassPath} for platform the test is running on,
  61.150 -     * it uses the sun.boot.class.path property to find out the boot path roots.
  61.151 -     * @return ClassPath
  61.152 -     * @throws java.io.IOException when boot path property contains non valid path
  61.153 -     */
  61.154 -    public static ClassPath createBootClassPath () throws IOException {
  61.155 -        String bootPath = System.getProperty ("sun.boot.class.path");
  61.156 -        String[] paths = bootPath.split(File.pathSeparator);
  61.157 -        List<URL>roots = new ArrayList<URL> (paths.length);
  61.158 -        for (String path : paths) {
  61.159 -            File f = new File (path);            
  61.160 -            if (!f.exists()) {
  61.161 -                continue;
  61.162 -            }
  61.163 -            URL url = f.toURI().toURL();
  61.164 -            if (FileUtil.isArchiveFile(url)) {
  61.165 -                url = FileUtil.getArchiveRoot(url);
  61.166 -            }
  61.167 -            roots.add (url);
  61.168 -        }
  61.169 -        return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
  61.170 -    }
  61.171 -    /**
  61.172 -     * Returns a string which contains the contents of a file.
  61.173 -     *
  61.174 -     * @param f the file to be read
  61.175 -     * @return the contents of the file(s).
  61.176 -     */
  61.177 -    public final static String copyFileToString (java.io.File f) throws java.io.IOException {
  61.178 -        int s = (int)f.length ();
  61.179 -        byte[] data = new byte[s];
  61.180 -        int len = new FileInputStream (f).read (data);
  61.181 -        if (len != s)
  61.182 -            throw new EOFException("truncated file");
  61.183 -        return new String (data);
  61.184 -    }
  61.185 -    
  61.186 -    /**
  61.187 -     * Returns a string which contains the contents of a GZIP compressed file.
  61.188 -     *
  61.189 -     * @param f the file to be read
  61.190 -     * @return the contents of the file(s).
  61.191 -     */
  61.192 -    public final static String copyGZipFileToString (java.io.File f) throws java.io.IOException {
  61.193 -        GZIPInputStream is = new GZIPInputStream(new FileInputStream(f));
  61.194 -        byte[] arr = new byte[256 * 256];
  61.195 -        int first = 0;
  61.196 -        for(;;) {
  61.197 -            int len = is.read(arr, first, arr.length - first);
  61.198 -            if (first + len < arr.length) {
  61.199 -                return new String(arr, 0, first + len);
  61.200 -            }
  61.201 -        }
  61.202 -    }
  61.203 -    
  61.204 -    /**
  61.205 -     * Copies a string to a specified file.
  61.206 -     *
  61.207 -     * @param f the file to use.
  61.208 -     * @param content the contents of the returned file.
  61.209 -     * @return the created file
  61.210 -     */
  61.211 -    public final static File copyStringToFile (File f, String content) throws Exception {
  61.212 -        FileOutputStream os = new FileOutputStream(f);
  61.213 -        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
  61.214 -        FileUtil.copy(is, os);
  61.215 -        os.close ();
  61.216 -        is.close();
  61.217 -            
  61.218 -        return f;
  61.219 -    }
  61.220 -    
  61.221 -    /**
  61.222 -     * Copies a string to a specified file.
  61.223 -     *
  61.224 -     * @param f the {@link FilObject} to use.
  61.225 -     * @param content the contents of the returned file.
  61.226 -     * @return the created file
  61.227 -     */
  61.228 -    public final static FileObject copyStringToFile (FileObject f, String content) throws Exception {
  61.229 -        OutputStream os = f.getOutputStream();
  61.230 -        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
  61.231 -        FileUtil.copy(is, os);
  61.232 -        os.close ();
  61.233 -        is.close();
  61.234 -            
  61.235 -        return f;
  61.236 -    }   
  61.237 -
  61.238 -    private static final ClassPath EMPTY = ClassPathSupport.createClassPath(new URL[0]);
  61.239 -    
  61.240 -//    /**
  61.241 -//     * Prepare Java caches for given binary roots.
  61.242 -//     *
  61.243 -//     * @param urls to analyze
  61.244 -//     */
  61.245 -//    public final static void analyzeBinaries(final Collection<URL> urls) throws IOException {
  61.246 -//        final ClasspathInfo cpInfo = ClasspathInfo.create(EMPTY, EMPTY, EMPTY);
  61.247 -//        final ClassIndexManager mgr  = ClassIndexManager.getDefault();
  61.248 -//        final JavaSource js = JavaSource.create(cpInfo);
  61.249 -//        js.runUserActionTask(new Task<CompilationController>() {
  61.250 -//            public void run(CompilationController parameter) throws Exception {
  61.251 -//                for (final URL url : urls) {
  61.252 -//                    final ClassIndexImpl cii = mgr.createUsagesQuery(url, false);
  61.253 -//                    ClassIndexManager.getDefault().writeLock(new Action<Void>() {
  61.254 -//                        public Void run() throws IOException, InterruptedException {
  61.255 -//                            BinaryAnalyser ba = cii.getBinaryAnalyser();
  61.256 -//                            ba.start(url, new AtomicBoolean(false), new AtomicBoolean(false));
  61.257 -//                            ba.finish();
  61.258 -//                            return null;
  61.259 -//                        }
  61.260 -//                    });
  61.261 -//                }
  61.262 -//            }
  61.263 -//        }, true);
  61.264 -//    }
  61.265 -    
  61.266 -}
    62.1 --- a/borrowedtests/src/org/netbeans/modules/jackpot30/impl/TestUtils.java	Fri Jan 27 13:35:56 2012 +0100
    62.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.3 @@ -1,116 +0,0 @@
    62.4 -/*
    62.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    62.6 - *
    62.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    62.8 - *
    62.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   62.10 - * Other names may be trademarks of their respective owners.
   62.11 - *
   62.12 - * The contents of this file are subject to the terms of either the GNU
   62.13 - * General Public License Version 2 only ("GPL") or the Common
   62.14 - * Development and Distribution License("CDDL") (collectively, the
   62.15 - * "License"). You may not use this file except in compliance with the
   62.16 - * License. You can obtain a copy of the License at
   62.17 - * http://www.netbeans.org/cddl-gplv2.html
   62.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   62.19 - * specific language governing permissions and limitations under the
   62.20 - * License.  When distributing the software, include this License Header
   62.21 - * Notice in each file and include the License file at
   62.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   62.23 - * particular file as subject to the "Classpath" exception as provided
   62.24 - * by Oracle in the GPL Version 2 section of the License file that
   62.25 - * accompanied this code. If applicable, add the following below the
   62.26 - * License Header, with the fields enclosed by brackets [] replaced by
   62.27 - * your own identifying information:
   62.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   62.29 - *
   62.30 - * If you wish your version of this file to be governed by only the CDDL
   62.31 - * or only the GPL Version 2, indicate your decision by adding
   62.32 - * "[Contributor] elects to include this software in this distribution
   62.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   62.34 - * single choice of license, a recipient has the option to distribute
   62.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   62.36 - * to extend the choice of license to its licensees as provided above.
   62.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   62.38 - * Version 2 license, then the option applies only if the new code is
   62.39 - * made subject to such option by the copyright holder.
   62.40 - *
   62.41 - * Contributor(s):
   62.42 - *
   62.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
   62.44 - */
   62.45 -package org.netbeans.modules.jackpot30.impl;
   62.46 -
   62.47 -import java.io.ByteArrayInputStream;
   62.48 -import java.io.IOException;
   62.49 -import java.net.URL;
   62.50 -import java.net.URLConnection;
   62.51 -import java.net.URLStreamHandler;
   62.52 -import java.net.URLStreamHandlerFactory;
   62.53 -import java.util.HashMap;
   62.54 -import java.util.Map;
   62.55 -import junit.framework.Assert;
   62.56 -import org.openide.util.lookup.ServiceProvider;
   62.57 -
   62.58 -/**
   62.59 - *
   62.60 - * @author lahvac
   62.61 - */
   62.62 -public class TestUtils {
   62.63 -
   62.64 -    public static void clearRemoteContent() {
   62.65 -        content.clear();
   62.66 -    }
   62.67 -
   62.68 -    public static void addRemoteContent(URL url, String content) {
   62.69 -        TestUtils.content.put(url, content);
   62.70 -    }
   62.71 -
   62.72 -    private static final Map<URL, String> content = new HashMap<URL, String>();
   62.73 -
   62.74 -    @ServiceProvider(service=URLStreamHandlerFactory.class)
   62.75 -    public static final class URLStreamHandlerFactoryImpl implements URLStreamHandlerFactory {
   62.76 -
   62.77 -        public URLStreamHandler createURLStreamHandler(String protocol) {
   62.78 -            if ("test".equals(protocol)) {
   62.79 -                return new URLStreamHandlerImpl();
   62.80 -            }
   62.81 -
   62.82 -            return null;
   62.83 -        }
   62.84 -
   62.85 -    }
   62.86 -
   62.87 -    private static final class URLStreamHandlerImpl extends URLStreamHandler {
   62.88 -
   62.89 -        @Override
   62.90 -        protected URLConnection openConnection(URL u) throws IOException {
   62.91 -            String str = content.get(u);
   62.92 -
   62.93 -            Assert.assertNotNull(u.toExternalForm(), str);
   62.94 -
   62.95 -            return new TestURLConnection(u, str);
   62.96 -        }
   62.97 -
   62.98 -    }
   62.99 -
  62.100 -    private static final class TestURLConnection extends URLConnection {
  62.101 -
  62.102 -        private final String content;
  62.103 -
  62.104 -        public TestURLConnection(URL url, String content) {
  62.105 -            super(url);
  62.106 -            this.content = content;
  62.107 -        }
  62.108 -
  62.109 -        @Override
  62.110 -        public void connect() throws IOException {
  62.111 -        }
  62.112 -
  62.113 -        @Override
  62.114 -        public Object getContent() throws IOException {
  62.115 -            return new ByteArrayInputStream(content.getBytes("ASCII")); //XXX
  62.116 -        }
  62.117 -
  62.118 -    }
  62.119 -}
    63.1 --- a/borrowedtests/src/org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties	Fri Jan 27 13:35:56 2012 +0100
    63.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.3 @@ -1,38 +0,0 @@
    63.4 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    63.5 -#
    63.6 -# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    63.7 -#
    63.8 -# The contents of this file are subject to the terms of either the GNU
    63.9 -# General Public License Version 2 only ("GPL") or the Common
   63.10 -# Development and Distribution License("CDDL") (collectively, the
   63.11 -# "License"). You may not use this file except in compliance with the
   63.12 -# License. You can obtain a copy of the License at
   63.13 -# http://www.netbeans.org/cddl-gplv2.html
   63.14 -# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   63.15 -# specific language governing permissions and limitations under the
   63.16 -# License.  When distributing the software, include this License Header
   63.17 -# Notice in each file and include the License file at
   63.18 -# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   63.19 -# particular file as subject to the "Classpath" exception as provided
   63.20 -# by Sun in the GPL Version 2 section of the License file that
   63.21 -# accompanied this code. If applicable, add the following below the
   63.22 -# License Header, with the fields enclosed by brackets [] replaced by
   63.23 -# your own identifying information:
   63.24 -# "Portions Copyrighted [year] [name of copyright owner]"
   63.25 -#
   63.26 -# If you wish your version of this file to be governed by only the CDDL
   63.27 -# or only the GPL Version 2, indicate your decision by adding
   63.28 -# "[Contributor] elects to include this software in this distribution
   63.29 -# under the [CDDL or GPL Version 2] license." If you do not indicate a
   63.30 -# single choice of license, a recipient has the option to distribute
   63.31 -# your version of this file under either the CDDL, the GPL Version 2 or
   63.32 -# to extend the choice of license to its licensees as provided above.
   63.33 -# However, if you add GPL Version 2 code and therefore, elected the GPL
   63.34 -# Version 2 license, then the option applies only if the new code is
   63.35 -# made subject to such option by the copyright holder.
   63.36 -#
   63.37 -# Contributor(s):
   63.38 -#
   63.39 -# Portions Copyrighted 2009 Sun Microsystems, Inc.
   63.40 -
   63.41 -OpenIDE-Module-Name=Borrowed Test Infra
    64.1 --- a/borrowedtests/src/org/netbeans/modules/java/hints/TestUtilities.java	Fri Jan 27 13:35:56 2012 +0100
    64.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.3 @@ -1,60 +0,0 @@
    64.4 -/*
    64.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    64.6 - *
    64.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    64.8 - *
    64.9 - * The contents of this file are subject to the terms of either the GNU
   64.10 - * General Public License Version 2 only ("GPL") or the Common
   64.11 - * Development and Distribution License("CDDL") (collectively, the
   64.12 - * "License"). You may not use this file except in compliance with the
   64.13 - * License. You can obtain a copy of the License at
   64.14 - * http://www.netbeans.org/cddl-gplv2.html
   64.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   64.16 - * specific language governing permissions and limitations under the
   64.17 - * License.  When distributing the software, include this License Header
   64.18 - * Notice in each file and include the License file at
   64.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   64.20 - * particular file as subject to the "Classpath" exception as provided
   64.21 - * by Sun in the GPL Version 2 section of the License file that
   64.22 - * accompanied this code. If applicable, add the following below the
   64.23 - * License Header, with the fields enclosed by brackets [] replaced by
   64.24 - * your own identifying information:
   64.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   64.26 - *
   64.27 - * Contributor(s):
   64.28 - *
   64.29 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
   64.30 - */
   64.31 -package org.netbeans.modules.java.hints;
   64.32 -
   64.33 -import junit.framework.Assert;
   64.34 -
   64.35 -/**
   64.36 - *
   64.37 - * @author Jan Lahoda
   64.38 - */
   64.39 -public class TestUtilities {
   64.40 -
   64.41 -    private TestUtilities() {
   64.42 -    }
   64.43 -
   64.44 -    public static String detectOffsets(String source, int[] positionOrSpan) {
   64.45 -        //for now, the position/span delimiter is '|', without possibility of escaping:
   64.46 -        String[] split = source.split("\\|");
   64.47 -        
   64.48 -        Assert.assertTrue("incorrect number of position markers (|)", positionOrSpan.length == split.length - 1);
   64.49 -        
   64.50 -        StringBuilder sb = new StringBuilder();
   64.51 -        int index = 0;
   64.52 -        int offset = 0;
   64.53 -        
   64.54 -        for (String s : split) {
   64.55 -            sb.append(s);
   64.56 -            if (index < positionOrSpan.length)
   64.57 -                positionOrSpan[index++] = (offset += s.length());
   64.58 -        }
   64.59 -        
   64.60 -        return sb.toString();
   64.61 -    }
   64.62 -
   64.63 -}
    65.1 --- a/borrowedtests/src/org/netbeans/modules/java/hints/infrastructure/TreeRuleTestBase.java	Fri Jan 27 13:35:56 2012 +0100
    65.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.3 @@ -1,303 +0,0 @@
    65.4 -/*
    65.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    65.6 - *
    65.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    65.8 - *
    65.9 - * The contents of this file are subject to the terms of either the GNU
   65.10 - * General Public License Version 2 only ("GPL") or the Common
   65.11 - * Development and Distribution License("CDDL") (collectively, the
   65.12 - * "License"). You may not use this file except in compliance with the
   65.13 - * License. You can obtain a copy of the License at
   65.14 - * http://www.netbeans.org/cddl-gplv2.html
   65.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   65.16 - * specific language governing permissions and limitations under the
   65.17 - * License.  When distributing the software, include this License Header
   65.18 - * Notice in each file and include the License file at
   65.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   65.20 - * particular file as subject to the "Classpath" exception as provided
   65.21 - * by Sun in the GPL Version 2 section of the License file that
   65.22 - * accompanied this code. If applicable, add the following below the
   65.23 - * License Header, with the fields enclosed by brackets [] replaced by
   65.24 - * your own identifying information:
   65.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   65.26 - *
   65.27 - * Contributor(s):
   65.28 - *
   65.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   65.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   65.31 - * Microsystems, Inc. All Rights Reserved.
   65.32 - *
   65.33 - * If you wish your version of this file to be governed by only the CDDL
   65.34 - * or only the GPL Version 2, indicate your decision by adding
   65.35 - * "[Contributor] elects to include this software in this distribution
   65.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   65.37 - * single choice of license, a recipient has the option to distribute
   65.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   65.39 - * to extend the choice of license to its licensees as provided above.
   65.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   65.41 - * Version 2 license, then the option applies only if the new code is
   65.42 - * made subject to such option by the copyright holder.
   65.43 - */
   65.44 -package org.netbeans.modules.java.hints.infrastructure;
   65.45 -
   65.46 -import com.sun.source.util.TreePath;
   65.47 -import java.io.File;
   65.48 -import java.util.Arrays;
   65.49 -import java.util.Collections;
   65.50 -import java.util.LinkedList;
   65.51 -import java.util.List;
   65.52 -import java.util.logging.Level;
   65.53 -import java.util.logging.Logger;
   65.54 -import javax.swing.text.Document;
   65.55 -import org.netbeans.api.java.lexer.JavaTokenId;
   65.56 -import org.netbeans.api.java.source.CompilationInfo;
   65.57 -import org.netbeans.api.java.source.JavaSource;
   65.58 -import org.netbeans.api.java.source.JavaSource.Phase;
   65.59 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   65.60 -import org.netbeans.api.java.source.TestUtilities;
   65.61 -import org.netbeans.api.lexer.Language;
   65.62 -import org.netbeans.junit.NbTestCase;
   65.63 -import org.netbeans.modules.java.source.TreeLoader;
   65.64 -import org.netbeans.spi.editor.hints.ErrorDescription;
   65.65 -import org.netbeans.spi.editor.hints.Fix;
   65.66 -import org.openide.LifecycleManager;
   65.67 -import org.openide.cookies.EditorCookie;
   65.68 -import org.openide.filesystems.FileObject;
   65.69 -import org.openide.filesystems.FileUtil;
   65.70 -import org.openide.loaders.DataObject;
   65.71 -
   65.72 -/**
   65.73 - * @author Jan Lahoda
   65.74 - */
   65.75 -public abstract class TreeRuleTestBase extends NbTestCase {
   65.76 -    protected final Logger LOG;
   65.77 -    
   65.78 -    public TreeRuleTestBase(String name) {
   65.79 -        super(name);
   65.80 -        LOG = Logger.getLogger("test." + name);
   65.81 -    }
   65.82 -    
   65.83 -    @Override
   65.84 -    protected Level logLevel() {
   65.85 -        return Level.INFO;
   65.86 -    }
   65.87 -
   65.88 -    @Override
   65.89 -    protected void setUp() throws Exception {
   65.90 -        super.setUp();
   65.91 -        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[0]);
   65.92 -        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
   65.93 -    }
   65.94 -
   65.95 -    private void prepareTest(String fileName, String code) throws Exception {
   65.96 -        clearWorkDir();
   65.97 -        File wdFile = getWorkDir();
   65.98 -        FileUtil.refreshFor(wdFile);
   65.99 -
  65.100 -        FileObject wd = FileUtil.toFileObject(wdFile);
  65.101 -        assertNotNull(wd);
  65.102 -        sourceRoot = FileUtil.createFolder(wd, "src");
  65.103 -        FileObject buildRoot = FileUtil.createFolder(wd, "build");
  65.104 -        FileObject cache = FileUtil.createFolder(wd, "cache");
  65.105 -
  65.106 -        FileObject data = FileUtil.createData(sourceRoot, fileName);
  65.107 -        File dataFile = FileUtil.toFile(data);
  65.108 -        
  65.109 -        assertNotNull(dataFile);
  65.110 -        
  65.111 -        TestUtilities.copyStringToFile(dataFile, code);
  65.112 -        
  65.113 -        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache, extraClassPath());
  65.114 -        
  65.115 -        DataObject od = DataObject.find(data);
  65.116 -        EditorCookie ec = od.getCookie(EditorCookie.class);
  65.117 -        
  65.118 -        assertNotNull(ec);
  65.119 -        
  65.120 -        doc = ec.openDocument();
  65.121 -        doc.putProperty(Language.class, JavaTokenId.language());
  65.122 -        doc.putProperty("mimeType", "text/x-java");
  65.123 -        
  65.124 -        JavaSource js = JavaSource.forFileObject(data);
  65.125 -        
  65.126 -        assertNotNull(js);
  65.127 -        
  65.128 -        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
  65.129 -        
  65.130 -        assertNotNull(info);
  65.131 -    }
  65.132 -    
  65.133 -    private FileObject sourceRoot;
  65.134 -    private CompilationInfo info;
  65.135 -    private Document doc;
  65.136 -    
  65.137 -    protected abstract List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path);
  65.138 -    
  65.139 -    protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path, int offset) {
  65.140 -        return computeErrors(info, path);
  65.141 -    }
  65.142 -    
  65.143 -    protected String toDebugString(CompilationInfo info, Fix f) {
  65.144 -        return f.toString();
  65.145 -    }
  65.146 -    
  65.147 -    protected void performAnalysisTest(String fileName, String code, String... golden) throws Exception {
  65.148 -        int[] offset = new int[1];
  65.149 -        
  65.150 -        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
  65.151 -        
  65.152 -        performAnalysisTest(fileName, code, offset[0], golden);
  65.153 -    }
  65.154 -    
  65.155 -    protected void performAnalysisTest(String fileName, String code, int pos, String... golden) throws Exception {
  65.156 -        prepareTest(fileName, code);
  65.157 -        
  65.158 -        TreePath path = info.getTreeUtilities().pathFor(pos);
  65.159 -        
  65.160 -        List<ErrorDescription> errors = computeErrors(info, path, pos);
  65.161 -        List<String> errorsNames = new LinkedList<String>();
  65.162 -        
  65.163 -        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
  65.164 -        
  65.165 -        for (ErrorDescription e : errors) {
  65.166 -            errorsNames.add(e.toString());
  65.167 -        }
  65.168 -        
  65.169 -        assertTrue("The warnings provided by the hint do not match expected warnings. Provided warnings: " + errorsNames.toString(), Arrays.equals(golden, errorsNames.toArray(new String[0])));
  65.170 -    }
  65.171 -    
  65.172 -    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
  65.173 -        int[] offset = new int[1];
  65.174 -
  65.175 -        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
  65.176 -        
  65.177 -        return performFixTest(fileName, code, offset[0], errorDescriptionToString, fixDebugString, golden);
  65.178 -    }
  65.179 -    
  65.180 -    protected String performFixTest(String fileName, String code, int pos, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
  65.181 -        return performFixTest(fileName, code, pos, errorDescriptionToString, fixDebugString, fileName, golden);
  65.182 -    }
  65.183 -    
  65.184 -    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
  65.185 -        int[] offset = new int[1];
  65.186 -
  65.187 -        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
  65.188 -
  65.189 -        return performFixTest(fileName, code, offset[0], errorDescriptionToString, fixDebugString, goldenFileName, golden);
  65.190 -    }
  65.191 -    
  65.192 -    protected String performFixTest(String fileName, String code, int pos, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
  65.193 -        prepareTest(fileName, code);
  65.194 -        
  65.195 -        TreePath path = info.getTreeUtilities().pathFor(pos);
  65.196 -        
  65.197 -        List<ErrorDescription> errors = computeErrors(info, path, pos);
  65.198 -        
  65.199 -        ErrorDescription toFix = null;
  65.200 -        
  65.201 -        for (ErrorDescription d : errors) {
  65.202 -            if (errorDescriptionToString.equals(d.toString())) {
  65.203 -                toFix = d;
  65.204 -                break;
  65.205 -            }
  65.206 -        }
  65.207 -        
  65.208 -        assertNotNull("Error: \"" + errorDescriptionToString + "\" not found. All ErrorDescriptions: " + errors.toString(), toFix);
  65.209 -        
  65.210 -        assertTrue("Must be computed", toFix.getFixes().isComputed());
  65.211 -        
  65.212 -        List<Fix> fixes = toFix.getFixes().getFixes();
  65.213 -        List<String> fixNames = new LinkedList<String>();
  65.214 -        Fix toApply = null;
  65.215 -        
  65.216 -        for (Fix f : fixes) {
  65.217 -            if (fixDebugString.equals(toDebugString(info, f))) {
  65.218 -                toApply = f;
  65.219 -            }
  65.220 -            
  65.221 -            fixNames.add(toDebugString(info, f));
  65.222 -        }
  65.223 -        
  65.224 -        assertNotNull("Cannot find fix to invoke: " + fixNames.toString(), toApply);
  65.225 -        
  65.226 -        toApply.implement();
  65.227 -        
  65.228 -        FileObject toCheck = sourceRoot.getFileObject(goldenFileName);
  65.229 -        
  65.230 -        assertNotNull(toCheck);
  65.231 -        
  65.232 -        DataObject toCheckDO = DataObject.find(toCheck);
  65.233 -        EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
  65.234 -        Document toCheckDocument = ec.openDocument();
  65.235 -        
  65.236 -        String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());
  65.237 -        
  65.238 -        //ignore whitespaces:
  65.239 -        realCode = realCode.replaceAll("[ \t\n]+", " ");
  65.240 -
  65.241 -        if (golden != null) {
  65.242 -            assertEquals("The output code does not match the expected code.", golden, realCode);
  65.243 -        }
  65.244 -        
  65.245 -        LifecycleManager.getDefault().saveAll();
  65.246 -
  65.247 -        return realCode;
  65.248 -    }
  65.249 -    
  65.250 -    protected FileObject[] extraClassPath() {
  65.251 -        return new FileObject[0];
  65.252 -    }
  65.253 -
  65.254 -    // common tests to check nothing is reported
  65.255 -    public void testIssue105979() throws Exception {
  65.256 -        String before = "package test; class Test {" +
  65.257 -                "  return b;" +
  65.258 -                "}\n";
  65.259 -
  65.260 -        for (int i = 0; i < before.length(); i++) {
  65.261 -            LOG.info("testing position " + i + " at " + before.charAt(i));
  65.262 -            clearWorkDir();
  65.263 -            performAnalysisTest("test/Test.java", before, i);
  65.264 -}
  65.265 -    }
  65.266 -    public void testIssue108246() throws Exception {
  65.267 -
  65.268 -        String before = "package test; class Test {" +
  65.269 -            "  Integer ii = new Integer(0);" +
  65.270 -            "  String s = ii.toString();" +
  65.271 -            "\n}\n";
  65.272 -
  65.273 -        for (int i = 0; i < before.length(); i++) {
  65.274 -            LOG.info("testing position " + i + " at " + before.charAt(i));
  65.275 -            clearWorkDir();
  65.276 -            performAnalysisTest("test/Test.java", before, i);
  65.277 -        }
  65.278 -    }
  65.279 -
  65.280 -    public void testNoHintsForSimpleInitialize() throws Exception {
  65.281 -
  65.282 -        String before = "package test; class Test {" +
  65.283 -            " { java.lang.System.out.println(); } " +
  65.284 -            "}\n";
  65.285 -
  65.286 -        for (int i = 0; i < before.length(); i++) {
  65.287 -            LOG.info("testing position " + i + " at " + before.charAt(i));
  65.288 -            clearWorkDir();
  65.289 -            performAnalysisTest("test/Test.java", before, i);
  65.290 -        }
  65.291 -    }
  65.292 -
  65.293 -    public void testIssue113933() throws Exception {
  65.294 -
  65.295 -        String before = "package test; class Test {" +
  65.296 -            "  public void test() {" +
  65.297 -            "  super.A();" +
  65.298 -            "\n}\n}\n";
  65.299 -
  65.300 -        for (int i = 0; i < before.length(); i++) {
  65.301 -            LOG.info("testing position " + i + " at " + before.charAt(i));
  65.302 -            clearWorkDir();
  65.303 -            performAnalysisTest("test/Test.java", before, i);
  65.304 -        }
  65.305 -    }
  65.306 -}
    66.1 --- a/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/code/spi/TestBase.java	Fri Jan 27 13:35:56 2012 +0100
    66.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.3 @@ -1,341 +0,0 @@
    66.4 -/*
    66.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    66.6 - *
    66.7 - * Copyright 2009-2010 Oracle and/or its affiliates. All rights reserved.
    66.8 - *
    66.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   66.10 - * Other names may be trademarks of their respective owners.
   66.11 - *
   66.12 - * The contents of this file are subject to the terms of either the GNU
   66.13 - * General Public License Version 2 only ("GPL") or the Common
   66.14 - * Development and Distribution License("CDDL") (collectively, the
   66.15 - * "License"). You may not use this file except in compliance with the
   66.16 - * License. You can obtain a copy of the License at
   66.17 - * http://www.netbeans.org/cddl-gplv2.html
   66.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   66.19 - * specific language governing permissions and limitations under the
   66.20 - * License.  When distributing the software, include this License Header
   66.21 - * Notice in each file and include the License file at
   66.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   66.23 - * particular file as subject to the "Classpath" exception as provided
   66.24 - * by Oracle in the GPL Version 2 section of the License file that
   66.25 - * accompanied this code. If applicable, add the following below the
   66.26 - * License Header, with the fields enclosed by brackets [] replaced by
   66.27 - * your own identifying information:
   66.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   66.29 - *
   66.30 - * If you wish your version of this file to be governed by only the CDDL
   66.31 - * or only the GPL Version 2, indicate your decision by adding
   66.32 - * "[Contributor] elects to include this software in this distribution
   66.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   66.34 - * single choice of license, a recipient has the option to distribute
   66.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   66.36 - * to extend the choice of license to its licensees as provided above.
   66.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   66.38 - * Version 2 license, then the option applies only if the new code is
   66.39 - * made subject to such option by the copyright holder.
   66.40 - *
   66.41 - * Contributor(s):
   66.42 - *
   66.43 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   66.44 - */
   66.45 -
   66.46 -package org.netbeans.modules.java.hints.jackpot.code.spi;
   66.47 -
   66.48 -import java.io.File;
   66.49 -import java.lang.reflect.Method;
   66.50 -import java.util.ArrayList;
   66.51 -import java.util.Arrays;
   66.52 -import java.util.Collection;
   66.53 -import java.util.Collections;
   66.54 -import java.util.Comparator;
   66.55 -import java.util.HashMap;
   66.56 -import java.util.HashSet;
   66.57 -import java.util.LinkedList;
   66.58 -import java.util.List;
   66.59 -import java.util.Map;
   66.60 -import java.util.Map.Entry;
   66.61 -import java.util.Set;
   66.62 -import java.util.concurrent.atomic.AtomicBoolean;
   66.63 -import java.util.logging.Level;
   66.64 -import java.util.logging.Logger;
   66.65 -import javax.swing.text.Document;
   66.66 -import org.netbeans.api.java.lexer.JavaTokenId;
   66.67 -import org.netbeans.api.java.source.CompilationInfo;
   66.68 -import org.netbeans.api.java.source.JavaSource;
   66.69 -import org.netbeans.api.java.source.JavaSource.Phase;
   66.70 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   66.71 -import org.netbeans.api.java.source.TestUtilities;
   66.72 -import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory;
   66.73 -import org.netbeans.api.lexer.Language;
   66.74 -import org.netbeans.junit.NbTestCase;
   66.75 -import org.netbeans.modules.java.hints.jackpot.code.CodeHintProviderImpl;
   66.76 -import org.netbeans.modules.java.hints.jackpot.code.FSWrapper;
   66.77 -import org.netbeans.modules.java.hints.jackpot.code.FSWrapper.ClassWrapper;
   66.78 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
   66.79 -import org.netbeans.modules.java.hints.jackpot.spi.HintMetadata;
   66.80 -import org.netbeans.modules.java.hints.jackpot.spi.HintsRunner;
   66.81 -import org.netbeans.modules.java.source.TreeLoader;
   66.82 -import org.netbeans.spi.editor.hints.ErrorDescription;
   66.83 -import org.netbeans.spi.editor.hints.Fix;
   66.84 -import org.openide.LifecycleManager;
   66.85 -import org.openide.cookies.EditorCookie;
   66.86 -import org.openide.filesystems.FileObject;
   66.87 -import org.openide.filesystems.FileUtil;
   66.88 -import org.openide.loaders.DataObject;
   66.89 -import org.openide.util.NbBundle;
   66.90 -
   66.91 -/**
   66.92 - *
   66.93 - * @author lahvac
   66.94 - */
   66.95 -public abstract class TestBase extends NbTestCase {
   66.96 -    private final Class<?> hintClass;
   66.97 -    protected final Logger LOG;
   66.98 -
   66.99 -    public TestBase(String name, Class<?> hintClass) {
  66.100 -        super(name);
  66.101 -        this.hintClass = hintClass;
  66.102 -        LOG = Logger.getLogger("test." + name);
  66.103 -    }
  66.104 -
  66.105 -    @Override
  66.106 -    protected Level logLevel() {
  66.107 -        return Level.INFO;
  66.108 -    }
  66.109 -
  66.110 -    @Override
  66.111 -    protected void setUp() throws Exception {
  66.112 -        super.setUp();
  66.113 -        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml", "META-INF/generated-layer.xml"}, new Object[0]);
  66.114 -        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
  66.115 -    }
  66.116 -
  66.117 -    private String sourceLevel = "1.5";
  66.118 -
  66.119 -    protected void setSourceLevel(String sourceLevel) {
  66.120 -        this.sourceLevel = sourceLevel;
  66.121 -    }
  66.122 -    
  66.123 -    protected void prepareTest(String fileName, String code) throws Exception {
  66.124 -        clearWorkDir();
  66.125 -        File wdFile = getWorkDir();
  66.126 -        FileUtil.refreshFor(wdFile);
  66.127 -
  66.128 -        FileObject wd = FileUtil.toFileObject(wdFile);
  66.129 -        assertNotNull(wd);
  66.130 -        sourceRoot = FileUtil.createFolder(wd, "src");
  66.131 -        FileObject buildRoot = FileUtil.createFolder(wd, "build");
  66.132 -        FileObject cache = FileUtil.createFolder(wd, "cache");
  66.133 -
  66.134 -        FileObject data = FileUtil.createData(sourceRoot, fileName);
  66.135 -        File dataFile = FileUtil.toFile(data);
  66.136 -
  66.137 -        assertNotNull(dataFile);
  66.138 -
  66.139 -        TestUtilities.copyStringToFile(dataFile, code);
  66.140 -
  66.141 -        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache, extraClassPath());
  66.142 -
  66.143 -        SourceUtilsTestUtil.setSourceLevel(data, sourceLevel);
  66.144 -
  66.145 -        DataObject od = DataObject.find(data);
  66.146 -        EditorCookie ec = od.getCookie(EditorCookie.class);
  66.147 -
  66.148 -        assertNotNull(ec);
  66.149 -
  66.150 -        doc = ec.openDocument();
  66.151 -        doc.putProperty(Language.class, JavaTokenId.language());
  66.152 -        doc.putProperty("mimeType", "text/x-java");
  66.153 -
  66.154 -        JavaSource js = JavaSource.forFileObject(data);
  66.155 -
  66.156 -        assertNotNull(js);
  66.157 -
  66.158 -        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
  66.159 -
  66.160 -        assertNotNull(info);
  66.161 -    }
  66.162 -
  66.163 -    private FileObject sourceRoot;
  66.164 -    private CompilationInfo info;
  66.165 -    private Document doc;
  66.166 -
  66.167 -    protected final void setTestFileCaretLocation(int pos) throws Exception {
  66.168 -        Method m = CaretAwareJavaSourceTaskFactory.class.getDeclaredMethod("setLastPosition", FileObject.class, int.class);
  66.169 -
  66.170 -        m.setAccessible(true);
  66.171 -        m.invoke(null, info.getFileObject(), pos);
  66.172 -    }
  66.173 -
  66.174 -    private List<ErrorDescription> computeErrors(CompilationInfo info) {
  66.175 -        Map<HintMetadata, Collection<HintDescription>> hints = new HashMap<HintMetadata, Collection<HintDescription>>();
  66.176 -
  66.177 -        ClassWrapper found = null;
  66.178 -
  66.179 -        for (ClassWrapper w : FSWrapper.listClasses()) {
  66.180 -            if (w.getName().equals(hintClass.getName())) {
  66.181 -                found = w;
  66.182 -                break;
  66.183 -            }
  66.184 -        }
  66.185 -
  66.186 -        assertNotNull(found);
  66.187 -        
  66.188 -        CodeHintProviderImpl.processClass(found, hints);
  66.189 -
  66.190 -        List<HintDescription> total = new LinkedList<HintDescription>();
  66.191 -
  66.192 -        for (Collection<? extends HintDescription> l : hints.values()) {
  66.193 -            total.addAll(l);
  66.194 -        }
  66.195 -
  66.196 -        List<ErrorDescription> result = new ArrayList<ErrorDescription>();
  66.197 -        
  66.198 -        for (Entry<HintDescription, List<ErrorDescription>> e : HintsRunner.computeErrors(info, total, new AtomicBoolean()).entrySet()) {
  66.199 -            result.addAll(e.getValue());
  66.200 -        }
  66.201 -
  66.202 -        return result;
  66.203 -    }
  66.204 -
  66.205 -    protected String toDebugString(CompilationInfo info, Fix f) {
  66.206 -        return "FixImpl";
  66.207 -    }
  66.208 -
  66.209 -    protected void performAnalysisTest(String fileName, String code, String... golden) throws Exception {
  66.210 -        prepareTest(fileName, code);
  66.211 -
  66.212 -        List<ErrorDescription> errors = computeErrors(info);
  66.213 -        Collections.sort (errors, ERRORS_COMPARATOR);
  66.214 -        List<String> errorsNames = new LinkedList<String>();
  66.215 -
  66.216 -        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
  66.217 -
  66.218 -        for (ErrorDescription e : errors) {
  66.219 -            errorsNames.add(e.toString());
  66.220 -        }
  66.221 -
  66.222 -        assertTrue("The warnings provided by the hint do not match expected warnings. Provided warnings: " + errorsNames.toString(), Arrays.equals(golden, errorsNames.toArray(new String[0])));
  66.223 -    }
  66.224 -
  66.225 -    protected void performAnalysisContainsTest(String fileName, String code, String... golden) throws Exception {
  66.226 -        prepareTest(fileName, code);
  66.227 -
  66.228 -        Set<String> goldenSet = new HashSet<String>();
  66.229 -        for (String s : golden) {
  66.230 -            goldenSet.add(s);
  66.231 -        }
  66.232 -
  66.233 -        List<ErrorDescription> errors = computeErrors(info);
  66.234 -        Collections.sort (errors, ERRORS_COMPARATOR);
  66.235 -        List<String> errorsNames = new LinkedList<String>();
  66.236 -
  66.237 -        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
  66.238 -
  66.239 -        for (ErrorDescription d : errors) {
  66.240 -            goldenSet.remove(d.toString());
  66.241 -            errorsNames.add(d.toString());
  66.242 -        }
  66.243 -        assertTrue("The warnings provided by the hint do not contain expected warnings. Provided warnings: " + errorsNames.toString(), goldenSet.isEmpty());
  66.244 -    }
  66.245 -
  66.246 -    protected void performAnalysisExcludesTest(String fileName, String code, String... golden) throws Exception {
  66.247 -        prepareTest(fileName, code);
  66.248 -
  66.249 -        Set<String> goldenSet = new HashSet<String>();
  66.250 -        for (String s : golden) {
  66.251 -            goldenSet.add(s);
  66.252 -        }
  66.253 -
  66.254 -        List<ErrorDescription> errors = computeErrors(info);
  66.255 -        Collections.sort (errors, ERRORS_COMPARATOR);
  66.256 -        List<String> errorsNames = new LinkedList<String>();
  66.257 -
  66.258 -        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
  66.259 -
  66.260 -        boolean fail = false;
  66.261 -        for (ErrorDescription d : errors) {
  66.262 -            if (goldenSet.remove(d.getDescription()))
  66.263 -                fail = true;
  66.264 -            errorsNames.add(d.toString());
  66.265 -        }
  66.266 -        assertFalse("The warnings provided by the hint do not exclude expected warnings. Provided warnings: " + errorsNames.toString(), fail);
  66.267 -    }
  66.268 -
  66.269 -    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
  66.270 -        return performFixTest(fileName, code, errorDescriptionToString, fixDebugString, fileName, golden);
  66.271 -    }
  66.272 -
  66.273 -    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
  66.274 -        prepareTest(fileName, code);
  66.275 -
  66.276 -        List<ErrorDescription> errors = computeErrors(info);
  66.277 -        Collections.sort (errors, ERRORS_COMPARATOR);
  66.278 -
  66.279 -        ErrorDescription toFix = null;
  66.280 -
  66.281 -        for (ErrorDescription d : errors) {
  66.282 -            if (errorDescriptionToString.equals(d.toString())) {
  66.283 -                toFix = d;
  66.284 -                break;
  66.285 -            }
  66.286 -        }
  66.287 -
  66.288 -        assertNotNull("Error: \"" + errorDescriptionToString + "\" not found. All ErrorDescriptions: " + errors.toString(), toFix);
  66.289 -
  66.290 -        assertTrue("Must be computed", toFix.getFixes().isComputed());
  66.291 -
  66.292 -        List<Fix> fixes = toFix.getFixes().getFixes();
  66.293 -        List<String> fixNames = new LinkedList<String>();
  66.294 -        Fix toApply = null;
  66.295 -
  66.296 -        for (Fix f : fixes) {
  66.297 -            if (fixDebugString.equals(toDebugString(info, f))) {
  66.298 -                toApply = f;
  66.299 -            }
  66.300 -
  66.301 -            fixNames.add(toDebugString(info, f));
  66.302 -        }
  66.303 -
  66.304 -        assertNotNull("Cannot find fix to invoke: " + fixNames.toString(), toApply);
  66.305 -
  66.306 -        toApply.implement();
  66.307 -
  66.308 -        FileObject toCheck = sourceRoot.getFileObject(goldenFileName);
  66.309 -
  66.310 -        assertNotNull(toCheck);
  66.311 -
  66.312 -        DataObject toCheckDO = DataObject.find(toCheck);
  66.313 -        EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
  66.314 -        Document toCheckDocument = ec.openDocument();
  66.315 -
  66.316 -        String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());
  66.317 -
  66.318 -        //ignore whitespaces:
  66.319 -        realCode = realCode.replaceAll("[ \t\n]+", " ");
  66.320 -
  66.321 -        if (golden != null) {
  66.322 -            assertEquals("The output code does not match the expected code.", golden, realCode);
  66.323 -        }
  66.324 -
  66.325 -        LifecycleManager.getDefault().saveAll();
  66.326 -
  66.327 -        return realCode;
  66.328 -    }
  66.329 -
  66.330 -    protected FileObject[] extraClassPath() {
  66.331 -        return new FileObject[0];
  66.332 -    }
  66.333 -
  66.334 -    static {
  66.335 -        NbBundle.setBranding("test");
  66.336 -    }
  66.337 -
  66.338 -    private static final Comparator<ErrorDescription> ERRORS_COMPARATOR = new Comparator<ErrorDescription> () {
  66.339 -
  66.340 -        public int compare (ErrorDescription e1, ErrorDescription e2) {
  66.341 -            return e1.getRange ().getBegin ().getOffset () - e2.getRange ().getBegin ().getOffset ();
  66.342 -        }
  66.343 -    };
  66.344 -}
    67.1 --- a/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/impl/pm/BulkSearchTestPerformer.java	Fri Jan 27 13:35:56 2012 +0100
    67.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.3 @@ -1,664 +0,0 @@
    67.4 -/*
    67.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    67.6 - *
    67.7 - * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    67.8 - *
    67.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   67.10 - * Other names may be trademarks of their respective owners.
   67.11 - *
   67.12 - * The contents of this file are subject to the terms of either the GNU
   67.13 - * General Public License Version 2 only ("GPL") or the Common
   67.14 - * Development and Distribution License("CDDL") (collectively, the
   67.15 - * "License"). You may not use this file except in compliance with the
   67.16 - * License. You can obtain a copy of the License at
   67.17 - * http://www.netbeans.org/cddl-gplv2.html
   67.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   67.19 - * specific language governing permissions and limitations under the
   67.20 - * License.  When distributing the software, include this License Header
   67.21 - * Notice in each file and include the License file at
   67.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   67.23 - * particular file as subject to the "Classpath" exception as provided
   67.24 - * by Oracle in the GPL Version 2 section of the License file that
   67.25 - * accompanied this code. If applicable, add the following below the
   67.26 - * License Header, with the fields enclosed by brackets [] replaced by
   67.27 - * your own identifying information:
   67.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   67.29 - *
   67.30 - * If you wish your version of this file to be governed by only the CDDL
   67.31 - * or only the GPL Version 2, indicate your decision by adding
   67.32 - * "[Contributor] elects to include this software in this distribution
   67.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   67.34 - * single choice of license, a recipient has the option to distribute
   67.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   67.36 - * to extend the choice of license to its licensees as provided above.
   67.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   67.38 - * Version 2 license, then the option applies only if the new code is
   67.39 - * made subject to such option by the copyright holder.
   67.40 - *
   67.41 - * Contributor(s):
   67.42 - *
   67.43 - * Portions Copyrighted 2009 Sun Microsystems, Inc.
   67.44 - */
   67.45 -
   67.46 -package org.netbeans.modules.java.hints.jackpot.impl.pm;
   67.47 -
   67.48 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
   67.49 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
   67.50 -import com.sun.source.util.TreePath;
   67.51 -import java.io.ByteArrayInputStream;
   67.52 -import java.io.ByteArrayOutputStream;
   67.53 -import java.io.File;
   67.54 -import java.util.Arrays;
   67.55 -import java.util.Collection;
   67.56 -import java.util.Collections;
   67.57 -import java.util.HashMap;
   67.58 -import java.util.HashSet;
   67.59 -import java.util.LinkedList;
   67.60 -import java.util.List;
   67.61 -import java.util.Map;
   67.62 -import java.util.Map.Entry;
   67.63 -import java.util.Set;
   67.64 -import java.util.regex.Pattern;
   67.65 -import javax.swing.text.Document;
   67.66 -import org.netbeans.api.java.lexer.JavaTokenId;
   67.67 -import org.netbeans.api.java.source.CompilationInfo;
   67.68 -import org.netbeans.api.java.source.JavaSource;
   67.69 -import org.netbeans.api.java.source.JavaSource.Phase;
   67.70 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   67.71 -import org.netbeans.api.java.source.TestUtilities;
   67.72 -import org.netbeans.api.java.source.TreePathHandle;
   67.73 -import org.netbeans.api.lexer.Language;
   67.74 -import org.netbeans.junit.NbTestCase;
   67.75 -import org.netbeans.modules.java.source.TreeLoader;
   67.76 -import org.openide.cookies.EditorCookie;
   67.77 -import org.openide.filesystems.FileObject;
   67.78 -import org.openide.filesystems.FileUtil;
   67.79 -import org.openide.loaders.DataObject;
   67.80 -import static org.junit.Assert.*;
   67.81 -
   67.82 -/**
   67.83 - *
   67.84 - * @author lahvac
   67.85 - */
   67.86 -public abstract class BulkSearchTestPerformer extends NbTestCase {
   67.87 -
   67.88 -    public BulkSearchTestPerformer(String name) {
   67.89 -        super(name);
   67.90 -    }
   67.91 -
   67.92 -    @Override
   67.93 -    protected void setUp() throws Exception {
   67.94 -        super.setUp();
   67.95 -        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[0]);
   67.96 -        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
   67.97 -    }
   67.98 -
   67.99 -//    public static TestSuite suite() {
  67.100 -//        NbTestSuite s = new NbTestSuite();
  67.101 -//
  67.102 -//        s.addTestSuite(NFABasedBulkSearchTest.class);
  67.103 -//
  67.104 -//        return s;
  67.105 -//    }
  67.106 -
  67.107 -    public void testSimple1() throws Exception {
  67.108 -        performTest("package test; public class Test { private void test() { System.err./**/println(\"\");}}",
  67.109 -                    Collections.singletonMap("System.err.println(\"\")", Arrays.asList("System.err./**/println(\"\")")),
  67.110 -                    Arrays.asList("System.err.println(\"\" + \"\")"));
  67.111 -    }
  67.112 -
  67.113 -    public void testDontCare() throws Exception {
  67.114 -        performTest("package test; public class Test { private void test() { System.err./**/println(\"\" + \"\");}}",
  67.115 -                    Collections.singletonMap("System.err.println($1)", Arrays.asList("System.err./**/println(\"\" + \"\")")),
  67.116 -                    Collections.<String>emptyList());
  67.117 -    }
  67.118 -
  67.119 -    public void testMemberSelectAndIdentifier() throws Exception {
  67.120 -        performTest("package test; public class Test { private static void test() { test();}}",
  67.121 -                    Collections.singletonMap("test.Test.test()", Arrays.asList("test()")),
  67.122 -                    Collections.<String>emptyList());
  67.123 -    }
  67.124 -
  67.125 -    public void testUnpureMemberSelect() throws Exception {
  67.126 -        performTest("package test; public class Test { private static void test() { new StringBuilder().append(\"\");}}",
  67.127 -                    Collections.<String, List<String>>emptyMap(),
  67.128 -                    Arrays.asList("test.append(\"\")"));
  67.129 -    }
  67.130 -
  67.131 -    public void testMemberSelectWithVariables1() throws Exception {
  67.132 -        performTest("package test; public class Test { private static void test() { new StringBuilder().append(\"\");}}",
  67.133 -                    Collections.singletonMap("$0.append(\"\")", Arrays.asList("new StringBuilder().append(\"\")")),
  67.134 -                    Collections.<String>emptyList());
  67.135 -    }
  67.136 -
  67.137 -    public void testMemberSelectWithVariables2() throws Exception {
  67.138 -        performTest("package test; public class Test { private void append(char c) { append(\"\");}}",
  67.139 -                    Collections.singletonMap("$0.append(\"\")", Arrays.asList("append(\"\")")),
  67.140 -                    Collections.<String>emptyList());
  67.141 -    }
  67.142 -
  67.143 -    public void testLocalVariables() throws Exception {
  67.144 -        performTest("package test; public class Test { private void test() { { int y; y = 1; } }}",
  67.145 -                    Collections.singletonMap("{ int $1; $1 = 1; }", Arrays.asList("{ int y; y = 1; }")),
  67.146 -                    Collections.<String>emptyList());
  67.147 -    }
  67.148 -
  67.149 -    public void testAssert() throws Exception {
  67.150 -        performTest("package test; public class Test { private void test() { assert true : \"\"; }}",
  67.151 -                    Collections.singletonMap("assert $1 : $2;", Arrays.asList("assert true : \"\";")),
  67.152 -                    Collections.<String>emptyList());
  67.153 -    }
  67.154 -
  67.155 -    public void testStatementAndSingleBlockStatementAreSame1() throws Exception {
  67.156 -        performTest("package test; public class Test { private void test() { { int y; { y = 1; } } }}",
  67.157 -                    Collections.singletonMap("{ int $1; $1 = 1; }", Arrays.asList("{ int y; { y = 1; } }")),
  67.158 -                    Collections.<String>emptyList());
  67.159 -    }
  67.160 -
  67.161 -    public void testStatementAndSingleBlockStatementAreSame2() throws Exception {
  67.162 -        performTest("package test; public class Test { private void test() { { int y; y = 1; } }}",
  67.163 -                    Collections.singletonMap("{ int $1; { $1 = 1; } }", Arrays.asList("{ int y; y = 1; }")),
  67.164 -                    Collections.<String>emptyList());
  67.165 -    }
  67.166 -
  67.167 -    public void testStatementVariables1() throws Exception {
  67.168 -        performTest("package test; public class Test { public int test1() { if (true) return 1; else return 2; } }",
  67.169 -                    Collections.singletonMap("if ($1) $2; else $3;", Arrays.asList("if (true) return 1; else return 2;")),
  67.170 -                    Collections.<String>emptyList());
  67.171 -    }
  67.172 -
  67.173 -    public void testMultiStatementVariables1() throws Exception {
  67.174 -        performTest("package test; public class Test { public int test1(int i) { System.err.println(i); System.err.println(i); i = 3; System.err.println(i); System.err.println(i); return i; } }",
  67.175 -                    Collections.singletonMap("{ $s1$; i = 3; $s2$; return i; }", Arrays.asList("{ System.err.println(i); System.err.println(i); i = 3; System.err.println(i); System.err.println(i); return i; }")),
  67.176 -                    Collections.<String>emptyList());
  67.177 -    }
  67.178 -
  67.179 -    public void testMultiStatementVariables2() throws Exception {
  67.180 -        performTest("package test; public class Test { public int test1(int i) { i = 3; return i; } }",
  67.181 -                    Collections.singletonMap("{ $s1$; i = 3; $s2$; return i; }", Arrays.asList("{ i = 3; return i; }")),
  67.182 -                    Collections.<String>emptyList());
  67.183 -    }
  67.184 -
  67.185 -    public void testMultiStatementVariablesAndBlocks1() throws Exception {
  67.186 -        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
  67.187 -                    Collections.singletonMap("if ($c) {$s1$; System.err.println(); $s2$; }", Arrays.asList("if (true) System.err.println();")),
  67.188 -                    Collections.<String>emptyList());
  67.189 -    }
  67.190 -
  67.191 -    public void testMultiStatementVariablesAndBlocks2() throws Exception {
  67.192 -        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
  67.193 -                    Collections.singletonMap("if ($c) {$s1$; System.err.println(); }", Arrays.asList("if (true) System.err.println();")),
  67.194 -                    Collections.<String>emptyList());
  67.195 -    }
  67.196 -
  67.197 -    public void testMultiStatementVariablesAndBlocks3() throws Exception {
  67.198 -        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
  67.199 -                    Collections.singletonMap("if ($c) {System.err.println(); $s2$; }", Arrays.asList("if (true) System.err.println();")),
  67.200 -                    Collections.<String>emptyList());
  67.201 -    }
  67.202 -
  67.203 -    public void testMultiStatementVariablesAndBlocks4() throws Exception {
  67.204 -        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
  67.205 -                    Collections.singletonMap("{ $s1$; System.err.println(); $s2$; }", Arrays.asList("System.err.println();")),
  67.206 -                    Collections.<String>emptyList());
  67.207 -    }
  67.208 -
  67.209 -    public void testTwoPatterns() throws Exception {
  67.210 -        Map<String, List<String>> contained = new HashMap<String, List<String>>();
  67.211 -
  67.212 -        contained.put("if ($a) $ret = $b; else $ret = $c;", Arrays.asList("if (b) q = 2; else q = 3;"));
  67.213 -        contained.put("{ $p$; $T $v; if($a) $v = $b; else $v = $c; $q$; }", Arrays.asList("{ int q; if (b) q = 2; else q = 3; }"));
  67.214 -
  67.215 -        performTest("package test; public class Test { public void test1(boolean b) { int q; if (b) q = 2; else q = 3; } }",
  67.216 -                    contained,
  67.217 -                    Collections.<String>emptyList());
  67.218 -    }
  67.219 -
  67.220 -    public void testEffectiveNewClass() throws Exception {
  67.221 -        performTest("package test; import javax.swing.ImageIcon; public class Test { public void test1(java.awt.Image i) { new ImageIcon(i); new String(i); } }",
  67.222 -                    Collections.singletonMap("new javax.swing.ImageIcon($1)", Arrays.asList("new ImageIcon(i)")),
  67.223 -                    Collections.<String>emptyList());
  67.224 -    }
  67.225 -
  67.226 -    public void testSynchronizedAndMultiStatementVariables() throws Exception {
  67.227 -        performTest("package test; public class Test {public void test() { Object o = null; int i = 0; synchronized (o) {} } }",
  67.228 -                    Collections.singletonMap("synchronized($var) {$stmts$;}", Arrays.asList("synchronized (o) {}")),
  67.229 -                    Collections.<String>emptyList());
  67.230 -    }
  67.231 -
  67.232 -    public void testJackpot30_2() throws Exception {
  67.233 -        String code = "package test;\n" +
  67.234 -                      "public class Test {\n" +
  67.235 -                      "    private void m() {\n" +
  67.236 -                      "        a(c.i().getFileObject());\n" +
  67.237 -                      "        if (span != null && span[0] != (-1) && span[1] != (-1));\n" +
  67.238 -                      "    }\n" +
  67.239 -                      "}\n";
  67.240 -
  67.241 -        performTest(code,
  67.242 -                    Collections.<String, List<String>>emptyMap(),
  67.243 -                    Arrays.asList("$0.getFileObject($1)"));
  67.244 -    }
  67.245 -
  67.246 -    public void testIdentifierInPureMemberSelect() throws Exception {
  67.247 -        String code = "package test;\n" +
  67.248 -                       "public class Test {\n" +
  67.249 -                       "     public Test test;\n" +
  67.250 -                       "     public String name;\n" +
  67.251 -                       "     private void test() {\n" +
  67.252 -                       "         Test t = null;\n" +
  67.253 -                       "         String s = t.test.name;\n" +
  67.254 -                       "     }\n" +
  67.255 -                       "}\n";
  67.256 -
  67.257 -        performTest(code,
  67.258 -                    Collections.singletonMap("$Test.test", Arrays.asList("test", "t.test")),
  67.259 -                    Collections.<String>emptyList());
  67.260 -    }
  67.261 -
  67.262 -    public void testNoExponentialTimeComplexity() throws Exception {
  67.263 -        try {
  67.264 -        String code = "package test;\n" +
  67.265 -                      "public class Test {\n" +
  67.266 -                      "    private void test() {\n" +
  67.267 -                      "        Object o;\n" +
  67.268 -                      "        if(o == null) {\n" +
  67.269 -                      "            f(\"\");\n" +
  67.270 -                      "        }|\n" +
  67.271 -                      "    }\n" +
  67.272 -                      "}";
  67.273 -        String pattern = "{ $p$; $T $v; if($a) $v = $b; else $v = $c; }";
  67.274 -
  67.275 -        measure(code, "\na(\"\");", 5, pattern); //to load needed classes, etc.
  67.276 -
  67.277 -        int rep = 1;
  67.278 -        long baseline;
  67.279 -
  67.280 -        while (true) {
  67.281 -            baseline = measure(code, "\na(\"\");", rep, pattern);
  67.282 -
  67.283 -            if (baseline >= 2000) {
  67.284 -                break;
  67.285 -            }
  67.286 -
  67.287 -            rep *= 2;
  67.288 -        }
  67.289 -
  67.290 -        long doubleSize = measure(code, "\na(\"\");", 2 * rep, pattern);
  67.291 -
  67.292 -        assertTrue("baseline=" + baseline + ", actual=" + String.valueOf(doubleSize), doubleSize <= 4 * baseline);
  67.293 -        } catch (OutOfMemoryError oome) {
  67.294 -            //OK
  67.295 -        }
  67.296 -    }
  67.297 -
  67.298 -    public void testMultiParameter1() throws Exception {
  67.299 -        performTest("package test; public class Test { { java.util.Arrays.asList(\"a\", \"b\", \"c\"); } }",
  67.300 -                    Collections.singletonMap("java.util.Arrays.asList($params$)", Arrays.asList("java.util.Arrays.asList(\"a\", \"b\", \"c\")")),
  67.301 -                    Collections.<String>emptyList());
  67.302 -    }
  67.303 -
  67.304 -    public void testMultiParameter2() throws Exception {
  67.305 -        performTest("package test; public class Test { { java.util.Arrays.asList(); } }",
  67.306 -                    Collections.singletonMap("java.util.Arrays.asList($params$)", Arrays.asList("java.util.Arrays.asList()")),
  67.307 -                    Collections.<String>emptyList());
  67.308 -    }
  67.309 -
  67.310 -    public void testTypeParameter() throws Exception {
  67.311 -        performTest("package test; public class Test { { java.util.Arrays.<String>asList(); } }",
  67.312 -                    Collections.singletonMap("java.util.Arrays.<$1>asList($params$)", Arrays.asList("java.util.Arrays.<String>asList()")),
  67.313 -                    Collections.<String>emptyList());
  67.314 -    }
  67.315 -
  67.316 -    public void testField1() throws Exception {
  67.317 -        String code = "package test;\n" +
  67.318 -                       "public class Test {\n" +
  67.319 -                       "     String name = null;\n" +
  67.320 -                       "}\n";
  67.321 -
  67.322 -        performTest(code,
  67.323 -                    Collections.singletonMap("$modifiers$ java.lang.String $name = $initializer;", Arrays.asList("String name = null;")),
  67.324 -                    Collections.<String>emptyList());
  67.325 -    }
  67.326 -
  67.327 -    public void testField2() throws Exception {
  67.328 -        String code = "package test;\n" +
  67.329 -                       "public class Test {\n" +
  67.330 -                       "     private String name = null;\n" +
  67.331 -                       "}\n";
  67.332 -
  67.333 -        performTest(code,
  67.334 -                    Collections.singletonMap("$modifiers$ java.lang.String $name = $initializer;", Arrays.asList("private String name = null;")),
  67.335 -                    Collections.<String>emptyList());
  67.336 -    }
  67.337 -
  67.338 -    public void testMemberSelectWithVariable() throws Exception {
  67.339 -        String code = "package test;\n" +
  67.340 -                      "import java.util.Arrays;\n" +
  67.341 -                      "public class Test {" +
  67.342 -                      "     {\n" +
  67.343 -                      "          foo.bar(0, 3, 4);\n" +
  67.344 -                      "     }\n" +
  67.345 -                      "}\n";
  67.346 -
  67.347 -        performTest(code,
  67.348 -                    Collections.singletonMap("$foo.$bar($p1, $p2$)", Arrays.asList("foo.bar(0, 3, 4)")),
  67.349 -                    Collections.<String>emptyList());
  67.350 -    }
  67.351 -
  67.352 -    public void testCheckIdentifiers1() throws Exception {
  67.353 -        String code = "package test;\n" +
  67.354 -                      "import static java.util.Arrays.*;\n" +
  67.355 -                      "public class Test {" +
  67.356 -                      "     {\n" +
  67.357 -                      "          toString(new int[] {0, 3, 4});\n" +
  67.358 -                      "     }\n" +
  67.359 -                      "}\n";
  67.360 -
  67.361 -        performTest(code,
  67.362 -                    Collections.singletonMap("java.util.Arrays.toString($x)", Arrays.asList("toString(new int[] {0, 3, 4})")),
  67.363 -                    Collections.<String>emptyList());
  67.364 -    }
  67.365 -
  67.366 -    public void testCheckIdentifiers2() throws Exception {
  67.367 -        String code = "package test;\n" +
  67.368 -                      "public class Test {" +
  67.369 -                      "     {\n" +
  67.370 -                      "          toString(new int[] {0, 3, 4});\n" +
  67.371 -                      "     }\n" +
  67.372 -                      "}\n";
  67.373 -
  67.374 -        performTest(code,
  67.375 -                    Collections.<String, List<String>>emptyMap(),
  67.376 -                    Collections.singletonList("java.util.Arrays.toString($x)"));
  67.377 -    }
  67.378 -
  67.379 -    public void testCheckIdentifiers3() throws Exception {
  67.380 -        String code = "package test;\n" +
  67.381 -                      "import static java.util.Arrays.*;\n" +
  67.382 -                      "public class Test {" +
  67.383 -                      "     {\n" +
  67.384 -                      "          Foo.toString(new int[] {0, 3, 4});\n" +
  67.385 -                      "     }\n" +
  67.386 -                      "}\n";
  67.387 -
  67.388 -        performTest(code,
  67.389 -                    Collections.<String, List<String>>emptyMap(),
  67.390 -                    Collections.singletonList("java.util.Arrays.toString($x)"));
  67.391 -    }
  67.392 -
  67.393 -    public void testCheckIdentifiers4() throws Exception {
  67.394 -        String code = "package test;\n" +
  67.395 -                      "public class Test {" +
  67.396 -                      "     {\n" +
  67.397 -                      "          java.util.Arrays.toString(new int[] {0, 3, 4});\n" +
  67.398 -                      "     }\n" +
  67.399 -                      "}\n";
  67.400 -
  67.401 -        performTest(code,
  67.402 -                    Collections.singletonMap("Arrays", Arrays.asList("java.util.Arrays")), //could be imported in the input pattern
  67.403 -                    Collections.<String>emptyList());
  67.404 -    }
  67.405 -
  67.406 -    public void testLambdaInput() throws Exception {
  67.407 -        String code = "package test; public class Test {public void test() { new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { return true; } }; } }";
  67.408 -
  67.409 -        performTest(code,
  67.410 -                    Collections.singletonMap("new $type() {public $retType $name($params$) { $body$; } }", Arrays.asList("new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { return true; } }")),
  67.411 -
  67.412 -                    Collections.<String>emptyList());
  67.413 -    }
  67.414 -
  67.415 -    public void testDoubleCheckedLockingWithVariable() throws Exception {
  67.416 -        String dcl =  "if (o == null) {\n" +
  67.417 -                      "              Object o1 = new Object();\n" +
  67.418 -                      "              synchronized (Test.class) {\n" +
  67.419 -                      "                  if (o == null) {\n" +
  67.420 -                      "                      o = o1;\n" +
  67.421 -                      "                  }\n" +
  67.422 -                      "              }\n" +
  67.423 -                      "          }";
  67.424 -        String code = "package test;\n" +
  67.425 -                      "public class Test {\n" +
  67.426 -                      "     private Object o;\n" +
  67.427 -                      "     private void t() {\n" +
  67.428 -                      "          " + dcl + "\n" +
  67.429 -                      "     }\n" +
  67.430 -                      "}\n";
  67.431 -
  67.432 -        performTest(code,
  67.433 -                    Collections.singletonMap("if ($var == null) {$pref$; synchronized ($lock) { if ($var == null) { $init$; } } }", Arrays.asList(dcl)),
  67.434 -                    Collections.<String>emptyList());
  67.435 -    }
  67.436 -
  67.437 -    public void testMethodName1() throws Exception {
  67.438 -        String code = "package test; public class Test {public void test() { clone(); } }";
  67.439 -
  67.440 -        performTest(code,
  67.441 -                    Collections.<String, List<String>>emptyMap(),
  67.442 -                    Collections.<String>singletonList("public void clone() {$stmts$;}"));
  67.443 -    }
  67.444 -
  67.445 -    public void testMethodName2() throws Exception {
  67.446 -        String code = "package test; public class Test {public void test() { clone(); } }";
  67.447 -
  67.448 -        performTest(code,
  67.449 -                    Collections.singletonMap("public void test() {$stmts$;}", Arrays.asList("public void test() { clone(); }")),
  67.450 -                    Collections.<String>emptyList());
  67.451 -    }
  67.452 -
  67.453 -    private long measure(String baseCode, String toInsert, int repetitions, String pattern) throws Exception {
  67.454 -        int pos = baseCode.indexOf('|');
  67.455 -
  67.456 -        assertTrue(pos != (-1));
  67.457 -
  67.458 -        baseCode = baseCode.replaceAll(Pattern.quote("|"), "");
  67.459 -        
  67.460 -        StringBuilder code = new StringBuilder(baseCode.length() + repetitions * toInsert.length());
  67.461 -
  67.462 -        code.append(baseCode);
  67.463 -        
  67.464 -        while (repetitions-- > 0) {
  67.465 -            code.insert(pos, toInsert);
  67.466 -        }
  67.467 -
  67.468 -        long startTime = System.currentTimeMillis();
  67.469 -
  67.470 -        performTest(code.toString(),
  67.471 -                    Collections.<String, List<String>>emptyMap(),
  67.472 -                    Arrays.asList(pattern));
  67.473 -
  67.474 -        long endTime = System.currentTimeMillis();
  67.475 -
  67.476 -        return endTime - startTime;
  67.477 -    }
  67.478 -
  67.479 -    public void XtestMeasureTime() throws Exception {
  67.480 -        String code = TestUtilities.copyFileToString(new File("/usr/local/home/lahvac/src/nb//outgoing/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java"));
  67.481 -        List<String> patterns = new LinkedList<String>();
  67.482 -
  67.483 -        for (int cntr = 0; cntr < 1000; cntr++) {
  67.484 -            patterns.add("System.err.println($1)");
  67.485 -        }
  67.486 -
  67.487 -        performTest(code,
  67.488 -                    Collections.<String, List<String>>emptyMap(),
  67.489 -                    patterns);
  67.490 -    }
  67.491 -
  67.492 -    public void testMatches1() throws Exception {
  67.493 -        performMatchesTest("package test; public class Test { private void test() { f.isDirectory(); } }", Arrays.asList("$1.isDirectory()", "new ImageIcon($1)"), true);
  67.494 -    }
  67.495 -
  67.496 -    public void testSerialization() throws Exception {
  67.497 -        String text = "package test; public class Test { public void test1(boolean b) { int q; if (b) q = 2; else q = 3; } }";
  67.498 -
  67.499 -        prepareTest("test/Test.java", text);
  67.500 -
  67.501 -        ByteArrayOutputStream out = new ByteArrayOutputStream();
  67.502 -        EncodingContext ec = new EncodingContext(out, false);
  67.503 -
  67.504 -        createSearch().encode(info.getCompilationUnit(), ec);
  67.505 -        
  67.506 -        boolean matches = createSearch().matches(new ByteArrayInputStream(out.toByteArray()), createSearch().create(info, "{ $p$; $T $v; if($a) $v = $b; else $v = $c; $q$; }"));
  67.507 -
  67.508 -        assertTrue(matches);
  67.509 -    }
  67.510 -
  67.511 -    public void testFrequencies() throws Exception {
  67.512 -        String text = "package test; public class Test { public void test1(boolean b) { java.io.File f = null; f.isDirectory(); f.isDirectory(); new javax.swing.ImageIcon(null); } }";
  67.513 -
  67.514 -        prepareTest("test/Test.java", text);
  67.515 -
  67.516 -        ByteArrayOutputStream out = new ByteArrayOutputStream();
  67.517 -        EncodingContext ec = new EncodingContext(out, false);
  67.518 -
  67.519 -        createSearch().encode(info.getCompilationUnit(), ec);
  67.520 -        
  67.521 -        Map<String, Integer> actual = createSearch().matchesWithFrequencies(new ByteArrayInputStream(out.toByteArray()), createSearch().create(info, "$1.isDirectory()", "new ImageIcon($1)"));
  67.522 -        Map<String, Integer> golden = new HashMap<String, Integer>();
  67.523 -
  67.524 -        golden.put("$1.isDirectory()", 2);
  67.525 -        golden.put("new ImageIcon($1)", 1);
  67.526 -
  67.527 -        assertEquals(golden, actual);
  67.528 -    }
  67.529 -
  67.530 -    public void testPatternEncodingAndIdentifiers() throws Exception {
  67.531 -        String text = "package test; public class Test { }";
  67.532 -
  67.533 -        prepareTest("test/Test.java", text);
  67.534 -
  67.535 -        BulkPattern bp = createSearch().create(info, "$0.isDirectory()");
  67.536 -
  67.537 -        assertEquals(Arrays.asList(new HashSet<String>(Arrays.asList("isDirectory"))), bp.getIdentifiers());
  67.538 -        //TODO: the actual code for kinds differs for NFABased search and REBased search:
  67.539 -//        assertEquals(Arrays.asList(new HashSet<String>(Arrays.asList(Kind.METHOD_INVOCATION.name()))), bp.getKinds());
  67.540 -    }
  67.541 -
  67.542 -    protected abstract BulkSearch createSearch();
  67.543 -    
  67.544 -    private void performMatchesTest(String text, List<String> patterns, boolean golden) throws Exception {
  67.545 -        prepareTest("test/Test.java", text);
  67.546 -
  67.547 -        BulkPattern p = createSearch().create(info, patterns);
  67.548 -
  67.549 -        boolean result = createSearch().matches(info, new TreePath(info.getCompilationUnit()), p);
  67.550 -
  67.551 -        assertEquals(golden, result);
  67.552 -    }
  67.553 -    
  67.554 -    private void performTest(String text, Map<String, List<String>> containedPatterns, Collection<String> notContainedPatterns) throws Exception {
  67.555 -        prepareTest("test/Test.java", text);
  67.556 -
  67.557 -        List<String> patterns = new LinkedList<String>();
  67.558 -
  67.559 -        patterns.addAll(containedPatterns.keySet());
  67.560 -        patterns.addAll(notContainedPatterns);
  67.561 -
  67.562 -        long s1 = System.currentTimeMillis();
  67.563 -        BulkPattern p = createSearch().create(info, patterns);
  67.564 -        long e1 = System.currentTimeMillis();
  67.565 -
  67.566 -//        System.err.println("create: " + (e1 - s1));
  67.567 -
  67.568 -        long s2 = System.currentTimeMillis();
  67.569 -        Map<String, Collection<TreePath>> result = createSearch().match(info, new TreePath(info.getCompilationUnit()), p);
  67.570 -        long e2 = System.currentTimeMillis();
  67.571 -
  67.572 -//        System.err.println("match: " + (e2 - s2));
  67.573 -
  67.574 -        assertTrue(result.toString(), result.keySet().containsAll(containedPatterns.keySet()));
  67.575 -
  67.576 -        for (Entry<String, Collection<TreePath>> e : result.entrySet()) {
  67.577 -            List<String> actual = new LinkedList<String>();
  67.578 -
  67.579 -            for (TreePath tp : e.getValue()) {
  67.580 -                assertNotNull(TreePathHandle.create(tp, info).resolve(info));
  67.581 -                
  67.582 -                int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tp.getLeaf());
  67.583 -                int end   = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), tp.getLeaf());
  67.584 -
  67.585 -                actual.add(info.getText().substring(start, end));
  67.586 -            }
  67.587 -
  67.588 -            assertEquals(e.getKey(), containedPatterns.get(e.getKey()), actual);
  67.589 -        }
  67.590 -
  67.591 -
  67.592 -        Set<String> none = new HashSet<String>(result.keySet());
  67.593 -
  67.594 -        none.retainAll(notContainedPatterns);
  67.595 -
  67.596 -        assertTrue(none.isEmpty());
  67.597 -
  67.598 -        if (!verifyIndexingData())
  67.599 -            return ;
  67.600 -        
  67.601 -        //ensure the returned identifiers/treeKinds are correct:
  67.602 -        ByteArrayOutputStream data = new ByteArrayOutputStream();
  67.603 -        EncodingContext ec = new EncodingContext(data, false);
  67.604 -        
  67.605 -        createSearch().encode(info.getCompilationUnit(), ec);
  67.606 -
  67.607 -        for (int i = 0; i < containedPatterns.size(); i++) {
  67.608 -            assertTrue("expected: " + p.getIdentifiers().get(i) + ", but exist only: " + ec.getIdentifiers(), ec.getIdentifiers().containsAll(p.getIdentifiers().get(i)));
  67.609 -            
  67.610 -            for (List<String> phrase : p.getRequiredContent().get(i)) {
  67.611 -                assertTrue("expected: " + phrase + ", but exist only: " + ec.getContent() + "(all phrases: " + p.getRequiredContent().get(i) + ")", Collections.indexOfSubList(ec.getContent(), phrase) != (-1));
  67.612 -            }
  67.613 -        }
  67.614 -
  67.615 -        data.close();
  67.616 -        assertEquals(!containedPatterns.isEmpty(), createSearch().matches(new ByteArrayInputStream(data.toByteArray()), p));
  67.617 -    }
  67.618 -    
  67.619 -    private void prepareTest(String fileName, String code) throws Exception {
  67.620 -        clearWorkDir();
  67.621 -
  67.622 -        FileUtil.refreshFor(File.listRoots());
  67.623 -
  67.624 -        FileObject workFO = FileUtil.toFileObject(getWorkDir());
  67.625 -
  67.626 -        assertNotNull(workFO);
  67.627 -
  67.628 -        workFO.refresh();
  67.629 -
  67.630 -        sourceRoot = workFO.createFolder("src");
  67.631 -        FileObject buildRoot  = workFO.createFolder("build");
  67.632 -        FileObject cache = workFO.createFolder("cache");
  67.633 -
  67.634 -        FileObject data = FileUtil.createData(sourceRoot, fileName);
  67.635 -        File dataFile = FileUtil.toFile(data);
  67.636 -
  67.637 -        assertNotNull(dataFile);
  67.638 -
  67.639 -        TestUtilities.copyStringToFile(dataFile, code);
  67.640 -
  67.641 -        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache);
  67.642 -
  67.643 -        DataObject od = DataObject.find(data);
  67.644 -        EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
  67.645 -
  67.646 -        assertNotNull(ec);
  67.647 -
  67.648 -        doc = ec.openDocument();
  67.649 -        doc.putProperty(Language.class, JavaTokenId.language());
  67.650 -
  67.651 -        JavaSource js = JavaSource.forFileObject(data);
  67.652 -
  67.653 -        assertNotNull(js);
  67.654 -
  67.655 -        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
  67.656 -
  67.657 -        assertNotNull(info);
  67.658 -    }
  67.659 -
  67.660 -    private FileObject sourceRoot;
  67.661 -    private CompilationInfo info;
  67.662 -    private Document doc;
  67.663 -
  67.664 -    protected boolean verifyIndexingData() {
  67.665 -        return true;
  67.666 -    }
  67.667 -}
    68.1 --- a/borrowedtests/src/org/netbeans/modules/java/source/transform/Transformer.java	Fri Jan 27 13:35:56 2012 +0100
    68.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.3 @@ -1,133 +0,0 @@
    68.4 -/*
    68.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    68.6 - *
    68.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    68.8 - *
    68.9 - * The contents of this file are subject to the terms of either the GNU
   68.10 - * General Public License Version 2 only ("GPL") or the Common
   68.11 - * Development and Distribution License("CDDL") (collectively, the
   68.12 - * "License"). You may not use this file except in compliance with the
   68.13 - * License. You can obtain a copy of the License at
   68.14 - * http://www.netbeans.org/cddl-gplv2.html
   68.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   68.16 - * specific language governing permissions and limitations under the
   68.17 - * License.  When distributing the software, include this License Header
   68.18 - * Notice in each file and include the License file at
   68.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   68.20 - * particular file as subject to the "Classpath" exception as provided
   68.21 - * by Sun in the GPL Version 2 section of the License file that
   68.22 - * accompanied this code. If applicable, add the following below the
   68.23 - * License Header, with the fields enclosed by brackets [] replaced by
   68.24 - * your own identifying information:
   68.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   68.26 - *
   68.27 - * Contributor(s):
   68.28 - *
   68.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   68.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
   68.31 - * Microsystems, Inc. All Rights Reserved.
   68.32 - *
   68.33 - * If you wish your version of this file to be governed by only the CDDL
   68.34 - * or only the GPL Version 2, indicate your decision by adding
   68.35 - * "[Contributor] elects to include this software in this distribution
   68.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   68.37 - * single choice of license, a recipient has the option to distribute
   68.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   68.39 - * to extend the choice of license to its licensees as provided above.
   68.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   68.41 - * Version 2 license, then the option applies only if the new code is
   68.42 - * made subject to such option by the copyright holder.
   68.43 - */
   68.44 -
   68.45 -package org.netbeans.modules.java.source.transform;
   68.46 -
   68.47 -import org.netbeans.modules.java.source.query.CommentHandler;
   68.48 -import org.openide.util.NbBundle;
   68.49 -import com.sun.source.tree.*;
   68.50 -import com.sun.source.util.TreeScanner;
   68.51 -import com.sun.tools.javac.model.JavacTypes;
   68.52 -import com.sun.tools.javac.util.Context;
   68.53 -import java.util.List;
   68.54 -import java.util.logging.*;
   68.55 -import javax.lang.model.util.Types;
   68.56 -import org.netbeans.api.java.source.WorkingCopy;
   68.57 -import org.netbeans.modules.java.source.builder.ASTService;
   68.58 -import org.netbeans.modules.java.source.builder.CommentHandlerService;
   68.59 -import org.netbeans.modules.java.source.builder.TreeFactory;
   68.60 -
   68.61 -/**
   68.62 - * A Transformer is an Query that modifies the model.  Model transformation
   68.63 - * is done by a supplied ImmutableTreeTranslator implementation.  A new context
   68.64 - * is set upon successful completion of this Transformer.
   68.65 - */
   68.66 -public abstract class Transformer<R, P> extends TreeScanner<R,P> {
   68.67 -
   68.68 -    CommentHandler commentHandler;
   68.69 -    public TreeFactory make;
   68.70 -    protected WorkingCopy copy;
   68.71 -    protected String refactoringDescription;
   68.72 -    protected Types types; // used by tests
   68.73 -    private String failureMessage;
   68.74 -    protected ASTService model;
   68.75 -
   68.76 -    static final Logger logger = Logger.getLogger("org.netbeans.modules.java.source");
   68.77 -
   68.78 -    public void init() {
   68.79 -    }
   68.80 -
   68.81 -    /**
   68.82 -     * Initialize and associate this Query instance with the
   68.83 -     * specified QueryEnvironment.
   68.84 -     */
   68.85 -    public void attach(Context context, WorkingCopy copy) {
   68.86 -        make = TreeFactory.instance(context);
   68.87 -        types = JavacTypes.instance(context);
   68.88 -        commentHandler = CommentHandlerService.instance(context);
   68.89 -        model = ASTService.instance(context);
   68.90 -        this.copy = copy;
   68.91 -    }
   68.92 -
   68.93 -    /**
   68.94 -     * Release any instance data created during attach() invocation.  This
   68.95 -     * is necessary because the Java reflection support may cache created
   68.96 -     * instances, preventing the session data from being garbage-collected.
   68.97 -     */
   68.98 -    public void release() {
   68.99 -        //changes.release();  // enable when async results are supported
  68.100 -        //result.release()
  68.101 -        make = null;
  68.102 -        types = null;
  68.103 -        this.copy = null;
  68.104 -    }
  68.105 -
  68.106 -    public void destroy() {}
  68.107 -    
  68.108 -    public String getRefactoringDescription() {
  68.109 -        return refactoringDescription != null ? refactoringDescription : "Unnamed Refactoring";
  68.110 -    }
  68.111 -
  68.112 -    public void setRefactoringDescription(String description) {
  68.113 -        refactoringDescription = description;
  68.114 -    }
  68.115 -
  68.116 -    public void apply(Tree t) {
  68.117 -        t.accept(this, null);
  68.118 -    }
  68.119 -
  68.120 -    String getString(String key) {
  68.121 -        return NbBundle.getBundle(Transformer.class).getString(key); //NOI18N
  68.122 -    }
  68.123 -
  68.124 -    /**
  68.125 -     * True if no translation failures occurred.
  68.126 -     */
  68.127 -    protected boolean translationSuccessful() {
  68.128 -        return failureMessage == null;
  68.129 -    }
  68.130 -
  68.131 -    public final void copyCommentTo(Tree from, Tree to) {
  68.132 -        if (from != null && to != null) {
  68.133 -            commentHandler.copyComments(from, to);
  68.134 -        }
  68.135 -    }
  68.136 -}
    69.1 --- a/borrowedtests/src/org/netbeans/modules/java/source/usages/IndexUtil.java	Fri Jan 27 13:35:56 2012 +0100
    69.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.3 @@ -1,58 +0,0 @@
    69.4 -/*
    69.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    69.6 - *
    69.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    69.8 - *
    69.9 - * The contents of this file are subject to the terms of either the GNU
   69.10 - * General Public License Version 2 only ("GPL") or the Common
   69.11 - * Development and Distribution License("CDDL") (collectively, the
   69.12 - * "License"). You may not use this file except in compliance with the
   69.13 - * License. You can obtain a copy of the License at
   69.14 - * http://www.netbeans.org/cddl-gplv2.html
   69.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   69.16 - * specific language governing permissions and limitations under the
   69.17 - * License.  When distributing the software, include this License Header
   69.18 - * Notice in each file and include the License file at
   69.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   69.20 - * particular file as subject to the "Classpath" exception as provided
   69.21 - * by Sun in the GPL Version 2 section of the License file that
   69.22 - * accompanied this code. If applicable, add the following below the
   69.23 - * License Header, with the fields enclosed by brackets [] replaced by
   69.24 - * your own identifying information:
   69.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   69.26 - *
   69.27 - * Contributor(s):
   69.28 - *
   69.29 - * The Original Software is NetBeans. The Initial Developer of the Original
   69.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
   69.31 - * Microsystems, Inc. All Rights Reserved.
   69.32 - *
   69.33 - * If you wish your version of this file to be governed by only the CDDL
   69.34 - * or only the GPL Version 2, indicate your decision by adding
   69.35 - * "[Contributor] elects to include this software in this distribution
   69.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   69.37 - * single choice of license, a recipient has the option to distribute
   69.38 - * your version of this file under either the CDDL, the GPL Version 2 or
   69.39 - * to extend the choice of license to its licensees as provided above.
   69.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   69.41 - * Version 2 license, then the option applies only if the new code is
   69.42 - * made subject to such option by the copyright holder.
   69.43 - */
   69.44 -
   69.45 -package org.netbeans.modules.java.source.usages;
   69.46 -
   69.47 -import java.io.File;
   69.48 -import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   69.49 -import org.openide.filesystems.FileUtil;
   69.50 -
   69.51 -/**
   69.52 - *
   69.53 - * @author Tomas Zezula
   69.54 - */
   69.55 -public class IndexUtil {
   69.56 -
   69.57 -    public static void setCacheFolder (final File cacheFolder) {
   69.58 -        CacheFolder.setCacheFolder(FileUtil.toFileObject(cacheFolder));
   69.59 -    }
   69.60 -
   69.61 -}
    70.1 --- a/borrowedtests/src/org/netbeans/modules/parsing/impl/indexing/MimeTypes.java	Fri Jan 27 13:35:56 2012 +0100
    70.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.3 @@ -1,66 +0,0 @@
    70.4 -/*
    70.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    70.6 - *
    70.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    70.8 - *
    70.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   70.10 - * Other names may be trademarks of their respective owners.
   70.11 - *
   70.12 - * The contents of this file are subject to the terms of either the GNU
   70.13 - * General Public License Version 2 only ("GPL") or the Common
   70.14 - * Development and Distribution License("CDDL") (collectively, the
   70.15 - * "License"). You may not use this file except in compliance with the
   70.16 - * License. You can obtain a copy of the License at
   70.17 - * http://www.netbeans.org/cddl-gplv2.html
   70.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   70.19 - * specific language governing permissions and limitations under the
   70.20 - * License.  When distributing the software, include this License Header
   70.21 - * Notice in each file and include the License file at
   70.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   70.23 - * particular file as subject to the "Classpath" exception as provided
   70.24 - * by Oracle in the GPL Version 2 section of the License file that
   70.25 - * accompanied this code. If applicable, add the following below the
   70.26 - * License Header, with the fields enclosed by brackets [] replaced by
   70.27 - * your own identifying information:
   70.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   70.29 - *
   70.30 - * If you wish your version of this file to be governed by only the CDDL
   70.31 - * or only the GPL Version 2, indicate your decision by adding
   70.32 - * "[Contributor] elects to include this software in this distribution
   70.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   70.34 - * single choice of license, a recipient has the option to distribute
   70.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   70.36 - * to extend the choice of license to its licensees as provided above.
   70.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   70.38 - * Version 2 license, then the option applies only if the new code is
   70.39 - * made subject to such option by the copyright holder.
   70.40 - *
   70.41 - * Contributor(s):
   70.42 - *
   70.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
   70.44 - */
   70.45 -package org.netbeans.modules.parsing.impl.indexing;
   70.46 -
   70.47 -import java.util.Set;
   70.48 -import org.netbeans.api.annotations.common.CheckForNull;
   70.49 -import org.netbeans.api.annotations.common.NonNull;
   70.50 -import org.openide.util.Parameters;
   70.51 -
   70.52 -/**
   70.53 - *
   70.54 - * @author Tomas Zezula
   70.55 - */
   70.56 -public class MimeTypes {
   70.57 -
   70.58 -    private MimeTypes() {}
   70.59 -
   70.60 -    public static void setAllMimeTypes(@NonNull final Set<String> allMimeTypes) {
   70.61 -        Parameters.notNull("allMimeTypes", allMimeTypes);   //NOI18N
   70.62 -        Util.allMimeTypes = allMimeTypes;
   70.63 -    }
   70.64 -
   70.65 -    @CheckForNull
   70.66 -    public static Set<String> getAllMimeTypes() {
   70.67 -        return Util.allMimeTypes;
   70.68 -    }
   70.69 -}
    71.1 --- a/borrowedtests/src/org/openide/util/test/AnnotationProcessorTestUtils.java	Fri Jan 27 13:35:56 2012 +0100
    71.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.3 @@ -1,139 +0,0 @@
    71.4 -/*
    71.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    71.6 - *
    71.7 - * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
    71.8 - *
    71.9 - * The contents of this file are subject to the terms of either the GNU
   71.10 - * General Public License Version 2 only ("GPL") or the Common
   71.11 - * Development and Distribution License("CDDL") (collectively, the
   71.12 - * "License"). You may not use this file except in compliance with the
   71.13 - * License. You can obtain a copy of the License at
   71.14 - * http://www.netbeans.org/cddl-gplv2.html
   71.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   71.16 - * specific language governing permissions and limitations under the
   71.17 - * License.  When distributing the software, include this License Header
   71.18 - * Notice in each file and include the License file at
   71.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   71.20 - * particular file as subject to the "Classpath" exception as provided
   71.21 - * by Sun in the GPL Version 2 section of the License file that
   71.22 - * accompanied this code. If applicable, add the following below the
   71.23 - * License Header, with the fields enclosed by brackets [] replaced by
   71.24 - * your own identifying information:
   71.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   71.26 - *
   71.27 - * If you wish your version of this file to be governed by only the CDDL
   71.28 - * or only the GPL Version 2, indicate your decision by adding
   71.29 - * "[Contributor] elects to include this software in this distribution
   71.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   71.31 - * single choice of license, a recipient has the option to distribute
   71.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   71.33 - * to extend the choice of license to its licensees as provided above.
   71.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   71.35 - * Version 2 license, then the option applies only if the new code is
   71.36 - * made subject to such option by the copyright holder.
   71.37 - *
   71.38 - * Contributor(s):
   71.39 - *
   71.40 - * Portions Copyrighted 2008 Sun Microsystems, Inc.
   71.41 - */
   71.42 -
   71.43 -package org.openide.util.test;
   71.44 -
   71.45 -import java.io.File;
   71.46 -import java.io.FileWriter;
   71.47 -import java.io.IOException;
   71.48 -import java.io.OutputStream;
   71.49 -import java.io.PrintWriter;
   71.50 -import java.io.Writer;
   71.51 -import java.util.ArrayList;
   71.52 -import java.util.List;
   71.53 -import java.util.regex.Pattern;
   71.54 -import javax.tools.JavaCompiler;
   71.55 -import javax.tools.ToolProvider;
   71.56 -import junit.framework.Assert;
   71.57 -
   71.58 -/**
   71.59 - * Utilities useful to those testing JSR 269 annotation processors.
   71.60 - * <p>If you just want to test that the output of the processor is correct,
   71.61 - * you do not need to do anything special:
   71.62 - * just use the annotation on some sample classes nested inside your unit test.
   71.63 - * They will be processed, and you check that your SPI loads them correctly.
   71.64 - * These utilities are useful mainly in case you want to check that the processor
   71.65 - * rejects erroneous sources, and that any messages it prints are reasonable;
   71.66 - * that it behaves correctly on incremental compilations; etc.
   71.67 - */
   71.68 -public class AnnotationProcessorTestUtils {
   71.69 -
   71.70 -    private AnnotationProcessorTestUtils() {}
   71.71 -
   71.72 -    /**
   71.73 -     * Create a source file.
   71.74 -     * @param dir source root
   71.75 -     * @param clazz a fully-qualified class name
   71.76 -     * @param content lines of text (skip package decl)
   71.77 -     */
   71.78 -    public static void makeSource(File dir, String clazz, String... content) throws IOException {
   71.79 -        File f = new File(dir, clazz.replace('.', File.separatorChar) + ".java");
   71.80 -        f.getParentFile().mkdirs();
   71.81 -        Writer w = new FileWriter(f);
   71.82 -        try {
   71.83 -            PrintWriter pw = new PrintWriter(w);
   71.84 -            String pkg = clazz.replaceFirst("\\.[^.]+$", "");
   71.85 -            if (!pkg.equals(clazz)) {
   71.86 -                pw.println("package " + pkg + ";");
   71.87 -            }
   71.88 -            for (String line : content) {
   71.89 -                pw.println(line);
   71.90 -            }
   71.91 -            pw.flush();
   71.92 -        } finally {
   71.93 -            w.close();
   71.94 -        }
   71.95 -    }
   71.96 -
   71.97 -    /**
   71.98 -     * Run the Java compiler.
   71.99 -     * (A JSR 199 implementation must be available.)
  71.100 -     * @param src a source root (runs javac on all *.java it finds matching {@code srcIncludes})
  71.101 -     * @param srcIncludes a pattern of source files names without path to compile (useful for testing incremental compiles), or null for all
  71.102 -     * @param dest a dest dir to compile classes to
  71.103 -     * @param cp classpath entries; if null, use Java classpath of test
  71.104 -     * @param stderr output stream to print messages to, or null for test console (i.e. do not capture)
  71.105 -     * @return true if compilation succeeded, false if it failed
  71.106 -     */
  71.107 -    public static boolean runJavac(File src, String srcIncludes, File dest, File[] cp, OutputStream stderr) {
  71.108 -        List<String> args = new ArrayList<String>();
  71.109 -        args.add("-classpath");
  71.110 -        if (cp != null) {
  71.111 -            StringBuffer b = new StringBuffer();
  71.112 -            for (File entry : cp) {
  71.113 -                b.append(File.pathSeparatorChar);
  71.114 -                b.append(entry.getAbsolutePath());
  71.115 -            }
  71.116 -            args.add(b.toString());
  71.117 -        } else {
  71.118 -            args.add(System.getProperty("java.class.path"));
  71.119 -        }
  71.120 -        args.add("-d");
  71.121 -        args.add(dest.getAbsolutePath());
  71.122 -        args.add("-sourcepath");
  71.123 -        args.add(src.getAbsolutePath());
  71.124 -        dest.mkdirs();
  71.125 -        scan(args, src, srcIncludes);
  71.126 -        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  71.127 -        Assert.assertNotNull("no JSR 199 compiler impl found; try e.g.: " +
  71.128 -                "test.unit.run.cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar", compiler);
  71.129 -        //System.err.println("running javac with args: " + args);
  71.130 -        return compiler.run(null, null, stderr, args.toArray(new String[args.size()])) == 0;
  71.131 -    }
  71.132 -    private static void scan(List<String> names, File f, String includes) {
  71.133 -        if (f.isDirectory()) {
  71.134 -            for (File kid : f.listFiles()) {
  71.135 -                scan(names, kid, includes);
  71.136 -            }
  71.137 -        } else if (f.getName().endsWith(".java") && (includes == null || Pattern.compile(includes).matcher(f.getName()).find())) {
  71.138 -            names.add(f.getAbsolutePath());
  71.139 -        }
  71.140 -    }
  71.141 -
  71.142 -}
    72.1 --- a/build.xml	Fri Jan 27 13:35:56 2012 +0100
    72.2 +++ b/build.xml	Sat Feb 11 18:35:10 2012 +0100
    72.3 @@ -43,6 +43,16 @@
    72.4      <target name="test" depends="suite.test">
    72.5          <subant target="test" buildpath="${server.modules}" inheritall="false"/>
    72.6      </target>
    72.7 +    
    72.8 +    <property name="subprojects" value="remoting/common:remoting/ide:remoting/server/indexer:remoting/server/web/web.main:language/ide:duplicates/ide" />
    72.9 +
   72.10 +    <target name="build-subprojects">
   72.11 +        <subant target="build" buildpath="${subprojects}" inheritall="false"/>
   72.12 +    </target>
   72.13 +
   72.14 +    <target name="test-subprojects">
   72.15 +        <subant target="test" buildpath="${subprojects}" inheritall="false"/>
   72.16 +    </target>
   72.17  
   72.18  <!--    <target name="coverage-report" depends="testcoverage-suite.coverage-report">
   72.19          <subant target="test" buildpath="${server.modules}" inheritall="false"/>
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/duplicates/ide/build.xml	Sat Feb 11 18:35:10 2012 +0100
    73.3 @@ -0,0 +1,8 @@
    73.4 +<?xml version="1.0" encoding="UTF-8"?>
    73.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
    73.6 +<!-- for some information on what you could do (e.g. targets to override). -->
    73.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
    73.8 +<project name="duplicates-ide" basedir=".">
    73.9 +    <description>Builds the module suite ide.</description>
   73.10 +    <import file="nbproject/build-impl.xml"/>
   73.11 +</project>
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/duplicates/ide/impl/build.xml	Sat Feb 11 18:35:10 2012 +0100
    74.3 @@ -0,0 +1,9 @@
    74.4 +<?xml version="1.0" encoding="UTF-8"?>
    74.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
    74.6 +<!-- for some information on what you could do (e.g. targets to override). -->
    74.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
    74.8 +<project name="org.netbeans.modules.jackpot30.duplicates.impl" default="netbeans" basedir=".">
    74.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.duplicates.impl.</description>
   74.10 +    <import file="nbproject/build-impl.xml"/>
   74.11 +    <import file="../../../findbugs-import.xml" />
   74.12 +</project>
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/duplicates/ide/impl/manifest.mf	Sat Feb 11 18:35:10 2012 +0100
    75.3 @@ -0,0 +1,5 @@
    75.4 +Manifest-Version: 1.0
    75.5 +OpenIDE-Module: org.netbeans.modules.jackpot30.duplicates.impl
    75.6 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/duplicates/impl/Bundle.properties
    75.7 +OpenIDE-Module-Specification-Version: 1.0
    75.8 +
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/duplicates/ide/impl/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
    76.3 @@ -0,0 +1,45 @@
    76.4 +<?xml version="1.0" encoding="UTF-8"?>
    76.5 +<!--
    76.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
    76.7 +***         EDIT ../build.xml INSTEAD         ***
    76.8 +-->
    76.9 +<project name="org.netbeans.modules.jackpot30.duplicates.impl-impl" basedir="..">
   76.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
   76.11 +        <condition>
   76.12 +            <not>
   76.13 +                <antversion atleast="1.7.1"/>
   76.14 +            </not>
   76.15 +        </condition>
   76.16 +    </fail>
   76.17 +    <property file="nbproject/private/suite-private.properties"/>
   76.18 +    <property file="nbproject/suite.properties"/>
   76.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
   76.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
   76.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
   76.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
   76.23 +        <attribute name="name"/>
   76.24 +        <attribute name="value"/>
   76.25 +        <sequential>
   76.26 +            <property name="@{name}" value="${@{value}}"/>
   76.27 +        </sequential>
   76.28 +    </macrodef>
   76.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
   76.30 +        <attribute name="property"/>
   76.31 +        <attribute name="value"/>
   76.32 +        <sequential>
   76.33 +            <property name="@{property}" value="@{value}"/>
   76.34 +        </sequential>
   76.35 +    </macrodef>
   76.36 +    <property file="${user.properties.file}"/>
   76.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   76.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   76.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
   76.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
   76.41 +        <condition>
   76.42 +            <not>
   76.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
   76.44 +            </not>
   76.45 +        </condition>
   76.46 +    </fail>
   76.47 +    <import file="${harness.dir}/build.xml"/>
   76.48 +</project>
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/duplicates/ide/impl/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
    77.3 @@ -0,0 +1,8 @@
    77.4 +build.xml.data.CRC32=f3f3f30d
    77.5 +build.xml.script.CRC32=b45f306d
    77.6 +build.xml.stylesheet.CRC32=a56c6a5b@2.49
    77.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
    77.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    77.9 +nbproject/build-impl.xml.data.CRC32=f3f3f30d
   77.10 +nbproject/build-impl.xml.script.CRC32=5fd8da83
   77.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/duplicates/ide/impl/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
    78.3 @@ -0,0 +1,2 @@
    78.4 +javac.source=1.6
    78.5 +javac.compilerargs=-Xlint -Xlint:-serial
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/duplicates/ide/impl/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
    79.3 @@ -0,0 +1,390 @@
    79.4 +<?xml version="1.0" encoding="UTF-8"?>
    79.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
    79.6 +    <type>org.netbeans.modules.apisupport.project</type>
    79.7 +    <configuration>
    79.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
    79.9 +            <code-name-base>org.netbeans.modules.jackpot30.duplicates.impl</code-name-base>
   79.10 +            <suite-component/>
   79.11 +            <module-dependencies>
   79.12 +                <dependency>
   79.13 +                    <code-name-base>org.jdesktop.layout</code-name-base>
   79.14 +                    <build-prerequisite/>
   79.15 +                    <compile-dependency/>
   79.16 +                    <run-dependency>
   79.17 +                        <release-version>1</release-version>
   79.18 +                        <specification-version>1.7.0.103</specification-version>
   79.19 +                    </run-dependency>
   79.20 +                </dependency>
   79.21 +                <dependency>
   79.22 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
   79.23 +                    <build-prerequisite/>
   79.24 +                    <compile-dependency/>
   79.25 +                    <run-dependency>
   79.26 +                        <release-version>1</release-version>
   79.27 +                        <specification-version>1.0</specification-version>
   79.28 +                    </run-dependency>
   79.29 +                </dependency>
   79.30 +                <dependency>
   79.31 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
   79.32 +                    <build-prerequisite/>
   79.33 +                    <compile-dependency/>
   79.34 +                    <run-dependency>
   79.35 +                        <release-version>1</release-version>
   79.36 +                        <specification-version>1.19</specification-version>
   79.37 +                    </run-dependency>
   79.38 +                </dependency>
   79.39 +                <dependency>
   79.40 +                    <code-name-base>org.netbeans.api.progress</code-name-base>
   79.41 +                    <build-prerequisite/>
   79.42 +                    <compile-dependency/>
   79.43 +                    <run-dependency>
   79.44 +                        <release-version>1</release-version>
   79.45 +                        <specification-version>1.13.0.1</specification-version>
   79.46 +                    </run-dependency>
   79.47 +                </dependency>
   79.48 +                <dependency>
   79.49 +                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
   79.50 +                    <build-prerequisite/>
   79.51 +                    <compile-dependency/>
   79.52 +                    <run-dependency>
   79.53 +                        <specification-version>7.5.0.3</specification-version>
   79.54 +                    </run-dependency>
   79.55 +                </dependency>
   79.56 +                <dependency>
   79.57 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
   79.58 +                    <build-prerequisite/>
   79.59 +                    <compile-dependency/>
   79.60 +                    <run-dependency>
   79.61 +                        <release-version>1</release-version>
   79.62 +                        <implementation-version/>
   79.63 +                    </run-dependency>
   79.64 +                </dependency>
   79.65 +                <dependency>
   79.66 +                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
   79.67 +                    <build-prerequisite/>
   79.68 +                    <compile-dependency/>
   79.69 +                    <run-dependency>
   79.70 +                        <release-version>1-3</release-version>
   79.71 +                        <specification-version>2.13</specification-version>
   79.72 +                    </run-dependency>
   79.73 +                </dependency>
   79.74 +                <dependency>
   79.75 +                    <code-name-base>org.netbeans.modules.diff</code-name-base>
   79.76 +                    <build-prerequisite/>
   79.77 +                    <compile-dependency/>
   79.78 +                    <run-dependency>
   79.79 +                        <release-version>1</release-version>
   79.80 +                        <implementation-version/>
   79.81 +                    </run-dependency>
   79.82 +                </dependency>
   79.83 +                <dependency>
   79.84 +                    <code-name-base>org.netbeans.modules.editor</code-name-base>
   79.85 +                    <build-prerequisite/>
   79.86 +                    <compile-dependency/>
   79.87 +                    <run-dependency>
   79.88 +                        <release-version>3</release-version>
   79.89 +                        <specification-version>1.56.0.5.13.6</specification-version>
   79.90 +                    </run-dependency>
   79.91 +                </dependency>
   79.92 +                <dependency>
   79.93 +                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
   79.94 +                    <build-prerequisite/>
   79.95 +                    <compile-dependency/>
   79.96 +                    <run-dependency>
   79.97 +                        <release-version>1-3</release-version>
   79.98 +                        <specification-version>1.38.0.9.2</specification-version>
   79.99 +                    </run-dependency>
  79.100 +                </dependency>
  79.101 +                <dependency>
  79.102 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
  79.103 +                    <build-prerequisite/>
  79.104 +                    <compile-dependency/>
  79.105 +                    <run-dependency>
  79.106 +                        <release-version>1</release-version>
  79.107 +                        <specification-version>1.13.0.2</specification-version>
  79.108 +                    </run-dependency>
  79.109 +                </dependency>
  79.110 +                <dependency>
  79.111 +                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
  79.112 +                    <build-prerequisite/>
  79.113 +                    <compile-dependency/>
  79.114 +                    <run-dependency>
  79.115 +                        <release-version>1</release-version>
  79.116 +                        <specification-version>1.12</specification-version>
  79.117 +                    </run-dependency>
  79.118 +                </dependency>
  79.119 +                <dependency>
  79.120 +                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
  79.121 +                    <build-prerequisite/>
  79.122 +                    <compile-dependency/>
  79.123 +                    <run-dependency>
  79.124 +                        <release-version>1</release-version>
  79.125 +                        <specification-version>1.25</specification-version>
  79.126 +                    </run-dependency>
  79.127 +                </dependency>
  79.128 +                <dependency>
  79.129 +                    <code-name-base>org.netbeans.modules.jackpot30.common</code-name-base>
  79.130 +                    <build-prerequisite/>
  79.131 +                    <compile-dependency/>
  79.132 +                    <run-dependency>
  79.133 +                        <specification-version>1.0</specification-version>
  79.134 +                    </run-dependency>
  79.135 +                </dependency>
  79.136 +                <dependency>
  79.137 +                    <code-name-base>org.netbeans.modules.jackpot30.remoting.api</code-name-base>
  79.138 +                    <build-prerequisite/>
  79.139 +                    <compile-dependency/>
  79.140 +                    <run-dependency>
  79.141 +                        <specification-version>1.8</specification-version>
  79.142 +                    </run-dependency>
  79.143 +                </dependency>
  79.144 +                <dependency>
  79.145 +                    <code-name-base>org.netbeans.modules.java.editor</code-name-base>
  79.146 +                    <build-prerequisite/>
  79.147 +                    <compile-dependency/>
  79.148 +                    <run-dependency>
  79.149 +                        <release-version>1</release-version>
  79.150 +                        <implementation-version/>
  79.151 +                    </run-dependency>
  79.152 +                </dependency>
  79.153 +                <dependency>
  79.154 +                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
  79.155 +                    <build-prerequisite/>
  79.156 +                    <compile-dependency/>
  79.157 +                    <run-dependency>
  79.158 +                        <release-version>1</release-version>
  79.159 +                        <implementation-version/>
  79.160 +                    </run-dependency>
  79.161 +                </dependency>
  79.162 +                <dependency>
  79.163 +                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
  79.164 +                    <build-prerequisite/>
  79.165 +                    <compile-dependency/>
  79.166 +                    <run-dependency>
  79.167 +                        <release-version>1</release-version>
  79.168 +                        <specification-version>1.9</specification-version>
  79.169 +                    </run-dependency>
  79.170 +                </dependency>
  79.171 +                <dependency>
  79.172 +                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
  79.173 +                    <build-prerequisite/>
  79.174 +                    <compile-dependency/>
  79.175 +                    <run-dependency>
  79.176 +                        <release-version>1</release-version>
  79.177 +                        <specification-version>1.12</specification-version>
  79.178 +                    </run-dependency>
  79.179 +                </dependency>
  79.180 +                <dependency>
  79.181 +                    <code-name-base>org.netbeans.modules.java.preprocessorbridge</code-name-base>
  79.182 +                    <build-prerequisite/>
  79.183 +                    <compile-dependency/>
  79.184 +                    <run-dependency>
  79.185 +                        <implementation-version/>
  79.186 +                    </run-dependency>
  79.187 +                </dependency>
  79.188 +                <dependency>
  79.189 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
  79.190 +                    <build-prerequisite/>
  79.191 +                    <compile-dependency/>
  79.192 +                    <run-dependency>
  79.193 +                        <implementation-version/>
  79.194 +                    </run-dependency>
  79.195 +                </dependency>
  79.196 +                <dependency>
  79.197 +                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
  79.198 +                    <build-prerequisite/>
  79.199 +                    <compile-dependency/>
  79.200 +                    <run-dependency>
  79.201 +                        <release-version>2</release-version>
  79.202 +                        <specification-version>1.34</specification-version>
  79.203 +                    </run-dependency>
  79.204 +                </dependency>
  79.205 +                <dependency>
  79.206 +                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
  79.207 +                    <build-prerequisite/>
  79.208 +                    <compile-dependency/>
  79.209 +                    <run-dependency>
  79.210 +                        <release-version>1</release-version>
  79.211 +                        <specification-version>1.20</specification-version>
  79.212 +                    </run-dependency>
  79.213 +                </dependency>
  79.214 +                <dependency>
  79.215 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
  79.216 +                    <build-prerequisite/>
  79.217 +                    <compile-dependency/>
  79.218 +                    <run-dependency>
  79.219 +                        <release-version>1</release-version>
  79.220 +                        <implementation-version/>
  79.221 +                    </run-dependency>
  79.222 +                </dependency>
  79.223 +                <dependency>
  79.224 +                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
  79.225 +                    <build-prerequisite/>
  79.226 +                    <compile-dependency/>
  79.227 +                    <run-dependency>
  79.228 +                        <release-version>1</release-version>
  79.229 +                        <specification-version>1.24</specification-version>
  79.230 +                    </run-dependency>
  79.231 +                </dependency>
  79.232 +                <dependency>
  79.233 +                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
  79.234 +                    <build-prerequisite/>
  79.235 +                    <compile-dependency/>
  79.236 +                    <run-dependency>
  79.237 +                        <release-version>1</release-version>
  79.238 +                        <specification-version>1.35.0.6</specification-version>
  79.239 +                    </run-dependency>
  79.240 +                </dependency>
  79.241 +                <dependency>
  79.242 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
  79.243 +                    <build-prerequisite/>
  79.244 +                    <compile-dependency/>
  79.245 +                    <run-dependency>
  79.246 +                        <release-version>1</release-version>
  79.247 +                        <specification-version>1.15</specification-version>
  79.248 +                    </run-dependency>
  79.249 +                </dependency>
  79.250 +                <dependency>
  79.251 +                    <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
  79.252 +                    <build-prerequisite/>
  79.253 +                    <compile-dependency/>
  79.254 +                    <run-dependency>
  79.255 +                        <specification-version>1.6</specification-version>
  79.256 +                    </run-dependency>
  79.257 +                </dependency>
  79.258 +                <dependency>
  79.259 +                    <code-name-base>org.netbeans.modules.refactoring.java</code-name-base>
  79.260 +                    <build-prerequisite/>
  79.261 +                    <compile-dependency/>
  79.262 +                    <run-dependency>
  79.263 +                        <release-version>1</release-version>
  79.264 +                        <specification-version>1.6</specification-version>
  79.265 +                    </run-dependency>
  79.266 +                </dependency>
  79.267 +                <dependency>
  79.268 +                    <code-name-base>org.netbeans.modules.sendopts</code-name-base>
  79.269 +                    <build-prerequisite/>
  79.270 +                    <compile-dependency/>
  79.271 +                    <run-dependency>
  79.272 +                        <release-version>2</release-version>
  79.273 +                        <specification-version>2.4</specification-version>
  79.274 +                    </run-dependency>
  79.275 +                </dependency>
  79.276 +                <dependency>
  79.277 +                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
  79.278 +                    <build-prerequisite/>
  79.279 +                    <compile-dependency/>
  79.280 +                    <run-dependency>
  79.281 +                        <release-version>0-1</release-version>
  79.282 +                        <specification-version>1.7.0.7.2</specification-version>
  79.283 +                    </run-dependency>
  79.284 +                </dependency>
  79.285 +                <dependency>
  79.286 +                    <code-name-base>org.openide.awt</code-name-base>
  79.287 +                    <build-prerequisite/>
  79.288 +                    <compile-dependency/>
  79.289 +                    <run-dependency>
  79.290 +                        <specification-version>7.7.0.1</specification-version>
  79.291 +                    </run-dependency>
  79.292 +                </dependency>
  79.293 +                <dependency>
  79.294 +                    <code-name-base>org.openide.dialogs</code-name-base>
  79.295 +                    <build-prerequisite/>
  79.296 +                    <compile-dependency/>
  79.297 +                    <run-dependency>
  79.298 +                        <specification-version>7.10</specification-version>
  79.299 +                    </run-dependency>
  79.300 +                </dependency>
  79.301 +                <dependency>
  79.302 +                    <code-name-base>org.openide.filesystems</code-name-base>
  79.303 +                    <build-prerequisite/>
  79.304 +                    <compile-dependency/>
  79.305 +                    <run-dependency>
  79.306 +                        <specification-version>7.21.0.1.1</specification-version>
  79.307 +                    </run-dependency>
  79.308 +                </dependency>
  79.309 +                <dependency>
  79.310 +                    <code-name-base>org.openide.loaders</code-name-base>
  79.311 +                    <build-prerequisite/>
  79.312 +                    <compile-dependency/>
  79.313 +                    <run-dependency>
  79.314 +                        <specification-version>7.5</specification-version>
  79.315 +                    </run-dependency>
  79.316 +                </dependency>
  79.317 +                <dependency>
  79.318 +                    <code-name-base>org.openide.modules</code-name-base>
  79.319 +                    <build-prerequisite/>
  79.320 +                    <compile-dependency/>
  79.321 +                    <run-dependency>
  79.322 +                        <specification-version>7.10</specification-version>
  79.323 +                    </run-dependency>
  79.324 +                </dependency>
  79.325 +                <dependency>
  79.326 +                    <code-name-base>org.openide.nodes</code-name-base>
  79.327 +                    <build-prerequisite/>
  79.328 +                    <compile-dependency/>
  79.329 +                    <run-dependency>
  79.330 +                        <specification-version>7.9.0.1</specification-version>
  79.331 +                    </run-dependency>
  79.332 +                </dependency>
  79.333 +                <dependency>
  79.334 +                    <code-name-base>org.openide.text</code-name-base>
  79.335 +                    <build-prerequisite/>
  79.336 +                    <compile-dependency/>
  79.337 +                    <run-dependency>
  79.338 +                        <specification-version>6.22</specification-version>
  79.339 +                    </run-dependency>
  79.340 +                </dependency>
  79.341 +                <dependency>
  79.342 +                    <code-name-base>org.openide.util</code-name-base>
  79.343 +                    <build-prerequisite/>
  79.344 +                    <compile-dependency/>
  79.345 +                    <run-dependency>
  79.346 +                        <specification-version>8.0</specification-version>
  79.347 +                    </run-dependency>
  79.348 +                </dependency>
  79.349 +                <dependency>
  79.350 +                    <code-name-base>org.openide.util.lookup</code-name-base>
  79.351 +                    <build-prerequisite/>
  79.352 +                    <compile-dependency/>
  79.353 +                    <run-dependency>
  79.354 +                        <specification-version>8.0.0.1</specification-version>
  79.355 +                    </run-dependency>
  79.356 +                </dependency>
  79.357 +                <dependency>
  79.358 +                    <code-name-base>org.openide.windows</code-name-base>
  79.359 +                    <build-prerequisite/>
  79.360 +                    <compile-dependency/>
  79.361 +                    <run-dependency>
  79.362 +                        <specification-version>6.27</specification-version>
  79.363 +                    </run-dependency>
  79.364 +                </dependency>
  79.365 +            </module-dependencies>
  79.366 +            <test-dependencies>
  79.367 +                <test-type>
  79.368 +                    <name>unit</name>
  79.369 +                    <test-dependency>
  79.370 +                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
  79.371 +                        <compile-dependency/>
  79.372 +                    </test-dependency>
  79.373 +                    <test-dependency>
  79.374 +                        <code-name-base>org.netbeans.modules.jackpot30.common.test</code-name-base>
  79.375 +                        <recursive/>
  79.376 +                        <compile-dependency/>
  79.377 +                    </test-dependency>
  79.378 +                    <test-dependency>
  79.379 +                        <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
  79.380 +                        <recursive/>
  79.381 +                        <compile-dependency/>
  79.382 +                    </test-dependency>
  79.383 +                    <test-dependency>
  79.384 +                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
  79.385 +                        <recursive/>
  79.386 +                        <compile-dependency/>
  79.387 +                    </test-dependency>
  79.388 +                </test-type>
  79.389 +            </test-dependencies>
  79.390 +            <public-packages/>
  79.391 +        </data>
  79.392 +    </configuration>
  79.393 +</project>
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/duplicates/ide/impl/nbproject/suite.properties	Sat Feb 11 18:35:10 2012 +0100
    80.3 @@ -0,0 +1,1 @@
    80.4 +suite.dir=${basedir}/..
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/duplicates/impl/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
    81.3 @@ -0,0 +1,1 @@
    81.4 +OpenIDE-Module-Name=Jackpot 3.0 Duplicates Impl
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
    82.3 @@ -0,0 +1,3 @@
    82.4 +CTL_GlobalFindDuplicates=Global Find Duplicates
    82.5 +DuplicatesListPanel.findMore.text=<html><body><a href="">Look for More</a>
    82.6 +DuplicatesListPanel.progressLabel.text=
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java	Sat Feb 11 18:35:10 2012 +0100
    83.3 @@ -0,0 +1,458 @@
    83.4 +/*
    83.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    83.6 + *
    83.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    83.8 + *
    83.9 + * The contents of this file are subject to the terms of either the GNU
   83.10 + * General Public License Version 2 only ("GPL") or the Common
   83.11 + * Development and Distribution License("CDDL") (collectively, the
   83.12 + * "License"). You may not use this file except in compliance with the
   83.13 + * License. You can obtain a copy of the License at
   83.14 + * http://www.netbeans.org/cddl-gplv2.html
   83.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   83.16 + * specific language governing permissions and limitations under the
   83.17 + * License.  When distributing the software, include this License Header
   83.18 + * Notice in each file and include the License file at
   83.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   83.20 + * particular file as subject to the "Classpath" exception as provided
   83.21 + * by Sun in the GPL Version 2 section of the License file that
   83.22 + * accompanied this code. If applicable, add the following below the
   83.23 + * License Header, with the fields enclosed by brackets [] replaced by
   83.24 + * your own identifying information:
   83.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   83.26 + *
   83.27 + * If you wish your version of this file to be governed by only the CDDL
   83.28 + * or only the GPL Version 2, indicate your decision by adding
   83.29 + * "[Contributor] elects to include this software in this distribution
   83.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   83.31 + * single choice of license, a recipient has the option to distribute
   83.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   83.33 + * to extend the choice of license to its licensees as provided above.
   83.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   83.35 + * Version 2 license, then the option applies only if the new code is
   83.36 + * made subject to such option by the copyright holder.
   83.37 + *
   83.38 + * Contributor(s):
   83.39 + *
   83.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   83.41 + */
   83.42 +package org.netbeans.modules.jackpot30.impl.duplicates;
   83.43 +
   83.44 +import com.sun.source.tree.CompilationUnitTree;
   83.45 +import com.sun.source.tree.Tree;
   83.46 +import com.sun.source.util.SourcePositions;
   83.47 +import com.sun.source.util.TreePath;
   83.48 +import com.sun.source.util.TreePathScanner;
   83.49 +import com.sun.source.util.Trees;
   83.50 +import java.io.ByteArrayOutputStream;
   83.51 +import java.io.File;
   83.52 +import java.io.IOException;
   83.53 +import java.net.URL;
   83.54 +import java.security.DigestOutputStream;
   83.55 +import java.security.MessageDigest;
   83.56 +import java.security.NoSuchAlgorithmException;
   83.57 +import java.util.ArrayList;
   83.58 +import java.util.Arrays;
   83.59 +import java.util.BitSet;
   83.60 +import java.util.Collection;
   83.61 +import java.util.Collections;
   83.62 +import java.util.Comparator;
   83.63 +import java.util.HashMap;
   83.64 +import java.util.HashSet;
   83.65 +import java.util.Iterator;
   83.66 +import java.util.LinkedHashMap;
   83.67 +import java.util.LinkedList;
   83.68 +import java.util.List;
   83.69 +import java.util.Map;
   83.70 +import java.util.Map.Entry;
   83.71 +import java.util.NoSuchElementException;
   83.72 +import java.util.Set;
   83.73 +import java.util.TreeMap;
   83.74 +import java.util.concurrent.atomic.AtomicBoolean;
   83.75 +import javax.tools.JavaCompiler.CompilationTask;
   83.76 +import org.apache.lucene.document.Document;
   83.77 +import org.apache.lucene.index.IndexReader;
   83.78 +import org.apache.lucene.index.MultiReader;
   83.79 +import org.apache.lucene.index.Term;
   83.80 +import org.apache.lucene.index.TermEnum;
   83.81 +import org.apache.lucene.search.Collector;
   83.82 +import org.apache.lucene.search.IndexSearcher;
   83.83 +import org.apache.lucene.search.Query;
   83.84 +import org.apache.lucene.search.Searcher;
   83.85 +import org.apache.lucene.search.TermQuery;
   83.86 +import org.apache.lucene.store.FSDirectory;
   83.87 +import org.netbeans.api.annotations.common.CheckForNull;
   83.88 +import org.netbeans.api.java.classpath.ClassPath;
   83.89 +import org.netbeans.api.java.classpath.GlobalPathRegistry;
   83.90 +import org.netbeans.api.java.source.CompilationInfo;
   83.91 +import org.netbeans.api.progress.ProgressHandle;
   83.92 +import org.netbeans.modules.jackpot30.common.api.LuceneHelpers.BitSetCollector;
   83.93 +import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesCustomIndexerImpl;
   83.94 +import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesIndex;
   83.95 +import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
   83.96 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
   83.97 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
   83.98 +import org.netbeans.modules.java.source.JavaSourceAccessor;
   83.99 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
  83.100 +import org.openide.filesystems.FileObject;
  83.101 +import org.openide.filesystems.FileUtil;
  83.102 +import org.openide.filesystems.URLMapper;
  83.103 +import org.openide.util.Exceptions;
  83.104 +
  83.105 +
  83.106 +/**
  83.107 + *
  83.108 + * @author lahvac
  83.109 + */
  83.110 +public class ComputeDuplicates {
  83.111 +
  83.112 +    public Iterator<? extends DuplicateDescription> computeDuplicatesForAllOpenedProjects(ProgressHandle progress, AtomicBoolean cancel) throws IOException {
  83.113 +        Set<URL> urls = new HashSet<URL>();
  83.114 +
  83.115 +        for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
  83.116 +            for (ClassPath.Entry e : cp.entries()) {
  83.117 +                urls.add(e.getURL());
  83.118 +            }
  83.119 +        }
  83.120 +
  83.121 +        long start = System.currentTimeMillis();
  83.122 +        try {
  83.123 +            return computeDuplicates(urls, progress, cancel);
  83.124 +        } finally {
  83.125 +            System.err.println("duplicates for all open projects: " + (System.currentTimeMillis() - start));
  83.126 +        }
  83.127 +    }
  83.128 +
  83.129 +    public Iterator<? extends DuplicateDescription> computeDuplicates(Set<URL> forURLs, ProgressHandle progress, AtomicBoolean cancel) throws IOException {
  83.130 +        Map<IndexReader, FileObject> readers2Roots = new LinkedHashMap<IndexReader, FileObject>();
  83.131 +
  83.132 +        progress.progress("Updating indices");
  83.133 +
  83.134 +        for (URL u : forURLs) {
  83.135 +            try {
  83.136 +                //TODO: needs to be removed for server mode
  83.137 +                new DuplicatesCustomIndexerImpl.FactoryImpl().updateIndex(u, cancel); //TODO: show updating progress to the user
  83.138 +                
  83.139 +                File cacheRoot = cacheRoot(u);
  83.140 +
  83.141 +                File dir = new File(cacheRoot, DuplicatesIndex.NAME);
  83.142 +
  83.143 +                if (dir.listFiles() != null && dir.listFiles().length > 0) {
  83.144 +                    IndexReader reader = IndexReader.open(FSDirectory.open(dir), true);
  83.145 +
  83.146 +                    readers2Roots.put(reader, URLMapper.findFileObject(u));
  83.147 +                }
  83.148 +            } catch (IOException ex) {
  83.149 +                Exceptions.printStackTrace(ex);
  83.150 +            }
  83.151 +        }
  83.152 +        
  83.153 +        progress.progress("Searching for duplicates");
  83.154 +
  83.155 +        MultiReader r = new MultiReader(readers2Roots.keySet().toArray(new IndexReader[0]));
  83.156 +
  83.157 +        List<String> dd = new ArrayList<String>(getDuplicatedValues(r, "generalized", cancel));
  83.158 +
  83.159 +        sortHashes(dd);
  83.160 +
  83.161 +        //TODO: only show valuable duplicates?:
  83.162 +//        dd = dd.subList(0, dd.size() / 10 + 1);
  83.163 +
  83.164 +        return new DuplicatesIterator(readers2Roots, dd, 2);
  83.165 +    }
  83.166 +
  83.167 +    public static Iterator<? extends DuplicateDescription> XXXduplicatesOf(Map<IndexReader, FileObject> readers2Roots, Collection<String> hashes) {
  83.168 +        List<String> hashesList = new ArrayList<String>(hashes);
  83.169 +        sortHashes(hashesList);
  83.170 +        return new DuplicatesIterator(readers2Roots, hashesList, 1);
  83.171 +    }
  83.172 +
  83.173 +    private static File cacheRoot(URL sourceRoot) throws IOException {
  83.174 +        FileObject dataFolder = CacheFolder.getDataFolder(sourceRoot);
  83.175 +        FileObject cacheFO  = dataFolder.getFileObject(DuplicatesIndex.NAME + "/" +DuplicatesIndex.VERSION);
  83.176 +        File cache = cacheFO != null ? FileUtil.toFile(cacheFO) : null;
  83.177 +        
  83.178 +        return cache;
  83.179 +    }
  83.180 +    
  83.181 +    private static final class DuplicatesIterator implements Iterator<DuplicateDescription> {
  83.182 +        private final Map<IndexReader, FileObject> readers2Roots;
  83.183 +        private final Iterator<String> duplicateCandidates;
  83.184 +        private final int minDuplicates;
  83.185 +        private final List<DuplicateDescription> result = new LinkedList<DuplicateDescription>();
  83.186 +
  83.187 +        public DuplicatesIterator(Map<IndexReader, FileObject> readers2Roots, Iterable<String> duplicateCandidates, int minDuplicates) {
  83.188 +            this.readers2Roots = readers2Roots;
  83.189 +            this.duplicateCandidates = duplicateCandidates.iterator();
  83.190 +            this.minDuplicates = minDuplicates;
  83.191 +        }
  83.192 +
  83.193 +        private DuplicateDescription nextDescription() throws IOException {
  83.194 +        while (duplicateCandidates.hasNext()) {
  83.195 +            String longest = duplicateCandidates.next();
  83.196 +            List<Span> foundDuplicates = new LinkedList<Span>();
  83.197 +
  83.198 +            Query query = new TermQuery(new Term("generalized", longest));
  83.199 +
  83.200 +            for (Entry<IndexReader, FileObject> e : readers2Roots.entrySet()) {
  83.201 +                Searcher s = new IndexSearcher(e.getKey());
  83.202 +                BitSet matchingDocuments = new BitSet(e.getKey().maxDoc());
  83.203 +                Collector c = new BitSetCollector(matchingDocuments);
  83.204 +
  83.205 +                s.search(query, c);
  83.206 +
  83.207 +                for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum + 1)) {
  83.208 +                    final Document doc = e.getKey().document(docNum);
  83.209 +                    int pos = Arrays.binarySearch(doc.getValues("generalized"), longest);
  83.210 +
  83.211 +                    if (pos < 0) {
  83.212 +                        System.err.println("FOOBAR=" + pos);
  83.213 +                        continue;
  83.214 +                    }
  83.215 +                    
  83.216 +                    String spanSpec = doc.getValues("positions")[pos];
  83.217 +                    String relPath = doc.getField("path").stringValue();
  83.218 +
  83.219 +                    for (String spanPart : spanSpec.split(";")) {
  83.220 +                        Span span = Span.of(e.getValue().getFileObject(relPath), spanPart);
  83.221 +
  83.222 +                        if (span != null) {
  83.223 +                            foundDuplicates.add(span);
  83.224 +                        }
  83.225 +                    }
  83.226 +                }
  83.227 +            }
  83.228 +
  83.229 +            if (foundDuplicates.size() >= minDuplicates) {
  83.230 +                DuplicateDescription current = DuplicateDescription.of(foundDuplicates, getValue(longest), longest);
  83.231 +                boolean add = true;
  83.232 +
  83.233 +                for (Iterator<DuplicateDescription> it = result.iterator(); it.hasNext();) {
  83.234 +                    DuplicateDescription existing = it.next();
  83.235 +
  83.236 +                    if (subsumes(existing, current)) {
  83.237 +                        add = false;
  83.238 +                        break;
  83.239 +                    }
  83.240 +
  83.241 +                    if (subsumes(current, existing)) {
  83.242 +                        //can happen? (note that the duplicates are sorted by value)
  83.243 +                        it.remove();
  83.244 +                    }
  83.245 +                }
  83.246 +
  83.247 +                if (add) {
  83.248 +                    result.add(current);
  83.249 +                    return current;
  83.250 +                }
  83.251 +            }
  83.252 +
  83.253 +        }
  83.254 +        return null;
  83.255 +        }
  83.256 +
  83.257 +        private DuplicateDescription next;
  83.258 +
  83.259 +        public boolean hasNext() {
  83.260 +            if (next == null) {
  83.261 +                try {
  83.262 +                    next = nextDescription();
  83.263 +                } catch (IOException ex) {
  83.264 +                    Exceptions.printStackTrace(ex);
  83.265 +                }
  83.266 +            }
  83.267 +
  83.268 +            return next != null;
  83.269 +        }
  83.270 +
  83.271 +        public DuplicateDescription next() {
  83.272 +            if (!hasNext()) {
  83.273 +                throw new NoSuchElementException();
  83.274 +            }
  83.275 +
  83.276 +            DuplicateDescription r = next;
  83.277 +
  83.278 +            next = null;
  83.279 +            return r;
  83.280 +        }
  83.281 +
  83.282 +        public void remove() {
  83.283 +            throw new UnsupportedOperationException("Not supported.");
  83.284 +        }
  83.285 +
  83.286 +    }
  83.287 +
  83.288 +    private static List<String> getDuplicatedValues(IndexReader ir, String field, AtomicBoolean cancel) throws IOException {
  83.289 +        List<String> values = new ArrayList<String>();
  83.290 +        TermEnum terms = ir.terms( new Term(field));
  83.291 +        //while (terms.next()) {
  83.292 +        do {
  83.293 +            if (cancel.get()) return Collections.emptyList();
  83.294 +
  83.295 +            final Term term =  terms.term();
  83.296 +
  83.297 +            if ( !field.equals( term.field() ) ) {
  83.298 +                break;
  83.299 +            }
  83.300 +
  83.301 +            if (terms.docFreq() < 2) continue;
  83.302 +
  83.303 +            values.add(term.text());
  83.304 +        }
  83.305 +        while (terms.next());
  83.306 +        return values;
  83.307 +    }
  83.308 +
  83.309 +    private static long getValue(String encoded) {
  83.310 +        return Long.parseLong(encoded.substring(encoded.lastIndexOf(":") + 1));
  83.311 +    }
  83.312 +
  83.313 +    private static void sortHashes(List<String> hashes) {
  83.314 +        Collections.sort(hashes, new Comparator<String>() {
  83.315 +            public int compare(String arg0, String arg1) {
  83.316 +                return (int) Math.signum(getValue(arg1) - getValue(arg0));
  83.317 +            }
  83.318 +        });
  83.319 +    }
  83.320 +    
  83.321 +    private static boolean subsumes(DuplicateDescription bigger, DuplicateDescription smaller) {
  83.322 +        Set<FileObject> bFiles = new HashSet<FileObject>();
  83.323 +
  83.324 +        for (Span s : bigger.dupes) {
  83.325 +            bFiles.add(s.file);
  83.326 +        }
  83.327 +
  83.328 +        Set<FileObject> sFiles = new HashSet<FileObject>();
  83.329 +
  83.330 +        for (Span s : smaller.dupes) {
  83.331 +            sFiles.add(s.file);
  83.332 +        }
  83.333 +
  83.334 +        if (!bFiles.equals(sFiles)) return false;
  83.335 +
  83.336 +        Span testAgainst = bigger.dupes.get(0);
  83.337 +
  83.338 +        for (Span s : smaller.dupes) {
  83.339 +            if (s.file == testAgainst.file) {
  83.340 +                if (   (testAgainst.startOff <= s.startOff && testAgainst.endOff > s.endOff)
  83.341 +                    || (testAgainst.startOff < s.startOff && testAgainst.endOff >= s.endOff)) {
  83.342 +                    return true;
  83.343 +                }
  83.344 +            }
  83.345 +        }
  83.346 +
  83.347 +        return false;
  83.348 +    }
  83.349 +
  83.350 +    public static Map<String, long[]> encodeGeneralized(CompilationInfo info) {
  83.351 +        return encodeGeneralized(JavaSourceAccessor.getINSTANCE().getJavacTask(info), info.getCompilationUnit());
  83.352 +    }
  83.353 +
  83.354 +    public static Map<String, long[]> encodeGeneralized(final CompilationTask task, final CompilationUnitTree cut) {
  83.355 +        final SourcePositions sp = Trees.instance(task).getSourcePositions();
  83.356 +        final Map<String, Collection<Long>> positions = new HashMap<String, Collection<Long>>();
  83.357 +
  83.358 +        new TreePathScanner<Void, Void>() {
  83.359 +            @Override
  83.360 +            public Void scan(Tree tree, Void p) {
  83.361 +                if (tree == null) return null;
  83.362 +                if (getCurrentPath() != null) {
  83.363 +                    Tree generalizedPattern = Utilities.generalizePattern(task, new TreePath(getCurrentPath(), tree));
  83.364 +                    long value = Utilities.patternValue(generalizedPattern);
  83.365 +                    if (value >= MINIMAL_VALUE) {
  83.366 +                        {
  83.367 +                            DigestOutputStream baos = null;
  83.368 +                            try {
  83.369 +                                baos = new DigestOutputStream(new ByteArrayOutputStream(), MessageDigest.getInstance("MD5"));
  83.370 +                                final EncodingContext ec = new BulkSearch.EncodingContext(baos, true);
  83.371 +                                BulkSearch.getDefault().encode( generalizedPattern, ec);
  83.372 +                                StringBuilder text = new StringBuilder();
  83.373 +                                byte[] bytes = baos.getMessageDigest().digest();
  83.374 +                                for (int cntr = 0; cntr < 4; cntr++) {
  83.375 +                                    text.append(String.format("%02X", bytes[cntr]));
  83.376 +                                }
  83.377 +                                text.append(':').append(value);
  83.378 +                                String enc = text.toString();
  83.379 +                                Collection<Long> spanSpecs = positions.get(enc);
  83.380 +                                if (spanSpecs == null) {
  83.381 +                                    positions.put(enc, spanSpecs = new LinkedList<Long>());
  83.382 +//                                } else {
  83.383 +//                                    spanSpecs.append(";");
  83.384 +                                }
  83.385 +                                long start = sp.getStartPosition(cut, tree);
  83.386 +//                                spanSpecs.append(start).append(":").append(sp.getEndPosition(cut, tree) - start);
  83.387 +                                spanSpecs.add(start);
  83.388 +                                spanSpecs.add(sp.getEndPosition(cut, tree));
  83.389 +                            } catch (NoSuchAlgorithmException ex) {
  83.390 +                                Exceptions.printStackTrace(ex);
  83.391 +                           } finally {
  83.392 +                                try {
  83.393 +                                    baos.close();
  83.394 +                                } catch (IOException ex) {
  83.395 +                                    Exceptions.printStackTrace(ex);
  83.396 +                                }
  83.397 +                            }
  83.398 +                        }
  83.399 +                    }
  83.400 +                }
  83.401 +                return super.scan(tree, p);
  83.402 +            }
  83.403 +        }.scan(cut, null);
  83.404 +
  83.405 +        Map<String, long[]> result = new TreeMap<String, long[]>();
  83.406 +
  83.407 +        for (Entry<String, Collection<Long>> e : positions.entrySet()) {
  83.408 +            long[] spans = new long[e.getValue().size()];
  83.409 +            int idx = 0;
  83.410 +
  83.411 +            for (Long l : e.getValue()) {
  83.412 +                spans[idx++] = l;
  83.413 +            }
  83.414 +
  83.415 +            result.put(e.getKey(), spans);
  83.416 +        }
  83.417 +
  83.418 +        return result;
  83.419 +    }
  83.420 +
  83.421 +    private static final int MINIMAL_VALUE = 10;
  83.422 +
  83.423 +    public static final class DuplicateDescription {
  83.424 +
  83.425 +        public final List<Span> dupes;
  83.426 +        public final long value;
  83.427 +        public final String hash;
  83.428 +
  83.429 +        private DuplicateDescription(List<Span> dupes, long value, String hash) {
  83.430 +            this.dupes = dupes;
  83.431 +            this.value = value;
  83.432 +            this.hash = hash;
  83.433 +        }
  83.434 +
  83.435 +        public static DuplicateDescription of(List<Span> dupes, long value, String hash) {
  83.436 +            return new DuplicateDescription(dupes, value, hash);
  83.437 +        }
  83.438 +    }
  83.439 +
  83.440 +    public static final class Span {
  83.441 +        public final FileObject file;
  83.442 +        public final int startOff;
  83.443 +        public final int endOff;
  83.444 +
  83.445 +        public Span(FileObject file, int startOff, int endOff) {
  83.446 +            this.file = file;
  83.447 +            this.startOff = startOff;
  83.448 +            this.endOff = endOff;
  83.449 +        }
  83.450 +
  83.451 +        public static @CheckForNull Span of(FileObject file, String spanSpec) {
  83.452 +            String[] split = spanSpec.split(":");
  83.453 +            int start = Integer.valueOf(split[0]);
  83.454 +            int end = start + Integer.valueOf(split[1]);
  83.455 +            if (start < 0 || end < 0) return null; //XXX
  83.456 +
  83.457 +            return new Span(file, start, end);
  83.458 +        }
  83.459 +
  83.460 +    }
  83.461 +}
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.form	Sat Feb 11 18:35:10 2012 +0100
    84.3 @@ -0,0 +1,189 @@
    84.4 +<?xml version="1.1" encoding="UTF-8" ?>
    84.5 +
    84.6 +<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    84.7 +  <AuxValues>
    84.8 +    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
    84.9 +    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   84.10 +    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   84.11 +    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
   84.12 +    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
   84.13 +    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   84.14 +    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   84.15 +    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   84.16 +    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   84.17 +  </AuxValues>
   84.18 +
   84.19 +  <Layout>
   84.20 +    <DimensionLayout dim="0">
   84.21 +      <Group type="103" groupAlignment="0" attributes="0">
   84.22 +          <Group type="102" alignment="1" attributes="0">
   84.23 +              <EmptySpace max="-2" attributes="0"/>
   84.24 +              <Group type="103" groupAlignment="1" attributes="0">
   84.25 +                  <Component id="mainSplit2" alignment="0" pref="906" max="32767" attributes="0"/>
   84.26 +                  <Component id="jScrollPane1" alignment="0" pref="906" max="32767" attributes="0"/>
   84.27 +                  <Component id="jPanel1" alignment="1" min="-2" max="-2" attributes="0"/>
   84.28 +              </Group>
   84.29 +              <EmptySpace max="-2" attributes="0"/>
   84.30 +          </Group>
   84.31 +      </Group>
   84.32 +    </DimensionLayout>
   84.33 +    <DimensionLayout dim="1">
   84.34 +      <Group type="103" groupAlignment="0" attributes="0">
   84.35 +          <Group type="102" attributes="0">
   84.36 +              <EmptySpace min="-2" max="-2" attributes="0"/>
   84.37 +              <Component id="jScrollPane1" min="-2" pref="67" max="-2" attributes="0"/>
   84.38 +              <EmptySpace min="-2" max="-2" attributes="0"/>
   84.39 +              <Component id="mainSplit2" pref="467" max="32767" attributes="0"/>
   84.40 +              <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
   84.41 +              <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
   84.42 +              <EmptySpace min="-2" max="-2" attributes="0"/>
   84.43 +          </Group>
   84.44 +      </Group>
   84.45 +    </DimensionLayout>
   84.46 +  </Layout>
   84.47 +  <SubComponents>
   84.48 +    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
   84.49 +
   84.50 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   84.51 +      <SubComponents>
   84.52 +        <Component class="javax.swing.JList" name="duplicatesList">
   84.53 +          <Properties>
   84.54 +            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
   84.55 +              <StringArray count="0"/>
   84.56 +            </Property>
   84.57 +            <Property name="prototypeCellValue" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
   84.58 +              <Connection code="&quot;9999999999999999999999999999999999999999999999999999999999999999999999&quot;" type="code"/>
   84.59 +            </Property>
   84.60 +            <Property name="visibleRowCount" type="int" value="4"/>
   84.61 +          </Properties>
   84.62 +        </Component>
   84.63 +      </SubComponents>
   84.64 +    </Container>
   84.65 +    <Container class="javax.swing.JSplitPane" name="mainSplit2">
   84.66 +      <Properties>
   84.67 +        <Property name="dividerLocation" type="int" value="400"/>
   84.68 +      </Properties>
   84.69 +      <AuxValues>
   84.70 +        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new BalancedSplitPane()"/>
   84.71 +      </AuxValues>
   84.72 +
   84.73 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
   84.74 +      <SubComponents>
   84.75 +        <Container class="javax.swing.JPanel" name="rightPanel">
   84.76 +          <Constraints>
   84.77 +            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
   84.78 +              <JSplitPaneConstraints position="right"/>
   84.79 +            </Constraint>
   84.80 +          </Constraints>
   84.81 +
   84.82 +          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
   84.83 +          <SubComponents>
   84.84 +            <Component class="javax.swing.JComboBox" name="rightFileList">
   84.85 +              <Properties>
   84.86 +                <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
   84.87 +                  <StringArray count="0"/>
   84.88 +                </Property>
   84.89 +              </Properties>
   84.90 +              <Constraints>
   84.91 +                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
   84.92 +                  <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="324" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
   84.93 +                </Constraint>
   84.94 +              </Constraints>
   84.95 +            </Component>
   84.96 +            <Container class="javax.swing.JScrollPane" name="jScrollPane3">
   84.97 +              <AuxValues>
   84.98 +                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
   84.99 +              </AuxValues>
  84.100 +              <Constraints>
  84.101 +                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  84.102 +                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  84.103 +                </Constraint>
  84.104 +              </Constraints>
  84.105 +
  84.106 +              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  84.107 +              <SubComponents>
  84.108 +                <Component class="javax.swing.JEditorPane" name="right">
  84.109 +                </Component>
  84.110 +              </SubComponents>
  84.111 +            </Container>
  84.112 +          </SubComponents>
  84.113 +        </Container>
  84.114 +        <Container class="javax.swing.JPanel" name="leftPanel">
  84.115 +          <Constraints>
  84.116 +            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
  84.117 +              <JSplitPaneConstraints position="left"/>
  84.118 +            </Constraint>
  84.119 +          </Constraints>
  84.120 +
  84.121 +          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  84.122 +          <SubComponents>
  84.123 +            <Container class="javax.swing.JScrollPane" name="jScrollPane2">
  84.124 +              <AuxValues>
  84.125 +                <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
  84.126 +              </AuxValues>
  84.127 +              <Constraints>
  84.128 +                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  84.129 +                  <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="1.0"/>
  84.130 +                </Constraint>
  84.131 +              </Constraints>
  84.132 +
  84.133 +              <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
  84.134 +              <SubComponents>
  84.135 +                <Component class="javax.swing.JEditorPane" name="left">
  84.136 +                </Component>
  84.137 +              </SubComponents>
  84.138 +            </Container>
  84.139 +            <Component class="javax.swing.JComboBox" name="leftFileList">
  84.140 +              <Properties>
  84.141 +                <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
  84.142 +                  <StringArray count="0"/>
  84.143 +                </Property>
  84.144 +              </Properties>
  84.145 +              <Constraints>
  84.146 +                <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  84.147 +                  <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  84.148 +                </Constraint>
  84.149 +              </Constraints>
  84.150 +            </Component>
  84.151 +          </SubComponents>
  84.152 +        </Container>
  84.153 +      </SubComponents>
  84.154 +    </Container>
  84.155 +    <Container class="javax.swing.JPanel" name="jPanel1">
  84.156 +
  84.157 +      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
  84.158 +      <SubComponents>
  84.159 +        <Component class="javax.swing.JLabel" name="progressLabel">
  84.160 +          <Properties>
  84.161 +            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  84.162 +              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties" key="DuplicatesListPanel.progressLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  84.163 +            </Property>
  84.164 +          </Properties>
  84.165 +          <Constraints>
  84.166 +            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  84.167 +              <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
  84.168 +            </Constraint>
  84.169 +          </Constraints>
  84.170 +        </Component>
  84.171 +        <Component class="javax.swing.JLabel" name="findMore">
  84.172 +          <Properties>
  84.173 +            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
  84.174 +              <ResourceString bundle="org/netbeans/modules/jackpot30/impl/duplicates/Bundle.properties" key="DuplicatesListPanel.findMore.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
  84.175 +            </Property>
  84.176 +            <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
  84.177 +              <Color id="Hand Cursor"/>
  84.178 +            </Property>
  84.179 +          </Properties>
  84.180 +          <Events>
  84.181 +            <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="findMoreMouseClicked"/>
  84.182 +          </Events>
  84.183 +          <Constraints>
  84.184 +            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
  84.185 +              <GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
  84.186 +            </Constraint>
  84.187 +          </Constraints>
  84.188 +        </Component>
  84.189 +      </SubComponents>
  84.190 +    </Container>
  84.191 +  </SubComponents>
  84.192 +</Form>
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/DuplicatesListPanel.java	Sat Feb 11 18:35:10 2012 +0100
    85.3 @@ -0,0 +1,464 @@
    85.4 +/*
    85.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    85.6 + *
    85.7 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    85.8 + *
    85.9 + * The contents of this file are subject to the terms of either the GNU
   85.10 + * General Public License Version 2 only ("GPL") or the Common
   85.11 + * Development and Distribution License("CDDL") (collectively, the
   85.12 + * "License"). You may not use this file except in compliance with the
   85.13 + * License. You can obtain a copy of the License at
   85.14 + * http://www.netbeans.org/cddl-gplv2.html
   85.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   85.16 + * specific language governing permissions and limitations under the
   85.17 + * License.  When distributing the software, include this License Header
   85.18 + * Notice in each file and include the License file at
   85.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   85.20 + * particular file as subject to the "Classpath" exception as provided
   85.21 + * by Sun in the GPL Version 2 section of the License file that
   85.22 + * accompanied this code. If applicable, add the following below the
   85.23 + * License Header, with the fields enclosed by brackets [] replaced by
   85.24 + * your own identifying information:
   85.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   85.26 + *
   85.27 + * If you wish your version of this file to be governed by only the CDDL
   85.28 + * or only the GPL Version 2, indicate your decision by adding
   85.29 + * "[Contributor] elects to include this software in this distribution
   85.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   85.31 + * single choice of license, a recipient has the option to distribute
   85.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   85.33 + * to extend the choice of license to its licensees as provided above.
   85.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   85.35 + * Version 2 license, then the option applies only if the new code is
   85.36 + * made subject to such option by the copyright holder.
   85.37 + *
   85.38 + * Contributor(s):
   85.39 + *
   85.40 + * Portions Copyrighted 2009 Sun Microsystems, Inc.
   85.41 + */
   85.42 +package org.netbeans.modules.jackpot30.impl.duplicates;
   85.43 +
   85.44 +import java.awt.Color;
   85.45 +import java.awt.Component;
   85.46 +import java.awt.Rectangle;
   85.47 +import java.awt.event.ActionEvent;
   85.48 +import java.awt.event.ActionListener;
   85.49 +import java.io.IOException;
   85.50 +import java.util.Collection;
   85.51 +import java.util.Iterator;
   85.52 +import java.util.LinkedHashSet;
   85.53 +import java.util.Set;
   85.54 +import javax.swing.DefaultComboBoxModel;
   85.55 +import javax.swing.DefaultListCellRenderer;
   85.56 +import javax.swing.DefaultListModel;
   85.57 +import javax.swing.JEditorPane;
   85.58 +import javax.swing.JList;
   85.59 +import javax.swing.JSplitPane;
   85.60 +import javax.swing.SwingUtilities;
   85.61 +import javax.swing.event.ListSelectionEvent;
   85.62 +import javax.swing.event.ListSelectionListener;
   85.63 +import javax.swing.text.AttributeSet;
   85.64 +import javax.swing.text.BadLocationException;
   85.65 +import javax.swing.text.StyleConstants;
   85.66 +import org.netbeans.api.editor.mimelookup.MimePath;
   85.67 +import org.netbeans.api.editor.settings.AttributesUtilities;
   85.68 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   85.69 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   85.70 +import org.netbeans.spi.editor.highlighting.HighlightsLayer;
   85.71 +import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
   85.72 +import org.netbeans.spi.editor.highlighting.ZOrder;
   85.73 +import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
   85.74 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
   85.75 +import org.openide.filesystems.FileObject;
   85.76 +import org.openide.filesystems.FileUtil;
   85.77 +import org.openide.util.Exceptions;
   85.78 +import org.openide.util.Lookup;
   85.79 +import org.openide.util.RequestProcessor;
   85.80 +import org.openide.util.RequestProcessor.Task;
   85.81 +import org.openide.util.lookup.Lookups;
   85.82 +import org.openide.util.lookup.ServiceProvider;
   85.83 +
   85.84 +/**
   85.85 + *
   85.86 + * @author lahvac
   85.87 + */
   85.88 +public class DuplicatesListPanel extends javax.swing.JPanel {
   85.89 +    private final Collection<String> sourceRoots;
   85.90 +    private final Iterator<? extends DuplicateDescription> dupes;
   85.91 +
   85.92 +    private int targetCount;
   85.93 +
   85.94 +    public DuplicatesListPanel(Collection<String> sourceRoots, final Iterator<? extends DuplicateDescription> dupes) {
   85.95 +        this.sourceRoots = sourceRoots;
   85.96 +        this.dupes = dupes;
   85.97 +        
   85.98 +        initComponents();
   85.99 +
  85.100 +        left.setContentType("text/x-java");
  85.101 +        left.putClientProperty(DuplicatesListPanel.class, new OffsetsBag(left.getDocument()));
  85.102 +        
  85.103 +        right.setContentType("text/x-java");
  85.104 +        right.putClientProperty(DuplicatesListPanel.class, new OffsetsBag(right.getDocument()));
  85.105 +
  85.106 +        duplicatesList.setModel(new DefaultListModel());
  85.107 +        duplicatesList.setCellRenderer(new DuplicatesRendererImpl());
  85.108 +        duplicatesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
  85.109 +            public void valueChanged(ListSelectionEvent arg0) {
  85.110 +                DuplicateDescription dd = (DuplicateDescription) duplicatesList.getSelectedValue();
  85.111 +                DefaultComboBoxModel l = new DefaultComboBoxModel();
  85.112 +                DefaultComboBoxModel r = new DefaultComboBoxModel();
  85.113 +
  85.114 +                for (Span s : dd.dupes) {
  85.115 +                    l.addElement(s);
  85.116 +                    r.addElement(s);
  85.117 +                }
  85.118 +
  85.119 +                leftFileList.setModel(l);
  85.120 +                rightFileList.setModel(r);
  85.121 +
  85.122 +                leftFileList.setSelectedIndex(0);
  85.123 +                rightFileList.setSelectedIndex(1);
  85.124 +            }
  85.125 +        });
  85.126 +
  85.127 +        leftFileList.setRenderer(new SpanRendererImpl());
  85.128 +        leftFileList.addActionListener(new ActionListener() {
  85.129 +
  85.130 +            public void actionPerformed(ActionEvent e) {
  85.131 +                setSpan(left, (Span) leftFileList.getSelectedItem());
  85.132 +            }
  85.133 +        });
  85.134 +        rightFileList.setRenderer(new SpanRendererImpl());
  85.135 +        rightFileList.addActionListener(new ActionListener() {
  85.136 +            public void actionPerformed(ActionEvent e) {
  85.137 +                setSpan(right, (Span) rightFileList.getSelectedItem());
  85.138 +            }
  85.139 +        });
  85.140 +
  85.141 +        progressLabel.setText("Looking for duplicates...");
  85.142 +
  85.143 +        findMore();
  85.144 +    }
  85.145 +
  85.146 +    /** This method is called from within the constructor to
  85.147 +     * initialize the form.
  85.148 +     * WARNING: Do NOT modify this code. The content of this method is
  85.149 +     * always regenerated by the Form Editor.
  85.150 +     */
  85.151 +    @SuppressWarnings("unchecked")
  85.152 +    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  85.153 +    private void initComponents() {
  85.154 +        java.awt.GridBagConstraints gridBagConstraints;
  85.155 +
  85.156 +        jScrollPane1 = new javax.swing.JScrollPane();
  85.157 +        duplicatesList = new javax.swing.JList();
  85.158 +        mainSplit2 = new BalancedSplitPane();
  85.159 +        rightPanel = new javax.swing.JPanel();
  85.160 +        rightFileList = new javax.swing.JComboBox();
  85.161 +        jScrollPane3 = new javax.swing.JScrollPane();
  85.162 +        right = new javax.swing.JEditorPane();
  85.163 +        leftPanel = new javax.swing.JPanel();
  85.164 +        jScrollPane2 = new javax.swing.JScrollPane();
  85.165 +        left = new javax.swing.JEditorPane();
  85.166 +        leftFileList = new javax.swing.JComboBox();
  85.167 +        jPanel1 = new javax.swing.JPanel();
  85.168 +        progressLabel = new javax.swing.JLabel();
  85.169 +        findMore = new javax.swing.JLabel();
  85.170 +
  85.171 +        duplicatesList.setPrototypeCellValue("9999999999999999999999999999999999999999999999999999999999999999999999");
  85.172 +        duplicatesList.setVisibleRowCount(4);
  85.173 +        jScrollPane1.setViewportView(duplicatesList);
  85.174 +
  85.175 +        mainSplit2.setDividerLocation(400);
  85.176 +
  85.177 +        rightPanel.setLayout(new java.awt.GridBagLayout());
  85.178 +
  85.179 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.180 +        gridBagConstraints.gridx = 0;
  85.181 +        gridBagConstraints.gridy = 0;
  85.182 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  85.183 +        gridBagConstraints.ipadx = 324;
  85.184 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.185 +        gridBagConstraints.weightx = 1.0;
  85.186 +        rightPanel.add(rightFileList, gridBagConstraints);
  85.187 +
  85.188 +        jScrollPane3.setViewportView(right);
  85.189 +
  85.190 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.191 +        gridBagConstraints.gridx = 0;
  85.192 +        gridBagConstraints.gridy = 1;
  85.193 +        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  85.194 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.195 +        gridBagConstraints.weightx = 1.0;
  85.196 +        gridBagConstraints.weighty = 1.0;
  85.197 +        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  85.198 +        rightPanel.add(jScrollPane3, gridBagConstraints);
  85.199 +
  85.200 +        mainSplit2.setRightComponent(rightPanel);
  85.201 +
  85.202 +        leftPanel.setLayout(new java.awt.GridBagLayout());
  85.203 +
  85.204 +        jScrollPane2.setViewportView(left);
  85.205 +
  85.206 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.207 +        gridBagConstraints.gridx = 0;
  85.208 +        gridBagConstraints.gridy = 1;
  85.209 +        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  85.210 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.211 +        gridBagConstraints.weightx = 1.0;
  85.212 +        gridBagConstraints.weighty = 1.0;
  85.213 +        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
  85.214 +        leftPanel.add(jScrollPane2, gridBagConstraints);
  85.215 +
  85.216 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.217 +        gridBagConstraints.gridx = 0;
  85.218 +        gridBagConstraints.gridy = 0;
  85.219 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  85.220 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.221 +        gridBagConstraints.weightx = 1.0;
  85.222 +        leftPanel.add(leftFileList, gridBagConstraints);
  85.223 +
  85.224 +        mainSplit2.setLeftComponent(leftPanel);
  85.225 +
  85.226 +        jPanel1.setLayout(new java.awt.GridBagLayout());
  85.227 +
  85.228 +        progressLabel.setText(org.openide.util.NbBundle.getMessage(DuplicatesListPanel.class, "DuplicatesListPanel.progressLabel.text")); // NOI18N
  85.229 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.230 +        gridBagConstraints.gridx = 0;
  85.231 +        gridBagConstraints.gridy = 0;
  85.232 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  85.233 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.234 +        gridBagConstraints.weightx = 1.0;
  85.235 +        jPanel1.add(progressLabel, gridBagConstraints);
  85.236 +
  85.237 +        findMore.setText(org.openide.util.NbBundle.getMessage(DuplicatesListPanel.class, "DuplicatesListPanel.findMore.text")); // NOI18N
  85.238 +        findMore.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  85.239 +        findMore.addMouseListener(new java.awt.event.MouseAdapter() {
  85.240 +            public void mouseClicked(java.awt.event.MouseEvent evt) {
  85.241 +                findMoreMouseClicked(evt);
  85.242 +            }
  85.243 +        });
  85.244 +        gridBagConstraints = new java.awt.GridBagConstraints();
  85.245 +        gridBagConstraints.gridx = 1;
  85.246 +        gridBagConstraints.gridy = 0;
  85.247 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  85.248 +        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
  85.249 +        jPanel1.add(findMore, gridBagConstraints);
  85.250 +
  85.251 +        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  85.252 +        this.setLayout(layout);
  85.253 +        layout.setHorizontalGroup(
  85.254 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85.255 +            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  85.256 +                .addContainerGap()
  85.257 +                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  85.258 +                    .addComponent(mainSplit2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 906, Short.MAX_VALUE)
  85.259 +                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 906, Short.MAX_VALUE)
  85.260 +                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  85.261 +                .addContainerGap())
  85.262 +        );
  85.263 +        layout.setVerticalGroup(
  85.264 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85.265 +            .addGroup(layout.createSequentialGroup()
  85.266 +                .addContainerGap()
  85.267 +                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
  85.268 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  85.269 +                .addComponent(mainSplit2, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
  85.270 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  85.271 +                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  85.272 +                .addContainerGap())
  85.273 +        );
  85.274 +    }// </editor-fold>//GEN-END:initComponents
  85.275 +
  85.276 +    private void findMoreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findMoreMouseClicked
  85.277 +        findMore();
  85.278 +    }//GEN-LAST:event_findMoreMouseClicked
  85.279 +
  85.280 +    private void findMore() {
  85.281 +        targetCount = duplicatesList.getModel().getSize() + 100;
  85.282 +        findMore.setVisible(false);
  85.283 +        WORKER.schedule(0);
  85.284 +    }
  85.285 +
  85.286 +    private static String computeCommonPrefix(String origCommonPrefix, FileObject file) {
  85.287 +        String name = FileUtil.getFileDisplayName(file);
  85.288 +
  85.289 +        if (origCommonPrefix == null) return name;
  85.290 +
  85.291 +        int len = Math.min(origCommonPrefix.length(), name.length());
  85.292 +
  85.293 +        for (int cntr = 0; cntr < len; cntr++) {
  85.294 +            if (origCommonPrefix.charAt(cntr) != name.charAt(cntr)) {
  85.295 +                return origCommonPrefix.substring(0, cntr);
  85.296 +            }
  85.297 +        }
  85.298 +
  85.299 +        return origCommonPrefix;
  85.300 +    }
  85.301 +    
  85.302 +    private static void setSpan(JEditorPane pane, Span s) {
  85.303 +        try {
  85.304 +            pane.setText(s.file.asText());
  85.305 +
  85.306 +            Rectangle top = pane.modelToView(0);
  85.307 +            Rectangle start = pane.modelToView(s.startOff);
  85.308 +            Rectangle end = pane.modelToView(s.endOff);
  85.309 +
  85.310 +            if (top != null && start != null && end != null) {
  85.311 +                Rectangle toScroll = start.union(end);
  85.312 +
  85.313 +                pane.scrollRectToVisible(top);
  85.314 +                pane.scrollRectToVisible(toScroll);
  85.315 +            }
  85.316 +
  85.317 +            OffsetsBag bag = (OffsetsBag) pane.getClientProperty(DuplicatesListPanel.class);
  85.318 +
  85.319 +            bag.clear();
  85.320 +            bag.addHighlight(s.startOff, s.endOff, HIGHLIGHT);
  85.321 +        } catch (IOException ex) {
  85.322 +            Exceptions.printStackTrace(ex);
  85.323 +        } catch (BadLocationException ex) {
  85.324 +            Exceptions.printStackTrace(ex);
  85.325 +        }
  85.326 +    }
  85.327 +
  85.328 +    private static final AttributeSet HIGHLIGHT = AttributesUtilities.createImmutable(StyleConstants.Background, new Color(0xDF, 0xDF, 0xDF, 0xff));
  85.329 +
  85.330 +    private final class DuplicatesRendererImpl extends DefaultListCellRenderer {
  85.331 +        @Override
  85.332 +        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  85.333 +            if (!(value instanceof DuplicateDescription)) return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  85.334 +            DuplicateDescription dd = (DuplicateDescription) value;
  85.335 +            Set<FileObject> files = new LinkedHashSet<FileObject>();
  85.336 +            String commonPrefix = null;
  85.337 +
  85.338 +            for (Span s : dd.dupes) {
  85.339 +                commonPrefix = computeCommonPrefix(commonPrefix, s.file);
  85.340 +                files.add(s.file);
  85.341 +            }
  85.342 +
  85.343 +            StringBuilder cap = new StringBuilder();
  85.344 +
  85.345 +            OUTER: for (FileObject file : files) {
  85.346 +                String name = FileUtil.getFileDisplayName(file);
  85.347 +
  85.348 +                if (cap.length() > 0) {
  85.349 +                    cap.append("    ");
  85.350 +                }
  85.351 +                
  85.352 +                for (String sr : sourceRoots) {
  85.353 +                    if (name.startsWith(sr)) {
  85.354 +                        cap.append(name.substring(Math.max(0, sr.lastIndexOf('/') + 1)));
  85.355 +                        continue OUTER;
  85.356 +                    }
  85.357 +                }
  85.358 +            }
  85.359 +
  85.360 +            return super.getListCellRendererComponent(list, cap.toString(), index, isSelected, cellHasFocus);
  85.361 +        }
  85.362 +    }
  85.363 +
  85.364 +    private final class SpanRendererImpl extends DefaultListCellRenderer {
  85.365 +        @Override
  85.366 +        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  85.367 +            if (!(value instanceof Span)) {
  85.368 +                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  85.369 +            }
  85.370 +            Span span = (Span) value;
  85.371 +
  85.372 +            return super.getListCellRendererComponent(list, FileUtil.getFileDisplayName(span.file), index, isSelected, cellHasFocus);
  85.373 +        }
  85.374 +    }
  85.375 +
  85.376 +    public static final class HighlightLayerFactoryImpl implements HighlightsLayerFactory {
  85.377 +        public HighlightsLayer[] createLayers(Context cntxt) {
  85.378 +            OffsetsBag bag = (OffsetsBag) cntxt.getComponent().getClientProperty(DuplicatesListPanel.class);
  85.379 +
  85.380 +            if (bag != null) {
  85.381 +                return new HighlightsLayer[] {
  85.382 +                    HighlightsLayer.create(DuplicatesListPanel.class.getName(), ZOrder.CARET_RACK, true, bag)
  85.383 +                };
  85.384 +            }
  85.385 +
  85.386 +            return new HighlightsLayer[0];
  85.387 +        }
  85.388 +    }
  85.389 +
  85.390 +    @ServiceProvider(service=MimeDataProvider.class)
  85.391 +    public static final class MDPI implements MimeDataProvider {
  85.392 +
  85.393 +        private static final Lookup L = Lookups.singleton(new HighlightLayerFactoryImpl());
  85.394 +
  85.395 +        public Lookup getLookup(MimePath mp) {
  85.396 +            if (mp.getPath().startsWith("text/x-java")) {
  85.397 +                return L;
  85.398 +            }
  85.399 +
  85.400 +            return null;
  85.401 +        }
  85.402 +        
  85.403 +    }
  85.404 +
  85.405 +    private static final class BalancedSplitPane extends JSplitPane {
  85.406 +
  85.407 +        @Override
  85.408 +        @SuppressWarnings("deprecation")
  85.409 +        public void reshape(int x, int y, int w, int h) {
  85.410 +            super.reshape(x, y, w, h);
  85.411 +            SwingUtilities.invokeLater(new Runnable() {
  85.412 +                public void run() {
  85.413 +                    setDividerLocation(0.5);
  85.414 +                }
  85.415 +            });
  85.416 +        }
  85.417 +
  85.418 +    }
  85.419 +
  85.420 +    // Variables declaration - do not modify//GEN-BEGIN:variables
  85.421 +    private javax.swing.JList duplicatesList;
  85.422 +    private javax.swing.JLabel findMore;
  85.423 +    private javax.swing.JPanel jPanel1;
  85.424 +    private javax.swing.JScrollPane jScrollPane1;
  85.425 +    private javax.swing.JScrollPane jScrollPane2;
  85.426 +    private javax.swing.JScrollPane jScrollPane3;
  85.427 +    private javax.swing.JEditorPane left;
  85.428 +    private javax.swing.JComboBox leftFileList;
  85.429 +    private javax.swing.JPanel leftPanel;
  85.430 +    private javax.swing.JSplitPane mainSplit2;
  85.431 +    private javax.swing.JLabel progressLabel;
  85.432 +    private javax.swing.JEditorPane right;
  85.433 +    private javax.swing.JComboBox rightFileList;
  85.434 +    private javax.swing.JPanel rightPanel;
  85.435 +    // End of variables declaration//GEN-END:variables
  85.436 +
  85.437 +    private static final RequestProcessor DEFAULT_WORKER = new RequestProcessor(DuplicatesListPanel.class.getName(), 1, false, false);
  85.438 +    private final Task WORKER = DEFAULT_WORKER.create(new Runnable() {
  85.439 +        public void run() {
  85.440 +            if (dupes.hasNext()) {
  85.441 +                final DuplicateDescription dd = dupes.next();
  85.442 +
  85.443 +                SwingUtilities.invokeLater(new Runnable() {
  85.444 +
  85.445 +                    public void run() {
  85.446 +                        ((DefaultListModel)duplicatesList.getModel()).addElement(dd);
  85.447 +
  85.448 +                        int size = duplicatesList.getModel().getSize();
  85.449 +
  85.450 +                        if (size == 1) {
  85.451 +                            duplicatesList.setSelectedIndex(0);
  85.452 +                        }
  85.453 +                        
  85.454 +                        if (size >= targetCount) {
  85.455 +                            findMore.setVisible(true);
  85.456 +                            progressLabel.setText("Found " + size + " duplicated snippets.");
  85.457 +                        } else {
  85.458 +                            progressLabel.setText("Found " + size + " duplicated snippets and searching...");
  85.459 +                            WORKER.schedule(0);
  85.460 +                        }
  85.461 +                    }
  85.462 +                });
  85.463 +            }
  85.464 +        }
  85.465 +    });
  85.466 +
  85.467 +}
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/GlobalFindDuplicates.java	Sat Feb 11 18:35:10 2012 +0100
    86.3 @@ -0,0 +1,179 @@
    86.4 +/*
    86.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    86.6 + *
    86.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    86.8 + *
    86.9 + * The contents of this file are subject to the terms of either the GNU
   86.10 + * General Public License Version 2 only ("GPL") or the Common
   86.11 + * Development and Distribution License("CDDL") (collectively, the
   86.12 + * "License"). You may not use this file except in compliance with the
   86.13 + * License. You can obtain a copy of the License at
   86.14 + * http://www.netbeans.org/cddl-gplv2.html
   86.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   86.16 + * specific language governing permissions and limitations under the
   86.17 + * License.  When distributing the software, include this License Header
   86.18 + * Notice in each file and include the License file at
   86.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   86.20 + * particular file as subject to the "Classpath" exception as provided
   86.21 + * by Sun in the GPL Version 2 section of the License file that
   86.22 + * accompanied this code. If applicable, add the following below the
   86.23 + * License Header, with the fields enclosed by brackets [] replaced by
   86.24 + * your own identifying information:
   86.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   86.26 + *
   86.27 + * If you wish your version of this file to be governed by only the CDDL
   86.28 + * or only the GPL Version 2, indicate your decision by adding
   86.29 + * "[Contributor] elects to include this software in this distribution
   86.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   86.31 + * single choice of license, a recipient has the option to distribute
   86.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   86.33 + * to extend the choice of license to its licensees as provided above.
   86.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   86.35 + * Version 2 license, then the option applies only if the new code is
   86.36 + * made subject to such option by the copyright holder.
   86.37 + *
   86.38 + * Contributor(s):
   86.39 + *
   86.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   86.41 + */
   86.42 +package org.netbeans.modules.jackpot30.impl.duplicates;
   86.43 +
   86.44 +import java.awt.Dialog;
   86.45 +import java.awt.GridBagConstraints;
   86.46 +import java.awt.GridBagLayout;
   86.47 +import java.awt.Insets;
   86.48 +import java.awt.event.ActionEvent;
   86.49 +import java.awt.event.ActionListener;
   86.50 +import java.io.IOException;
   86.51 +import java.util.Collection;
   86.52 +import java.util.Iterator;
   86.53 +import java.util.LinkedList;
   86.54 +import java.util.concurrent.atomic.AtomicBoolean;
   86.55 +import javax.swing.JLabel;
   86.56 +import javax.swing.JPanel;
   86.57 +import javax.swing.SwingUtilities;
   86.58 +import org.netbeans.api.java.classpath.ClassPath;
   86.59 +import org.netbeans.api.java.classpath.GlobalPathRegistry;
   86.60 +import org.netbeans.api.progress.ProgressHandle;
   86.61 +import org.netbeans.api.progress.ProgressHandleFactory;
   86.62 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   86.63 +import org.openide.DialogDescriptor;
   86.64 +import org.openide.DialogDisplayer;
   86.65 +import org.openide.NotifyDescriptor;
   86.66 +import org.openide.filesystems.FileObject;
   86.67 +import org.openide.filesystems.FileUtil;
   86.68 +import org.openide.util.Exceptions;
   86.69 +import org.openide.util.HelpCtx;
   86.70 +import org.openide.util.RequestProcessor;
   86.71 +
   86.72 +public final class GlobalFindDuplicates implements ActionListener {
   86.73 +
   86.74 +    public void actionPerformed(ActionEvent e) {
   86.75 +        final Iterator<? extends DuplicateDescription>[] dupes = new Iterator[1];
   86.76 +        final ProgressHandle handle = ProgressHandleFactory.createHandle("Compute Duplicates");
   86.77 +        JPanel panel = createPanel(handle);
   86.78 +        final AtomicBoolean cancel = new AtomicBoolean();
   86.79 +        DialogDescriptor w = new DialogDescriptor(panel, "Computing Duplicates", true, new Object[] {DialogDescriptor.CANCEL_OPTION}, DialogDescriptor.CANCEL_OPTION, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, new ActionListener() {
   86.80 +            public void actionPerformed(ActionEvent e) {
   86.81 +                cancel.set(true);
   86.82 +            }
   86.83 +        });
   86.84 +
   86.85 +        w.setClosingOptions(null);
   86.86 +
   86.87 +        final Dialog d = DialogDisplayer.getDefault().createDialog(w);
   86.88 +        final AtomicBoolean done = new AtomicBoolean();
   86.89 +        final Collection<String> sourceRoots = new LinkedList<String>();
   86.90 +
   86.91 +        WORKER.post(new Runnable() {
   86.92 +            public void run() {
   86.93 +                try {
   86.94 +                    for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
   86.95 +                        for (ClassPath.Entry e : cp.entries()) {
   86.96 +                            FileObject root = e.getRoot();
   86.97 +
   86.98 +                            if (root == null) continue;
   86.99 +
  86.100 +                            sourceRoots.add(FileUtil.getFileDisplayName(root));
  86.101 +                        }
  86.102 +                    }
  86.103 +
  86.104 +                    dupes[0] = new ComputeDuplicates().computeDuplicatesForAllOpenedProjects(handle, cancel);
  86.105 +                    done.set(true);
  86.106 +                } catch (IOException ex) {
  86.107 +                    Exceptions.printStackTrace(ex);
  86.108 +                } finally {
  86.109 +                    handle.finish();
  86.110 +
  86.111 +                    SwingUtilities.invokeLater(new Runnable() {
  86.112 +                        public void run() {
  86.113 +                            d.setVisible(false);
  86.114 +                        }
  86.115 +                    });
  86.116 +                }
  86.117 +            }
  86.118 +        });
  86.119 +
  86.120 +        handle.start();
  86.121 +        handle.progress(" ");
  86.122 +
  86.123 +        d.setVisible(true);
  86.124 +
  86.125 +        if (!done.get()) {
  86.126 +            cancel.set(true);
  86.127 +            return;
  86.128 +        }
  86.129 +        
  86.130 +        if (cancel.get()) return;
  86.131 +
  86.132 +        NotifyDescriptor nd = new NotifyDescriptor.Message(new DuplicatesListPanel(sourceRoots, dupes[0]));
  86.133 +
  86.134 +        DialogDisplayer.getDefault().notifyLater(nd);
  86.135 +    }
  86.136 +
  86.137 +    private JPanel createPanel(ProgressHandle handle) {
  86.138 +        JPanel panel = new JPanel(new GridBagLayout());
  86.139 +        GridBagConstraints gridBagConstraints;
  86.140 +
  86.141 +        gridBagConstraints = new GridBagConstraints();
  86.142 +        gridBagConstraints.gridx = 0;
  86.143 +        gridBagConstraints.gridy = 0;
  86.144 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  86.145 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  86.146 +        gridBagConstraints.weightx = 1.0;
  86.147 +        gridBagConstraints.insets = new Insets(6, 6, 0, 6);
  86.148 +        panel.add(new JLabel("Computing Duplicates - Please Wait"), gridBagConstraints);
  86.149 +
  86.150 +        gridBagConstraints = new GridBagConstraints();
  86.151 +        gridBagConstraints.gridx = 0;
  86.152 +        gridBagConstraints.gridy = 1;
  86.153 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  86.154 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  86.155 +        gridBagConstraints.weightx = 1.0;
  86.156 +        gridBagConstraints.insets = new Insets(6, 6, 0, 6);
  86.157 +        panel.add(ProgressHandleFactory.createProgressComponent(handle), gridBagConstraints);
  86.158 +
  86.159 +        gridBagConstraints = new GridBagConstraints();
  86.160 +        gridBagConstraints.gridx = 0;
  86.161 +        gridBagConstraints.gridy = 2;
  86.162 +        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  86.163 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  86.164 +        gridBagConstraints.weightx = 1.0;
  86.165 +        gridBagConstraints.insets = new Insets(6, 6, 6, 6);
  86.166 +        panel.add(ProgressHandleFactory.createDetailLabelComponent(handle), gridBagConstraints);
  86.167 +
  86.168 +        gridBagConstraints = new GridBagConstraints();
  86.169 +        gridBagConstraints.gridx = 0;
  86.170 +        gridBagConstraints.gridy = 3;
  86.171 +        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  86.172 +        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
  86.173 +        gridBagConstraints.weightx = 1.0;
  86.174 +        gridBagConstraints.weighty = 1.0;
  86.175 +        panel.add(new JPanel(), gridBagConstraints);
  86.176 +
  86.177 +        return panel;
  86.178 +    }
  86.179 +
  86.180 +    private static final RequestProcessor WORKER = new RequestProcessor(GlobalFindDuplicates.class.getName(), 1);
  86.181 +    
  86.182 +}
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/hints/FindDuplicates.java	Sat Feb 11 18:35:10 2012 +0100
    87.3 @@ -0,0 +1,133 @@
    87.4 +/*
    87.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    87.6 + *
    87.7 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
    87.8 + *
    87.9 + * The contents of this file are subject to the terms of either the GNU
   87.10 + * General Public License Version 2 only ("GPL") or the Common
   87.11 + * Development and Distribution License("CDDL") (collectively, the
   87.12 + * "License"). You may not use this file except in compliance with the
   87.13 + * License. You can obtain a copy of the License at
   87.14 + * http://www.netbeans.org/cddl-gplv2.html
   87.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   87.16 + * specific language governing permissions and limitations under the
   87.17 + * License.  When distributing the software, include this License Header
   87.18 + * Notice in each file and include the License file at
   87.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   87.20 + * particular file as subject to the "Classpath" exception as provided
   87.21 + * by Sun in the GPL Version 2 section of the License file that
   87.22 + * accompanied this code. If applicable, add the following below the
   87.23 + * License Header, with the fields enclosed by brackets [] replaced by
   87.24 + * your own identifying information:
   87.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   87.26 + *
   87.27 + * If you wish your version of this file to be governed by only the CDDL
   87.28 + * or only the GPL Version 2, indicate your decision by adding
   87.29 + * "[Contributor] elects to include this software in this distribution
   87.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   87.31 + * single choice of license, a recipient has the option to distribute
   87.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   87.33 + * to extend the choice of license to its licensees as provided above.
   87.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   87.35 + * Version 2 license, then the option applies only if the new code is
   87.36 + * made subject to such option by the copyright holder.
   87.37 + *
   87.38 + * Contributor(s):
   87.39 + *
   87.40 + * Portions Copyrighted 2009 Sun Microsystems, Inc.
   87.41 + */
   87.42 +
   87.43 +package org.netbeans.modules.jackpot30.impl.duplicates.hints;
   87.44 +
   87.45 +import java.util.Collection;
   87.46 +import java.util.Collections;
   87.47 +import java.util.Iterator;
   87.48 +import java.util.LinkedList;
   87.49 +import java.util.List;
   87.50 +import java.util.Map;
   87.51 +import java.util.concurrent.atomic.AtomicBoolean;
   87.52 +import java.util.logging.Level;
   87.53 +import java.util.logging.Logger;
   87.54 +import org.netbeans.api.java.source.CancellableTask;
   87.55 +import org.netbeans.api.java.source.CompilationInfo;
   87.56 +import org.netbeans.api.java.source.JavaSource.Phase;
   87.57 +import org.netbeans.api.java.source.JavaSource.Priority;
   87.58 +import org.netbeans.api.java.source.JavaSourceTaskFactory;
   87.59 +import org.netbeans.api.java.source.support.EditorAwareJavaSourceTaskFactory;
   87.60 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates;
   87.61 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   87.62 +import org.netbeans.modules.jackpot30.impl.duplicates.indexing.RemoteDuplicatesIndex;
   87.63 +import org.netbeans.spi.editor.hints.ErrorDescription;
   87.64 +import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
   87.65 +import org.netbeans.spi.editor.hints.HintsController;
   87.66 +import org.netbeans.spi.editor.hints.Severity;
   87.67 +import org.openide.filesystems.FileObject;
   87.68 +import org.openide.util.NbCollections;
   87.69 +import org.openide.util.lookup.ServiceProvider;
   87.70 +
   87.71 +/**
   87.72 + *
   87.73 + * @author lahvac
   87.74 + */
   87.75 +public class FindDuplicates implements CancellableTask<CompilationInfo> {
   87.76 +
   87.77 +    private final AtomicBoolean cancel = new AtomicBoolean();
   87.78 +    
   87.79 +    public void run(CompilationInfo info) throws Exception {
   87.80 +        cancel.set(false);
   87.81 +
   87.82 +        long start = System.currentTimeMillis();
   87.83 +        try {
   87.84 +            Collection<? extends ErrorDescription> eds = computeErrorDescription(info);
   87.85 +
   87.86 +            if (cancel.get()) return;
   87.87 +
   87.88 +            if (eds == null) {
   87.89 +                eds = Collections.emptyList();
   87.90 +            }
   87.91 +
   87.92 +            HintsController.setErrors(info.getFileObject(), FindDuplicates.class.getName(), eds);
   87.93 +        } finally {
   87.94 +            long end = System.currentTimeMillis();
   87.95 +
   87.96 +            Logger.getLogger("TIMER").log(Level.FINE, "Duplicates in editor", new Object[] {info.getFileObject(), end - start});
   87.97 +        }
   87.98 +    }
   87.99 +
  87.100 +    private Collection<? extends ErrorDescription> computeErrorDescription(CompilationInfo info) throws Exception {
  87.101 +        List<ErrorDescription> result = new LinkedList<ErrorDescription>();
  87.102 +
  87.103 +        Map<String, long[]> encoded = ComputeDuplicates.encodeGeneralized(info);
  87.104 +        Iterator<? extends DuplicateDescription> duplicates = RemoteDuplicatesIndex.findDuplicates(encoded, info.getFileObject()).iterator();
  87.105 +
  87.106 +        for (DuplicateDescription dd : NbCollections.iterable(duplicates)) {
  87.107 +            long[] spans = encoded.get(dd.hash);
  87.108 +
  87.109 +            for (int c = 0; c < spans.length; c += 2) {
  87.110 +                if (cancel.get()) return null;
  87.111 +                result.add(ErrorDescriptionFactory.createErrorDescription(Severity.WARNING, "Duplicate of code from " + dd.dupes.get(0).file, info.getFileObject(), (int) spans[c], (int) spans[c + 1]));
  87.112 +            }
  87.113 +        }
  87.114 +
  87.115 +        return result;
  87.116 +    }
  87.117 +    
  87.118 +    public void cancel() {
  87.119 +        cancel.set(true);
  87.120 +    }
  87.121 +
  87.122 +    @ServiceProvider(service=JavaSourceTaskFactory.class)
  87.123 +    public static final class FactoryImpl extends EditorAwareJavaSourceTaskFactory {
  87.124 +
  87.125 +        public FactoryImpl() {
  87.126 +            super(Phase.RESOLVED, Priority.LOW);
  87.127 +        }
  87.128 +
  87.129 +        @Override
  87.130 +        protected CancellableTask<CompilationInfo> createTask(FileObject file) {
  87.131 +            return new FindDuplicates();
  87.132 +        }
  87.133 +        
  87.134 +    }
  87.135 +
  87.136 +}
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DeferredCustomIndexer.java	Sat Feb 11 18:35:10 2012 +0100
    88.3 @@ -0,0 +1,500 @@
    88.4 +/*
    88.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    88.6 + *
    88.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    88.8 + *
    88.9 + * The contents of this file are subject to the terms of either the GNU
   88.10 + * General Public License Version 2 only ("GPL") or the Common
   88.11 + * Development and Distribution License("CDDL") (collectively, the
   88.12 + * "License"). You may not use this file except in compliance with the
   88.13 + * License. You can obtain a copy of the License at
   88.14 + * http://www.netbeans.org/cddl-gplv2.html
   88.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   88.16 + * specific language governing permissions and limitations under the
   88.17 + * License.  When distributing the software, include this License Header
   88.18 + * Notice in each file and include the License file at
   88.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   88.20 + * particular file as subject to the "Classpath" exception as provided
   88.21 + * by Sun in the GPL Version 2 section of the License file that
   88.22 + * accompanied this code. If applicable, add the following below the
   88.23 + * License Header, with the fields enclosed by brackets [] replaced by
   88.24 + * your own identifying information:
   88.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   88.26 + *
   88.27 + * If you wish your version of this file to be governed by only the CDDL
   88.28 + * or only the GPL Version 2, indicate your decision by adding
   88.29 + * "[Contributor] elects to include this software in this distribution
   88.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   88.31 + * single choice of license, a recipient has the option to distribute
   88.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   88.33 + * to extend the choice of license to its licensees as provided above.
   88.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   88.35 + * Version 2 license, then the option applies only if the new code is
   88.36 + * made subject to such option by the copyright holder.
   88.37 + *
   88.38 + * Contributor(s):
   88.39 + *
   88.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   88.41 + */
   88.42 +
   88.43 +package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   88.44 +
   88.45 +import java.io.BufferedWriter;
   88.46 +import java.io.File;
   88.47 +import java.io.IOException;
   88.48 +import java.io.OutputStreamWriter;
   88.49 +import java.io.Writer;
   88.50 +import java.net.URL;
   88.51 +import java.util.Collection;
   88.52 +import java.util.Collections;
   88.53 +import java.util.HashMap;
   88.54 +import java.util.HashSet;
   88.55 +import java.util.Iterator;
   88.56 +import java.util.Map;
   88.57 +import java.util.Map.Entry;
   88.58 +import java.util.Set;
   88.59 +import java.util.concurrent.atomic.AtomicBoolean;
   88.60 +import java.util.logging.Level;
   88.61 +import java.util.logging.Logger;
   88.62 +import javax.swing.JButton;
   88.63 +import javax.swing.SwingUtilities;
   88.64 +import org.netbeans.api.annotations.common.NonNull;
   88.65 +import org.netbeans.api.java.classpath.ClassPath;
   88.66 +import org.netbeans.api.java.source.CancellableTask;
   88.67 +import org.netbeans.api.java.source.ClasspathInfo;
   88.68 +import org.netbeans.api.java.source.CompilationController;
   88.69 +import org.netbeans.api.java.source.CompilationInfo;
   88.70 +import org.netbeans.api.java.source.JavaSource;
   88.71 +import org.netbeans.api.java.source.JavaSource.Phase;
   88.72 +import org.netbeans.api.java.source.JavaSource.Priority;
   88.73 +import org.netbeans.api.java.source.JavaSourceTaskFactory;
   88.74 +import org.netbeans.api.java.source.Task;
   88.75 +import org.netbeans.api.progress.ProgressHandle;
   88.76 +import org.netbeans.api.progress.ProgressHandleFactory;
   88.77 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   88.78 +import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
   88.79 +import org.netbeans.modules.parsing.spi.indexing.Context;
   88.80 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
   88.81 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
   88.82 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
   88.83 +import org.openide.DialogDescriptor;
   88.84 +import org.openide.DialogDisplayer;
   88.85 +import org.openide.filesystems.FileAlreadyLockedException;
   88.86 +import org.openide.filesystems.FileObject;
   88.87 +import org.openide.filesystems.FileUtil;
   88.88 +import org.openide.filesystems.URLMapper;
   88.89 +import org.openide.util.Cancellable;
   88.90 +import org.openide.util.Exceptions;
   88.91 +import org.openide.util.Lookup;
   88.92 +import org.openide.util.lookup.ServiceProvider;
   88.93 +
   88.94 +/**
   88.95 + *
   88.96 + * @author lahvac
   88.97 + */
   88.98 +public abstract class DeferredCustomIndexer extends CustomIndexer {
   88.99 +
  88.100 +    private static final Logger LOG = Logger.getLogger(DeferredCustomIndexer.class.getName());
  88.101 +    
  88.102 +    private final DeferredCustomIndexerFactory factory;
  88.103 +
  88.104 +    protected DeferredCustomIndexer(DeferredCustomIndexerFactory factory) {
  88.105 +        this.factory = factory;
  88.106 +    }
  88.107 +
  88.108 +    protected abstract void doIndex(DeferredContext ctx, Collection<? extends FileObject> modifiedAndAdded, Collection<? extends String> removed) throws IOException;
  88.109 +
  88.110 +    @Override
  88.111 +    protected final void index(Iterable<? extends Indexable> files, Context context) {
  88.112 +        update(factory, context.getRootURI(), files, Collections.<Indexable>emptyList());
  88.113 +    }
  88.114 +
  88.115 +    private static void dump(File where, Iterable<? extends String> lines) {
  88.116 +        Writer out = null;
  88.117 +
  88.118 +        try {
  88.119 +            out = new BufferedWriter(new OutputStreamWriter(FileUtil.createData(where).getOutputStream(), "UTF-8"));
  88.120 +            
  88.121 +            for (String line : lines) {
  88.122 +                out.write(line);
  88.123 +                out.write("\n");
  88.124 +            }
  88.125 +        } catch (FileAlreadyLockedException ex) {
  88.126 +            Exceptions.printStackTrace(ex);
  88.127 +        } catch (IOException ex) {
  88.128 +            Exceptions.printStackTrace(ex);
  88.129 +        } finally {
  88.130 +            if (out != null) {
  88.131 +                try {
  88.132 +                    out.close();
  88.133 +                } catch (IOException ex) {
  88.134 +                    Exceptions.printStackTrace(ex);
  88.135 +                }
  88.136 +            }
  88.137 +        }
  88.138 +    }
  88.139 +
  88.140 +    private static Set<String> gatherRelativePaths(Iterable<? extends Indexable> it) {
  88.141 +        Set<String> result = new HashSet<String>();
  88.142 +
  88.143 +        for (Indexable i : it) {
  88.144 +            result.add(i.getRelativePath());
  88.145 +        }
  88.146 +
  88.147 +        return result;
  88.148 +    }
  88.149 +
  88.150 +    private static void update(DeferredCustomIndexerFactory factory, URL root, Iterable<? extends Indexable> modified, Iterable<? extends Indexable> deleted) {
  88.151 +        try {
  88.152 +            Set<String> mod = gatherRelativePaths(modified);
  88.153 +            Set<String> del = gatherRelativePaths(deleted);
  88.154 +
  88.155 +            File cacheRoot = cacheRoot(root, factory);
  88.156 +            
  88.157 +            File modifiedFile = new File(cacheRoot, "modified");
  88.158 +            FileObject modifiedFileFO = FileUtil.toFileObject(modifiedFile);
  88.159 +            Set<String> modifiedFiles = modifiedFileFO != null ? new HashSet<String>(modifiedFileFO.asLines("UTF-8")) : new HashSet<String>();
  88.160 +            boolean modifiedFilesChanged = modifiedFiles.removeAll(del);
  88.161 +
  88.162 +            modifiedFilesChanged |= modifiedFiles.addAll(mod);
  88.163 +
  88.164 +            if (modifiedFilesChanged) {
  88.165 +                dump(modifiedFile, modifiedFiles);
  88.166 +            }
  88.167 +
  88.168 +            File deletedFile = new File(cacheRoot, "deleted");
  88.169 +            FileObject deletedFileFO = FileUtil.toFileObject(deletedFile);
  88.170 +            Set<String> deletedFiles = deletedFileFO != null ? new HashSet<String>(deletedFileFO.asLines("UTF-8")) : new HashSet<String>();
  88.171 +
  88.172 +            boolean deletedFilesChanged = deletedFiles.removeAll(mod);
  88.173 +
  88.174 +            deletedFilesChanged |= deletedFiles.addAll(del);
  88.175 +
  88.176 +            if (deletedFilesChanged) {
  88.177 +                dump(deletedFile, deletedFiles);
  88.178 +            }
  88.179 +
  88.180 +            if (!modifiedFiles.isEmpty() || !deletedFiles.isEmpty()) {
  88.181 +                add2TODO(root, factory);
  88.182 +            }
  88.183 +        } catch (IOException ex) {
  88.184 +            Exceptions.printStackTrace(ex);
  88.185 +        }
  88.186 +    }
  88.187 +    
  88.188 +    public static abstract class DeferredCustomIndexerFactory extends CustomIndexerFactory {
  88.189 +
  88.190 +        public abstract DeferredCustomIndexer createIndexer();
  88.191 +
  88.192 +        @Override
  88.193 +        public final void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
  88.194 +            update(this, context.getRootURI(), Collections.<Indexable>emptyList(), deleted);
  88.195 +        }
  88.196 +
  88.197 +        @Override
  88.198 +        public final void filesDirty(Iterable<? extends Indexable> dirty, Context context) {}
  88.199 +
  88.200 +        @Override
  88.201 +        public final boolean supportsEmbeddedIndexers() {
  88.202 +            return false;
  88.203 +        }
  88.204 +
  88.205 +        @Override
  88.206 +        public final void rootsRemoved(Iterable<? extends URL> removedRoots) {
  88.207 +            super.rootsRemoved(removedRoots);
  88.208 +        }
  88.209 +
  88.210 +        @Override
  88.211 +        public final void scanFinished(Context context) {
  88.212 +            super.scanFinished(context);
  88.213 +        }
  88.214 +
  88.215 +        @Override
  88.216 +        public final boolean scanStarted(Context context) {
  88.217 +            return super.scanStarted(context);
  88.218 +        }
  88.219 +
  88.220 +        public void updateIndex(final URL root, final AtomicBoolean cancel) throws IOException {
  88.221 +            final FileObject rootFO = URLMapper.findFileObject(root);
  88.222 +            final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY);
  88.223 +
  88.224 +            JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
  88.225 +                public void run(CompilationController parameter) throws Exception {
  88.226 +                    if (cancel.get()) return ;
  88.227 +                    updateRoot(DeferredCustomIndexerFactory.this, root, rootFO, cancel);
  88.228 +                }
  88.229 +            }, true);
  88.230 +        }
  88.231 +
  88.232 +    }
  88.233 +
  88.234 +    public static final class DeferredContext {
  88.235 +        private final @NonNull URL root;
  88.236 +        private final @NonNull FileObject rootFileObject;
  88.237 +        private final @NonNull FileObject cacheRoot;
  88.238 +        private final @NonNull Set<? extends FileObject> modifiedAndAdded;
  88.239 +        private final @NonNull Set<? extends String> removed;
  88.240 +        private final @NonNull AtomicBoolean cancel;
  88.241 +
  88.242 +        public DeferredContext(URL root, FileObject rootFileObject, FileObject cacheRoot, Set<? extends FileObject> modifiedAndAdded, Set<? extends String> removed, AtomicBoolean cancel) {
  88.243 +            this.root = root;
  88.244 +            this.rootFileObject = rootFileObject;
  88.245 +            this.cacheRoot = cacheRoot;
  88.246 +            this.modifiedAndAdded = modifiedAndAdded;
  88.247 +            this.removed = removed;
  88.248 +            this.cancel = cancel;
  88.249 +        }
  88.250 +
  88.251 +        public @NonNull URL getRoot() {
  88.252 +            return root;
  88.253 +        }
  88.254 +
  88.255 +        public @NonNull FileObject getRootFileObject() {
  88.256 +            return rootFileObject;
  88.257 +        }
  88.258 +
  88.259 +        public FileObject getCacheRoot() {
  88.260 +            return cacheRoot;
  88.261 +        }
  88.262 +
  88.263 +        public boolean isCancelled() {
  88.264 +            return cancel.get();
  88.265 +        }
  88.266 +
  88.267 +        public void handledModifiedFile(FileObject file) {
  88.268 +            modifiedAndAdded.remove(file);
  88.269 +        }
  88.270 +
  88.271 +        public void handledRemovedFile(String relative) {
  88.272 +            removed.remove(relative);
  88.273 +        }
  88.274 +    }
  88.275 +
  88.276 +    /*return: true == done*/
  88.277 +    private static boolean updateRoot(DeferredCustomIndexerFactory factory, URL root, FileObject rootFO, AtomicBoolean cancel) throws IOException {
  88.278 +        LOG.log(Level.FINE, "updating: {0}, for indexer: {1}", new Object[] {root.toExternalForm(), factory.getIndexerName()});
  88.279 +         File cacheRoot = cacheRoot(root, factory);
  88.280 +         FileObject deletedFile = FileUtil.toFileObject(new File(cacheRoot, "deleted"));
  88.281 +         Set<String> deletedFiles = deletedFile != null ? new HashSet<String>(deletedFile.asLines("UTF-8")) : Collections.<String>emptySet();
  88.282 +
  88.283 +         FileObject modifiedFile = FileUtil.toFileObject(new File(cacheRoot, "modified"));
  88.284 +         Set<String> modifiedFiles = modifiedFile != null ? new HashSet<String>(modifiedFile.asLines("UTF-8")) : Collections.<String>emptySet();
  88.285 +
  88.286 +         Set<FileObject> toIndex = new HashSet<FileObject>();
  88.287 +
  88.288 +         for (String r : modifiedFiles) {
  88.289 +             FileObject f = rootFO.getFileObject(r);
  88.290 +
  88.291 +             if (f != null) {
  88.292 +                 toIndex.add(f);
  88.293 +             }
  88.294 +         }
  88.295 +
  88.296 +         if (!toIndex.isEmpty() || !modifiedFiles.isEmpty()) {
  88.297 +             factory.createIndexer().doIndex(new DeferredContext(root, rootFO, FileUtil.toFileObject(cacheRoot), toIndex, deletedFiles, cancel), new HashSet<FileObject>(toIndex), new HashSet<String>(deletedFiles));
  88.298 +         }
  88.299 +
  88.300 +         boolean done = true;
  88.301 +
  88.302 +         if (deletedFile != null) {
  88.303 +             if (deletedFiles.isEmpty()) {
  88.304 +                 deletedFile.delete();
  88.305 +             } else {
  88.306 +                 dump(new File(cacheRoot, "deleted"), deletedFiles);
  88.307 +                 done = false;
  88.308 +             }
  88.309 +         }
  88.310 +         if (modifiedFile != null) {
  88.311 +             if (toIndex.isEmpty()) {
  88.312 +                 modifiedFile.delete();
  88.313 +             }  else {
  88.314 +                 modifiedFiles.clear();
  88.315 +
  88.316 +                 for (FileObject f : toIndex) {
  88.317 +                     modifiedFiles.add(FileUtil.getRelativePath(rootFO, f));
  88.318 +                 }
  88.319 +
  88.320 +                 dump(new File(cacheRoot, "modified"), modifiedFiles);
  88.321 +                 done = false;
  88.322 +             }
  88.323 +         }
  88.324 +
  88.325 +         return done;
  88.326 +    }
  88.327 +
  88.328 +    private static final Map<String, TODO> todo = new HashMap<String, TODO>(); //XXX: synchronization!!!
  88.329 +
  88.330 +    private static void add2TODO(URL root, DeferredCustomIndexerFactory factory) {
  88.331 +        if (DISABLED_INDEXERS.contains(factory.getIndexerName())) return;
  88.332 +        
  88.333 +        boolean wasEmpty = todo.isEmpty();
  88.334 +        TODO roots = todo.get(factory.getIndexerName());
  88.335 +
  88.336 +        if (roots == null) {
  88.337 +            todo.put(factory.getIndexerName(), roots = new TODO(factory));
  88.338 +        }
  88.339 +
  88.340 +        roots.roots.add(root);
  88.341 +
  88.342 +        LOG.log(Level.FINE, "add2TODO, root: {0}, for factory: {1}, wasEmpty: {2}, todo: {3}", new Object[] {root.toExternalForm(), factory.getIndexerName(), wasEmpty, todo.toString()});
  88.343 +        
  88.344 +        if (wasEmpty) RunAsNeededFactory.fileChanged();
  88.345 +        else RunAsNeededFactory.refresh();
  88.346 +    }
  88.347 +    
  88.348 +    private static File cacheRoot(URL root, CustomIndexerFactory factory) throws IOException {
  88.349 +        FileObject indexBaseFolder = CacheFolder.getDataFolder(root);
  88.350 +        String path = SPIAccessor.getInstance().getIndexerPath(factory.getIndexerName(), factory.getIndexVersion());
  88.351 +        FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path);
  88.352 +        return FileUtil.toFile(indexFolder);
  88.353 +    }
  88.354 +
  88.355 +    private static final Set<String> DISABLED_INDEXERS = Collections.synchronizedSet(new HashSet<String>());
  88.356 +
  88.357 +    private static class UpdateWorker implements CancellableTask<CompilationInfo> {
  88.358 +
  88.359 +        private static ProgressHandle progressForCurrentFactory;
  88.360 +        private static DeferredCustomIndexerFactory currentFactory;
  88.361 +        
  88.362 +        private final AtomicBoolean cancel = new AtomicBoolean();
  88.363 +
  88.364 +        public void run(CompilationInfo parameter) throws Exception {
  88.365 +            cancel.set(false);
  88.366 +
  88.367 +            for (Iterator<Entry<String, TODO>> it = todo.entrySet().iterator(); it.hasNext();) {
  88.368 +                if (cancel.get()) return;
  88.369 +
  88.370 +                final Entry<String, TODO> e = it.next();
  88.371 +
  88.372 +                if (DISABLED_INDEXERS.contains(e.getKey())) {
  88.373 +                    it.remove();
  88.374 +                    continue;
  88.375 +                }
  88.376 +                
  88.377 +                if (currentFactory != e.getValue().factory) {
  88.378 +                    if (progressForCurrentFactory != null) {
  88.379 +                        progressForCurrentFactory.finish();
  88.380 +                    }
  88.381 +
  88.382 +                    currentFactory = e.getValue().factory;
  88.383 +                    progressForCurrentFactory = ProgressHandleFactory.createSystemHandle("Background indexing for: " + currentFactory.getIndexerName(), new Cancellable() {
  88.384 +                        public boolean cancel() {
  88.385 +                            assert SwingUtilities.isEventDispatchThread();
  88.386 +
  88.387 +                            JButton disableInThisSession = new JButton("Disable in This Session");
  88.388 +                            JButton disablePermanently = new JButton("Disable Permanently");
  88.389 +
  88.390 +                            disablePermanently.setEnabled(false);
  88.391 +
  88.392 +                            Object[] buttons = new Object[]{disableInThisSession, disablePermanently, DialogDescriptor.CANCEL_OPTION};
  88.393 +                            DialogDescriptor dd = new DialogDescriptor("Disable background indexing for: " + e.getValue().factory.getIndexerName(), "Disable Background Indexing", true, buttons, disableInThisSession, DialogDescriptor.DEFAULT_ALIGN, null, null);
  88.394 +
  88.395 +                            dd.setClosingOptions(buttons);
  88.396 +
  88.397 +                            Object result = DialogDisplayer.getDefault().notify(dd);
  88.398 +
  88.399 +                            if (result == disableInThisSession) {
  88.400 +                                DISABLED_INDEXERS.add(e.getKey());
  88.401 +                                return true;
  88.402 +                            } else if (result == disablePermanently) {
  88.403 +                                throw new UnsupportedOperationException();
  88.404 +                            } else {
  88.405 +                                return false;
  88.406 +                            }
  88.407 +                        }
  88.408 +                    });
  88.409 +
  88.410 +                    progressForCurrentFactory.start();
  88.411 +                }
  88.412 +
  88.413 +                for (Iterator<URL> factIt = e.getValue().roots.iterator(); factIt.hasNext();) {
  88.414 +                    if (cancel.get()) return;
  88.415 +
  88.416 +                    URL root = factIt.next();
  88.417 +                    FileObject rootFO = URLMapper.findFileObject(root);
  88.418 +
  88.419 +                    if (rootFO == null) {
  88.420 +                        //already deleted
  88.421 +                        it.remove();
  88.422 +                        continue;
  88.423 +                    }
  88.424 +
  88.425 +                    if (updateRoot(e.getValue().factory, root, rootFO, cancel)) {
  88.426 +                        factIt.remove();
  88.427 +                    } else {
  88.428 +                        if (!cancel.get()) {
  88.429 +                            LOG.log(Level.WARNING, "indexer: {0} did not update all files even if the process was not cancelled", currentFactory.getIndexerName());
  88.430 +                        }
  88.431 +                    }
  88.432 +                }
  88.433 +
  88.434 +                if (e.getValue().roots.isEmpty())
  88.435 +                    it.remove();
  88.436 +
  88.437 +                progressForCurrentFactory.finish();
  88.438 +                progressForCurrentFactory = null;
  88.439 +                currentFactory = null;
  88.440 +            }
  88.441 +
  88.442 +            if (todo.isEmpty()) RunAsNeededFactory.fileChanged();
  88.443 +        }
  88.444 +
  88.445 +        public void cancel() {
  88.446 +            cancel.set(true);
  88.447 +        }
  88.448 +    }
  88.449 +
  88.450 +    private static final class TODO {
  88.451 +        final DeferredCustomIndexerFactory factory;
  88.452 +        final Collection<URL> roots = new HashSet<URL>();
  88.453 +        TODO(DeferredCustomIndexerFactory factory) {
  88.454 +            this.factory = factory;
  88.455 +        }
  88.456 +    }
  88.457 +
  88.458 +    private static final boolean DEFERRED_INDEXER_ENABLED = Boolean.getBoolean(DeferredCustomIndexerFactory.class.getName() + ".enable");
  88.459 +    
  88.460 +    private static final FileObject EMPTY_FILE;
  88.461 +
  88.462 +    static {
  88.463 +        try {
  88.464 +            EMPTY_FILE = FileUtil.createMemoryFileSystem().getRoot().createData("empty.java");
  88.465 +        } catch (IOException ex) {
  88.466 +            throw new IllegalStateException(ex);
  88.467 +        }
  88.468 +    }
  88.469 +
  88.470 +    @ServiceProvider(service=JavaSourceTaskFactory.class)
  88.471 +    public static final class RunAsNeededFactory extends JavaSourceTaskFactory {
  88.472 +
  88.473 +        public RunAsNeededFactory() {
  88.474 +            super(Phase.PARSED, Priority.MIN);
  88.475 +        }
  88.476 +
  88.477 +        @Override
  88.478 +        protected CancellableTask<CompilationInfo> createTask(FileObject file) {
  88.479 +            return new UpdateWorker();
  88.480 +        }
  88.481 +
  88.482 +        @Override
  88.483 +        protected Collection<FileObject> getFileObjects() {
  88.484 +            return DEFERRED_INDEXER_ENABLED && !todo.isEmpty() ? Collections.singletonList(EMPTY_FILE) : Collections.<FileObject>emptyList();
  88.485 +        }
  88.486 +
  88.487 +        public static void fileChanged() {
  88.488 +            for (JavaSourceTaskFactory f : Lookup.getDefault().lookupAll(JavaSourceTaskFactory.class)) {
  88.489 +                if (f instanceof RunAsNeededFactory) {
  88.490 +                    ((RunAsNeededFactory) f).fileObjectsChanged();
  88.491 +                }
  88.492 +            }
  88.493 +        }
  88.494 +
  88.495 +        public static void refresh() {
  88.496 +            for (JavaSourceTaskFactory f : Lookup.getDefault().lookupAll(JavaSourceTaskFactory.class)) {
  88.497 +                if (f instanceof RunAsNeededFactory) {
  88.498 +                    ((RunAsNeededFactory) f).reschedule(EMPTY_FILE);
  88.499 +                }
  88.500 +            }
  88.501 +        }
  88.502 +    }
  88.503 +}
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java	Sat Feb 11 18:35:10 2012 +0100
    89.3 @@ -0,0 +1,131 @@
    89.4 +/*
    89.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    89.6 + *
    89.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    89.8 + *
    89.9 + * The contents of this file are subject to the terms of either the GNU
   89.10 + * General Public License Version 2 only ("GPL") or the Common
   89.11 + * Development and Distribution License("CDDL") (collectively, the
   89.12 + * "License"). You may not use this file except in compliance with the
   89.13 + * License. You can obtain a copy of the License at
   89.14 + * http://www.netbeans.org/cddl-gplv2.html
   89.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   89.16 + * specific language governing permissions and limitations under the
   89.17 + * License.  When distributing the software, include this License Header
   89.18 + * Notice in each file and include the License file at
   89.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   89.20 + * particular file as subject to the "Classpath" exception as provided
   89.21 + * by Sun in the GPL Version 2 section of the License file that
   89.22 + * accompanied this code. If applicable, add the following below the
   89.23 + * License Header, with the fields enclosed by brackets [] replaced by
   89.24 + * your own identifying information:
   89.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   89.26 + *
   89.27 + * If you wish your version of this file to be governed by only the CDDL
   89.28 + * or only the GPL Version 2, indicate your decision by adding
   89.29 + * "[Contributor] elects to include this software in this distribution
   89.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   89.31 + * single choice of license, a recipient has the option to distribute
   89.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   89.33 + * to extend the choice of license to its licensees as provided above.
   89.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   89.35 + * Version 2 license, then the option applies only if the new code is
   89.36 + * made subject to such option by the copyright holder.
   89.37 + *
   89.38 + * Contributor(s):
   89.39 + *
   89.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   89.41 + */
   89.42 +
   89.43 +package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   89.44 +
   89.45 +import java.io.IOException;
   89.46 +import java.net.URL;
   89.47 +import java.util.Collection;
   89.48 +import org.netbeans.api.java.source.ClasspathInfo;
   89.49 +import org.netbeans.api.java.source.CompilationController;
   89.50 +import org.netbeans.api.java.source.JavaSource;
   89.51 +import org.netbeans.api.java.source.JavaSource.Phase;
   89.52 +import org.netbeans.api.java.source.Task;
   89.53 +import org.netbeans.modules.parsing.impl.indexing.IndexableImpl;
   89.54 +import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
   89.55 +import org.openide.filesystems.FileObject;
   89.56 +import org.openide.util.Exceptions;
   89.57 +
   89.58 +/**
   89.59 + *
   89.60 + * @author lahvac
   89.61 + */
   89.62 +public class DuplicatesCustomIndexerImpl extends DeferredCustomIndexer {
   89.63 +
   89.64 +    public DuplicatesCustomIndexerImpl(DeferredCustomIndexerFactory factory) {
   89.65 +        super(factory);
   89.66 +    }
   89.67 +
   89.68 +    protected void doIndex(final DeferredContext ctx, Collection<? extends FileObject> modifiedAndAdded, Collection<? extends String> removed) throws IOException {
   89.69 +        final DuplicatesIndex[] w = new DuplicatesIndex[1];
   89.70 +
   89.71 +        try {
   89.72 +            w[0] = new DuplicatesIndex(ctx.getRoot(), ctx.getCacheRoot());
   89.73 +
   89.74 +            for (String r : removed) {
   89.75 +                w[0].remove(r);
   89.76 +                ctx.handledRemovedFile(r);
   89.77 +            }
   89.78 +
   89.79 +            final ClasspathInfo cpInfo = ClasspathInfo.create(ctx.getRootFileObject());
   89.80 +
   89.81 +            JavaSource.create(cpInfo, modifiedAndAdded).runUserActionTask(new Task<CompilationController>() {
   89.82 +                public void run(final CompilationController cc) throws Exception {
   89.83 +                    if (cc.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0)
   89.84 +                        return ;
   89.85 +
   89.86 +                    w[0].record(cc, SPIAccessor.getInstance().create(new IndexableImpl() {
   89.87 +                        @Override public String getRelativePath() {
   89.88 +                            throw new UnsupportedOperationException("Not supported yet.");
   89.89 +                        }
   89.90 +                        @Override public URL getURL() {
   89.91 +                            return cc.getFileObject().toURL();
   89.92 +                        }
   89.93 +                        @Override public String getMimeType() {
   89.94 +                            throw new UnsupportedOperationException("Not supported yet.");
   89.95 +                        }
   89.96 +                        @Override public boolean isTypeOf(String mimeType) {
   89.97 +                            throw new UnsupportedOperationException("Not supported yet.");
   89.98 +                        }
   89.99 +                    }), cc.getCompilationUnit());
  89.100 +
  89.101 +                    ctx.handledModifiedFile(cc.getFileObject());
  89.102 +                }
  89.103 +            }, true);
  89.104 +        } finally {
  89.105 +            if (w[0] != null) {
  89.106 +                try {
  89.107 +                    w[0].close();
  89.108 +                } catch (IOException ex) {
  89.109 +                    Exceptions.printStackTrace(ex);
  89.110 +                }
  89.111 +            }
  89.112 +        }
  89.113 +    }
  89.114 +    
  89.115 +    public static final class FactoryImpl extends DeferredCustomIndexerFactory {
  89.116 +
  89.117 +        @Override
  89.118 +        public DeferredCustomIndexer createIndexer() {
  89.119 +            return new DuplicatesCustomIndexerImpl(this);
  89.120 +        }
  89.121 +
  89.122 +        @Override
  89.123 +        public String getIndexerName() {
  89.124 +            return DuplicatesIndex.NAME;
  89.125 +        }
  89.126 +
  89.127 +        @Override
  89.128 +        public int getIndexVersion() {
  89.129 +            return DuplicatesIndex.VERSION;
  89.130 +        }
  89.131 +
  89.132 +    }
  89.133 +
  89.134 +}
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java	Sat Feb 11 18:35:10 2012 +0100
    90.3 @@ -0,0 +1,116 @@
    90.4 +/*
    90.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    90.6 + *
    90.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    90.8 + *
    90.9 + * The contents of this file are subject to the terms of either the GNU
   90.10 + * General Public License Version 2 only ("GPL") or the Common
   90.11 + * Development and Distribution License("CDDL") (collectively, the
   90.12 + * "License"). You may not use this file except in compliance with the
   90.13 + * License. You can obtain a copy of the License at
   90.14 + * http://www.netbeans.org/cddl-gplv2.html
   90.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   90.16 + * specific language governing permissions and limitations under the
   90.17 + * License.  When distributing the software, include this License Header
   90.18 + * Notice in each file and include the License file at
   90.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   90.20 + * particular file as subject to the "Classpath" exception as provided
   90.21 + * by Sun in the GPL Version 2 section of the License file that
   90.22 + * accompanied this code. If applicable, add the following below the
   90.23 + * License Header, with the fields enclosed by brackets [] replaced by
   90.24 + * your own identifying information:
   90.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   90.26 + *
   90.27 + * If you wish your version of this file to be governed by only the CDDL
   90.28 + * or only the GPL Version 2, indicate your decision by adding
   90.29 + * "[Contributor] elects to include this software in this distribution
   90.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   90.31 + * single choice of license, a recipient has the option to distribute
   90.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   90.33 + * to extend the choice of license to its licensees as provided above.
   90.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   90.35 + * Version 2 license, then the option applies only if the new code is
   90.36 + * made subject to such option by the copyright holder.
   90.37 + *
   90.38 + * Contributor(s):
   90.39 + *
   90.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   90.41 + */
   90.42 +
   90.43 +package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   90.44 +
   90.45 +import com.sun.source.tree.CompilationUnitTree;
   90.46 +import java.io.IOException;
   90.47 +import java.net.URL;
   90.48 +import java.util.Map;
   90.49 +import java.util.Map.Entry;
   90.50 +import java.util.logging.Level;
   90.51 +import java.util.logging.Logger;
   90.52 +import org.apache.lucene.document.Document;
   90.53 +import org.apache.lucene.document.Field;
   90.54 +import org.apache.lucene.document.Field.Index;
   90.55 +import org.apache.lucene.document.Field.Store;
   90.56 +import org.apache.lucene.index.Term;
   90.57 +import org.netbeans.api.java.source.CompilationInfo;
   90.58 +import org.netbeans.modules.jackpot30.common.api.IndexAccess;
   90.59 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates;
   90.60 +import org.netbeans.modules.java.source.JavaSourceAccessor;
   90.61 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
   90.62 +import org.openide.filesystems.FileObject;
   90.63 +import org.openide.filesystems.FileUtil;
   90.64 +import org.openide.util.Lookup;
   90.65 +
   90.66 +/**
   90.67 + *
   90.68 + * @author lahvac
   90.69 + */
   90.70 +public class DuplicatesIndex {
   90.71 +
   90.72 +    private final org.apache.lucene.index.IndexWriter luceneWriter;
   90.73 +
   90.74 +    DuplicatesIndex(URL sourceRoot, FileObject cacheRoot) throws IOException {
   90.75 +        luceneWriter = Lookup.getDefault().lookup(IndexAccess.class).getIndexWriter(sourceRoot, cacheRoot, NAME);
   90.76 +    }
   90.77 +
   90.78 +    public void record(final CompilationInfo info, Indexable idx, final CompilationUnitTree cut) throws IOException {
   90.79 +        String relative = Lookup.getDefault().lookup(IndexAccess.class).getRelativePath(idx);
   90.80 +
   90.81 +        try {
   90.82 +            final Document doc = new Document();
   90.83 +
   90.84 +            doc.add(new Field("path", relative, Field.Store.YES, Field.Index.NOT_ANALYZED));
   90.85 +
   90.86 +            final Map<String, long[]> positions = ComputeDuplicates.encodeGeneralized(JavaSourceAccessor.getINSTANCE().getJavacTask(info), cut);
   90.87 +
   90.88 +            for (Entry<String, long[]> e : positions.entrySet()) {
   90.89 +                doc.add(new Field("generalized", e.getKey(), Store.YES, Index.NOT_ANALYZED));
   90.90 +
   90.91 +                StringBuilder positionsSpec = new StringBuilder();
   90.92 +
   90.93 +                for (int i = 0; i < e.getValue().length; i += 2) {
   90.94 +                    if (positionsSpec.length() > 0) positionsSpec.append(';');
   90.95 +                    positionsSpec.append(e.getValue()[i]).append(':').append(e.getValue()[i + 1] - e.getValue()[i]);
   90.96 +                }
   90.97 +
   90.98 +                doc.add(new Field("positions", positionsSpec.toString(), Store.YES, Index.NO));
   90.99 +            }
  90.100 +
  90.101 +            luceneWriter.addDocument(doc);
  90.102 +        } catch (ThreadDeath td) {
  90.103 +            throw td;
  90.104 +        } catch (Throwable t) {
  90.105 +            Logger.getLogger(DuplicatesIndex.class.getName()).log(Level.WARNING, null, t);
  90.106 +        }
  90.107 +    }
  90.108 +
  90.109 +    public void remove(String relativePath) throws IOException {
  90.110 +        luceneWriter.deleteDocuments(new Term("path", relativePath));
  90.111 +    }
  90.112 +
  90.113 +    public void close() throws IOException {
  90.114 +        Lookup.getDefault().lookup(IndexAccess.class).finish();
  90.115 +    }
  90.116 +
  90.117 +    public static final String NAME = "duplicates"; //NOI18N
  90.118 +    public static final int    VERSION = 1; //NOI18N
  90.119 +}
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/duplicates/ide/impl/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndex.java	Sat Feb 11 18:35:10 2012 +0100
    91.3 @@ -0,0 +1,413 @@
    91.4 +/*
    91.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    91.6 + *
    91.7 + * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
    91.8 + *
    91.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   91.10 + * Other names may be trademarks of their respective owners.
   91.11 + *
   91.12 + * The contents of this file are subject to the terms of either the GNU
   91.13 + * General Public License Version 2 only ("GPL") or the Common
   91.14 + * Development and Distribution License("CDDL") (collectively, the
   91.15 + * "License"). You may not use this file except in compliance with the
   91.16 + * License. You can obtain a copy of the License at
   91.17 + * http://www.netbeans.org/cddl-gplv2.html
   91.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   91.19 + * specific language governing permissions and limitations under the
   91.20 + * License.  When distributing the software, include this License Header
   91.21 + * Notice in each file and include the License file at
   91.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   91.23 + * particular file as subject to the "Classpath" exception as provided
   91.24 + * by Oracle in the GPL Version 2 section of the License file that
   91.25 + * accompanied this code. If applicable, add the following below the
   91.26 + * License Header, with the fields enclosed by brackets [] replaced by
   91.27 + * your own identifying information:
   91.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   91.29 + *
   91.30 + * If you wish your version of this file to be governed by only the CDDL
   91.31 + * or only the GPL Version 2, indicate your decision by adding
   91.32 + * "[Contributor] elects to include this software in this distribution
   91.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   91.34 + * single choice of license, a recipient has the option to distribute
   91.35 + * your version of this file under either the CDDL, the GPL Version 2 or
   91.36 + * to extend the choice of license to its licensees as provided above.
   91.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   91.38 + * Version 2 license, then the option applies only if the new code is
   91.39 + * made subject to such option by the copyright holder.
   91.40 + *
   91.41 + * Contributor(s):
   91.42 + *
   91.43 + * Portions Copyrighted 2010 Sun Microsystems, Inc.
   91.44 + */
   91.45 +
   91.46 +package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   91.47 +
   91.48 +import java.io.File;
   91.49 +import java.io.IOException;
   91.50 +import java.net.URI;
   91.51 +import java.net.URISyntaxException;
   91.52 +import java.util.ArrayList;
   91.53 +import java.util.Arrays;
   91.54 +import java.util.BitSet;
   91.55 +import java.util.Collection;
   91.56 +import java.util.Collections;
   91.57 +import java.util.Comparator;
   91.58 +import java.util.HashSet;
   91.59 +import java.util.Iterator;
   91.60 +import java.util.LinkedHashMap;
   91.61 +import java.util.LinkedHashSet;
   91.62 +import java.util.LinkedList;
   91.63 +import java.util.List;
   91.64 +import java.util.Map;
   91.65 +import java.util.Map.Entry;
   91.66 +import java.util.Set;
   91.67 +import java.util.TreeMap;
   91.68 +import java.util.logging.Level;
   91.69 +import java.util.logging.Logger;
   91.70 +import org.apache.lucene.document.Document;
   91.71 +import org.apache.lucene.document.Field;
   91.72 +import org.apache.lucene.document.Field.Index;
   91.73 +import org.apache.lucene.document.Field.Store;
   91.74 +import org.apache.lucene.index.IndexReader;
   91.75 +import org.apache.lucene.index.IndexWriter;
   91.76 +import org.apache.lucene.index.IndexWriter.MaxFieldLength;
   91.77 +import org.apache.lucene.index.Term;
   91.78 +import org.apache.lucene.search.Collector;
   91.79 +import org.apache.lucene.search.IndexSearcher;
   91.80 +import org.apache.lucene.search.Query;
   91.81 +import org.apache.lucene.search.Searcher;
   91.82 +import org.apache.lucene.search.TermQuery;
   91.83 +import org.apache.lucene.store.FSDirectory;
   91.84 +import org.codeviation.pojson.Pojson;
   91.85 +import org.netbeans.modules.jackpot30.common.api.IndexAccess.NoAnalyzer;
   91.86 +import org.netbeans.modules.jackpot30.common.api.LuceneHelpers.BitSetCollector;
   91.87 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   91.88 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   91.89 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   91.90 +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
   91.91 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   91.92 +import org.openide.filesystems.FileObject;
   91.93 +import org.openide.filesystems.FileUtil;
   91.94 +import org.openide.filesystems.URLMapper;
   91.95 +import org.openide.util.Exceptions;
   91.96 +
   91.97 +/**
   91.98 + *
   91.99 + * @author lahvac
  91.100 + */
  91.101 +public class RemoteDuplicatesIndex {
  91.102 +
  91.103 +    private static final Logger TIMER = Logger.getLogger("TIMER");
  91.104 +
  91.105 +    public static List<DuplicateDescription> findDuplicates(Map<String, long[]> hashes, FileObject currentFile) throws IOException {
  91.106 +        return translate(hashes, findHashOccurrences(hashes.keySet(), currentFile), currentFile);
  91.107 +    }
  91.108 +
  91.109 +    private static Map<String, Map<RemoteIndex, Collection<String>>> findHashOccurrences(Collection<? extends String> hashes, FileObject currentFile) throws IOException {
  91.110 +        Map<URI, Collection<RemoteIndex>> indices = new LinkedHashMap<URI, Collection<RemoteIndex>>();
  91.111 +
  91.112 +        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
  91.113 +            try {
  91.114 +                URI uri = ri.remote.toURI();
  91.115 +                Collection<RemoteIndex> list = indices.get(uri);
  91.116 +
  91.117 +                if (list == null) {
  91.118 +                    indices.put(uri, list = new ArrayList<RemoteIndex>());
  91.119 +                }
  91.120 +
  91.121 +                list.add(ri);
  91.122 +            } catch (URISyntaxException ex) {
  91.123 +                Exceptions.printStackTrace(ex);
  91.124 +            }
  91.125 +        }
  91.126 +
  91.127 +        Map<String, Map<RemoteIndex, Collection<String>>> result = new LinkedHashMap<String, Map<RemoteIndex, Collection<String>>>();
  91.128 +        long localTime = 0;
  91.129 +        long remoteTime = 0;
  91.130 +
  91.131 +        for (URI ri : indices.keySet()) {
  91.132 +            Set<String> toProcess = new LinkedHashSet<String>(hashes);
  91.133 +            Map<String, Map<String, Collection<? extends String>>> indexResult = new LinkedHashMap<String, Map<String, Collection<? extends String>>>();
  91.134 +
  91.135 +            long locS = System.currentTimeMillis();
  91.136 +            indexResult.putAll(findHashOccurrencesInLocalCache(ri, toProcess));
  91.137 +            localTime += System.currentTimeMillis() - locS;
  91.138 +
  91.139 +            toProcess.removeAll(result.keySet());
  91.140 +
  91.141 +            if (!toProcess.isEmpty()) {
  91.142 +                long remS = System.currentTimeMillis();
  91.143 +                Map<String, Map<String, Collection<? extends String>>> remoteResults = findHashOccurrencesRemote(ri, toProcess);
  91.144 +                remoteTime += System.currentTimeMillis() - remS;
  91.145 +
  91.146 +                Map<String, Map<String, Collection<? extends String>>> toSave = new LinkedHashMap<String, Map<String, Collection<? extends String>>>(remoteResults);
  91.147 +
  91.148 +                for (String hash : toProcess) {
  91.149 +                    if (!toSave.containsKey(hash)) {
  91.150 +                        toSave.put(hash, Collections.<String, Collection<? extends String>>emptyMap());
  91.151 +                    }
  91.152 +                }
  91.153 +
  91.154 +                saveToLocalCache(ri, toSave);
  91.155 +
  91.156 +                indexResult.putAll(remoteResults);
  91.157 +            }
  91.158 +
  91.159 +            for (Entry<String, Map<String, Collection<? extends String>>> e : indexResult.entrySet()) {
  91.160 +                Map<RemoteIndex, Collection<String>> hashResult = result.get(e.getKey());
  91.161 +
  91.162 +                if (hashResult == null) {
  91.163 +                    result.put(e.getKey(), hashResult = new LinkedHashMap<RemoteIndex, Collection<String>>());
  91.164 +                }
  91.165 +
  91.166 +                for (Entry<String, Collection<? extends String>> insideHash : e.getValue().entrySet()) {
  91.167 +                    RemoteIndex current = null;
  91.168 +
  91.169 +                    for (RemoteIndex r : indices.get(ri)) {
  91.170 +                        if (r.remoteSegment.equals(insideHash.getKey())) {
  91.171 +                            current = r;
  91.172 +                            break;
  91.173 +                        }
  91.174 +                    }
  91.175 +
  91.176 +                    if (current == null) {
  91.177 +                        continue;
  91.178 +                    }
  91.179 +
  91.180 +                    Collection<String> dupes = hashResult.get(current);
  91.181 +
  91.182 +                    if (dupes == null) {
  91.183 +                        hashResult.put(current, dupes = new HashSet<String>());
  91.184 +                    }
  91.185 +
  91.186 +                    dupes.addAll(insideHash.getValue());
  91.187 +                }
  91.188 +            }
  91.189 +        }
  91.190 +
  91.191 +        TIMER.log(Level.FINE, "local hash duplicates", new Object[] {currentFile, localTime});
  91.192 +        TIMER.log(Level.FINE, "remote hash duplicates", new Object[] {currentFile, remoteTime});
  91.193 +        return result;
  91.194 +    }
  91.195 +
  91.196 +    private static Map<String, Map<String, Collection<? extends String>>> findHashOccurrencesRemote(URI remoteIndex, Iterable<? extends String> hashes) {
  91.197 +        try {
  91.198 +            String indexURL = remoteIndex.toASCIIString();
  91.199 +            URI u = new URI(indexURL + "/findDuplicates?hashes=" + WebUtilities.escapeForQuery(Pojson.save(hashes)));
  91.200 +            String hashesMap = WebUtilities.requestStringResponse(u);
  91.201 +
  91.202 +            if (hashesMap == null) {
  91.203 +                //some kind of error while getting the duplicates (cannot access remote server)?
  91.204 +                //ignore:
  91.205 +                return Collections.emptyMap();
  91.206 +            }
  91.207 +            return Pojson.load(LinkedHashMap.class, hashesMap);
  91.208 +        } catch (URISyntaxException ex) {
  91.209 +            //XXX: better handling?
  91.210 +            Exceptions.printStackTrace(ex);
  91.211 +            return Collections.emptyMap();
  91.212 +        }
  91.213 +    }
  91.214 +
  91.215 +    private static volatile IndexReader readerCache;
  91.216 +
  91.217 +    private static File findLocalCacheDir(URI uri) throws IOException {
  91.218 +        return FileUtil.toFile(FileUtil.createFolder(CacheFolder.getDataFolder(uri.toURL()), "remote-duplicates"));
  91.219 +    }
  91.220 +
  91.221 +    private static Map<String, Map<String, Collection<? extends String>>> findHashOccurrencesInLocalCache(URI uri, Iterable<? extends String> hashes) throws IOException {
  91.222 +        IndexReader reader = readerCache;
  91.223 +
  91.224 +        if (reader == null) {
  91.225 +            File dir = findLocalCacheDir(uri);
  91.226 +
  91.227 +            if (dir.listFiles() != null && dir.listFiles().length > 0) {
  91.228 +                readerCache = reader = IndexReader.open(FSDirectory.open(dir), true);
  91.229 +            }
  91.230 +        }
  91.231 +
  91.232 +        if (reader == null) {
  91.233 +            return Collections.emptyMap();
  91.234 +        }
  91.235 +
  91.236 +        Map<String, Map<String, Collection<String>>> result = new LinkedHashMap<String, Map<String, Collection<String>>>();
  91.237 +
  91.238 +        for (Entry<String, Collection<? extends String>> e : containsHash(reader, hashes).entrySet()) {
  91.239 +            Map<String, Collection<String>> forHash = result.get(e.getKey());
  91.240 +
  91.241 +            if (forHash == null) {
  91.242 +                result.put(e.getKey(), forHash = new LinkedHashMap<String, Collection<String>>());
  91.243 +            }
  91.244 +
  91.245 +            for (String path : e.getValue()) {
  91.246 +                String segment = path.substring(0, path.indexOf('/'));
  91.247 +
  91.248 +                path = path.substring(path.indexOf('/') + 1);
  91.249 +
  91.250 +                Collection<String> list = forHash.get(segment);
  91.251 +
  91.252 +                if (list == null) {
  91.253 +                    forHash.put(segment, list = new LinkedList<String>());
  91.254 +                }
  91.255 +
  91.256 +                list.add(path);
  91.257 +            }
  91.258 +        }
  91.259 +
  91.260 +        return (Map)result; //XXX
  91.261 +    }
  91.262 +
  91.263 +    private static void saveToLocalCache(URI uri, Map<String, Map<String, Collection<? extends String>>> what) throws IOException {
  91.264 +        IndexReader r = readerCache;
  91.265 +
  91.266 +        if (r != null) {
  91.267 +            r.close();
  91.268 +            readerCache = null;
  91.269 +        }
  91.270 +        
  91.271 +        IndexWriter w = new IndexWriter(FSDirectory.open(findLocalCacheDir(uri)), new NoAnalyzer(), MaxFieldLength.UNLIMITED);
  91.272 +
  91.273 +        for (Entry<String, Map<String, Collection<? extends String>>> e : what.entrySet()) {
  91.274 +            Document doc = new Document();
  91.275 +
  91.276 +            doc.add(new Field("hash", e.getKey(), Store.YES, Index.NOT_ANALYZED));
  91.277 +
  91.278 +            for (Entry<String, Collection<? extends String>> pe : e.getValue().entrySet()) {
  91.279 +                for (String path : pe.getValue()) {
  91.280 +                    doc.add(new Field("path", pe.getKey() + "/" + path, Store.YES, Index.NO));
  91.281 +                }
  91.282 +            }
  91.283 +
  91.284 +            w.addDocument(doc);
  91.285 +        }
  91.286 +
  91.287 +        w.optimize();
  91.288 +        w.close();
  91.289 +    }
  91.290 +    
  91.291 +    private static List<DuplicateDescription> translate(Map<String, long[]> hashes, Map<String, Map<RemoteIndex, Collection<String>>> occ, FileObject currentFile) {
  91.292 +        Map<String, Map<RemoteIndex, Collection<String>>> sorted = hashMap();
  91.293 +        Map<long[], DuplicateDescription> result = new LinkedHashMap<long[], DuplicateDescription>();
  91.294 +        List<long[]> seen = new LinkedList<long[]>();
  91.295 +
  91.296 +        sorted.putAll(occ);
  91.297 +
  91.298 +        OUTER: for (Entry<String, Map<RemoteIndex, Collection<String>>> e : occ.entrySet()) {
  91.299 +            long[] currentSpan = hashes.get(e.getKey());
  91.300 +
  91.301 +            for (Iterator<Entry<long[], DuplicateDescription>> it = result.entrySet().iterator(); it.hasNext();) {
  91.302 +                Entry<long[], DuplicateDescription> span = it.next();
  91.303 +
  91.304 +                if (span.getKey()[0] <= currentSpan[0] && span.getKey()[1] >= currentSpan[1]) {
  91.305 +                    continue OUTER;
  91.306 +                }
  91.307 +
  91.308 +                if (currentSpan[0] <= span.getKey()[0] && currentSpan[1] >= span.getKey()[1]) {
  91.309 +                    it.remove();
  91.310 +                }
  91.311 +            }
  91.312 +
  91.313 +            if (currentSpan[0] == (-1) || currentSpan[1] == (-1)) continue;
  91.314 +            
  91.315 +            seen.add(currentSpan);
  91.316 +            
  91.317 +            String longest = e.getKey();
  91.318 +            List<Span> foundDuplicates = new LinkedList<Span>();
  91.319 +
  91.320 +            for (Entry<RemoteIndex, Collection<String>> root2Occurrences : e.getValue().entrySet()) {
  91.321 +                FileObject localRoot = URLMapper.findFileObject(root2Occurrences.getKey().getLocalFolder());
  91.322 +
  91.323 +                for (String cand : root2Occurrences.getValue()) {
  91.324 +                    FileObject o = localRoot.getFileObject(cand);
  91.325 +
  91.326 +                    if (o == null) continue; //XXX log!
  91.327 +                    if (areEquivalent(currentFile, o)) continue;
  91.328 +                    
  91.329 +                    foundDuplicates.add(new Span(o, -1, -1));
  91.330 +                }
  91.331 +            }
  91.332 +
  91.333 +            if (foundDuplicates.isEmpty()) continue;
  91.334 +            
  91.335 +            DuplicateDescription current = DuplicateDescription.of(foundDuplicates, getValue(longest), longest);
  91.336 +
  91.337 +            result.put(currentSpan, current);
  91.338 +        }
  91.339 +
  91.340 +        return new LinkedList<DuplicateDescription>(result.values());
  91.341 +    }
  91.342 +
  91.343 +    private static boolean areEquivalent(FileObject f1, FileObject f2) {
  91.344 +        return f1.equals(f2);
  91.345 +    }
  91.346 +
  91.347 +    private static long getValue(String encoded) {
  91.348 +        return Long.parseLong(encoded.substring(encoded.lastIndexOf(":") + 1));
  91.349 +    }
  91.350 +
  91.351 +    private static <T> TreeMap<String, T> hashMap() {
  91.352 +        return new TreeMap<String, T>(new Comparator<String>() {
  91.353 +            public int compare(String arg0, String arg1) {
  91.354 +                return (int) Math.signum(getValue(arg1) - getValue(arg0));
  91.355 +            }
  91.356 +        });
  91.357 +    }
  91.358 +
  91.359 +    private static boolean subsumes(DuplicateDescription bigger, DuplicateDescription smaller) {
  91.360 +        Set<FileObject> bFiles = new HashSet<FileObject>();
  91.361 +
  91.362 +        for (Span s : bigger.dupes) {
  91.363 +            bFiles.add(s.file);
  91.364 +        }
  91.365 +
  91.366 +        Set<FileObject> sFiles = new HashSet<FileObject>();
  91.367 +
  91.368 +        for (Span s : smaller.dupes) {
  91.369 +            sFiles.add(s.file);
  91.370 +        }
  91.371 +
  91.372 +        if (!bFiles.equals(sFiles)) return false;
  91.373 +
  91.374 +        Span testAgainst = bigger.dupes.get(0);
  91.375 +
  91.376 +        for (Span s : smaller.dupes) {
  91.377 +            if (s.file == testAgainst.file) {
  91.378 +                if (   (testAgainst.startOff <= s.startOff && testAgainst.endOff > s.endOff)
  91.379 +                    || (testAgainst.startOff < s.startOff && testAgainst.endOff >= s.endOff)) {
  91.380 +                    return true;
  91.381 +                }
  91.382 +            }
  91.383 +        }
  91.384 +
  91.385 +        return false;
  91.386 +    }
  91.387 +
  91.388 +    public static Map<String, Collection<? extends String>> containsHash(IndexReader reader, Iterable<? extends String> hashes) throws IOException {
  91.389 +        Map<String, Collection<? extends String>> result = new LinkedHashMap<String, Collection<? extends String>>();
  91.390 +
  91.391 +        for (String hash : hashes) {
  91.392 +            Collection<String> found = new LinkedList<String>();
  91.393 +            Query query = new TermQuery(new Term("hash", hash));
  91.394 +            Searcher s = new IndexSearcher(reader);
  91.395 +            BitSet matchingDocuments = new BitSet(reader.maxDoc());
  91.396 +            Collector c = new BitSetCollector(matchingDocuments);
  91.397 +
  91.398 +            s.search(query, c);
  91.399 +
  91.400 +            boolean wasFound = false;
  91.401 +
  91.402 +            for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum + 1)) {
  91.403 +                final Document doc = reader.document(docNum);
  91.404 +
  91.405 +                found.addAll(Arrays.asList(doc.getValues("path")));
  91.406 +                wasFound = true;
  91.407 +            }
  91.408 +
  91.409 +            if (wasFound) {
  91.410 +                result.put(hash, found);
  91.411 +            }
  91.412 +        }
  91.413 +
  91.414 +        return result;
  91.415 +    }
  91.416 +}
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/duplicates/ide/impl/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicatesTest.java	Sat Feb 11 18:35:10 2012 +0100
    92.3 @@ -0,0 +1,133 @@
    92.4 +/*
    92.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    92.6 + *
    92.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
    92.8 + *
    92.9 + * The contents of this file are subject to the terms of either the GNU
   92.10 + * General Public License Version 2 only ("GPL") or the Common
   92.11 + * Development and Distribution License("CDDL") (collectively, the
   92.12 + * "License"). You may not use this file except in compliance with the
   92.13 + * License. You can obtain a copy of the License at
   92.14 + * http://www.netbeans.org/cddl-gplv2.html
   92.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   92.16 + * specific language governing permissions and limitations under the
   92.17 + * License.  When distributing the software, include this License Header
   92.18 + * Notice in each file and include the License file at
   92.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   92.20 + * particular file as subject to the "Classpath" exception as provided
   92.21 + * by Sun in the GPL Version 2 section of the License file that
   92.22 + * accompanied this code. If applicable, add the following below the
   92.23 + * License Header, with the fields enclosed by brackets [] replaced by
   92.24 + * your own identifying information:
   92.25 + * "Portions Copyrighted [year] [name of copyright owner]"
   92.26 + *
   92.27 + * If you wish your version of this file to be governed by only the CDDL
   92.28 + * or only the GPL Version 2, indicate your decision by adding
   92.29 + * "[Contributor] elects to include this software in this distribution
   92.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   92.31 + * single choice of license, a recipient has the option to distribute
   92.32 + * your version of this file under either the CDDL, the GPL Version 2 or
   92.33 + * to extend the choice of license to its licensees as provided above.
   92.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   92.35 + * Version 2 license, then the option applies only if the new code is
   92.36 + * made subject to such option by the copyright holder.
   92.37 + *
   92.38 + * Contributor(s):
   92.39 + *
   92.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
   92.41 + */
   92.42 +
   92.43 +package org.netbeans.modules.jackpot30.impl.duplicates;
   92.44 +
   92.45 +import org.netbeans.api.progress.ProgressHandle;
   92.46 +import org.openide.filesystems.FileObject;
   92.47 +import java.util.HashMap;
   92.48 +import java.util.Map;
   92.49 +import java.util.concurrent.atomic.AtomicBoolean;
   92.50 +import org.netbeans.api.java.source.TestUtilities;
   92.51 +import org.netbeans.api.progress.ProgressHandleFactory;
   92.52 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   92.53 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   92.54 +import org.netbeans.modules.jackpot30.common.test.IndexTestBase;
   92.55 +import org.openide.filesystems.FileUtil;
   92.56 +import org.openide.util.NbCollections;
   92.57 +import static org.junit.Assert.*;
   92.58 +import org.netbeans.api.editor.mimelookup.MimePath;
   92.59 +import org.netbeans.modules.jackpot30.impl.duplicates.indexing.DuplicatesCustomIndexerImpl;
   92.60 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
   92.61 +import org.openide.util.Lookup;
   92.62 +import org.openide.util.lookup.Lookups;
   92.63 +import org.openide.util.lookup.ServiceProvider;
   92.64 +
   92.65 +/**
   92.66 + *
   92.67 + * @author lahvac
   92.68 + */
   92.69 +public class ComputeDuplicatesTest extends IndexTestBase {
   92.70 +
   92.71 +    public ComputeDuplicatesTest(String name) {
   92.72 +        super(name);
   92.73 +    }
   92.74 +
   92.75 +    public void testDuplicateDuplicates() throws Exception {
   92.76 +        writeFilesAndWaitForScan(src,
   92.77 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
   92.78 +                                 new File("test/Test2.java", "package test; public class Test2 { private int a; private void test() { java.io.File f = null; f.isDirectory(); } }"));
   92.79 +
   92.80 +        verifyDuplicates("test/Test1.java",
   92.81 +                         "private void test() { java.io.File f = null; f.isDirectory(); }",
   92.82 +                         "test/Test2.java",
   92.83 +                         "private void test() { java.io.File f = null; f.isDirectory(); }");
   92.84 +    }
   92.85 +
   92.86 +    public void testCrossIndex() throws Exception {
   92.87 +        writeFilesAndWaitForScan(src,
   92.88 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"));
   92.89 +
   92.90 +        writeFilesAndWaitForScan(src2,
   92.91 +                                 new File("test/Test2.java", "package test; public class Test2 { private int a; private void test() { java.io.File f = null; f.isDirectory(); } }"));
   92.92 +
   92.93 +        verifyDuplicates("test/Test1.java",
   92.94 +                         "private void test() { java.io.File f = null; f.isDirectory(); }",
   92.95 +                         "test/Test2.java",
   92.96 +                         "private void test() { java.io.File f = null; f.isDirectory(); }");
   92.97 +    }
   92.98 +
   92.99 +    private void verifyDuplicates(String... fileAndDuplicateCode) throws Exception {
  92.100 +        Map<String, String> duplicatesGolden = new HashMap<String, String>();
  92.101 +
  92.102 +        for (int cntr = 0; cntr < fileAndDuplicateCode.length; cntr += 2) {
  92.103 +            duplicatesGolden.put(fileAndDuplicateCode[cntr], fileAndDuplicateCode[cntr + 1]);
  92.104 +        }
  92.105 +
  92.106 +        Map<String, String> duplicatesReal = new HashMap<String, String>();
  92.107 +        ProgressHandle handle = ProgressHandleFactory.createHandle("test");
  92.108 +
  92.109 +        handle.start();
  92.110 +        
  92.111 +        for (DuplicateDescription dd : NbCollections.iterable(new ComputeDuplicates().computeDuplicatesForAllOpenedProjects(handle, new AtomicBoolean()))) {
  92.112 +            for (Span s : dd.dupes) {
  92.113 +                duplicatesReal.put(relativePath(s.file), TestUtilities.copyFileToString(FileUtil.toFile(s.file)).substring(s.startOff, s.endOff));
  92.114 +            }
  92.115 +        }
  92.116 +
  92.117 +        assertEquals(duplicatesGolden, duplicatesReal);
  92.118 +    }
  92.119 +
  92.120 +    private String relativePath(FileObject file) {
  92.121 +        return FileUtil.isParentOf(src, file) ? FileUtil.getRelativePath(src, file) : FileUtil.getRelativePath(src2, file);
  92.122 +    }
  92.123 +    
  92.124 +    @ServiceProvider(service=MimeDataProvider.class)
  92.125 +    public static final class MimeDataProviderImpl implements MimeDataProvider {
  92.126 +
  92.127 +        private final Lookup L = Lookups.fixed(new DuplicatesCustomIndexerImpl.FactoryImpl());
  92.128 +        
  92.129 +        @Override
  92.130 +        public Lookup getLookup(MimePath mimePath) {
  92.131 +            if ("text/x-java".equals(mimePath.getPath())) return L;
  92.132 +            return Lookup.EMPTY;
  92.133 +        }
  92.134 +        
  92.135 +    }
  92.136 +}
  92.137 \ No newline at end of file
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/duplicates/ide/impl/test/unit/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/RemoteDuplicatesIndexTest.java	Sat Feb 11 18:35:10 2012 +0100
    93.3 @@ -0,0 +1,133 @@
    93.4 +/*
    93.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    93.6 + *
    93.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    93.8 + *
    93.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   93.10 + * Other names may be trademarks of their respective owners.
   93.11 + *
   93.12 + * The contents of this file are subject to the terms of either the GNU
   93.13 + * General Public License Version 2 only ("GPL") or the Common
   93.14 + * Development and Distribution License("CDDL") (collectively, the
   93.15 + * "License"). You may not use this file except in compliance with the
   93.16 + * License. You can obtain a copy of the License at
   93.17 + * http://www.netbeans.org/cddl-gplv2.html
   93.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   93.19 + * specific language governing permissions and limitations under the
   93.20 + * License.  When distributing the software, include this License Header
   93.21 + * Notice in each file and include the License file at
   93.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   93.23 + * particular file as subject to the "Classpath" exception as provided
   93.24 + * by Oracle in the GPL Version 2 section of the License file that
   93.25 + * accompanied this code. If applicable, add the following below the
   93.26 + * License Header, with the fields enclosed by brackets [] replaced by
   93.27 + * your own identifying information:
   93.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   93.29 + *
   93.30 + * If you wish your version of this file to be governed by only the CDDL
   93.31 + * or only the GPL Version 2, indicate your decision by adding
   93.32 + * "[Contributor] elects to include this software in this distribution
   93.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   93.34 + * single choice of license, a recipient has the option to distribute
   93.35 + * your version of this file under either the CDDL, the GPL Version 2 or
   93.36 + * to extend the choice of license to its licensees as provided above.
   93.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   93.38 + * Version 2 license, then the option applies only if the new code is
   93.39 + * made subject to such option by the copyright holder.
   93.40 + *
   93.41 + * Contributor(s):
   93.42 + *
   93.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
   93.44 + */
   93.45 +package org.netbeans.modules.jackpot30.impl.duplicates.indexing;
   93.46 +
   93.47 +import java.io.File;
   93.48 +import java.net.URL;
   93.49 +import java.util.ArrayList;
   93.50 +import java.util.Arrays;
   93.51 +import java.util.HashMap;
   93.52 +import java.util.List;
   93.53 +import java.util.Map;
   93.54 +import org.netbeans.api.java.source.TestUtilities;
   93.55 +import static org.junit.Assert.*;
   93.56 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
   93.57 +import org.netbeans.core.startup.Main;
   93.58 +import org.netbeans.junit.NbTestCase;
   93.59 +import org.netbeans.modules.jackpot30.impl.TestUtils;
   93.60 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.DuplicateDescription;
   93.61 +import org.netbeans.modules.jackpot30.impl.duplicates.ComputeDuplicates.Span;
   93.62 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   93.63 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
   93.64 +import org.openide.filesystems.FileObject;
   93.65 +import org.openide.filesystems.FileUtil;
   93.66 +
   93.67 +/**
   93.68 + *
   93.69 + * @author lahvac
   93.70 + */
   93.71 +public class RemoteDuplicatesIndexTest extends NbTestCase {
   93.72 +
   93.73 +    public RemoteDuplicatesIndexTest(String name) {
   93.74 +        super(name);
   93.75 +    }
   93.76 +
   93.77 +    public void setUp() throws Exception {
   93.78 +        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
   93.79 +        Main.initializeURLFactory();
   93.80 +        TestUtils.clearRemoteContent();
   93.81 +        super.setUp();
   93.82 +    }
   93.83 +
   93.84 +    public void testFindHashOccurrences() throws Exception {
   93.85 +        clearWorkDir();
   93.86 +        File cacheDir = new File(getWorkDir(), "cache");
   93.87 +        File dataDir = new File(getWorkDir(), "data");
   93.88 +
   93.89 +        CacheFolder.setCacheFolder(FileUtil.createFolder(cacheDir));
   93.90 +
   93.91 +        FileObject data1 = FileUtil.createFolder(new File(dataDir, "data1"));
   93.92 +        FileObject data2 = FileUtil.createFolder(new File(dataDir, "data2"));
   93.93 +        FileObject source = FileUtil.createData(new File(dataDir, "src/Test.java"));
   93.94 +
   93.95 +        TestUtilities.copyStringToFile(data1.createData("T1.java"), "0123456789");
   93.96 +        TestUtilities.copyStringToFile(data1.createData("T2.java"), "0123456789");
   93.97 +        TestUtilities.copyStringToFile(data2.createData("T3.java"), "0123456789");
   93.98 +        TestUtilities.copyStringToFile(data2.createData("T4.java"), "0123456789");
   93.99 +        
  93.100 +        TestUtils.addRemoteContent(new URL("test://test/index/findDuplicates?hashes=[%0A%20%20%20%20%2200%22,%0A%20%20%20%20%2201%22,%0A%20%20%20%20%2202%22%0A]"), "{ \"00\": { \"foo1\": [ \"T1.java\", \"T2.java\" ], \"foo2\": [ \"T3.java\", \"T4.java\" ] } }");
  93.101 +        RemoteIndex.saveIndices(Arrays.asList(RemoteIndex.create(FileUtil.toFile(data1).toURI().toURL(), new URL("test://test/index"), "foo1"),
  93.102 +                                              RemoteIndex.create(FileUtil.toFile(data2).toURI().toURL(), new URL("test://test/index"), "foo2")));
  93.103 +
  93.104 +        TestUtilities.copyStringToFile(source, "01234567890123456789");
  93.105 +        
  93.106 +        Map<String, long[]> hashes = new HashMap<String, long[]>();
  93.107 +
  93.108 +        hashes.put("00", new long[] {1, 2, 5, 6});
  93.109 +        hashes.put("01", new long[] {8, 9});
  93.110 +        hashes.put("02", new long[] {3, 4});
  93.111 +        
  93.112 +        List<DuplicateDescription> duplicates = RemoteDuplicatesIndex.findDuplicates(hashes, source);
  93.113 +        List<String> duplicatesReal = new ArrayList<String>();
  93.114 +
  93.115 +        for (DuplicateDescription dd : duplicates) {
  93.116 +            for (Span s : dd.dupes) {
  93.117 +                duplicatesReal.add(s.file.getName());
  93.118 +            }
  93.119 +        }
  93.120 +
  93.121 +        assertEquals(Arrays.asList("T2", "T1", "T4", "T3"), duplicatesReal);
  93.122 +
  93.123 +        //check local cache:
  93.124 +        duplicates = RemoteDuplicatesIndex.findDuplicates(hashes, source);
  93.125 +        duplicatesReal = new ArrayList<String>();
  93.126 +
  93.127 +        for (DuplicateDescription dd : duplicates) {
  93.128 +            for (Span s : dd.dupes) {
  93.129 +                duplicatesReal.add(s.file.getName());
  93.130 +            }
  93.131 +        }
  93.132 +
  93.133 +        assertEquals(Arrays.asList("T2", "T1", "T4", "T3"), duplicatesReal);
  93.134 +    }
  93.135 +
  93.136 +}
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/duplicates/ide/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
    94.3 @@ -0,0 +1,50 @@
    94.4 +<?xml version="1.0" encoding="UTF-8"?>
    94.5 +<!--
    94.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
    94.7 +***         EDIT ../build.xml INSTEAD         ***
    94.8 +-->
    94.9 +<project name="duplicates-ide-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
   94.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
   94.11 +        <condition>
   94.12 +            <not>
   94.13 +                <antversion atleast="1.7.1"/>
   94.14 +            </not>
   94.15 +        </condition>
   94.16 +    </fail>
   94.17 +    <property file="nbproject/private/platform-private.properties"/>
   94.18 +    <property file="nbproject/platform.properties"/>
   94.19 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
   94.20 +        <attribute name="name"/>
   94.21 +        <attribute name="value"/>
   94.22 +        <sequential>
   94.23 +            <property name="@{name}" value="${@{value}}"/>
   94.24 +        </sequential>
   94.25 +    </macrodef>
   94.26 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
   94.27 +        <attribute name="property"/>
   94.28 +        <attribute name="value"/>
   94.29 +        <sequential>
   94.30 +            <property name="@{property}" value="@{value}"/>
   94.31 +        </sequential>
   94.32 +    </macrodef>
   94.33 +    <property file="${user.properties.file}"/>
   94.34 +    <sproject:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir"/>
   94.35 +    <sproject:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir"/>
   94.36 +    <sproject:evalprops property="cluster.path.evaluated" value="${cluster.path}"/>
   94.37 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
   94.38 +        <condition>
   94.39 +            <not>
   94.40 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
   94.41 +            </not>
   94.42 +        </condition>
   94.43 +    </fail>
   94.44 +    <ant antfile="nbproject/platform.xml"/>
   94.45 +    <fail message="Cannot find NetBeans build harness. ${line.separator}Check that nbplatform.${nbplatform.active}.netbeans.dest.dir and nbplatform.${nbplatform.active}.harness.dir are defined. ${line.separator}On a developer machine these are normally defined in ${user.properties.file}=${netbeans.user}/build.properties ${line.separator}but for automated builds you should pass these properties to Ant explicitly. ${line.separator}You may instead download the harness and platform: -Dbootstrap.url=.../tasks.jar -Dautoupdate.catalog.url=.../updates.xml">
   94.46 +        <condition>
   94.47 +            <not>
   94.48 +                <available file="${harness.dir}/suite.xml"/>
   94.49 +            </not>
   94.50 +        </condition>
   94.51 +    </fail>
   94.52 +    <import file="${harness.dir}/suite.xml"/>
   94.53 +</project>
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/duplicates/ide/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
    95.3 @@ -0,0 +1,11 @@
    95.4 +build.xml.data.CRC32=891734f5
    95.5 +build.xml.script.CRC32=82b74f72
    95.6 +build.xml.stylesheet.CRC32=eaf9f76a@2.49
    95.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
    95.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    95.9 +nbproject/build-impl.xml.data.CRC32=44b3f6ba
   95.10 +nbproject/build-impl.xml.script.CRC32=d800a24f
   95.11 +nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.49
   95.12 +nbproject/platform.xml.data.CRC32=44b3f6ba
   95.13 +nbproject/platform.xml.script.CRC32=db9e1f43
   95.14 +nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.49
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/duplicates/ide/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
    96.3 @@ -0,0 +1,19 @@
    96.4 +cluster.path=\
    96.5 +    ${nbplatform.active.dir}/apisupport:\
    96.6 +    ${nbplatform.active.dir}/cnd:\
    96.7 +    ${nbplatform.active.dir}/dlight:\
    96.8 +    ${nbplatform.active.dir}/enterprise:\
    96.9 +    ${nbplatform.active.dir}/harness:\
   96.10 +    ${nbplatform.active.dir}/ide:\
   96.11 +    ${nbplatform.active.dir}/java:\
   96.12 +    ${nbplatform.active.dir}/nb:\
   96.13 +    ${nbplatform.active.dir}/platform:\
   96.14 +    ${nbplatform.active.dir}/profiler:\
   96.15 +    ${nbplatform.active.dir}/websvccommon:\
   96.16 +    ../../remoting/common/build/cluster:\
   96.17 +    ../../remoting/ide/build/cluster
   96.18 +extcluster.../../remoting/common/build/cluster.javadoc=
   96.19 +extcluster.../../remoting/common/build/cluster.sources=../../remoting/common
   96.20 +extcluster.../../remoting/ide/build/cluster.javadoc=
   96.21 +extcluster.../../remoting/ide/build/cluster.sources=../../remoting/ide
   96.22 +nbplatform.active=default
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/duplicates/ide/nbproject/platform.xml	Sat Feb 11 18:35:10 2012 +0100
    97.3 @@ -0,0 +1,34 @@
    97.4 +<?xml version="1.0" encoding="UTF-8"?>
    97.5 +<project name="platform" default="download" basedir="..">
    97.6 +    <condition property="download.required">
    97.7 +        <and>
    97.8 +            <not>
    97.9 +                <available file="${harness.dir}/suite.xml"/>
   97.10 +            </not>
   97.11 +            <isset property="bootstrap.url"/>
   97.12 +            <isset property="autoupdate.catalog.url"/>
   97.13 +        </and>
   97.14 +    </condition>
   97.15 +    <target name="download" if="download.required">
   97.16 +        <mkdir dir="${harness.dir}"/>
   97.17 +        <pathconvert pathsep="|" property="download.clusters">
   97.18 +            <mapper type="flatten"/>
   97.19 +            <path path="${cluster.path}"/>
   97.20 +        </pathconvert>
   97.21 +        <property name="disabled.modules" value=""/>
   97.22 +        <pathconvert property="module.includes" pathsep="">
   97.23 +            <mapper type="glob" from="${basedir}${file.separator}*" to="(?!\Q*\E)"/>
   97.24 +            <path>
   97.25 +                <filelist files="${disabled.modules}" dir="."/>
   97.26 +            </path>
   97.27 +        </pathconvert>
   97.28 +        <echo message="Downloading clusters ${download.clusters}"/>
   97.29 +        <property name="tasks.jar" location="${java.io.tmpdir}/tasks.jar"/>
   97.30 +        <get src="${bootstrap.url}" dest="${tasks.jar}" usetimestamp="true" verbose="true"/>
   97.31 +        <taskdef name="autoupdate" classname="org.netbeans.nbbuild.AutoUpdate" classpath="${tasks.jar}"/>
   97.32 +        <autoupdate installdir="${nbplatform.active.dir}" updatecenter="${autoupdate.catalog.url}">
   97.33 +            <modules includes="${module.includes}.*" clusters="${download.clusters}"/>
   97.34 +            <modules includes="org[.]netbeans[.]modules[.]apisupport[.]harness" clusters="harness"/>
   97.35 +        </autoupdate>
   97.36 +    </target>
   97.37 +</project>
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/duplicates/ide/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
    98.3 @@ -0,0 +1,3 @@
    98.4 +modules=\
    98.5 +    ${project.org.netbeans.modules.jackpot30.duplicates.impl}
    98.6 +project.org.netbeans.modules.jackpot30.duplicates.impl=impl
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/duplicates/ide/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
    99.3 @@ -0,0 +1,9 @@
    99.4 +<?xml version="1.0" encoding="UTF-8"?>
    99.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
    99.6 +    <type>org.netbeans.modules.apisupport.project.suite</type>
    99.7 +    <configuration>
    99.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-suite-project/1">
    99.9 +            <name>duplicates-ide</name>
   99.10 +        </data>
   99.11 +    </configuration>
   99.12 +</project>
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/language/ide/build.xml	Sat Feb 11 18:35:10 2012 +0100
   100.3 @@ -0,0 +1,8 @@
   100.4 +<?xml version="1.0" encoding="UTF-8"?>
   100.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   100.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   100.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   100.8 +<project name="language-ide" basedir=".">
   100.9 +    <description>Builds the module suite language.</description>
  100.10 +    <import file="nbproject/build-impl.xml"/>
  100.11 +</project>
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/language/ide/indexing/build.xml	Sat Feb 11 18:35:10 2012 +0100
   101.3 @@ -0,0 +1,9 @@
   101.4 +<?xml version="1.0" encoding="UTF-8"?>
   101.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   101.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   101.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   101.8 +<project name="org.netbeans.modules.jackpot30.indexing" default="netbeans" basedir=".">
   101.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.indexing.</description>
  101.10 +    <import file="nbproject/build-impl.xml"/>
  101.11 +    <import file="../../../findbugs-import.xml" />
  101.12 +</project>
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/language/ide/indexing/manifest.mf	Sat Feb 11 18:35:10 2012 +0100
   102.3 @@ -0,0 +1,5 @@
   102.4 +Manifest-Version: 1.0
   102.5 +OpenIDE-Module: org.netbeans.modules.jackpot30.indexing
   102.6 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/indexing/Bundle.properties
   102.7 +OpenIDE-Module-Specification-Version: 1.0
   102.8 +
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/language/ide/indexing/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   103.3 @@ -0,0 +1,45 @@
   103.4 +<?xml version="1.0" encoding="UTF-8"?>
   103.5 +<!--
   103.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   103.7 +***         EDIT ../build.xml INSTEAD         ***
   103.8 +-->
   103.9 +<project name="org.netbeans.modules.jackpot30.indexing-impl" basedir="..">
  103.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  103.11 +        <condition>
  103.12 +            <not>
  103.13 +                <antversion atleast="1.7.1"/>
  103.14 +            </not>
  103.15 +        </condition>
  103.16 +    </fail>
  103.17 +    <property file="nbproject/private/suite-private.properties"/>
  103.18 +    <property file="nbproject/suite.properties"/>
  103.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
  103.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
  103.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
  103.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
  103.23 +        <attribute name="name"/>
  103.24 +        <attribute name="value"/>
  103.25 +        <sequential>
  103.26 +            <property name="@{name}" value="${@{value}}"/>
  103.27 +        </sequential>
  103.28 +    </macrodef>
  103.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
  103.30 +        <attribute name="property"/>
  103.31 +        <attribute name="value"/>
  103.32 +        <sequential>
  103.33 +            <property name="@{property}" value="@{value}"/>
  103.34 +        </sequential>
  103.35 +    </macrodef>
  103.36 +    <property file="${user.properties.file}"/>
  103.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  103.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  103.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  103.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  103.41 +        <condition>
  103.42 +            <not>
  103.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  103.44 +            </not>
  103.45 +        </condition>
  103.46 +    </fail>
  103.47 +    <import file="${harness.dir}/build.xml"/>
  103.48 +</project>
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/language/ide/indexing/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   104.3 @@ -0,0 +1,8 @@
   104.4 +build.xml.data.CRC32=68c5618a
   104.5 +build.xml.script.CRC32=f0946049
   104.6 +build.xml.stylesheet.CRC32=a56c6a5b@2.49
   104.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   104.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   104.9 +nbproject/build-impl.xml.data.CRC32=27490bcc
  104.10 +nbproject/build-impl.xml.script.CRC32=d49586b3
  104.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
   105.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.2 +++ b/language/ide/indexing/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   105.3 @@ -0,0 +1,2 @@
   105.4 +javac.source=1.6
   105.5 +javac.compilerargs=-Xlint -Xlint:-serial
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/language/ide/indexing/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   106.3 @@ -0,0 +1,390 @@
   106.4 +<?xml version="1.0" encoding="UTF-8"?>
   106.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   106.6 +    <type>org.netbeans.modules.apisupport.project</type>
   106.7 +    <configuration>
   106.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
   106.9 +            <code-name-base>org.netbeans.modules.jackpot30.indexing</code-name-base>
  106.10 +            <suite-component/>
  106.11 +            <module-dependencies>
  106.12 +                <dependency>
  106.13 +                    <code-name-base>org.jdesktop.layout</code-name-base>
  106.14 +                    <build-prerequisite/>
  106.15 +                    <compile-dependency/>
  106.16 +                    <run-dependency>
  106.17 +                        <release-version>1</release-version>
  106.18 +                        <specification-version>1.7.0.103</specification-version>
  106.19 +                    </run-dependency>
  106.20 +                </dependency>
  106.21 +                <dependency>
  106.22 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
  106.23 +                    <build-prerequisite/>
  106.24 +                    <compile-dependency/>
  106.25 +                    <run-dependency>
  106.26 +                        <release-version>1</release-version>
  106.27 +                        <specification-version>1.0</specification-version>
  106.28 +                    </run-dependency>
  106.29 +                </dependency>
  106.30 +                <dependency>
  106.31 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
  106.32 +                    <build-prerequisite/>
  106.33 +                    <compile-dependency/>
  106.34 +                    <run-dependency>
  106.35 +                        <release-version>1</release-version>
  106.36 +                        <specification-version>1.19</specification-version>
  106.37 +                    </run-dependency>
  106.38 +                </dependency>
  106.39 +                <dependency>
  106.40 +                    <code-name-base>org.netbeans.api.progress</code-name-base>
  106.41 +                    <build-prerequisite/>
  106.42 +                    <compile-dependency/>
  106.43 +                    <run-dependency>
  106.44 +                        <release-version>1</release-version>
  106.45 +                        <specification-version>1.13.0.1</specification-version>
  106.46 +                    </run-dependency>
  106.47 +                </dependency>
  106.48 +                <dependency>
  106.49 +                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
  106.50 +                    <build-prerequisite/>
  106.51 +                    <compile-dependency/>
  106.52 +                    <run-dependency>
  106.53 +                        <specification-version>7.5.0.3</specification-version>
  106.54 +                    </run-dependency>
  106.55 +                </dependency>
  106.56 +                <dependency>
  106.57 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
  106.58 +                    <build-prerequisite/>
  106.59 +                    <compile-dependency/>
  106.60 +                    <run-dependency>
  106.61 +                        <release-version>1</release-version>
  106.62 +                        <implementation-version/>
  106.63 +                    </run-dependency>
  106.64 +                </dependency>
  106.65 +                <dependency>
  106.66 +                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
  106.67 +                    <build-prerequisite/>
  106.68 +                    <compile-dependency/>
  106.69 +                    <run-dependency>
  106.70 +                        <release-version>1-3</release-version>
  106.71 +                        <specification-version>2.13</specification-version>
  106.72 +                    </run-dependency>
  106.73 +                </dependency>
  106.74 +                <dependency>
  106.75 +                    <code-name-base>org.netbeans.modules.diff</code-name-base>
  106.76 +                    <build-prerequisite/>
  106.77 +                    <compile-dependency/>
  106.78 +                    <run-dependency>
  106.79 +                        <release-version>1</release-version>
  106.80 +                        <implementation-version/>
  106.81 +                    </run-dependency>
  106.82 +                </dependency>
  106.83 +                <dependency>
  106.84 +                    <code-name-base>org.netbeans.modules.editor</code-name-base>
  106.85 +                    <build-prerequisite/>
  106.86 +                    <compile-dependency/>
  106.87 +                    <run-dependency>
  106.88 +                        <release-version>3</release-version>
  106.89 +                        <specification-version>1.56.0.5.13.6</specification-version>
  106.90 +                    </run-dependency>
  106.91 +                </dependency>
  106.92 +                <dependency>
  106.93 +                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
  106.94 +                    <build-prerequisite/>
  106.95 +                    <compile-dependency/>
  106.96 +                    <run-dependency>
  106.97 +                        <release-version>1-3</release-version>
  106.98 +                        <specification-version>1.38.0.9.2</specification-version>
  106.99 +                    </run-dependency>
 106.100 +                </dependency>
 106.101 +                <dependency>
 106.102 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
 106.103 +                    <build-prerequisite/>
 106.104 +                    <compile-dependency/>
 106.105 +                    <run-dependency>
 106.106 +                        <release-version>1</release-version>
 106.107 +                        <specification-version>1.13.0.2</specification-version>
 106.108 +                    </run-dependency>
 106.109 +                </dependency>
 106.110 +                <dependency>
 106.111 +                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
 106.112 +                    <build-prerequisite/>
 106.113 +                    <compile-dependency/>
 106.114 +                    <run-dependency>
 106.115 +                        <release-version>1</release-version>
 106.116 +                        <specification-version>1.12</specification-version>
 106.117 +                    </run-dependency>
 106.118 +                </dependency>
 106.119 +                <dependency>
 106.120 +                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
 106.121 +                    <build-prerequisite/>
 106.122 +                    <compile-dependency/>
 106.123 +                    <run-dependency>
 106.124 +                        <release-version>1</release-version>
 106.125 +                        <specification-version>1.25</specification-version>
 106.126 +                    </run-dependency>
 106.127 +                </dependency>
 106.128 +                <dependency>
 106.129 +                    <code-name-base>org.netbeans.modules.jackpot30.common</code-name-base>
 106.130 +                    <build-prerequisite/>
 106.131 +                    <compile-dependency/>
 106.132 +                    <run-dependency>
 106.133 +                        <specification-version>1.0</specification-version>
 106.134 +                    </run-dependency>
 106.135 +                </dependency>
 106.136 +                <dependency>
 106.137 +                    <code-name-base>org.netbeans.modules.jackpot30.remoting.api</code-name-base>
 106.138 +                    <build-prerequisite/>
 106.139 +                    <compile-dependency/>
 106.140 +                    <run-dependency>
 106.141 +                        <specification-version>1.8</specification-version>
 106.142 +                    </run-dependency>
 106.143 +                </dependency>
 106.144 +                <dependency>
 106.145 +                    <code-name-base>org.netbeans.modules.java.editor</code-name-base>
 106.146 +                    <build-prerequisite/>
 106.147 +                    <compile-dependency/>
 106.148 +                    <run-dependency>
 106.149 +                        <release-version>1</release-version>
 106.150 +                        <implementation-version/>
 106.151 +                    </run-dependency>
 106.152 +                </dependency>
 106.153 +                <dependency>
 106.154 +                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
 106.155 +                    <build-prerequisite/>
 106.156 +                    <compile-dependency/>
 106.157 +                    <run-dependency>
 106.158 +                        <release-version>1</release-version>
 106.159 +                        <implementation-version/>
 106.160 +                    </run-dependency>
 106.161 +                </dependency>
 106.162 +                <dependency>
 106.163 +                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
 106.164 +                    <build-prerequisite/>
 106.165 +                    <compile-dependency/>
 106.166 +                    <run-dependency>
 106.167 +                        <release-version>1</release-version>
 106.168 +                        <specification-version>1.9</specification-version>
 106.169 +                    </run-dependency>
 106.170 +                </dependency>
 106.171 +                <dependency>
 106.172 +                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
 106.173 +                    <build-prerequisite/>
 106.174 +                    <compile-dependency/>
 106.175 +                    <run-dependency>
 106.176 +                        <release-version>1</release-version>
 106.177 +                        <specification-version>1.12</specification-version>
 106.178 +                    </run-dependency>
 106.179 +                </dependency>
 106.180 +                <dependency>
 106.181 +                    <code-name-base>org.netbeans.modules.java.preprocessorbridge</code-name-base>
 106.182 +                    <build-prerequisite/>
 106.183 +                    <compile-dependency/>
 106.184 +                    <run-dependency>
 106.185 +                        <implementation-version/>
 106.186 +                    </run-dependency>
 106.187 +                </dependency>
 106.188 +                <dependency>
 106.189 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
 106.190 +                    <build-prerequisite/>
 106.191 +                    <compile-dependency/>
 106.192 +                    <run-dependency>
 106.193 +                        <implementation-version/>
 106.194 +                    </run-dependency>
 106.195 +                </dependency>
 106.196 +                <dependency>
 106.197 +                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
 106.198 +                    <build-prerequisite/>
 106.199 +                    <compile-dependency/>
 106.200 +                    <run-dependency>
 106.201 +                        <release-version>2</release-version>
 106.202 +                        <specification-version>1.34</specification-version>
 106.203 +                    </run-dependency>
 106.204 +                </dependency>
 106.205 +                <dependency>
 106.206 +                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
 106.207 +                    <build-prerequisite/>
 106.208 +                    <compile-dependency/>
 106.209 +                    <run-dependency>
 106.210 +                        <release-version>1</release-version>
 106.211 +                        <specification-version>1.20</specification-version>
 106.212 +                    </run-dependency>
 106.213 +                </dependency>
 106.214 +                <dependency>
 106.215 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
 106.216 +                    <build-prerequisite/>
 106.217 +                    <compile-dependency/>
 106.218 +                    <run-dependency>
 106.219 +                        <release-version>1</release-version>
 106.220 +                        <implementation-version/>
 106.221 +                    </run-dependency>
 106.222 +                </dependency>
 106.223 +                <dependency>
 106.224 +                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
 106.225 +                    <build-prerequisite/>
 106.226 +                    <compile-dependency/>
 106.227 +                    <run-dependency>
 106.228 +                        <release-version>1</release-version>
 106.229 +                        <specification-version>1.24</specification-version>
 106.230 +                    </run-dependency>
 106.231 +                </dependency>
 106.232 +                <dependency>
 106.233 +                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
 106.234 +                    <build-prerequisite/>
 106.235 +                    <compile-dependency/>
 106.236 +                    <run-dependency>
 106.237 +                        <release-version>1</release-version>
 106.238 +                        <specification-version>1.35.0.6</specification-version>
 106.239 +                    </run-dependency>
 106.240 +                </dependency>
 106.241 +                <dependency>
 106.242 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
 106.243 +                    <build-prerequisite/>
 106.244 +                    <compile-dependency/>
 106.245 +                    <run-dependency>
 106.246 +                        <release-version>1</release-version>
 106.247 +                        <specification-version>1.15</specification-version>
 106.248 +                    </run-dependency>
 106.249 +                </dependency>
 106.250 +                <dependency>
 106.251 +                    <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
 106.252 +                    <build-prerequisite/>
 106.253 +                    <compile-dependency/>
 106.254 +                    <run-dependency>
 106.255 +                        <specification-version>1.6</specification-version>
 106.256 +                    </run-dependency>
 106.257 +                </dependency>
 106.258 +                <dependency>
 106.259 +                    <code-name-base>org.netbeans.modules.refactoring.java</code-name-base>
 106.260 +                    <build-prerequisite/>
 106.261 +                    <compile-dependency/>
 106.262 +                    <run-dependency>
 106.263 +                        <release-version>1</release-version>
 106.264 +                        <specification-version>1.6</specification-version>
 106.265 +                    </run-dependency>
 106.266 +                </dependency>
 106.267 +                <dependency>
 106.268 +                    <code-name-base>org.netbeans.modules.sendopts</code-name-base>
 106.269 +                    <build-prerequisite/>
 106.270 +                    <compile-dependency/>
 106.271 +                    <run-dependency>
 106.272 +                        <release-version>2</release-version>
 106.273 +                        <specification-version>2.4</specification-version>
 106.274 +                    </run-dependency>
 106.275 +                </dependency>
 106.276 +                <dependency>
 106.277 +                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
 106.278 +                    <build-prerequisite/>
 106.279 +                    <compile-dependency/>
 106.280 +                    <run-dependency>
 106.281 +                        <release-version>0-1</release-version>
 106.282 +                        <specification-version>1.7.0.7.2</specification-version>
 106.283 +                    </run-dependency>
 106.284 +                </dependency>
 106.285 +                <dependency>
 106.286 +                    <code-name-base>org.openide.awt</code-name-base>
 106.287 +                    <build-prerequisite/>
 106.288 +                    <compile-dependency/>
 106.289 +                    <run-dependency>
 106.290 +                        <specification-version>7.7.0.1</specification-version>
 106.291 +                    </run-dependency>
 106.292 +                </dependency>
 106.293 +                <dependency>
 106.294 +                    <code-name-base>org.openide.dialogs</code-name-base>
 106.295 +                    <build-prerequisite/>
 106.296 +                    <compile-dependency/>
 106.297 +                    <run-dependency>
 106.298 +                        <specification-version>7.10</specification-version>
 106.299 +                    </run-dependency>
 106.300 +                </dependency>
 106.301 +                <dependency>
 106.302 +                    <code-name-base>org.openide.filesystems</code-name-base>
 106.303 +                    <build-prerequisite/>
 106.304 +                    <compile-dependency/>
 106.305 +                    <run-dependency>
 106.306 +                        <specification-version>7.21.0.1.1</specification-version>
 106.307 +                    </run-dependency>
 106.308 +                </dependency>
 106.309 +                <dependency>
 106.310 +                    <code-name-base>org.openide.loaders</code-name-base>
 106.311 +                    <build-prerequisite/>
 106.312 +                    <compile-dependency/>
 106.313 +                    <run-dependency>
 106.314 +                        <specification-version>7.5</specification-version>
 106.315 +                    </run-dependency>
 106.316 +                </dependency>
 106.317 +                <dependency>
 106.318 +                    <code-name-base>org.openide.modules</code-name-base>
 106.319 +                    <build-prerequisite/>
 106.320 +                    <compile-dependency/>
 106.321 +                    <run-dependency>
 106.322 +                        <specification-version>7.10</specification-version>
 106.323 +                    </run-dependency>
 106.324 +                </dependency>
 106.325 +                <dependency>
 106.326 +                    <code-name-base>org.openide.nodes</code-name-base>
 106.327 +                    <build-prerequisite/>
 106.328 +                    <compile-dependency/>
 106.329 +                    <run-dependency>
 106.330 +                        <specification-version>7.9.0.1</specification-version>
 106.331 +                    </run-dependency>
 106.332 +                </dependency>
 106.333 +                <dependency>
 106.334 +                    <code-name-base>org.openide.text</code-name-base>
 106.335 +                    <build-prerequisite/>
 106.336 +                    <compile-dependency/>
 106.337 +                    <run-dependency>
 106.338 +                        <specification-version>6.22</specification-version>
 106.339 +                    </run-dependency>
 106.340 +                </dependency>
 106.341 +                <dependency>
 106.342 +                    <code-name-base>org.openide.util</code-name-base>
 106.343 +                    <build-prerequisite/>
 106.344 +                    <compile-dependency/>
 106.345 +                    <run-dependency>
 106.346 +                        <specification-version>8.0</specification-version>
 106.347 +                    </run-dependency>
 106.348 +                </dependency>
 106.349 +                <dependency>
 106.350 +                    <code-name-base>org.openide.util.lookup</code-name-base>
 106.351 +                    <build-prerequisite/>
 106.352 +                    <compile-dependency/>
 106.353 +                    <run-dependency>
 106.354 +                        <specification-version>8.0.0.1</specification-version>
 106.355 +                    </run-dependency>
 106.356 +                </dependency>
 106.357 +                <dependency>
 106.358 +                    <code-name-base>org.openide.windows</code-name-base>
 106.359 +                    <build-prerequisite/>
 106.360 +                    <compile-dependency/>
 106.361 +                    <run-dependency>
 106.362 +                        <specification-version>6.27</specification-version>
 106.363 +                    </run-dependency>
 106.364 +                </dependency>
 106.365 +            </module-dependencies>
 106.366 +            <test-dependencies>
 106.367 +                <test-type>
 106.368 +                    <name>unit</name>
 106.369 +                    <test-dependency>
 106.370 +                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
 106.371 +                        <compile-dependency/>
 106.372 +                    </test-dependency>
 106.373 +                    <test-dependency>
 106.374 +                        <code-name-base>org.netbeans.modules.jackpot30.common.test</code-name-base>
 106.375 +                        <recursive/>
 106.376 +                        <compile-dependency/>
 106.377 +                    </test-dependency>
 106.378 +                    <test-dependency>
 106.379 +                        <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
 106.380 +                        <recursive/>
 106.381 +                        <compile-dependency/>
 106.382 +                    </test-dependency>
 106.383 +                    <test-dependency>
 106.384 +                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
 106.385 +                        <recursive/>
 106.386 +                        <compile-dependency/>
 106.387 +                    </test-dependency>
 106.388 +                </test-type>
 106.389 +            </test-dependencies>
 106.390 +            <public-packages/>
 106.391 +        </data>
 106.392 +    </configuration>
 106.393 +</project>
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/language/ide/indexing/nbproject/suite.properties	Sat Feb 11 18:35:10 2012 +0100
   107.3 @@ -0,0 +1,1 @@
   107.4 +suite.dir=${basedir}/..
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
   108.3 @@ -0,0 +1,1 @@
   108.4 +OpenIDE-Module-Name=Jackpot 3.0 Indexing
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/BatchUtilities.java	Sat Feb 11 18:35:10 2012 +0100
   109.3 @@ -0,0 +1,121 @@
   109.4 +/*
   109.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   109.6 + *
   109.7 + * Copyright 2008-2010 Sun Microsystems, Inc. All rights reserved.
   109.8 + *
   109.9 + * The contents of this file are subject to the terms of either the GNU
  109.10 + * General Public License Version 2 only ("GPL") or the Common
  109.11 + * Development and Distribution License("CDDL") (collectively, the
  109.12 + * "License"). You may not use this file except in compliance with the
  109.13 + * License. You can obtain a copy of the License at
  109.14 + * http://www.netbeans.org/cddl-gplv2.html
  109.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  109.16 + * specific language governing permissions and limitations under the
  109.17 + * License.  When distributing the software, include this License Header
  109.18 + * Notice in each file and include the License file at
  109.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  109.20 + * particular file as subject to the "Classpath" exception as provided
  109.21 + * by Sun in the GPL Version 2 section of the License file that
  109.22 + * accompanied this code. If applicable, add the following below the
  109.23 + * License Header, with the fields enclosed by brackets [] replaced by
  109.24 + * your own identifying information:
  109.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  109.26 + *
  109.27 + * If you wish your version of this file to be governed by only the CDDL
  109.28 + * or only the GPL Version 2, indicate your decision by adding
  109.29 + * "[Contributor] elects to include this software in this distribution
  109.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  109.31 + * single choice of license, a recipient has the option to distribute
  109.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  109.33 + * to extend the choice of license to its licensees as provided above.
  109.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  109.35 + * Version 2 license, then the option applies only if the new code is
  109.36 + * made subject to such option by the copyright holder.
  109.37 + *
  109.38 + * Contributor(s):
  109.39 + *
  109.40 + * Portions Copyrighted 2008-2010 Sun Microsystems, Inc.
  109.41 + */
  109.42 +
  109.43 +package org.netbeans.modules.jackpot30.indexing.batch;
  109.44 +
  109.45 +import java.io.IOException;
  109.46 +import java.io.Reader;
  109.47 +import java.io.StringReader;
  109.48 +import java.io.Writer;
  109.49 +import java.nio.charset.Charset;
  109.50 +import org.netbeans.api.annotations.common.NullAllowed;
  109.51 +import org.netbeans.api.java.source.ModificationResult;
  109.52 +import org.netbeans.api.queries.FileEncodingQuery;
  109.53 +import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider;
  109.54 +import org.netbeans.modules.diff.builtin.visualizer.TextDiffVisualizer;
  109.55 +import org.netbeans.spi.diff.DiffProvider;
  109.56 +import org.openide.filesystems.FileObject;
  109.57 +import org.openide.filesystems.FileUtil;
  109.58 +
  109.59 +/**
  109.60 + *
  109.61 + * @author Jan Lahoda
  109.62 + */
  109.63 +public class BatchUtilities {
  109.64 +
  109.65 +    public static void exportDiff(ModificationResult result, @NullAllowed FileObject relativeTo, Writer out) throws IOException {
  109.66 +        for (FileObject f : result.getModifiedFileObjects()) {
  109.67 +            Charset c = FileEncodingQuery.getEncoding(f);
  109.68 +            String orig = new String(f.asBytes(), c);
  109.69 +            String nue = result.getResultingSource(f);
  109.70 +
  109.71 +            if (orig.equals(nue)) {
  109.72 +                continue;
  109.73 +            }
  109.74 +
  109.75 +            String name = relativeTo != null ? FileUtil.getRelativePath(relativeTo, f) : FileUtil.toFile(f).getAbsolutePath();
  109.76 +            
  109.77 +            doExportDiff(name, orig, nue, out);
  109.78 +        }
  109.79 +    }
  109.80 +
  109.81 +    //copied from the diff module:
  109.82 +    private static void doExportDiff(String name, String original, String modified, Writer out) throws IOException {
  109.83 +        DiffProvider diff = new BuiltInDiffProvider();//(DiffProvider) Lookup.getDefault().lookup(DiffProvider.class);
  109.84 +
  109.85 +        Reader r1 = null;
  109.86 +        Reader r2 = null;
  109.87 +        org.netbeans.api.diff.Difference[] differences;
  109.88 +
  109.89 +        try {
  109.90 +            r1 = new StringReader(original);
  109.91 +            r2 = new StringReader(modified);
  109.92 +            differences = diff.computeDiff(r1, r2);
  109.93 +        } finally {
  109.94 +            if (r1 != null) try { r1.close(); } catch (Exception e) {}
  109.95 +            if (r2 != null) try { r2.close(); } catch (Exception e) {}
  109.96 +        }
  109.97 +
  109.98 +        try {
  109.99 +            r1 = new StringReader(original);
 109.100 +            r2 = new StringReader(modified);
 109.101 +            TextDiffVisualizer.TextDiffInfo info = new TextDiffVisualizer.TextDiffInfo(
 109.102 +                name, // NOI18N
 109.103 +                name,  // NOI18N
 109.104 +                null,
 109.105 +                null,
 109.106 +                r1,
 109.107 +                r2,
 109.108 +                differences
 109.109 +            );
 109.110 +            info.setContextMode(true, 3);
 109.111 +            String diffText;
 109.112 +//            if (format == unifiedFilter) {
 109.113 +                diffText = TextDiffVisualizer.differenceToUnifiedDiffText(info);
 109.114 +//            } else {
 109.115 +//                diffText = TextDiffVisualizer.differenceToNormalDiffText(info);
 109.116 +//            }
 109.117 +            out.write(diffText);
 109.118 +        } finally {
 109.119 +            if (r1 != null) try { r1.close(); } catch (Exception e) {}
 109.120 +            if (r2 != null) try { r2.close(); } catch (Exception e) {}
 109.121 +        }
 109.122 +    }
 109.123 +
 109.124 +}
   110.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
   110.3 @@ -0,0 +1,49 @@
   110.4 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   110.5 +#
   110.6 +# Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
   110.7 +#
   110.8 +# The contents of this file are subject to the terms of either the GNU
   110.9 +# General Public License Version 2 only ("GPL") or the Common
  110.10 +# Development and Distribution License("CDDL") (collectively, the
  110.11 +# "License"). You may not use this file except in compliance with the
  110.12 +# License. You can obtain a copy of the License at
  110.13 +# http://www.netbeans.org/cddl-gplv2.html
  110.14 +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  110.15 +# specific language governing permissions and limitations under the
  110.16 +# License.  When distributing the software, include this License Header
  110.17 +# Notice in each file and include the License file at
  110.18 +# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  110.19 +# particular file as subject to the "Classpath" exception as provided
  110.20 +# by Sun in the GPL Version 2 section of the License file that
  110.21 +# accompanied this code. If applicable, add the following below the
  110.22 +# License Header, with the fields enclosed by brackets [] replaced by
  110.23 +# your own identifying information:
  110.24 +# "Portions Copyrighted [year] [name of copyright owner]"
  110.25 +#
  110.26 +# Contributor(s):
  110.27 +#
  110.28 +#The Original Software is NetBeans. The Initial Developer of the Original
  110.29 +# Software is Sun Microsystems, Inc. Portions Copyright 2008-2009 Sun
  110.30 +#Microsystems, Inc. All Rights Reserved.
  110.31 +#
  110.32 +# If you wish your version of this file to be governed by only the CDDL
  110.33 +# or only the GPL Version 2, indicate your decision by adding
  110.34 +# "[Contributor] elects to include this software in this distribution
  110.35 +# under the [CDDL or GPL Version 2] license." If you do not indicate a
  110.36 +# single choice of license, a recipient has the option to distribute
  110.37 +# your version of this file under either the CDDL, the GPL Version 2 or
  110.38 +# to extend the choice of license to its licensees as provided above.
  110.39 +# However, if you add GPL Version 2 code and therefore, elected the GPL
  110.40 +# Version 2 license, then the option applies only if the new code is
  110.41 +# made subject to such option by the copyright holder.
  110.42 +
  110.43 +CTL_BatchApplyAction=Batch Apply Hint
  110.44 +SD_ApplyTransformations=applies specified transformation(s) on specified project or all opened projects
  110.45 +SD_ApplyTransformationsProject=projects on which the transformations should be applied
  110.46 +SelectHint.jLabel1.text=Select Hint:
  110.47 +SelectHint.addHint.text=>>
  110.48 +SelectHint.addAllHints.text=>>>
  110.49 +SelectHint.removeHint.text=<<
  110.50 +SelectHint.removeAllHints.text=<<<
  110.51 +SelectHint.selectedHintsLabel.text=Selected Hints
  110.52 +SelectHint.allHintsLabel.text_1=All Hints:
   111.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/EnhancedScopes.java	Sat Feb 11 18:35:10 2012 +0100
   111.3 @@ -0,0 +1,497 @@
   111.4 +/*
   111.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   111.6 + *
   111.7 + * Copyright 2009-2011 Sun Microsystems, Inc. All rights reserved.
   111.8 + *
   111.9 + * The contents of this file are subject to the terms of either the GNU
  111.10 + * General Public License Version 2 only ("GPL") or the Common
  111.11 + * Development and Distribution License("CDDL") (collectively, the
  111.12 + * "License"). You may not use this file except in compliance with the
  111.13 + * License. You can obtain a copy of the License at
  111.14 + * http://www.netbeans.org/cddl-gplv2.html
  111.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  111.16 + * specific language governing permissions and limitations under the
  111.17 + * License.  When distributing the software, include this License Header
  111.18 + * Notice in each file and include the License file at
  111.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  111.20 + * particular file as subject to the "Classpath" exception as provided
  111.21 + * by Sun in the GPL Version 2 section of the License file that
  111.22 + * accompanied this code. If applicable, add the following below the
  111.23 + * License Header, with the fields enclosed by brackets [] replaced by
  111.24 + * your own identifying information:
  111.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  111.26 + *
  111.27 + * If you wish your version of this file to be governed by only the CDDL
  111.28 + * or only the GPL Version 2, indicate your decision by adding
  111.29 + * "[Contributor] elects to include this software in this distribution
  111.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  111.31 + * single choice of license, a recipient has the option to distribute
  111.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  111.33 + * to extend the choice of license to its licensees as provided above.
  111.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  111.35 + * Version 2 license, then the option applies only if the new code is
  111.36 + * made subject to such option by the copyright holder.
  111.37 + *
  111.38 + * Contributor(s):
  111.39 + *
  111.40 + * Portions Copyrighted 2009-2011 Sun Microsystems, Inc.
  111.41 + */
  111.42 +
  111.43 +package org.netbeans.modules.jackpot30.indexing.batch;
  111.44 +
  111.45 +import java.io.BufferedInputStream;
  111.46 +import java.io.BufferedOutputStream;
  111.47 +import java.io.File;
  111.48 +import java.io.FileInputStream;
  111.49 +import java.io.FileOutputStream;
  111.50 +import java.io.IOException;
  111.51 +import java.io.InputStream;
  111.52 +import java.io.OutputStream;
  111.53 +import java.net.MalformedURLException;
  111.54 +import java.net.URI;
  111.55 +import java.net.URISyntaxException;
  111.56 +import java.net.URL;
  111.57 +import java.util.ArrayList;
  111.58 +import java.util.Collection;
  111.59 +import java.util.Collections;
  111.60 +import java.util.HashMap;
  111.61 +import java.util.HashSet;
  111.62 +import java.util.Iterator;
  111.63 +import java.util.LinkedList;
  111.64 +import java.util.List;
  111.65 +import java.util.Map;
  111.66 +import java.util.Map.Entry;
  111.67 +import java.util.Properties;
  111.68 +import java.util.Set;
  111.69 +import java.util.concurrent.Callable;
  111.70 +import java.util.concurrent.atomic.AtomicBoolean;
  111.71 +import java.util.logging.Level;
  111.72 +import java.util.logging.Logger;
  111.73 +import org.codeviation.pojson.Pojson;
  111.74 +import org.netbeans.api.java.classpath.ClassPath;
  111.75 +import org.netbeans.api.java.source.ClasspathInfo;
  111.76 +import org.netbeans.api.java.source.CompilationController;
  111.77 +import org.netbeans.api.java.source.JavaSource;
  111.78 +import org.netbeans.api.java.source.Task;
  111.79 +import org.netbeans.modules.jackpot30.indexing.index.IndexQuery;
  111.80 +import org.netbeans.modules.jackpot30.indexing.index.Indexer;
  111.81 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
  111.82 +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
  111.83 +import static org.netbeans.modules.jackpot30.remoting.api.WebUtilities.escapeForQuery;
  111.84 +import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
  111.85 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Folder;
  111.86 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.IndexEnquirer;
  111.87 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.LocalIndexEnquirer;
  111.88 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.MapIndices;
  111.89 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Resource;
  111.90 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Scope;
  111.91 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.VerifiedSpansCallBack;
  111.92 +import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
  111.93 +import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
  111.94 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
  111.95 +import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
  111.96 +import org.netbeans.modules.java.hints.jackpot.spi.Trigger.PatternDescription;
  111.97 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaIndexerPlugin;
  111.98 +import org.netbeans.modules.parsing.impl.indexing.FileObjectIndexable;
  111.99 +import org.netbeans.modules.parsing.impl.indexing.IndexableImpl;
 111.100 +import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
 111.101 +import org.netbeans.spi.editor.hints.ErrorDescription;
 111.102 +import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
 111.103 +import org.netbeans.spi.editor.hints.Severity;
 111.104 +import org.openide.filesystems.FileObject;
 111.105 +import org.openide.filesystems.FileUtil;
 111.106 +import org.openide.filesystems.URLMapper;
 111.107 +import org.openide.util.Exceptions;
 111.108 +
 111.109 +/**
 111.110 + *
 111.111 + * @author lahvac
 111.112 + */
 111.113 +public class EnhancedScopes {
 111.114 +
 111.115 +    private static final Logger LOG = Logger.getLogger(EnhancedScopes.class.getName());
 111.116 +
 111.117 +    public static Scope allRemote() {
 111.118 +        return new RemoteIndexScope();
 111.119 +    }
 111.120 +
 111.121 +    public static final class GivenFolderScope extends Scope {
 111.122 +
 111.123 +        public final String folder;
 111.124 +        public final String indexURL;
 111.125 +        public final String subIndex;
 111.126 +        public final boolean update;
 111.127 +
 111.128 +        public GivenFolderScope(String folder, String indexURL, String subIndex, boolean update) {
 111.129 +            this.folder = folder;
 111.130 +            this.indexURL = indexURL;
 111.131 +            this.subIndex = subIndex;
 111.132 +            this.update = update;
 111.133 +        }
 111.134 +
 111.135 +        @Override
 111.136 +        public String getDisplayName() {
 111.137 +            return folder;
 111.138 +        }
 111.139 +
 111.140 +        @Override
 111.141 +        public Collection<? extends Folder> getTodo() {
 111.142 +            return Collections.singletonList(new Folder(FileUtil.toFileObject(new File(folder))));
 111.143 +        }
 111.144 +
 111.145 +        @Override
 111.146 +        public MapIndices getIndexMapper(Iterable<? extends HintDescription> patterns) {
 111.147 +            MapIndices mapper;
 111.148 +
 111.149 +            if (indexURL != null) {
 111.150 +                if (subIndex == null) {
 111.151 +                    mapper = new MapIndices() {
 111.152 +                        public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
 111.153 +                            try {
 111.154 +                                return new SimpleIndexIndexEnquirer(root, createOrUpdateIndex(root, new File(indexURL), update, progress, recursive));
 111.155 +                            } catch (IOException ex) {
 111.156 +                                Exceptions.printStackTrace(ex);
 111.157 +                                return null;
 111.158 +                            }
 111.159 +                        }
 111.160 +                    };
 111.161 +                } else {
 111.162 +                    mapper = new MapIndices() {
 111.163 +                        public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
 111.164 +                            progress.startNextPart(1);
 111.165 +                            try {
 111.166 +                                return new SimpleIndexIndexEnquirer(root, IndexQuery.remote(RemoteIndex.create(root.toURL(), new URL(indexURL), subIndex)));
 111.167 +                            } catch (MalformedURLException ex) {
 111.168 +                                Exceptions.printStackTrace(ex);
 111.169 +                                return null;
 111.170 +                            }
 111.171 +                        }
 111.172 +                    };
 111.173 +                }
 111.174 +            } else {
 111.175 +                mapper = Scopes.getDefaultIndicesMapper();
 111.176 +            }
 111.177 +
 111.178 +            return mapper;
 111.179 +        }
 111.180 +
 111.181 +    }
 111.182 +
 111.183 +    private static final class RemoteIndexScope extends Scope {
 111.184 +        @Override
 111.185 +        public String getDisplayName() {
 111.186 +            return "All Remote Indices";
 111.187 +        }
 111.188 +
 111.189 +        @Override
 111.190 +        public Collection<? extends Folder> getTodo() {
 111.191 +            Collection<Folder> todo = new HashSet<Folder>();
 111.192 +
 111.193 +            for (RemoteIndex remoteIndex : RemoteIndex.loadIndices()) {
 111.194 +                FileObject localFolder = URLMapper.findFileObject(remoteIndex.getLocalFolder());
 111.195 +
 111.196 +                if (localFolder == null) continue;
 111.197 +                todo.add(new Folder(localFolder));
 111.198 +            }
 111.199 +
 111.200 +            return todo;
 111.201 +        }
 111.202 +
 111.203 +        @Override
 111.204 +        public MapIndices getIndexMapper(final Iterable<? extends HintDescription> patterns) {
 111.205 +            return new MapIndices() {
 111.206 +                public IndexEnquirer findIndex(FileObject root, ProgressHandleWrapper progress, boolean recursive) {
 111.207 +                    for (RemoteIndex remoteIndex : RemoteIndex.loadIndices()) {
 111.208 +                        FileObject localFolder = URLMapper.findFileObject(remoteIndex.getLocalFolder());
 111.209 +
 111.210 +                        if (localFolder == null) continue;
 111.211 +                        if (localFolder == root) {
 111.212 +                            return enquirerForRemoteIndex(root, remoteIndex, patterns);
 111.213 +                        }
 111.214 +                    }
 111.215 +                    throw new IllegalStateException();
 111.216 +                }
 111.217 +            };
 111.218 +        }
 111.219 +    }
 111.220 +
 111.221 +    private static IndexQuery createOrUpdateIndex(final FileObject src, File indexRoot, boolean update, ProgressHandleWrapper progress, boolean recursive) throws IOException {
 111.222 +        final JavaIndexerPlugin index = new Indexer.FactoryImpl().create(src.toURL(), FileUtil.toFileObject(indexRoot));
 111.223 +
 111.224 +        File timeStampsFile = new File(indexRoot, "timestamps.properties");
 111.225 +        Properties timeStamps = new Properties();
 111.226 +
 111.227 +        if (timeStampsFile.exists()) {
 111.228 +            if (!update) {
 111.229 +                progress.startNextPart(1);
 111.230 +                return IndexQuery.open(src.toURL());
 111.231 +            }
 111.232 +
 111.233 +            InputStream in = null;
 111.234 +
 111.235 +            try {
 111.236 +                in = new BufferedInputStream(new FileInputStream(timeStampsFile));
 111.237 +                timeStamps.load(in);
 111.238 +            } catch (IOException ex) {
 111.239 +                Exceptions.printStackTrace(ex);
 111.240 +            } finally {
 111.241 +                try {
 111.242 +                    if (in != null)
 111.243 +                        in.close();
 111.244 +                } catch (IOException ex) {
 111.245 +                    Exceptions.printStackTrace(ex);
 111.246 +                }
 111.247 +            }
 111.248 +        }
 111.249 +
 111.250 +        Collection<FileObject> collected = new LinkedList<FileObject>();
 111.251 +        Set<String> removed = new HashSet<String>(timeStamps.stringPropertyNames());
 111.252 +
 111.253 +        org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities.recursive(src, src, collected, progress, 0, timeStamps, removed, recursive);
 111.254 +
 111.255 +        for (String r : removed) {
 111.256 +            index.delete(SPIAccessor.getInstance().create(new FakeIndexableImpl(r)));
 111.257 +        }
 111.258 +        
 111.259 +        JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY), collected);
 111.260 +        
 111.261 +        js.runUserActionTask(new Task<CompilationController>() {
 111.262 +            @Override public void run(CompilationController parameter) throws Exception {
 111.263 +                if (parameter.toPhase(JavaSource.Phase.PARSED).compareTo(JavaSource.Phase.PARSED) < 0) return;
 111.264 +                
 111.265 +                index.process(parameter.getCompilationUnit(), SPIAccessor.getInstance().create(new FileObjectIndexable(src, parameter.getFileObject())), null);
 111.266 +            }
 111.267 +        }, true);
 111.268 +        
 111.269 +        OutputStream out = null;
 111.270 +
 111.271 +        try {
 111.272 +            out = new BufferedOutputStream(new FileOutputStream(timeStampsFile));
 111.273 +            timeStamps.store(out, null);
 111.274 +        } finally {
 111.275 +            try {
 111.276 +                if (out != null) {
 111.277 +                    out.close();
 111.278 +                }
 111.279 +            } catch (IOException ex) {
 111.280 +                Exceptions.printStackTrace(ex);
 111.281 +            }
 111.282 +        }
 111.283 +
 111.284 +        return IndexQuery.open(src.toURL());
 111.285 +    }
 111.286 +    
 111.287 +    private static final class FakeIndexableImpl implements IndexableImpl {
 111.288 +
 111.289 +        private final String path;
 111.290 +
 111.291 +        public FakeIndexableImpl(String path) {
 111.292 +            this.path = path;
 111.293 +        }
 111.294 +        
 111.295 +        @Override public String getRelativePath() {
 111.296 +            return path;
 111.297 +        }
 111.298 +
 111.299 +        @Override public URL getURL() {
 111.300 +            throw new UnsupportedOperationException("Not supported yet.");
 111.301 +        }
 111.302 +
 111.303 +        @Override public String getMimeType() {
 111.304 +            throw new UnsupportedOperationException("Not supported yet.");
 111.305 +        }
 111.306 +
 111.307 +        @Override public boolean isTypeOf(String mimeType) {
 111.308 +            throw new UnsupportedOperationException("Not supported yet.");
 111.309 +        }
 111.310 +        
 111.311 +    }
 111.312 +
 111.313 +    private static boolean isAttributedIndexWithSpans(RemoteIndex remoteIndex) {
 111.314 +        try {
 111.315 +            URI capabilitiesURI = new URI(remoteIndex.remote.toExternalForm() + "/capabilities");
 111.316 +            String capabilitiesString = WebUtilities.requestStringResponse(capabilitiesURI);
 111.317 +
 111.318 +            if (capabilitiesURI == null) return false;
 111.319 +
 111.320 +            @SuppressWarnings("unchecked")
 111.321 +            Map<String, Object> capabilities = Pojson.load(HashMap.class, capabilitiesString);
 111.322 +
 111.323 +            return capabilities.get("attributed") == Boolean.TRUE; //TODO: should also check "methods contains findWithSpans"
 111.324 +        } catch (URISyntaxException ex) {
 111.325 +            LOG.log(Level.FINE, null, ex);
 111.326 +            return false;
 111.327 +        }
 111.328 +    }
 111.329 +
 111.330 +    private static IndexEnquirer enquirerForRemoteIndex(FileObject src, RemoteIndex remoteIndex, Iterable<? extends HintDescription> hints) {
 111.331 +        boolean fullySupported = isAttributedIndexWithSpans(remoteIndex);
 111.332 +        StringBuilder textualRepresentation = new StringBuilder();
 111.333 +
 111.334 +        for (HintDescription hd : hints) {
 111.335 +            if (!(hd.getTrigger() instanceof PatternDescription)) {
 111.336 +                fullySupported = false;
 111.337 +                break;
 111.338 +            }
 111.339 +
 111.340 +            if (((PatternDescription) hd.getTrigger()).getImports().iterator().hasNext()) {
 111.341 +                fullySupported = false;
 111.342 +            }
 111.343 +
 111.344 +            if (!fullySupported) break;
 111.345 +
 111.346 +            String hintText = hd.getHintText();
 111.347 +
 111.348 +            if (hintText != null) {
 111.349 +                textualRepresentation.append(hintText);
 111.350 +            } else {
 111.351 +                textualRepresentation.append(defaultHintText(hd));
 111.352 +                fullySupported = false;
 111.353 +            }
 111.354 +
 111.355 +            textualRepresentation.append("\n");
 111.356 +        }
 111.357 +
 111.358 +        if (fullySupported) {
 111.359 +            return new RemoteFullyAttributedIndexEnquirer(src, remoteIndex, textualRepresentation.toString());
 111.360 +        } else {
 111.361 +            return new SimpleIndexIndexEnquirer(src, IndexQuery.remote(remoteIndex));
 111.362 +        }
 111.363 +    }
 111.364 +
 111.365 +    private static final class SimpleIndexIndexEnquirer extends LocalIndexEnquirer {
 111.366 +        private final IndexQuery idx;
 111.367 +        public SimpleIndexIndexEnquirer(FileObject src, IndexQuery idx) {
 111.368 +            super(src);
 111.369 +            this.idx = idx;
 111.370 +        }
 111.371 +        public Collection<? extends Resource> findResources(final Iterable<? extends HintDescription> hints, ProgressHandleWrapper progress, final Callable<BulkPattern> bulkPattern, final Collection<? super MessageImpl> problems) {
 111.372 +            final Collection<Resource> result = new ArrayList<Resource>();
 111.373 +
 111.374 +            progress.startNextPart(1);
 111.375 +
 111.376 +            try {
 111.377 +                BulkPattern bp = bulkPattern.call();
 111.378 +
 111.379 +                for (String candidate : idx.findCandidates(bp)) {
 111.380 +                    result.add(new Resource(this, candidate, hints, bp));
 111.381 +                }
 111.382 +            } catch (Exception ex) {
 111.383 +                Exceptions.printStackTrace(ex);
 111.384 +            }
 111.385 +
 111.386 +            return result;
 111.387 +        }
 111.388 +
 111.389 +    }
 111.390 +
 111.391 +    private static final class RemoteFullyAttributedIndexEnquirer extends IndexEnquirer {
 111.392 +        private final RemoteIndex remoteIndex;
 111.393 +        private final String textualHintRepresentation;
 111.394 +        public RemoteFullyAttributedIndexEnquirer(FileObject src, RemoteIndex remoteIndex, String textualHintRepresentation) {
 111.395 +            super(src);
 111.396 +            assert isAttributedIndexWithSpans(remoteIndex);
 111.397 +            this.remoteIndex = remoteIndex;
 111.398 +            this.textualHintRepresentation = textualHintRepresentation;
 111.399 +        }
 111.400 +        public Collection<? extends Resource> findResources(final Iterable<? extends HintDescription> hints, ProgressHandleWrapper progress, final Callable<BulkPattern> bulkPattern, final Collection<? super MessageImpl> problems) {
 111.401 +            final Collection<Resource> result = new ArrayList<Resource>();
 111.402 +
 111.403 +            progress.startNextPart(1);
 111.404 +
 111.405 +            try {
 111.406 +                URI u = new URI(remoteIndex.remote.toExternalForm() + "/find?path=" + escapeForQuery(remoteIndex.remoteSegment) + "&pattern=" + escapeForQuery(textualHintRepresentation));
 111.407 +
 111.408 +                for (String occurrence : new ArrayList<String>(WebUtilities.requestStringArrayResponse(u))) {
 111.409 +                    try {
 111.410 +                        BulkPattern bp = bulkPattern.call();
 111.411 +                        result.add(new Resource(this, occurrence, hints, bp));
 111.412 +                    } catch (Exception ex) {
 111.413 +                        //from bulkPattern.call()? should not happen.
 111.414 +                        Exceptions.printStackTrace(ex);
 111.415 +                    }
 111.416 +                }
 111.417 +
 111.418 +            } catch (URISyntaxException ex) {
 111.419 +                Exceptions.printStackTrace(ex);
 111.420 +            }
 111.421 +
 111.422 +            return result;
 111.423 +        }
 111.424 +
 111.425 +        @Override
 111.426 +        public void validateResource(Collection<? extends Resource> resources, ProgressHandleWrapper progress, VerifiedSpansCallBack callback, boolean doNotRegisterClassPath, Collection<? super MessageImpl> problems, AtomicBoolean cancel) {
 111.427 +            for (Resource r : resources) {
 111.428 +                try {
 111.429 +                    URI spanURI = new URI(remoteIndex.remote.toExternalForm() + "/findSpans?path=" + escapeForQuery(remoteIndex.remoteSegment) + "&relativePath=" + escapeForQuery(r.getRelativePath()) + "&pattern=" + escapeForQuery(textualHintRepresentation));
 111.430 +                    FileObject fo = r.getResolvedFile();
 111.431 +
 111.432 +                    if (fo == null) {
 111.433 +                        callback.cannotVerifySpan(r);
 111.434 +                    } else {
 111.435 +                        List<ErrorDescription> result = new ArrayList<ErrorDescription>();
 111.436 +
 111.437 +                        for (int[] span : parseSpans(WebUtilities.requestStringResponse(spanURI))) {
 111.438 +                            result.add(ErrorDescriptionFactory.createErrorDescription(Severity.WARNING, "Occurrence", fo, span[0], span[1]));
 111.439 +                        }
 111.440 +
 111.441 +                        callback.spansVerified(null, r, result);
 111.442 +                    }
 111.443 +                } catch (Exception ex) {
 111.444 +                    Exceptions.printStackTrace(ex);
 111.445 +                }
 111.446 +            }
 111.447 +        }
 111.448 +
 111.449 +    }
 111.450 +
 111.451 +    private static Iterable<int[]> parseSpans(String from) {
 111.452 +        if (from.isEmpty()) {
 111.453 +            return Collections.emptyList();
 111.454 +        }
 111.455 +        String[] split = from.split(":");
 111.456 +        List<int[]> result = new LinkedList<int[]>();
 111.457 +
 111.458 +        for (int i = 0; i < split.length; i += 2) {
 111.459 +            result.add(new int[] {
 111.460 +                Integer.parseInt(split[i + 0].trim()),
 111.461 +                Integer.parseInt(split[i + 1].trim())
 111.462 +            });
 111.463 +        }
 111.464 +
 111.465 +        return result;
 111.466 +    }
 111.467 +
 111.468 +    private static String defaultHintText(HintDescription hd) {
 111.469 +        StringBuilder result = new StringBuilder();
 111.470 +
 111.471 +        PatternDescription pd = (PatternDescription) hd.getTrigger();
 111.472 +
 111.473 +        if (pd == null) return null;
 111.474 +
 111.475 +        if (pd.getImports().iterator().hasNext()) {
 111.476 +            //cannot currently handle patterns with imports:
 111.477 +            return null;
 111.478 +        }
 111.479 +
 111.480 +        result.append(pd.getPattern());
 111.481 +
 111.482 +        if (!pd.getConstraints().isEmpty()) {
 111.483 +            result.append(" :: ");
 111.484 +
 111.485 +            for (Iterator<Entry<String, String>> it = pd.getConstraints().entrySet().iterator(); it.hasNext(); ) {
 111.486 +                Entry<String, String> e = it.next();
 111.487 +
 111.488 +                result.append(e.getKey()).append(" instanceof ").append(e.getValue());
 111.489 +
 111.490 +                if (it.hasNext()) {
 111.491 +                    result.append(" && ");
 111.492 +                }
 111.493 +            }
 111.494 +        }
 111.495 +
 111.496 +        result.append(";;\n");
 111.497 +
 111.498 +        return result.toString();
 111.499 +    }
 111.500 +}
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/batch/OptionProcessorImpl.java	Sat Feb 11 18:35:10 2012 +0100
   112.3 @@ -0,0 +1,276 @@
   112.4 +/*
   112.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   112.6 + *
   112.7 + * Copyright 2008-2010 Sun Microsystems, Inc. All rights reserved.
   112.8 + *
   112.9 + * The contents of this file are subject to the terms of either the GNU
  112.10 + * General Public License Version 2 only ("GPL") or the Common
  112.11 + * Development and Distribution License("CDDL") (collectively, the
  112.12 + * "License"). You may not use this file except in compliance with the
  112.13 + * License. You can obtain a copy of the License at
  112.14 + * http://www.netbeans.org/cddl-gplv2.html
  112.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  112.16 + * specific language governing permissions and limitations under the
  112.17 + * License.  When distributing the software, include this License Header
  112.18 + * Notice in each file and include the License file at
  112.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  112.20 + * particular file as subject to the "Classpath" exception as provided
  112.21 + * by Sun in the GPL Version 2 section of the License file that
  112.22 + * accompanied this code. If applicable, add the following below the
  112.23 + * License Header, with the fields enclosed by brackets [] replaced by
  112.24 + * your own identifying information:
  112.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  112.26 + *
  112.27 + * If you wish your version of this file to be governed by only the CDDL
  112.28 + * or only the GPL Version 2, indicate your decision by adding
  112.29 + * "[Contributor] elects to include this software in this distribution
  112.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  112.31 + * single choice of license, a recipient has the option to distribute
  112.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  112.33 + * to extend the choice of license to its licensees as provided above.
  112.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  112.35 + * Version 2 license, then the option applies only if the new code is
  112.36 + * made subject to such option by the copyright holder.
  112.37 + *
  112.38 + * Contributor(s):
  112.39 + *
  112.40 + * Portions Copyrighted 2008-2010 Sun Microsystems, Inc.
  112.41 + */
  112.42 +
  112.43 +package org.netbeans.modules.jackpot30.indexing.batch;
  112.44 +
  112.45 +import java.io.File;
  112.46 +import java.io.IOException;
  112.47 +import java.util.ArrayList;
  112.48 +import java.util.Arrays;
  112.49 +import java.util.Collection;
  112.50 +import java.util.HashMap;
  112.51 +import java.util.HashSet;
  112.52 +import java.util.LinkedList;
  112.53 +import java.util.List;
  112.54 +import java.util.Map;
  112.55 +import java.util.Set;
  112.56 +import java.util.TreeMap;
  112.57 +import java.util.logging.Logger;
  112.58 +import org.netbeans.api.java.classpath.ClassPath;
  112.59 +import org.netbeans.api.java.source.ModificationResult;
  112.60 +import org.netbeans.api.project.Project;
  112.61 +import org.netbeans.api.project.ProjectManager;
  112.62 +import org.netbeans.api.project.ProjectUtils;
  112.63 +import org.netbeans.api.project.SourceGroup;
  112.64 +import org.netbeans.api.project.ui.OpenProjects;
  112.65 +import org.netbeans.api.sendopts.CommandException;
  112.66 +import org.netbeans.modules.java.hints.jackpot.impl.MessageImpl;
  112.67 +import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
  112.68 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch;
  112.69 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.BatchResult;
  112.70 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchSearch.Folder;
  112.71 +import org.netbeans.modules.java.hints.jackpot.impl.batch.BatchUtilities;
  112.72 +import org.netbeans.modules.java.hints.jackpot.impl.batch.ProgressHandleWrapper;
  112.73 +import org.netbeans.modules.java.hints.jackpot.impl.batch.Scopes;
  112.74 +import org.netbeans.modules.java.hints.jackpot.spi.HintContext.MessageKind;
  112.75 +import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
  112.76 +import org.netbeans.spi.java.classpath.support.ClassPathSupport;
  112.77 +import org.netbeans.spi.sendopts.Env;
  112.78 +import org.netbeans.spi.sendopts.Option;
  112.79 +import org.netbeans.spi.sendopts.OptionProcessor;
  112.80 +import org.openide.filesystems.FileObject;
  112.81 +import org.openide.filesystems.FileUtil;
  112.82 +import org.openide.util.lookup.ServiceProvider;
  112.83 +
  112.84 +/**
  112.85 + *
  112.86 + * @author Jan Lahoda
  112.87 + */
  112.88 +@ServiceProvider(service=OptionProcessor.class)
  112.89 +public class OptionProcessorImpl extends OptionProcessor {
  112.90 +
  112.91 +    private static final Logger LOG = Logger.getLogger(OptionProcessorImpl.class.getName());
  112.92 +
  112.93 +    private static final String APPLY_TRANSFORMATIONS_PROJECT_OPTION = "apply-transformations-project";
  112.94 +
  112.95 +    private static final Option LIST = Option.withoutArgument(Option.NO_SHORT_NAME, "list-hints-transformation");
  112.96 +    private static final Option APPLY_TRANSFORMATIONS = Option.shortDescription(
  112.97 +                                                            Option.requiredArgument(Option.NO_SHORT_NAME, "apply-transformations"),
  112.98 +                                                            "org.netbeans.modules.jackpot30.impl.batch.Bundle",
  112.99 +                                                            "SD_ApplyTransformations");
 112.100 +    private static final Option APPLY_TRANSFORMATIONS_PROJECT = Option.shortDescription(
 112.101 +                                                            Option.additionalArguments(Option.NO_SHORT_NAME, APPLY_TRANSFORMATIONS_PROJECT_OPTION),
 112.102 +                                                            "org.netbeans.modules.jackpot30.impl.batch.Bundle",
 112.103 +                                                            "SD_ApplyTransformationsProject");
 112.104 +
 112.105 +    private static final Set<Option> OPTIONS = new HashSet<Option>(Arrays.asList(LIST, APPLY_TRANSFORMATIONS, APPLY_TRANSFORMATIONS_PROJECT));
 112.106 +
 112.107 +    @Override
 112.108 +    protected Set<Option> getOptions() {
 112.109 +        return OPTIONS;
 112.110 +    }
 112.111 +
 112.112 +    @Override
 112.113 +    protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
 112.114 +        List<Project> projects = new LinkedList<Project>();
 112.115 +        Map<String, List<ClassPath>> classPaths = new HashMap<String, List<ClassPath>>();
 112.116 +
 112.117 +        if (optionValues.containsKey(APPLY_TRANSFORMATIONS_PROJECT)) {
 112.118 +            String[] projectNames = optionValues.get(APPLY_TRANSFORMATIONS_PROJECT);
 112.119 +
 112.120 +            if (projectNames.length == 0) {
 112.121 +                env.getErrorStream().println("At least one parameter needed for " + APPLY_TRANSFORMATIONS_PROJECT_OPTION);
 112.122 +                throw new CommandException(1);
 112.123 +            }
 112.124 +
 112.125 +            FileObject currentDirectory = FileUtil.toFileObject(env.getCurrentDirectory());
 112.126 +
 112.127 +            OUTER: for (String p : projectNames) {
 112.128 +                FileObject projectFile = currentDirectory.getFileObject(p);
 112.129 +
 112.130 +                if (projectFile == null) {
 112.131 +                    projectFile = FileUtil.toFileObject(new File(p));
 112.132 +                }
 112.133 +
 112.134 +                if (projectFile == null) {
 112.135 +                    env.getErrorStream().println("Ignoring file " + p + " - cannot be found.");
 112.136 +                    continue;
 112.137 +                }
 112.138 +
 112.139 +                if (!projectFile.isFolder()) {
 112.140 +                    env.getErrorStream().println("Ignoring file " + p + " - not a folder.");
 112.141 +                    continue;
 112.142 +                }
 112.143 +
 112.144 +                Project project = null;
 112.145 +                String  error   = null;
 112.146 +
 112.147 +                try {
 112.148 +                    project = ProjectManager.getDefault().findProject(projectFile);
 112.149 +                } catch (IOException ex) {
 112.150 +                    error = ex.getLocalizedMessage();
 112.151 +                } catch (IllegalArgumentException ex) {
 112.152 +                    error = ex.getLocalizedMessage();
 112.153 +                }
 112.154 +
 112.155 +                if (project == null) {
 112.156 +                    if (error == null) {
 112.157 +                        env.getErrorStream().println("Ignoring file " + p + " - not a project.");
 112.158 +                    } else {
 112.159 +                        env.getErrorStream().println("Ignoring file " + p + " - not a project (" + error + ").");
 112.160 +                    }
 112.161 +
 112.162 +                    continue;
 112.163 +                }
 112.164 +
 112.165 +                for (SourceGroup sg : ProjectUtils.getSources(project).getSourceGroups("java")) {
 112.166 +                    FileObject root = sg.getRootFolder();
 112.167 +
 112.168 +                    for (String type : Arrays.asList(ClassPath.BOOT, ClassPath.COMPILE, ClassPath.SOURCE)) {
 112.169 +                        if (!handleClassPath(root, type, env, p, classPaths)) {
 112.170 +                            continue OUTER;
 112.171 +                        }
 112.172 +                    }
 112.173 +                }
 112.174 +
 112.175 +                projects.add(project);
 112.176 +            }
 112.177 +        } else {
 112.178 +            projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
 112.179 +        }
 112.180 +
 112.181 +        if (optionValues.containsKey(LIST)) {
 112.182 +            env.getOutputStream().println("Supported Hints:");
 112.183 +
 112.184 +            Set<ClassPath> cps = new HashSet<ClassPath>();
 112.185 +
 112.186 +            for (List<ClassPath> c : classPaths.values()) {
 112.187 +                cps.addAll(c);
 112.188 +            }
 112.189 +
 112.190 +            Set<String> displayNames = Utilities.sortOutHints(Utilities.listAllHints(cps), new TreeMap<String, Collection<HintDescription>>()).keySet();
 112.191 +
 112.192 +            for (String displayName : displayNames) {
 112.193 +                env.getOutputStream().println(displayName);
 112.194 +            }
 112.195 +        }
 112.196 +
 112.197 +        if (optionValues.containsKey(APPLY_TRANSFORMATIONS)) {
 112.198 +            String hintsArg = optionValues.get(APPLY_TRANSFORMATIONS)[0];
 112.199 +            List<HintDescription> hintDescriptions = new LinkedList<HintDescription>();
 112.200 +            Set<ClassPath> cps = new HashSet<ClassPath>();
 112.201 +
 112.202 +            for (List<ClassPath> c : classPaths.values()) {
 112.203 +                cps.addAll(c);
 112.204 +            }
 112.205 +
 112.206 +            Map<String, Collection<HintDescription>> sorted = Utilities.sortOutHints(Utilities.listAllHints(cps), new TreeMap<String, Collection<HintDescription>>());
 112.207 +
 112.208 +            for (String hint : hintsArg.split(":")) {
 112.209 +                Collection<HintDescription> descs = sorted.get(hint);
 112.210 +
 112.211 +                if (descs == null) {
 112.212 +                    env.getErrorStream().println("Unknown hint: " + hint);
 112.213 +                    continue;
 112.214 +                }
 112.215 +
 112.216 +                hintDescriptions.addAll(descs);
 112.217 +            }
 112.218 +
 112.219 +            Collection<Folder> roots = new ArrayList<Folder>();
 112.220 +
 112.221 +            for (FileObject f : BatchUtilities.getSourceGroups(projects)) {
 112.222 +                roots.add(new Folder(f));
 112.223 +            }
 112.224 +
 112.225 +            BatchResult candidates = BatchSearch.findOccurrences(hintDescriptions, Scopes.specifiedFoldersScope(roots.toArray(new Folder[0])));
 112.226 +            List<MessageImpl> problems = new LinkedList<MessageImpl>(candidates.problems);
 112.227 +            Collection<? extends ModificationResult> res = BatchUtilities.applyFixes(candidates, new ProgressHandleWrapper(100), null, problems);
 112.228 +            Set<FileObject> modified = new HashSet<FileObject>();
 112.229 +
 112.230 +            for (ModificationResult mr : res) {
 112.231 +                try {
 112.232 +                    mr.commit();
 112.233 +                } catch (IOException ex) {
 112.234 +                    ex.printStackTrace(env.getErrorStream());
 112.235 +                    problems.add(new MessageImpl(MessageKind.ERROR, "Cannot apply changes: " + ex.getLocalizedMessage()));
 112.236 +                }
 112.237 +                modified.addAll(mr.getModifiedFileObjects());
 112.238 +            }
 112.239 +
 112.240 +            try {
 112.241 +                BatchUtilities.removeUnusedImports(modified);
 112.242 +            } catch (IOException ex) {
 112.243 +                ex.printStackTrace(env.getErrorStream());
 112.244 +                problems.add(new MessageImpl(MessageKind.ERROR, "Cannot remove unused imports: " + ex.getLocalizedMessage()));
 112.245 +            }
 112.246 +
 112.247 +            if (!problems.isEmpty()) {
 112.248 +                env.getErrorStream().println("Problem encountered while applying the transformations:");
 112.249 +
 112.250 +                for (MessageImpl problem : problems) {
 112.251 +                    env.getErrorStream().println(problem.text);
 112.252 +                }
 112.253 +            }
 112.254 +        }
 112.255 +
 112.256 +    }
 112.257 +
 112.258 +    private boolean handleClassPath(FileObject root, String type, Env env, String p, Map<String, List<ClassPath>> classPaths) {
 112.259 +        ClassPath cp = ClassPath.getClassPath(root, type);
 112.260 +
 112.261 +        if (cp == null) {
 112.262 +            env.getErrorStream().println("Ignoring file " + p + " - no " + type + " classpath for source group: " + FileUtil.getFileDisplayName(root));
 112.263 +            return false;
 112.264 +        }
 112.265 +
 112.266 +        List<ClassPath> cps = classPaths.get(type);
 112.267 +
 112.268 +        if (cps == null) {
 112.269 +            classPaths.put(type, cps = new LinkedList<ClassPath>());
 112.270 +        }
 112.271 +
 112.272 +        cp = ClassPathSupport.createProxyClassPath(cp);
 112.273 +
 112.274 +        cps.add(cp);
 112.275 +
 112.276 +        return true;
 112.277 +    }
 112.278 +
 112.279 +}
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/index/IndexQuery.java	Sat Feb 11 18:35:10 2012 +0100
   113.3 @@ -0,0 +1,259 @@
   113.4 +/*
   113.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   113.6 + *
   113.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
   113.8 + *
   113.9 + * The contents of this file are subject to the terms of either the GNU
  113.10 + * General Public License Version 2 only ("GPL") or the Common
  113.11 + * Development and Distribution License("CDDL") (collectively, the
  113.12 + * "License"). You may not use this file except in compliance with the
  113.13 + * License. You can obtain a copy of the License at
  113.14 + * http://www.netbeans.org/cddl-gplv2.html
  113.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  113.16 + * specific language governing permissions and limitations under the
  113.17 + * License.  When distributing the software, include this License Header
  113.18 + * Notice in each file and include the License file at
  113.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  113.20 + * particular file as subject to the "Classpath" exception as provided
  113.21 + * by Sun in the GPL Version 2 section of the License file that
  113.22 + * accompanied this code. If applicable, add the following below the
  113.23 + * License Header, with the fields enclosed by brackets [] replaced by
  113.24 + * your own identifying information:
  113.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  113.26 + *
  113.27 + * If you wish your version of this file to be governed by only the CDDL
  113.28 + * or only the GPL Version 2, indicate your decision by adding
  113.29 + * "[Contributor] elects to include this software in this distribution
  113.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  113.31 + * single choice of license, a recipient has the option to distribute
  113.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  113.33 + * to extend the choice of license to its licensees as provided above.
  113.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  113.35 + * Version 2 license, then the option applies only if the new code is
  113.36 + * made subject to such option by the copyright holder.
  113.37 + *
  113.38 + * Contributor(s):
  113.39 + *
  113.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
  113.41 + */
  113.42 +
  113.43 +package org.netbeans.modules.jackpot30.indexing.index;
  113.44 +
  113.45 +import java.io.ByteArrayInputStream;
  113.46 +import java.io.File;
  113.47 +import java.io.IOException;
  113.48 +import java.net.URI;
  113.49 +import java.net.URISyntaxException;
  113.50 +import java.net.URL;
  113.51 +import java.util.ArrayList;
  113.52 +import java.util.BitSet;
  113.53 +import java.util.Collection;
  113.54 +import java.util.Collections;
  113.55 +import java.util.HashMap;
  113.56 +import java.util.List;
  113.57 +import java.util.Map;
  113.58 +import java.util.zip.DataFormatException;
  113.59 +import org.apache.lucene.document.CompressionTools;
  113.60 +import org.apache.lucene.document.Document;
  113.61 +import org.apache.lucene.document.FieldSelector;
  113.62 +import org.apache.lucene.document.FieldSelectorResult;
  113.63 +import org.apache.lucene.index.IndexReader;
  113.64 +import org.apache.lucene.index.Term;
  113.65 +import org.apache.lucene.queryParser.ParseException;
  113.66 +import org.apache.lucene.search.BooleanClause;
  113.67 +import org.apache.lucene.search.BooleanQuery;
  113.68 +import org.apache.lucene.search.Collector;
  113.69 +import org.apache.lucene.search.IndexSearcher;
  113.70 +import org.apache.lucene.search.PhraseQuery;
  113.71 +import org.apache.lucene.search.Query;
  113.72 +import org.apache.lucene.search.Searcher;
  113.73 +import org.apache.lucene.search.TermQuery;
  113.74 +import org.apache.lucene.store.FSDirectory;
  113.75 +import org.codeviation.pojson.Pojson;
  113.76 +import org.netbeans.api.annotations.common.NonNull;
  113.77 +import org.netbeans.api.annotations.common.NullAllowed;
  113.78 +import org.netbeans.modules.jackpot30.common.api.LuceneHelpers.BitSetCollector;
  113.79 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
  113.80 +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
  113.81 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
  113.82 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
  113.83 +import org.netbeans.modules.java.hints.jackpot.spi.HintDescription.AdditionalQueryConstraints;
  113.84 +import org.netbeans.modules.java.source.indexing.JavaIndex;
  113.85 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
  113.86 +import org.openide.filesystems.FileObject;
  113.87 +import org.openide.filesystems.FileUtil;
  113.88 +import org.openide.util.Exceptions;
  113.89 +
  113.90 +/**
  113.91 + *
  113.92 + * @author lahvac
  113.93 + */
  113.94 +public abstract class IndexQuery {
  113.95 +
  113.96 +    public abstract Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException;
  113.97 +
  113.98 +    public abstract Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException;
  113.99 +    
 113.100 +    private static final class LocalIndexQuery extends IndexQuery {
 113.101 +        private final @NullAllowed File cacheDir;
 113.102 +
 113.103 +        public LocalIndexQuery(@NullAllowed File cacheDir) {
 113.104 +            this.cacheDir = cacheDir;
 113.105 +        }
 113.106 +
 113.107 +        public Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException {
 113.108 +            return findCandidates(pattern, false).keySet();
 113.109 +        }
 113.110 +
 113.111 +        public Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException {
 113.112 +            return findCandidates(pattern, true);
 113.113 +        }
 113.114 +
 113.115 +        private Map<String, Map<String, Integer>> findCandidates(BulkPattern pattern, boolean withFrequencies) throws IOException {
 113.116 +            IndexReader reader = cacheDir != null ? IndexReader.open(FSDirectory.open(cacheDir)) : null;
 113.117 +
 113.118 +            if (reader == null) {
 113.119 +                 return Collections.emptyMap();
 113.120 +            }
 113.121 +
 113.122 +            try {
 113.123 +            Searcher s = new IndexSearcher(reader);
 113.124 +            BitSet matchingDocuments = new BitSet(reader.maxDoc());
 113.125 +            Collector c = new BitSetCollector(matchingDocuments);
 113.126 +
 113.127 +            try {
 113.128 +                s.search(query(pattern), c);
 113.129 +            } catch (ParseException ex) {
 113.130 +                throw new IOException(ex);
 113.131 +            }
 113.132 +
 113.133 +            Map<String, Map<String, Integer>> result = new HashMap<String, Map<String, Integer>>();
 113.134 +
 113.135 +            for (int docNum = matchingDocuments.nextSetBit(0); docNum >= 0; docNum = matchingDocuments.nextSetBit(docNum+1)) {
 113.136 +                try {
 113.137 +                    final Document doc = reader.document(docNum, new FieldSelector() {
 113.138 +                        public FieldSelectorResult accept(String string) {
 113.139 +                            return "encoded".equals(string) || "path".equals(string) ? FieldSelectorResult.LOAD : FieldSelectorResult.NO_LOAD;
 113.140 +                        }
 113.141 +                    });
 113.142 +
 113.143 +                    ByteArrayInputStream in = new ByteArrayInputStream(CompressionTools.decompress(doc.getField("encoded").getBinaryValue()));
 113.144 +
 113.145 +                    try {
 113.146 +                        Map<String, Integer> freqs;
 113.147 +                        boolean matches;
 113.148 +
 113.149 +                        if (withFrequencies) {
 113.150 +                            freqs = BulkSearch.getDefault().matchesWithFrequencies(in, pattern);
 113.151 +                            matches = !freqs.isEmpty();
 113.152 +                        } else {
 113.153 +                            freqs = null;
 113.154 +                            matches = BulkSearch.getDefault().matches(in, pattern);
 113.155 +                        }
 113.156 +
 113.157 +                        if (matches) {
 113.158 +                            result.put(doc.getField("path").stringValue(), freqs);
 113.159 +                            continue;
 113.160 +                        }
 113.161 +                    } finally {
 113.162 +                        in.close();
 113.163 +                    }
 113.164 +                } catch (DataFormatException ex) {
 113.165 +                    throw new IOException(ex);
 113.166 +                }
 113.167 +            }
 113.168 +
 113.169 +            return result;
 113.170 +            } finally {
 113.171 +                reader.close();
 113.172 +            }
 113.173 +        }
 113.174 +
 113.175 +        private Query query(BulkPattern pattern) throws ParseException {
 113.176 +            BooleanQuery result = new BooleanQuery();
 113.177 +
 113.178 +            for (int cntr = 0; cntr < pattern.getIdentifiers().size(); cntr++) {
 113.179 +                assert !pattern.getRequiredContent().get(cntr).isEmpty();
 113.180 +
 113.181 +                BooleanQuery emb = new BooleanQuery();
 113.182 +
 113.183 +                for (List<String> c : pattern.getRequiredContent().get(cntr)) {
 113.184 +                    if (c.isEmpty()) continue;
 113.185 +
 113.186 +                    PhraseQuery pq = new PhraseQuery();
 113.187 +
 113.188 +                    for (String s : c) {
 113.189 +                        pq.add(new Term("content", s));
 113.190 +                    }
 113.191 +
 113.192 +                    emb.add(pq, BooleanClause.Occur.MUST);
 113.193 +                }
 113.194 +
 113.195 +                AdditionalQueryConstraints additionalConstraints = pattern.getAdditionalConstraints().get(cntr);
 113.196 +
 113.197 +                if (additionalConstraints != null && !additionalConstraints.requiredErasedTypes.isEmpty()) {
 113.198 +                    BooleanQuery constraintsQuery = new BooleanQuery();
 113.199 +
 113.200 +                    constraintsQuery.add(new TermQuery(new Term("attributed", "false")), BooleanClause.Occur.SHOULD);
 113.201 +
 113.202 +                    BooleanQuery constr = new BooleanQuery();
 113.203 +
 113.204 +                    for (String tc : additionalConstraints.requiredErasedTypes) {
 113.205 +                        constr.add(new TermQuery(new Term("erasedTypes", tc)), BooleanClause.Occur.MUST);
 113.206 +                    }
 113.207 +
 113.208 +                    constraintsQuery.add(constr, BooleanClause.Occur.SHOULD);
 113.209 +                    emb.add(constraintsQuery, BooleanClause.Occur.MUST);
 113.210 +                }
 113.211 +
 113.212 +                result.add(emb, BooleanClause.Occur.SHOULD);
 113.213 +            }
 113.214 +
 113.215 +            return result;
 113.216 +        }
 113.217 +    }
 113.218 +    
 113.219 +    private static final class RemoteIndexQuery extends IndexQuery {
 113.220 +        private final RemoteIndex idx;
 113.221 +
 113.222 +        public RemoteIndexQuery(RemoteIndex idx) {
 113.223 +            this.idx = idx;
 113.224 +        }
 113.225 +        
 113.226 +        @Override
 113.227 +        public Collection<? extends String> findCandidates(BulkPattern pattern) throws IOException {
 113.228 +            try {
 113.229 +                StringBuilder patterns = new StringBuilder();
 113.230 +
 113.231 +                for (String p : pattern.getPatterns()) {
 113.232 +                    patterns.append(p);
 113.233 +                    patterns.append(";;");
 113.234 +                }
 113.235 +
 113.236 +                URI u = new URI(idx.remote.toExternalForm() + "?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&pattern=" + WebUtilities.escapeForQuery(patterns.toString()));
 113.237 +
 113.238 +                return new ArrayList<String>(WebUtilities.requestStringArrayResponse(u));
 113.239 +            } catch (URISyntaxException ex) {
 113.240 +                //XXX: better handling?
 113.241 +                Exceptions.printStackTrace(ex);
 113.242 +                return Collections.emptyList();
 113.243 +            }
 113.244 +        }
 113.245 +        @Override
 113.246 +        public Map<String, Map<String, Integer>> findCandidatesWithFrequencies(BulkPattern pattern) throws IOException {
 113.247 +            throw new UnsupportedOperationException("Not supported yet.");
 113.248 +        }
 113.249 +    }
 113.250 +    
 113.251 +    public static IndexQuery open(URL sourceRoot) throws IOException {
 113.252 +        FileObject dataFolder = CacheFolder.getDataFolder(sourceRoot);
 113.253 +        FileObject cacheFO  = dataFolder.getFileObject(JavaIndex.NAME + "/" + JavaIndex.VERSION + "/" + Indexer.INDEX_NAME);
 113.254 +        File cache = cacheFO != null ? FileUtil.toFile(cacheFO) : null;
 113.255 +        
 113.256 +        return new LocalIndexQuery(cache);
 113.257 +    }
 113.258 +
 113.259 +    public static IndexQuery remote(RemoteIndex idx) {
 113.260 +        return new RemoteIndexQuery(idx);
 113.261 +    }
 113.262 +}
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/language/ide/indexing/src/org/netbeans/modules/jackpot30/indexing/index/Indexer.java	Sat Feb 11 18:35:10 2012 +0100
   114.3 @@ -0,0 +1,231 @@
   114.4 +/*
   114.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   114.6 + *
   114.7 + * Copyright 2009-2012 Sun Microsystems, Inc. All rights reserved.
   114.8 + *
   114.9 + * The contents of this file are subject to the terms of either the GNU
  114.10 + * General Public License Version 2 only ("GPL") or the Common
  114.11 + * Development and Distribution License("CDDL") (collectively, the
  114.12 + * "License"). You may not use this file except in compliance with the
  114.13 + * License. You can obtain a copy of the License at
  114.14 + * http://www.netbeans.org/cddl-gplv2.html
  114.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  114.16 + * specific language governing permissions and limitations under the
  114.17 + * License.  When distributing the software, include this License Header
  114.18 + * Notice in each file and include the License file at
  114.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  114.20 + * particular file as subject to the "Classpath" exception as provided
  114.21 + * by Sun in the GPL Version 2 section of the License file that
  114.22 + * accompanied this code. If applicable, add the following below the
  114.23 + * License Header, with the fields enclosed by brackets [] replaced by
  114.24 + * your own identifying information:
  114.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  114.26 + *
  114.27 + * If you wish your version of this file to be governed by only the CDDL
  114.28 + * or only the GPL Version 2, indicate your decision by adding
  114.29 + * "[Contributor] elects to include this software in this distribution
  114.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  114.31 + * single choice of license, a recipient has the option to distribute
  114.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  114.33 + * to extend the choice of license to its licensees as provided above.
  114.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  114.35 + * Version 2 license, then the option applies only if the new code is
  114.36 + * made subject to such option by the copyright holder.
  114.37 + *
  114.38 + * Contributor(s):
  114.39 + *
  114.40 + * Portions Copyrighted 2009-2012 Sun Microsystems, Inc.
  114.41 + */
  114.42 +
  114.43 +package org.netbeans.modules.jackpot30.indexing.index;
  114.44 +
  114.45 +import org.netbeans.modules.jackpot30.common.api.IndexAccess;
  114.46 +import com.sun.source.tree.CompilationUnitTree;
  114.47 +import com.sun.source.tree.Tree;
  114.48 +import com.sun.source.util.TreePath;
  114.49 +import com.sun.source.util.TreePathScanner;
  114.50 +import com.sun.source.util.Trees;
  114.51 +import java.io.ByteArrayOutputStream;
  114.52 +import java.io.IOException;
  114.53 +import java.net.URL;
  114.54 +import java.util.Collections;
  114.55 +import java.util.HashSet;
  114.56 +import java.util.Iterator;
  114.57 +import java.util.Set;
  114.58 +import java.util.logging.Level;
  114.59 +import java.util.logging.Logger;
  114.60 +import javax.lang.model.type.ArrayType;
  114.61 +import javax.lang.model.type.TypeKind;
  114.62 +import javax.lang.model.type.TypeMirror;
  114.63 +import javax.lang.model.util.Types;
  114.64 +import org.apache.lucene.analysis.TokenStream;
  114.65 +import org.apache.lucene.analysis.tokenattributes.TermAttribute;
  114.66 +import org.apache.lucene.document.CompressionTools;
  114.67 +import org.apache.lucene.document.Document;
  114.68 +import org.apache.lucene.document.Field;
  114.69 +import org.apache.lucene.index.CorruptIndexException;
  114.70 +import org.apache.lucene.index.IndexWriter;
  114.71 +import org.apache.lucene.index.Term;
  114.72 +import org.netbeans.api.annotations.common.NonNull;
  114.73 +import org.netbeans.api.editor.mimelookup.MimeRegistration;
  114.74 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
  114.75 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
  114.76 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaIndexerPlugin;
  114.77 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
  114.78 +import org.openide.filesystems.FileObject;
  114.79 +import org.openide.util.Exceptions;
  114.80 +import org.openide.util.Lookup;
  114.81 +
  114.82 +/**
  114.83 + *
  114.84 + * @author lahvac
  114.85 + */
  114.86 +public final class Indexer implements JavaIndexerPlugin {
  114.87 +
  114.88 +    public static final String INDEX_NAME = "jackpot30";
  114.89 +    private final @NonNull URL root;
  114.90 +    private final @NonNull FileObject cacheRoot;
  114.91 +    private final @NonNull IndexAccess access;
  114.92 +
  114.93 +    private  Indexer(URL root, FileObject cacheRoot) {
  114.94 +        this.root = root;
  114.95 +        this.cacheRoot = cacheRoot;
  114.96 +        this.access = Lookup.getDefault().lookup(IndexAccess.class);
  114.97 +    }
  114.98 +    
  114.99 +    @Override
 114.100 +    public void process (@NonNull CompilationUnitTree toProcess, @NonNull Indexable indexable, @NonNull Lookup services) {
 114.101 +        IndexWriter luceneWriter = access.getIndexWriter(root, cacheRoot, INDEX_NAME);
 114.102 +        String relative = access.getRelativePath(indexable);
 114.103 +        ByteArrayOutputStream out = null;
 114.104 +        EncodingContext ec;
 114.105 +
 114.106 +        try {
 114.107 +            out = new ByteArrayOutputStream();
 114.108 +
 114.109 +            ec = new EncodingContext(out, false);
 114.110 +
 114.111 +            BulkSearch.getDefault().encode(toProcess, ec);
 114.112 +
 114.113 +            luceneWriter.deleteDocuments(new Term("path", relative));
 114.114 +
 114.115 +            Document doc = new Document();
 114.116 +
 114.117 +            doc.add(new Field("content", new TokenStreamImpl(ec.getContent())));
 114.118 +            out.close();
 114.119 +            doc.add(new Field("encoded", CompressionTools.compress(out.toByteArray()), Field.Store.YES));
 114.120 +            doc.add(new Field("path", relative, Field.Store.YES, Field.Index.NOT_ANALYZED));
 114.121 +
 114.122 +            if (services != null) {
 114.123 +                final Set<String> erased = new HashSet<String>();
 114.124 +                final Trees trees = services.lookup(Trees.class);
 114.125 +                final Types types = services.lookup(Types.class);
 114.126 +
 114.127 +                new TreePathScanner<Void, Void>() {
 114.128 +                    @Override
 114.129 +                    public Void scan(Tree tree, Void p) {
 114.130 +                        if (tree != null) {
 114.131 +                            TreePath tp = new TreePath(getCurrentPath(), tree);
 114.132 +                            TypeMirror type = trees.getTypeMirror(tp);
 114.133 +
 114.134 +                            if (type != null) {
 114.135 +                                if (type.getKind() == TypeKind.ARRAY) {
 114.136 +                                    erased.add(types.erasure(type).toString());
 114.137 +                                    type = ((ArrayType) type).getComponentType();
 114.138 +                                }
 114.139 +
 114.140 +                                if (type.getKind().isPrimitive() || type.getKind() == TypeKind.DECLARED) {
 114.141 +                                    addErasedTypeAndSuperTypes(types, erased, type);
 114.142 +                                }
 114.143 +                            }
 114.144 +
 114.145 +                            //bounds for type variables!!!
 114.146 +                        }
 114.147 +                        return super.scan(tree, p);
 114.148 +                    }
 114.149 +                }.scan(toProcess, null);
 114.150 +
 114.151 +                doc.add(new Field("erasedTypes", new TokenStreamImpl(erased)));
 114.152 +            }
 114.153 +            
 114.154 +            luceneWriter.addDocument(doc);
 114.155 +        } catch (ThreadDeath td) {
 114.156 +            throw td;
 114.157 +        } catch (Throwable t) {
 114.158 +            Logger.getLogger(Indexer.class.getName()).log(Level.WARNING, null, t);
 114.159 +        } finally {
 114.160 +            if (out != null) {
 114.161 +                try {
 114.162 +                    out.close();
 114.163 +                } catch (IOException ex) {
 114.164 +                    Exceptions.printStackTrace(ex);
 114.165 +                }
 114.166 +            }
 114.167 +        }
 114.168 +    }
 114.169 +
 114.170 +
 114.171 +    @Override
 114.172 +    public void delete (@NonNull Indexable indexable) {
 114.173 +        IndexWriter luceneWriter = access.getIndexWriter(root, cacheRoot, INDEX_NAME);
 114.174 +        String relative = access.getRelativePath(indexable);
 114.175 +        
 114.176 +        try {
 114.177 +            luceneWriter.deleteDocuments(new Term("path", relative));
 114.178 +        } catch (CorruptIndexException ex) {
 114.179 +            Logger.getLogger(Indexer.class.getName()).log(Level.WARNING, null, ex);
 114.180 +        } catch (IOException ex) {
 114.181 +            Logger.getLogger(Indexer.class.getName()).log(Level.WARNING, null, ex);
 114.182 +        }
 114.183 +    }
 114.184 +
 114.185 +    @Override
 114.186 +    public void finish () {
 114.187 +        access.finish();
 114.188 +    }
 114.189 +
 114.190 +    private static void addErasedTypeAndSuperTypes(Types javacTypes, Set<String> types, TypeMirror type) {
 114.191 +        if (type.getKind() == TypeKind.DECLARED) {
 114.192 +            if (types.add(javacTypes.erasure(type).toString())) {
 114.193 +                for (TypeMirror sup : javacTypes.directSupertypes(type)) {
 114.194 +                    addErasedTypeAndSuperTypes(javacTypes, types, sup);
 114.195 +                }
 114.196 +            }
 114.197 +        } else if (type.getKind().isPrimitive()) {
 114.198 +            types.add(type.toString());
 114.199 +        }
 114.200 +    }
 114.201 +
 114.202 +    public static final class TokenStreamImpl extends TokenStream {
 114.203 +
 114.204 +        private final Iterator<? extends String> tokens;
 114.205 +        private final TermAttribute termAtt;
 114.206 +
 114.207 +        public TokenStreamImpl(Iterable<? extends String> tokens) {
 114.208 +            this.tokens = tokens != null ? tokens.iterator() : /*???*/Collections.<String>emptyList().iterator();
 114.209 +            this.termAtt = addAttribute(TermAttribute.class);
 114.210 +        }
 114.211 +
 114.212 +        @Override
 114.213 +        public boolean incrementToken() throws IOException {
 114.214 +            if (!tokens.hasNext())
 114.215 +                return false;
 114.216 +
 114.217 +            String t = tokens.next();
 114.218 +
 114.219 +            termAtt.setTermBuffer(t);
 114.220 +            
 114.221 +            return true;
 114.222 +        }
 114.223 +    }
 114.224 +
 114.225 +    @MimeRegistration(mimeType="text/x-java", service=Factory.class)
 114.226 +    public static final class FactoryImpl implements Factory {
 114.227 +
 114.228 +        @Override
 114.229 +        public JavaIndexerPlugin create(URL root, FileObject cacheFolder) {
 114.230 +            return new Indexer(root, cacheFolder);
 114.231 +        }
 114.232 +        
 114.233 +    }
 114.234 +}
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/language/ide/indexing/test/unit/src/org/netbeans/modules/jackpot30/indexing/index/IndexerTest.java	Sat Feb 11 18:35:10 2012 +0100
   115.3 @@ -0,0 +1,302 @@
   115.4 +/*
   115.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   115.6 + *
   115.7 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
   115.8 + *
   115.9 + * The contents of this file are subject to the terms of either the GNU
  115.10 + * General Public License Version 2 only ("GPL") or the Common
  115.11 + * Development and Distribution License("CDDL") (collectively, the
  115.12 + * "License"). You may not use this file except in compliance with the
  115.13 + * License. You can obtain a copy of the License at
  115.14 + * http://www.netbeans.org/cddl-gplv2.html
  115.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  115.16 + * specific language governing permissions and limitations under the
  115.17 + * License.  When distributing the software, include this License Header
  115.18 + * Notice in each file and include the License file at
  115.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  115.20 + * particular file as subject to the "Classpath" exception as provided
  115.21 + * by Sun in the GPL Version 2 section of the License file that
  115.22 + * accompanied this code. If applicable, add the following below the
  115.23 + * License Header, with the fields enclosed by brackets [] replaced by
  115.24 + * your own identifying information:
  115.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  115.26 + *
  115.27 + * If you wish your version of this file to be governed by only the CDDL
  115.28 + * or only the GPL Version 2, indicate your decision by adding
  115.29 + * "[Contributor] elects to include this software in this distribution
  115.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  115.31 + * single choice of license, a recipient has the option to distribute
  115.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  115.33 + * to extend the choice of license to its licensees as provided above.
  115.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  115.35 + * Version 2 license, then the option applies only if the new code is
  115.36 + * made subject to such option by the copyright holder.
  115.37 + *
  115.38 + * Contributor(s):
  115.39 + *
  115.40 + * Portions Copyrighted 2009 Sun Microsystems, Inc.
  115.41 + */
  115.42 +
  115.43 +package org.netbeans.modules.jackpot30.indexing.index;
  115.44 +
  115.45 +import java.net.URL;
  115.46 +import java.util.Arrays;
  115.47 +import java.util.Collections;
  115.48 +import java.util.HashMap;
  115.49 +import java.util.HashSet;
  115.50 +import java.util.Map;
  115.51 +import java.util.Set;
  115.52 +import org.netbeans.api.editor.mimelookup.MimePath;
  115.53 +import org.netbeans.api.java.classpath.ClassPath;
  115.54 +import org.netbeans.api.java.source.ClasspathInfo;
  115.55 +import org.netbeans.api.java.source.CompilationController;
  115.56 +import org.netbeans.api.java.source.JavaSource;
  115.57 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
  115.58 +import org.netbeans.api.java.source.Task;
  115.59 +import org.netbeans.api.java.source.TestUtilities;
  115.60 +import org.netbeans.modules.jackpot30.common.test.IndexTestBase;
  115.61 +import org.netbeans.modules.java.hints.jackpot.impl.Utilities;
  115.62 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
  115.63 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
  115.64 +import org.netbeans.modules.java.hints.jackpot.spi.HintDescription.AdditionalQueryConstraints;
  115.65 +import org.netbeans.modules.parsing.api.indexing.IndexingManager;
  115.66 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
  115.67 +import org.netbeans.spi.java.classpath.support.ClassPathSupport;
  115.68 +import org.openide.filesystems.FileObject;
  115.69 +import org.openide.filesystems.FileUtil;
  115.70 +import org.openide.util.Lookup;
  115.71 +import org.openide.util.lookup.Lookups;
  115.72 +import org.openide.util.lookup.ServiceProvider;
  115.73 +
  115.74 +
  115.75 +/**
  115.76 + *
  115.77 + * @author lahvac
  115.78 + */
  115.79 +public class IndexerTest extends IndexTestBase {
  115.80 +
  115.81 +    public IndexerTest(String name) {
  115.82 +        super(name);
  115.83 +    }
  115.84 +
  115.85 +    public void testMultiplePatternsIndexing() throws Exception {
  115.86 +        writeFilesAndWaitForScan(src,
  115.87 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
  115.88 +                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
  115.89 +
  115.90 +        String[] patterns = new String[] {
  115.91 +            "$1.isDirectory()",
  115.92 +            "new ImageIcon($1)"
  115.93 +        };
  115.94 +
  115.95 +        verifyIndex(patterns, "test/Test1.java", "test/Test2.java");
  115.96 +    }
  115.97 +
  115.98 +    public void testLambdaPattern() throws Exception {
  115.99 +        writeFilesAndWaitForScan(src,
 115.100 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { Runnable r = new Runnable() { public void run() { System.err.println(); } } } }"));
 115.101 +
 115.102 +        String[] patterns = new String[] {
 115.103 +            "new $type() {\n $mods$ $resultType $methodName($args$) {\n $statements$;\n }\n }\n",
 115.104 +        };
 115.105 +
 115.106 +        verifyIndex(patterns, "test/Test1.java");
 115.107 +    }
 115.108 +
 115.109 +    public void testUpdates() throws Exception {
 115.110 +        String[] patterns = new String[] {
 115.111 +            "$1.isDirectory()",
 115.112 +            "new ImageIcon($1)"
 115.113 +        };
 115.114 +
 115.115 +        writeFilesAndWaitForScan(src,
 115.116 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
 115.117 +                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
 115.118 +
 115.119 +        verifyIndex(patterns, "test/Test1.java", "test/Test2.java");
 115.120 +//        assertEquals(2, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
 115.121 +
 115.122 +        src.getFileObject("test/Test1.java").delete();
 115.123 +
 115.124 +        assertNull(src.getFileObject("test/Test1.java"));
 115.125 +
 115.126 +        IndexingManager.getDefault().refreshIndexAndWait(src.toURL(), null, true);
 115.127 +
 115.128 +        verifyIndex(patterns, "test/Test2.java");
 115.129 +//        assertEquals(1, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
 115.130 +
 115.131 +        FileObject test3 = FileUtil.createData(src, "test/Test3.java");
 115.132 +        TestUtilities.copyStringToFile(test3, "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }");
 115.133 +
 115.134 +        IndexingManager.getDefault().refreshIndexAndWait(src.toURL(), null, true);
 115.135 +
 115.136 +        verifyIndex(patterns, "test/Test2.java", "test/Test3.java");
 115.137 +//        assertEquals(2, FileBasedIndex.get(src.getURL()).getIndexInfo().totalFiles);
 115.138 +    }
 115.139 +
 115.140 +    public void testPartiallyAttributed1() throws Exception {
 115.141 +        writeFilesAndWaitForScan(src,
 115.142 +                   new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
 115.143 +                   new File("test/Test2.java", "package test; public class Test2 { private void isDirectory() { this.isDirectory(); } }"),
 115.144 +                   new File("test/Test3.java", "package test; public class Test3 { private void isDirectory() { this.isDirectory(); } }"));
 115.145 +
 115.146 +        verifyIndex("$1.isDirectory()", new AdditionalQueryConstraints(Collections.singleton("java.io.File")), "test/Test1.java");
 115.147 +    }
 115.148 +
 115.149 +    public void testPartiallyAttributed2() throws Exception {
 115.150 +        writeFilesAndWaitForScan(src,
 115.151 +                   new File("test/Test1.java", "package test; public class Test1 { private void test() { String str = null; int l = str.length(); } }"));
 115.152 +
 115.153 +        verifyIndex("$1.length()", new AdditionalQueryConstraints(Collections.singleton("java.lang.CharSequence")), "test/Test1.java");
 115.154 +    }
 115.155 +
 115.156 +    public void testFrequencies() throws Exception {
 115.157 +        writeFilesAndWaitForScan(src,
 115.158 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); f.isDirectory(); } }"),
 115.159 +                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); java.io.File f = null; f.isDirectory(); } }"),
 115.160 +                                 new File("test/Test3.java", "package test; public class Test3 { private void test() { new javax.swing.ImageIcon(null); new javax.swing.ImageIcon(null); } }")
 115.161 +                                );
 115.162 +
 115.163 +        String[] patterns = new String[] {
 115.164 +            "$1.isDirectory()",
 115.165 +            "new ImageIcon($1)"
 115.166 +        };
 115.167 +
 115.168 +        Map<String, Map<String, Integer>> golden = new HashMap<String, Map<String, Integer>>();
 115.169 +        
 115.170 +        golden.put("test/Test3.java", Collections.singletonMap("new ImageIcon($1)", 2));
 115.171 +        golden.put("test/Test1.java", Collections.singletonMap("$1.isDirectory()", 2));
 115.172 +        
 115.173 +        Map<String, Integer> freqsTest2 = new HashMap<String, Integer>();
 115.174 +        
 115.175 +        freqsTest2.put("$1.isDirectory()", 1);
 115.176 +        freqsTest2.put("new ImageIcon($1)", 1);
 115.177 +        
 115.178 +        golden.put("test/Test2.java", freqsTest2);
 115.179 +        
 115.180 +        verifyIndexWithFrequencies(patterns, golden);
 115.181 +    }
 115.182 +
 115.183 +    public void testInnerClass() throws Exception {
 115.184 +        writeFilesAndWaitForScan(src,
 115.185 +                                 new File("test/Test1.java", "package test; public class Test1 { private static final class O implements Iterable<String> { private String next; private String computeNext() { return null; } public String hasNext() { next = computeNext(); return next != null; } } }"));
 115.186 +
 115.187 +        verifyIndex("$this.computeNext()", new AdditionalQueryConstraints(Collections.singleton("test.Test1.O")), "test/Test1.java");
 115.188 +    }
 115.189 +
 115.190 +    public void testIndexing() throws Exception {
 115.191 +        writeFilesAndWaitForScan(src,
 115.192 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); } }"),
 115.193 +                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
 115.194 +
 115.195 +        verifyIndex("$1.isDirectory()", "test/Test1.java");
 115.196 +        verifyIndex("new ImageIcon($1)", "test/Test2.java");
 115.197 +        
 115.198 +        writeFilesAndWaitForScan(src,
 115.199 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); new javax.swing.ImageIcon(null); } }"),
 115.200 +                                 new File("test/Test2.java", "package test; public class Test2 { private void test() { new javax.swing.ImageIcon(null); } }"));
 115.201 +
 115.202 +        verifyIndex("$1.isDirectory()", "test/Test1.java");
 115.203 +        verifyIndex("new ImageIcon($1)", "test/Test1.java", "test/Test2.java");
 115.204 +        
 115.205 +        writeFilesAndWaitForScan(src,
 115.206 +                                 new File("test/Test1.java", "package test; public class Test1 { private void test() { java.io.File f = null; f.isDirectory(); new javax.swing.ImageIcon(null); } }"),
 115.207 +                                 new File("test/Test2.java", "package test; public class Test2 { }"));
 115.208 +
 115.209 +        verifyIndex("$1.isDirectory()", "test/Test1.java");
 115.210 +        verifyIndex("new ImageIcon($1)", "test/Test1.java");
 115.211 +    }
 115.212 +    
 115.213 +    private void verifyIndex(final String[] patterns, String... containedIn) throws Exception {
 115.214 +        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
 115.215 +        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
 115.216 +                                                    EMPTY,
 115.217 +                                                    EMPTY);
 115.218 +
 115.219 +        final Set<String> real = new HashSet<String>();
 115.220 +        
 115.221 +        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
 115.222 +            public void run(CompilationController parameter) throws Exception {
 115.223 +                real.addAll(IndexQuery.open(src.toURL()).findCandidates(BulkSearch.getDefault().create(parameter, patterns)));
 115.224 +            }
 115.225 +        }, true);
 115.226 +
 115.227 +        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
 115.228 +
 115.229 +        assertEquals(golden, real);
 115.230 +    }
 115.231 +
 115.232 +    private void verifyIndex(final String pattern, final AdditionalQueryConstraints additionalConstraints, String... containedIn) throws Exception {
 115.233 +        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
 115.234 +        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
 115.235 +                                                    EMPTY,
 115.236 +                                                    EMPTY);
 115.237 +
 115.238 +        final Set<String> real = new HashSet<String>();
 115.239 +
 115.240 +        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
 115.241 +            public void run(CompilationController parameter) throws Exception {
 115.242 +                BulkPattern bulkPattern = BulkSearch.getDefault().create(Collections.singletonList(pattern),
 115.243 +                                                                          Collections.singletonList(Utilities.parseAndAttribute(parameter, pattern, null)),
 115.244 +                                                                          Collections.singletonList(additionalConstraints));
 115.245 +                
 115.246 +                real.addAll(IndexQuery.open(src.toURL()).findCandidates(bulkPattern));
 115.247 +            }
 115.248 +        }, true);
 115.249 +
 115.250 +        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
 115.251 +
 115.252 +        assertEquals(golden, real);
 115.253 +    }
 115.254 +
 115.255 +    private void verifyIndexWithFrequencies(final String[] patterns, Map<String, Map<String, Integer>> golden) throws Exception {
 115.256 +        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
 115.257 +        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
 115.258 +                                                    EMPTY,
 115.259 +                                                    EMPTY);
 115.260 +
 115.261 +        final Map<String, Map<String, Integer>> real = new HashMap<String, Map<String, Integer>>();
 115.262 +
 115.263 +        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
 115.264 +            public void run(CompilationController parameter) throws Exception {
 115.265 +                real.putAll(IndexQuery.open(src.toURL()).findCandidatesWithFrequencies(BulkSearch.getDefault().create(parameter, patterns)));
 115.266 +            }
 115.267 +        }, true);
 115.268 +
 115.269 +        assertEquals(golden, real);
 115.270 +    }
 115.271 +
 115.272 +    private void verifyIndex(final String pattern, String... containedIn) throws Exception {
 115.273 +        ClassPath EMPTY = ClassPathSupport.createClassPath(new FileObject[0]);
 115.274 +        ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])),
 115.275 +                                                    EMPTY,
 115.276 +                                                    EMPTY);
 115.277 +
 115.278 +        final Set<String> real = new HashSet<String>();
 115.279 +        
 115.280 +        JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
 115.281 +            public void run(CompilationController parameter) throws Exception {
 115.282 +                real.addAll(IndexQuery.open(src.toURL()).findCandidates(BulkSearch.getDefault().create(parameter, pattern)));
 115.283 +            }
 115.284 +        }, true);
 115.285 +
 115.286 +        Set<String> golden = new HashSet<String>(Arrays.asList(containedIn));
 115.287 +
 115.288 +        assertEquals(golden, real);
 115.289 +    }
 115.290 +    
 115.291 +    @ServiceProvider(service=MimeDataProvider.class)
 115.292 +    public static final class MimeDataProviderImpl implements MimeDataProvider {
 115.293 +
 115.294 +        private static final Lookup L = Lookups.fixed(new Indexer.FactoryImpl());
 115.295 +        
 115.296 +        @Override
 115.297 +        public Lookup getLookup(MimePath mp) {
 115.298 +            if ("text/x-java".equals(mp.getPath())) {
 115.299 +                return L;
 115.300 +            }
 115.301 +            return Lookup.EMPTY;
 115.302 +        }
 115.303 +        
 115.304 +    }
 115.305 +}
 115.306 \ No newline at end of file
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/language/ide/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   116.3 @@ -0,0 +1,50 @@
   116.4 +<?xml version="1.0" encoding="UTF-8"?>
   116.5 +<!--
   116.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   116.7 +***         EDIT ../build.xml INSTEAD         ***
   116.8 +-->
   116.9 +<project name="language-ide-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
  116.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  116.11 +        <condition>
  116.12 +            <not>
  116.13 +                <antversion atleast="1.7.1"/>
  116.14 +            </not>
  116.15 +        </condition>
  116.16 +    </fail>
  116.17 +    <property file="nbproject/private/platform-private.properties"/>
  116.18 +    <property file="nbproject/platform.properties"/>
  116.19 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
  116.20 +        <attribute name="name"/>
  116.21 +        <attribute name="value"/>
  116.22 +        <sequential>
  116.23 +            <property name="@{name}" value="${@{value}}"/>
  116.24 +        </sequential>
  116.25 +    </macrodef>
  116.26 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
  116.27 +        <attribute name="property"/>
  116.28 +        <attribute name="value"/>
  116.29 +        <sequential>
  116.30 +            <property name="@{property}" value="@{value}"/>
  116.31 +        </sequential>
  116.32 +    </macrodef>
  116.33 +    <property file="${user.properties.file}"/>
  116.34 +    <sproject:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir"/>
  116.35 +    <sproject:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir"/>
  116.36 +    <sproject:evalprops property="cluster.path.evaluated" value="${cluster.path}"/>
  116.37 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  116.38 +        <condition>
  116.39 +            <not>
  116.40 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  116.41 +            </not>
  116.42 +        </condition>
  116.43 +    </fail>
  116.44 +    <ant antfile="nbproject/platform.xml"/>
  116.45 +    <fail message="Cannot find NetBeans build harness. ${line.separator}Check that nbplatform.${nbplatform.active}.netbeans.dest.dir and nbplatform.${nbplatform.active}.harness.dir are defined. ${line.separator}On a developer machine these are normally defined in ${user.properties.file}=${netbeans.user}/build.properties ${line.separator}but for automated builds you should pass these properties to Ant explicitly. ${line.separator}You may instead download the harness and platform: -Dbootstrap.url=.../tasks.jar -Dautoupdate.catalog.url=.../updates.xml">
  116.46 +        <condition>
  116.47 +            <not>
  116.48 +                <available file="${harness.dir}/suite.xml"/>
  116.49 +            </not>
  116.50 +        </condition>
  116.51 +    </fail>
  116.52 +    <import file="${harness.dir}/suite.xml"/>
  116.53 +</project>
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/language/ide/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   117.3 @@ -0,0 +1,11 @@
   117.4 +build.xml.data.CRC32=d27fe1de
   117.5 +build.xml.script.CRC32=466d9285
   117.6 +build.xml.stylesheet.CRC32=eaf9f76a@2.49
   117.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   117.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   117.9 +nbproject/build-impl.xml.data.CRC32=c11ee7c3
  117.10 +nbproject/build-impl.xml.script.CRC32=74ef45bc
  117.11 +nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.49
  117.12 +nbproject/platform.xml.data.CRC32=c11ee7c3
  117.13 +nbproject/platform.xml.script.CRC32=db9e1f43
  117.14 +nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.49
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/language/ide/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
   118.3 @@ -0,0 +1,16 @@
   118.4 +cluster.path=\
   118.5 +    ${nbplatform.active.dir}/apisupport:\
   118.6 +    ${nbplatform.active.dir}/harness:\
   118.7 +    ${nbplatform.active.dir}/ide:\
   118.8 +    ${nbplatform.active.dir}/java:\
   118.9 +    ${nbplatform.active.dir}/nb:\
  118.10 +    ${nbplatform.active.dir}/platform:\
  118.11 +    ${nbplatform.active.dir}/profiler:\
  118.12 +    ${nbplatform.active.dir}/websvccommon:\
  118.13 +    ../../remoting/common/build/cluster:\
  118.14 +    ../../remoting/ide/build/cluster
  118.15 +extcluster.../../remoting/ide/build/cluster.javadoc=
  118.16 +extcluster.../../remoting/ide/build/cluster.sources=../../remoting/ide
  118.17 +extcluster.../remoting/common/build/cluster.javadoc=
  118.18 +extcluster.../remoting/common/build/cluster.sources=../../remoting/common
  118.19 +nbplatform.active=default
   119.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.2 +++ b/language/ide/nbproject/platform.xml	Sat Feb 11 18:35:10 2012 +0100
   119.3 @@ -0,0 +1,34 @@
   119.4 +<?xml version="1.0" encoding="UTF-8"?>
   119.5 +<project name="platform" default="download" basedir="..">
   119.6 +    <condition property="download.required">
   119.7 +        <and>
   119.8 +            <not>
   119.9 +                <available file="${harness.dir}/suite.xml"/>
  119.10 +            </not>
  119.11 +            <isset property="bootstrap.url"/>
  119.12 +            <isset property="autoupdate.catalog.url"/>
  119.13 +        </and>
  119.14 +    </condition>
  119.15 +    <target name="download" if="download.required">
  119.16 +        <mkdir dir="${harness.dir}"/>
  119.17 +        <pathconvert pathsep="|" property="download.clusters">
  119.18 +            <mapper type="flatten"/>
  119.19 +            <path path="${cluster.path}"/>
  119.20 +        </pathconvert>
  119.21 +        <property name="disabled.modules" value=""/>
  119.22 +        <pathconvert property="module.includes" pathsep="">
  119.23 +            <mapper type="glob" from="${basedir}${file.separator}*" to="(?!\Q*\E)"/>
  119.24 +            <path>
  119.25 +                <filelist files="${disabled.modules}" dir="."/>
  119.26 +            </path>
  119.27 +        </pathconvert>
  119.28 +        <echo message="Downloading clusters ${download.clusters}"/>
  119.29 +        <property name="tasks.jar" location="${java.io.tmpdir}/tasks.jar"/>
  119.30 +        <get src="${bootstrap.url}" dest="${tasks.jar}" usetimestamp="true" verbose="true"/>
  119.31 +        <taskdef name="autoupdate" classname="org.netbeans.nbbuild.AutoUpdate" classpath="${tasks.jar}"/>
  119.32 +        <autoupdate installdir="${nbplatform.active.dir}" updatecenter="${autoupdate.catalog.url}">
  119.33 +            <modules includes="${module.includes}.*" clusters="${download.clusters}"/>
  119.34 +            <modules includes="org[.]netbeans[.]modules[.]apisupport[.]harness" clusters="harness"/>
  119.35 +        </autoupdate>
  119.36 +    </target>
  119.37 +</project>
   120.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.2 +++ b/language/ide/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   120.3 @@ -0,0 +1,3 @@
   120.4 +modules=\
   120.5 +    ${project.org.netbeans.modules.jackpot30.indexing}
   120.6 +project.org.netbeans.modules.jackpot30.indexing=indexing
   121.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.2 +++ b/language/ide/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   121.3 @@ -0,0 +1,9 @@
   121.4 +<?xml version="1.0" encoding="UTF-8"?>
   121.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   121.6 +    <type>org.netbeans.modules.apisupport.project.suite</type>
   121.7 +    <configuration>
   121.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-suite-project/1">
   121.9 +            <name>language-ide</name>
  121.10 +        </data>
  121.11 +    </configuration>
  121.12 +</project>
   122.1 --- a/nbproject/platform.properties	Fri Jan 27 13:35:56 2012 +0100
   122.2 +++ b/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
   122.3 @@ -1,8 +1,5 @@
   122.4  cluster.path=\
   122.5      ${nbplatform.active.dir}/apisupport:\
   122.6 -    ${nbplatform.active.dir}/cnd:\
   122.7 -    ${nbplatform.active.dir}/dlight:\
   122.8 -    ${nbplatform.active.dir}/enterprise:\
   122.9      ${nbplatform.active.dir}/harness:\
  122.10      ${nbplatform.active.dir}/ide:\
  122.11      ${nbplatform.active.dir}/java:\
  122.12 @@ -10,8 +7,10 @@
  122.13      ${nbplatform.active.dir}/platform:\
  122.14      ${nbplatform.active.dir}/profiler:\
  122.15      ${nbplatform.active.dir}/websvccommon:\
  122.16 -    borrowedtests/build/cluster:\
  122.17 -    remoting/ide/build/cluster
  122.18 +    remoting/ide/build/cluster:\
  122.19 +    remoting/common/build/cluster
  122.20 +extcluster.remoting/common/build/cluster.javadoc=
  122.21 +extcluster.remoting/common/build/cluster.sources=remoting/common
  122.22  extcluster.remoting/ide/build/cluster.javadoc=
  122.23 -extcluster.remoting/ide/build/cluster.sources=/usr/local/home/lahvac/tmp/jackpot/remoting/ide
  122.24 +extcluster.remoting/ide/build/cluster.sources=remoting/ide
  122.25  nbplatform.active=default
   123.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.2 +++ b/remoting/common/api/build.xml	Sat Feb 11 18:35:10 2012 +0100
   123.3 @@ -0,0 +1,8 @@
   123.4 +<?xml version="1.0" encoding="UTF-8"?>
   123.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   123.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   123.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   123.8 +<project name="org.netbeans.modules.jackpot30.common" default="netbeans" basedir=".">
   123.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.common.</description>
  123.10 +    <import file="nbproject/build-impl.xml"/>
  123.11 +</project>
   124.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.2 +++ b/remoting/common/api/manifest.mf	Sat Feb 11 18:35:10 2012 +0100
   124.3 @@ -0,0 +1,5 @@
   124.4 +Manifest-Version: 1.0
   124.5 +OpenIDE-Module: org.netbeans.modules.jackpot30.common
   124.6 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/common/Bundle.properties
   124.7 +OpenIDE-Module-Specification-Version: 1.0
   124.8 +
   125.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   125.2 +++ b/remoting/common/api/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   125.3 @@ -0,0 +1,45 @@
   125.4 +<?xml version="1.0" encoding="UTF-8"?>
   125.5 +<!--
   125.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   125.7 +***         EDIT ../build.xml INSTEAD         ***
   125.8 +-->
   125.9 +<project name="org.netbeans.modules.jackpot30.common-impl" basedir="..">
  125.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  125.11 +        <condition>
  125.12 +            <not>
  125.13 +                <antversion atleast="1.7.1"/>
  125.14 +            </not>
  125.15 +        </condition>
  125.16 +    </fail>
  125.17 +    <property file="nbproject/private/suite-private.properties"/>
  125.18 +    <property file="nbproject/suite.properties"/>
  125.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
  125.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
  125.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
  125.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
  125.23 +        <attribute name="name"/>
  125.24 +        <attribute name="value"/>
  125.25 +        <sequential>
  125.26 +            <property name="@{name}" value="${@{value}}"/>
  125.27 +        </sequential>
  125.28 +    </macrodef>
  125.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
  125.30 +        <attribute name="property"/>
  125.31 +        <attribute name="value"/>
  125.32 +        <sequential>
  125.33 +            <property name="@{property}" value="@{value}"/>
  125.34 +        </sequential>
  125.35 +    </macrodef>
  125.36 +    <property file="${user.properties.file}"/>
  125.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  125.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  125.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  125.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  125.41 +        <condition>
  125.42 +            <not>
  125.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  125.44 +            </not>
  125.45 +        </condition>
  125.46 +    </fail>
  125.47 +    <import file="${harness.dir}/build.xml"/>
  125.48 +</project>
   126.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.2 +++ b/remoting/common/api/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   126.3 @@ -0,0 +1,8 @@
   126.4 +build.xml.data.CRC32=06439b23
   126.5 +build.xml.script.CRC32=22857ef0
   126.6 +build.xml.stylesheet.CRC32=a56c6a5b@2.49
   126.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   126.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   126.9 +nbproject/build-impl.xml.data.CRC32=06439b23
  126.10 +nbproject/build-impl.xml.script.CRC32=29e163a7
  126.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
   127.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.2 +++ b/remoting/common/api/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   127.3 @@ -0,0 +1,2 @@
   127.4 +javac.source=1.6
   127.5 +javac.compilerargs=-Xlint -Xlint:-serial
   128.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   128.2 +++ b/remoting/common/api/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   128.3 @@ -0,0 +1,352 @@
   128.4 +<?xml version="1.0" encoding="UTF-8"?>
   128.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   128.6 +    <type>org.netbeans.modules.apisupport.project</type>
   128.7 +    <configuration>
   128.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
   128.9 +            <code-name-base>org.netbeans.modules.jackpot30.common</code-name-base>
  128.10 +            <suite-component/>
  128.11 +            <module-dependencies>
  128.12 +                <dependency>
  128.13 +                    <code-name-base>org.jdesktop.layout</code-name-base>
  128.14 +                    <build-prerequisite/>
  128.15 +                    <compile-dependency/>
  128.16 +                    <run-dependency>
  128.17 +                        <release-version>1</release-version>
  128.18 +                        <specification-version>1.7.0.103</specification-version>
  128.19 +                    </run-dependency>
  128.20 +                </dependency>
  128.21 +                <dependency>
  128.22 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
  128.23 +                    <build-prerequisite/>
  128.24 +                    <compile-dependency/>
  128.25 +                    <run-dependency>
  128.26 +                        <release-version>1</release-version>
  128.27 +                        <specification-version>1.0</specification-version>
  128.28 +                    </run-dependency>
  128.29 +                </dependency>
  128.30 +                <dependency>
  128.31 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
  128.32 +                    <build-prerequisite/>
  128.33 +                    <compile-dependency/>
  128.34 +                    <run-dependency>
  128.35 +                        <release-version>1</release-version>
  128.36 +                        <specification-version>1.19</specification-version>
  128.37 +                    </run-dependency>
  128.38 +                </dependency>
  128.39 +                <dependency>
  128.40 +                    <code-name-base>org.netbeans.api.progress</code-name-base>
  128.41 +                    <build-prerequisite/>
  128.42 +                    <compile-dependency/>
  128.43 +                    <run-dependency>
  128.44 +                        <release-version>1</release-version>
  128.45 +                        <specification-version>1.13.0.1</specification-version>
  128.46 +                    </run-dependency>
  128.47 +                </dependency>
  128.48 +                <dependency>
  128.49 +                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
  128.50 +                    <build-prerequisite/>
  128.51 +                    <compile-dependency/>
  128.52 +                    <run-dependency>
  128.53 +                        <specification-version>7.5.0.3</specification-version>
  128.54 +                    </run-dependency>
  128.55 +                </dependency>
  128.56 +                <dependency>
  128.57 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
  128.58 +                    <build-prerequisite/>
  128.59 +                    <compile-dependency/>
  128.60 +                    <run-dependency>
  128.61 +                        <release-version>1</release-version>
  128.62 +                        <implementation-version/>
  128.63 +                    </run-dependency>
  128.64 +                </dependency>
  128.65 +                <dependency>
  128.66 +                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
  128.67 +                    <build-prerequisite/>
  128.68 +                    <compile-dependency/>
  128.69 +                    <run-dependency>
  128.70 +                        <release-version>1-3</release-version>
  128.71 +                        <specification-version>2.13</specification-version>
  128.72 +                    </run-dependency>
  128.73 +                </dependency>
  128.74 +                <dependency>
  128.75 +                    <code-name-base>org.netbeans.modules.diff</code-name-base>
  128.76 +                    <build-prerequisite/>
  128.77 +                    <compile-dependency/>
  128.78 +                    <run-dependency>
  128.79 +                        <release-version>1</release-version>
  128.80 +                        <implementation-version/>
  128.81 +                    </run-dependency>
  128.82 +                </dependency>
  128.83 +                <dependency>
  128.84 +                    <code-name-base>org.netbeans.modules.editor</code-name-base>
  128.85 +                    <build-prerequisite/>
  128.86 +                    <compile-dependency/>
  128.87 +                    <run-dependency>
  128.88 +                        <release-version>3</release-version>
  128.89 +                        <specification-version>1.56.0.5.13.6</specification-version>
  128.90 +                    </run-dependency>
  128.91 +                </dependency>
  128.92 +                <dependency>
  128.93 +                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
  128.94 +                    <build-prerequisite/>
  128.95 +                    <compile-dependency/>
  128.96 +                    <run-dependency>
  128.97 +                        <release-version>1-3</release-version>
  128.98 +                        <specification-version>1.38.0.9.2</specification-version>
  128.99 +                    </run-dependency>
 128.100 +                </dependency>
 128.101 +                <dependency>
 128.102 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
 128.103 +                    <build-prerequisite/>
 128.104 +                    <compile-dependency/>
 128.105 +                    <run-dependency>
 128.106 +                        <release-version>1</release-version>
 128.107 +                        <specification-version>1.13.0.2</specification-version>
 128.108 +                    </run-dependency>
 128.109 +                </dependency>
 128.110 +                <dependency>
 128.111 +                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
 128.112 +                    <build-prerequisite/>
 128.113 +                    <compile-dependency/>
 128.114 +                    <run-dependency>
 128.115 +                        <release-version>1</release-version>
 128.116 +                        <specification-version>1.12</specification-version>
 128.117 +                    </run-dependency>
 128.118 +                </dependency>
 128.119 +                <dependency>
 128.120 +                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
 128.121 +                    <build-prerequisite/>
 128.122 +                    <compile-dependency/>
 128.123 +                    <run-dependency>
 128.124 +                        <release-version>1</release-version>
 128.125 +                        <specification-version>1.25</specification-version>
 128.126 +                    </run-dependency>
 128.127 +                </dependency>
 128.128 +                <dependency>
 128.129 +                    <code-name-base>org.netbeans.modules.java.editor</code-name-base>
 128.130 +                    <build-prerequisite/>
 128.131 +                    <compile-dependency/>
 128.132 +                    <run-dependency>
 128.133 +                        <release-version>1</release-version>
 128.134 +                        <implementation-version/>
 128.135 +                    </run-dependency>
 128.136 +                </dependency>
 128.137 +                <dependency>
 128.138 +                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
 128.139 +                    <build-prerequisite/>
 128.140 +                    <compile-dependency/>
 128.141 +                    <run-dependency>
 128.142 +                        <release-version>1</release-version>
 128.143 +                        <implementation-version/>
 128.144 +                    </run-dependency>
 128.145 +                </dependency>
 128.146 +                <dependency>
 128.147 +                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
 128.148 +                    <build-prerequisite/>
 128.149 +                    <compile-dependency/>
 128.150 +                    <run-dependency>
 128.151 +                        <release-version>1</release-version>
 128.152 +                        <specification-version>1.9</specification-version>
 128.153 +                    </run-dependency>
 128.154 +                </dependency>
 128.155 +                <dependency>
 128.156 +                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
 128.157 +                    <build-prerequisite/>
 128.158 +                    <compile-dependency/>
 128.159 +                    <run-dependency>
 128.160 +                        <release-version>1</release-version>
 128.161 +                        <specification-version>1.12</specification-version>
 128.162 +                    </run-dependency>
 128.163 +                </dependency>
 128.164 +                <dependency>
 128.165 +                    <code-name-base>org.netbeans.modules.java.preprocessorbridge</code-name-base>
 128.166 +                    <build-prerequisite/>
 128.167 +                    <compile-dependency/>
 128.168 +                    <run-dependency>
 128.169 +                        <implementation-version/>
 128.170 +                    </run-dependency>
 128.171 +                </dependency>
 128.172 +                <dependency>
 128.173 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
 128.174 +                    <build-prerequisite/>
 128.175 +                    <compile-dependency/>
 128.176 +                    <run-dependency>
 128.177 +                        <implementation-version/>
 128.178 +                    </run-dependency>
 128.179 +                </dependency>
 128.180 +                <dependency>
 128.181 +                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
 128.182 +                    <build-prerequisite/>
 128.183 +                    <compile-dependency/>
 128.184 +                    <run-dependency>
 128.185 +                        <release-version>2</release-version>
 128.186 +                        <specification-version>1.34</specification-version>
 128.187 +                    </run-dependency>
 128.188 +                </dependency>
 128.189 +                <dependency>
 128.190 +                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
 128.191 +                    <build-prerequisite/>
 128.192 +                    <compile-dependency/>
 128.193 +                    <run-dependency>
 128.194 +                        <release-version>1</release-version>
 128.195 +                        <specification-version>1.20</specification-version>
 128.196 +                    </run-dependency>
 128.197 +                </dependency>
 128.198 +                <dependency>
 128.199 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
 128.200 +                    <build-prerequisite/>
 128.201 +                    <compile-dependency/>
 128.202 +                    <run-dependency>
 128.203 +                        <release-version>1</release-version>
 128.204 +                        <implementation-version/>
 128.205 +                    </run-dependency>
 128.206 +                </dependency>
 128.207 +                <dependency>
 128.208 +                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
 128.209 +                    <build-prerequisite/>
 128.210 +                    <compile-dependency/>
 128.211 +                    <run-dependency>
 128.212 +                        <release-version>1</release-version>
 128.213 +                        <specification-version>1.24</specification-version>
 128.214 +                    </run-dependency>
 128.215 +                </dependency>
 128.216 +                <dependency>
 128.217 +                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
 128.218 +                    <build-prerequisite/>
 128.219 +                    <compile-dependency/>
 128.220 +                    <run-dependency>
 128.221 +                        <release-version>1</release-version>
 128.222 +                        <specification-version>1.35.0.6</specification-version>
 128.223 +                    </run-dependency>
 128.224 +                </dependency>
 128.225 +                <dependency>
 128.226 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
 128.227 +                    <build-prerequisite/>
 128.228 +                    <compile-dependency/>
 128.229 +                    <run-dependency>
 128.230 +                        <release-version>1</release-version>
 128.231 +                        <specification-version>1.15</specification-version>
 128.232 +                    </run-dependency>
 128.233 +                </dependency>
 128.234 +                <dependency>
 128.235 +                    <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
 128.236 +                    <build-prerequisite/>
 128.237 +                    <compile-dependency/>
 128.238 +                    <run-dependency>
 128.239 +                        <specification-version>1.6</specification-version>
 128.240 +                    </run-dependency>
 128.241 +                </dependency>
 128.242 +                <dependency>
 128.243 +                    <code-name-base>org.netbeans.modules.refactoring.java</code-name-base>
 128.244 +                    <build-prerequisite/>
 128.245 +                    <compile-dependency/>
 128.246 +                    <run-dependency>
 128.247 +                        <release-version>1</release-version>
 128.248 +                        <specification-version>1.6</specification-version>
 128.249 +                    </run-dependency>
 128.250 +                </dependency>
 128.251 +                <dependency>
 128.252 +                    <code-name-base>org.netbeans.modules.sendopts</code-name-base>
 128.253 +                    <build-prerequisite/>
 128.254 +                    <compile-dependency/>
 128.255 +                    <run-dependency>
 128.256 +                        <release-version>2</release-version>
 128.257 +                        <specification-version>2.4</specification-version>
 128.258 +                    </run-dependency>
 128.259 +                </dependency>
 128.260 +                <dependency>
 128.261 +                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
 128.262 +                    <build-prerequisite/>
 128.263 +                    <compile-dependency/>
 128.264 +                    <run-dependency>
 128.265 +                        <release-version>0-1</release-version>
 128.266 +                        <specification-version>1.7.0.7.2</specification-version>
 128.267 +                    </run-dependency>
 128.268 +                </dependency>
 128.269 +                <dependency>
 128.270 +                    <code-name-base>org.openide.awt</code-name-base>
 128.271 +                    <build-prerequisite/>
 128.272 +                    <compile-dependency/>
 128.273 +                    <run-dependency>
 128.274 +                        <specification-version>7.7.0.1</specification-version>
 128.275 +                    </run-dependency>
 128.276 +                </dependency>
 128.277 +                <dependency>
 128.278 +                    <code-name-base>org.openide.dialogs</code-name-base>
 128.279 +                    <build-prerequisite/>
 128.280 +                    <compile-dependency/>
 128.281 +                    <run-dependency>
 128.282 +                        <specification-version>7.10</specification-version>
 128.283 +                    </run-dependency>
 128.284 +                </dependency>
 128.285 +                <dependency>
 128.286 +                    <code-name-base>org.openide.filesystems</code-name-base>
 128.287 +                    <build-prerequisite/>
 128.288 +                    <compile-dependency/>
 128.289 +                    <run-dependency>
 128.290 +                        <specification-version>7.21.0.1.1</specification-version>
 128.291 +                    </run-dependency>
 128.292 +                </dependency>
 128.293 +                <dependency>
 128.294 +                    <code-name-base>org.openide.loaders</code-name-base>
 128.295 +                    <build-prerequisite/>
 128.296 +                    <compile-dependency/>
 128.297 +                    <run-dependency>
 128.298 +                        <specification-version>7.5</specification-version>
 128.299 +                    </run-dependency>
 128.300 +                </dependency>
 128.301 +                <dependency>
 128.302 +                    <code-name-base>org.openide.modules</code-name-base>
 128.303 +                    <build-prerequisite/>
 128.304 +                    <compile-dependency/>
 128.305 +                    <run-dependency>
 128.306 +                        <specification-version>7.10</specification-version>
 128.307 +                    </run-dependency>
 128.308 +                </dependency>
 128.309 +                <dependency>
 128.310 +                    <code-name-base>org.openide.nodes</code-name-base>
 128.311 +                    <build-prerequisite/>
 128.312 +                    <compile-dependency/>
 128.313 +                    <run-dependency>
 128.314 +                        <specification-version>7.9.0.1</specification-version>
 128.315 +                    </run-dependency>
 128.316 +                </dependency>
 128.317 +                <dependency>
 128.318 +                    <code-name-base>org.openide.text</code-name-base>
 128.319 +                    <build-prerequisite/>
 128.320 +                    <compile-dependency/>
 128.321 +                    <run-dependency>
 128.322 +                        <specification-version>6.22</specification-version>
 128.323 +                    </run-dependency>
 128.324 +                </dependency>
 128.325 +                <dependency>
 128.326 +                    <code-name-base>org.openide.util</code-name-base>
 128.327 +                    <build-prerequisite/>
 128.328 +                    <compile-dependency/>
 128.329 +                    <run-dependency>
 128.330 +                        <specification-version>8.0</specification-version>
 128.331 +                    </run-dependency>
 128.332 +                </dependency>
 128.333 +                <dependency>
 128.334 +                    <code-name-base>org.openide.util.lookup</code-name-base>
 128.335 +                    <build-prerequisite/>
 128.336 +                    <compile-dependency/>
 128.337 +                    <run-dependency>
 128.338 +                        <specification-version>8.0.0.1</specification-version>
 128.339 +                    </run-dependency>
 128.340 +                </dependency>
 128.341 +                <dependency>
 128.342 +                    <code-name-base>org.openide.windows</code-name-base>
 128.343 +                    <build-prerequisite/>
 128.344 +                    <compile-dependency/>
 128.345 +                    <run-dependency>
 128.346 +                        <specification-version>6.27</specification-version>
 128.347 +                    </run-dependency>
 128.348 +                </dependency>
 128.349 +            </module-dependencies>
 128.350 +            <public-packages>
 128.351 +                <package>org.netbeans.modules.jackpot30.common.api</package>
 128.352 +            </public-packages>
 128.353 +        </data>
 128.354 +    </configuration>
 128.355 +</project>
   129.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   129.2 +++ b/remoting/common/api/nbproject/suite.properties	Sat Feb 11 18:35:10 2012 +0100
   129.3 @@ -0,0 +1,1 @@
   129.4 +suite.dir=${basedir}/..
   130.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   130.2 +++ b/remoting/common/api/src/org/netbeans/modules/jackpot30/common/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
   130.3 @@ -0,0 +1,1 @@
   130.4 +OpenIDE-Module-Name=Jackpot 3.0 Common APIs
   131.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   131.2 +++ b/remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/IndexAccess.java	Sat Feb 11 18:35:10 2012 +0100
   131.3 @@ -0,0 +1,115 @@
   131.4 +/*
   131.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   131.6 + *
   131.7 + * Copyright 2012 Sun Microsystems, Inc. All rights reserved.
   131.8 + *
   131.9 + * The contents of this file are subject to the terms of either the GNU
  131.10 + * General Public License Version 2 only ("GPL") or the Common
  131.11 + * Development and Distribution License("CDDL") (collectively, the
  131.12 + * "License"). You may not use this file except in compliance with the
  131.13 + * License. You can obtain a copy of the License at
  131.14 + * http://www.netbeans.org/cddl-gplv2.html
  131.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  131.16 + * specific language governing permissions and limitations under the
  131.17 + * License.  When distributing the software, include this License Header
  131.18 + * Notice in each file and include the License file at
  131.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  131.20 + * particular file as subject to the "Classpath" exception as provided
  131.21 + * by Sun in the GPL Version 2 section of the License file that
  131.22 + * accompanied this code. If applicable, add the following below the
  131.23 + * License Header, with the fields enclosed by brackets [] replaced by
  131.24 + * your own identifying information:
  131.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  131.26 + *
  131.27 + * If you wish your version of this file to be governed by only the CDDL
  131.28 + * or only the GPL Version 2, indicate your decision by adding
  131.29 + * "[Contributor] elects to include this software in this distribution
  131.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  131.31 + * single choice of license, a recipient has the option to distribute
  131.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  131.33 + * to extend the choice of license to its licensees as provided above.
  131.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  131.35 + * Version 2 license, then the option applies only if the new code is
  131.36 + * made subject to such option by the copyright holder.
  131.37 + *
  131.38 + * Contributor(s):
  131.39 + *
  131.40 + * Portions Copyrighted 2012 Sun Microsystems, Inc.
  131.41 + */
  131.42 +
  131.43 +package org.netbeans.modules.jackpot30.common.api;
  131.44 +
  131.45 +import java.io.File;
  131.46 +import java.io.IOException;
  131.47 +import java.io.Reader;
  131.48 +import java.net.URISyntaxException;
  131.49 +import java.net.URL;
  131.50 +import org.apache.lucene.analysis.Analyzer;
  131.51 +import org.apache.lucene.analysis.TokenStream;
  131.52 +import org.apache.lucene.index.CorruptIndexException;
  131.53 +import org.apache.lucene.index.IndexWriter;
  131.54 +import org.apache.lucene.store.FSDirectory;
  131.55 +import org.apache.lucene.store.LockObtainFailedException;
  131.56 +import org.netbeans.api.annotations.common.NonNull;
  131.57 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
  131.58 +import org.openide.filesystems.FileObject;
  131.59 +import org.openide.filesystems.FileUtil;
  131.60 +import org.openide.util.lookup.ServiceProvider;
  131.61 +
  131.62 +/**
  131.63 + *
  131.64 + * @author lahvac
  131.65 + */
  131.66 +@ServiceProvider(service=IndexAccess.class)
  131.67 +public class IndexAccess {
  131.68 +    
  131.69 +    private URL root;
  131.70 +    private IndexWriter w;
  131.71 +    
  131.72 +    public @NonNull IndexWriter getIndexWriter(@NonNull URL root, @NonNull FileObject cacheRoot, @NonNull String subindexName) {
  131.73 +        if (w == null) {
  131.74 +            this.root = root;
  131.75 +            File cacheRootFile = FileUtil.toFile(cacheRoot);
  131.76 +            try {
  131.77 +                w = new IndexWriter(FSDirectory.open(new File(cacheRootFile, subindexName)), new NoAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
  131.78 +            } catch (CorruptIndexException ex) {
  131.79 +                throw new IllegalStateException(ex);
  131.80 +            } catch (LockObtainFailedException ex) {
  131.81 +                throw new IllegalStateException(ex);
  131.82 +            } catch (IOException ex) {
  131.83 +                throw new IllegalStateException(ex);
  131.84 +            }
  131.85 +        }
  131.86 +        
  131.87 +        return w;
  131.88 +    }
  131.89 +    
  131.90 +    public void finish() {
  131.91 +        this.root = null;
  131.92 +        try {
  131.93 +            w.close();
  131.94 +        } catch (CorruptIndexException ex) {
  131.95 +            throw new IllegalStateException(ex);
  131.96 +        } catch (IOException ex) {
  131.97 +            throw new IllegalStateException(ex);
  131.98 +        }
  131.99 +        w = null;
 131.100 +    }
 131.101 +    
 131.102 +    public String getRelativePath(Indexable i) {
 131.103 +        try {
 131.104 +            return root.toURI().relativize(i.getURL().toURI()).toString();
 131.105 +        } catch (URISyntaxException ex) {
 131.106 +            throw new IllegalStateException(ex);
 131.107 +        }
 131.108 +    }
 131.109 +    
 131.110 +    public static final class NoAnalyzer extends Analyzer {
 131.111 +
 131.112 +        @Override
 131.113 +        public TokenStream tokenStream(String string, Reader reader) {
 131.114 +            throw new UnsupportedOperationException("Should not be called");
 131.115 +        }
 131.116 +
 131.117 +    }
 131.118 +}
   132.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   132.2 +++ b/remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/JavaUtils.java	Sat Feb 11 18:35:10 2012 +0100
   132.3 @@ -0,0 +1,76 @@
   132.4 +/*
   132.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   132.6 + *
   132.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   132.8 + *
   132.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  132.10 + * Other names may be trademarks of their respective owners.
  132.11 + *
  132.12 + * The contents of this file are subject to the terms of either the GNU
  132.13 + * General Public License Version 2 only ("GPL") or the Common
  132.14 + * Development and Distribution License("CDDL") (collectively, the
  132.15 + * "License"). You may not use this file except in compliance with the
  132.16 + * License. You can obtain a copy of the License at
  132.17 + * http://www.netbeans.org/cddl-gplv2.html
  132.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  132.19 + * specific language governing permissions and limitations under the
  132.20 + * License.  When distributing the software, include this License Header
  132.21 + * Notice in each file and include the License file at
  132.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  132.23 + * particular file as subject to the "Classpath" exception as provided
  132.24 + * by Oracle in the GPL Version 2 section of the License file that
  132.25 + * accompanied this code. If applicable, add the following below the
  132.26 + * License Header, with the fields enclosed by brackets [] replaced by
  132.27 + * your own identifying information:
  132.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  132.29 + *
  132.30 + * If you wish your version of this file to be governed by only the CDDL
  132.31 + * or only the GPL Version 2, indicate your decision by adding
  132.32 + * "[Contributor] elects to include this software in this distribution
  132.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  132.34 + * single choice of license, a recipient has the option to distribute
  132.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  132.36 + * to extend the choice of license to its licensees as provided above.
  132.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  132.38 + * Version 2 license, then the option applies only if the new code is
  132.39 + * made subject to such option by the copyright holder.
  132.40 + *
  132.41 + * Contributor(s):
  132.42 + *
  132.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
  132.44 + */
  132.45 +package org.netbeans.modules.jackpot30.common.api;
  132.46 +
  132.47 +import java.util.EnumSet;
  132.48 +import java.util.Set;
  132.49 +import javax.lang.model.element.ElementKind;
  132.50 +import org.netbeans.api.java.source.ElementHandle;
  132.51 +import org.netbeans.api.java.source.SourceUtils;
  132.52 +
  132.53 +/**
  132.54 + *
  132.55 + * @author lahvac
  132.56 + */
  132.57 +public class JavaUtils {
  132.58 +    
  132.59 +    public static final Set<ElementKind> SUPPORTED_KINDS = EnumSet.of(ElementKind.PACKAGE, ElementKind.CLASS,
  132.60 +            ElementKind.INTERFACE, ElementKind.ENUM, ElementKind.ANNOTATION_TYPE, ElementKind.METHOD,
  132.61 +            ElementKind.CONSTRUCTOR, ElementKind.INSTANCE_INIT, ElementKind.STATIC_INIT,
  132.62 +            ElementKind.FIELD, ElementKind.ENUM_CONSTANT);
  132.63 +    
  132.64 +    public static String serialize(ElementHandle<?> h) {
  132.65 +        StringBuilder result = new StringBuilder();
  132.66 +
  132.67 +        result.append(h.getKind());
  132.68 +
  132.69 +        String[] signatures = SourceUtils.getJVMSignature(h);
  132.70 +
  132.71 +        for (String sig : signatures) {
  132.72 +            result.append(":");
  132.73 +            result.append(sig);
  132.74 +        }
  132.75 +
  132.76 +        return result.toString();
  132.77 +    }
  132.78 +    
  132.79 +}
   133.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.2 +++ b/remoting/common/api/src/org/netbeans/modules/jackpot30/common/api/LuceneHelpers.java	Sat Feb 11 18:35:10 2012 +0100
   133.3 @@ -0,0 +1,84 @@
   133.4 +/*
   133.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   133.6 + *
   133.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   133.8 + *
   133.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  133.10 + * Other names may be trademarks of their respective owners.
  133.11 + *
  133.12 + * The contents of this file are subject to the terms of either the GNU
  133.13 + * General Public License Version 2 only ("GPL") or the Common
  133.14 + * Development and Distribution License("CDDL") (collectively, the
  133.15 + * "License"). You may not use this file except in compliance with the
  133.16 + * License. You can obtain a copy of the License at
  133.17 + * http://www.netbeans.org/cddl-gplv2.html
  133.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  133.19 + * specific language governing permissions and limitations under the
  133.20 + * License.  When distributing the software, include this License Header
  133.21 + * Notice in each file and include the License file at
  133.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  133.23 + * particular file as subject to the "Classpath" exception as provided
  133.24 + * by Oracle in the GPL Version 2 section of the License file that
  133.25 + * accompanied this code. If applicable, add the following below the
  133.26 + * License Header, with the fields enclosed by brackets [] replaced by
  133.27 + * your own identifying information:
  133.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  133.29 + *
  133.30 + * If you wish your version of this file to be governed by only the CDDL
  133.31 + * or only the GPL Version 2, indicate your decision by adding
  133.32 + * "[Contributor] elects to include this software in this distribution
  133.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  133.34 + * single choice of license, a recipient has the option to distribute
  133.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  133.36 + * to extend the choice of license to its licensees as provided above.
  133.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  133.38 + * Version 2 license, then the option applies only if the new code is
  133.39 + * made subject to such option by the copyright holder.
  133.40 + *
  133.41 + * Contributor(s):
  133.42 + *
  133.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
  133.44 + */
  133.45 +package org.netbeans.modules.jackpot30.common.api;
  133.46 +
  133.47 +import java.util.BitSet;
  133.48 +import org.apache.lucene.index.IndexReader;
  133.49 +import org.apache.lucene.search.Collector;
  133.50 +import org.apache.lucene.search.Scorer;
  133.51 +
  133.52 +/**
  133.53 + *
  133.54 + * @author lahvac
  133.55 + */
  133.56 +public class LuceneHelpers {
  133.57 +    
  133.58 +    public static class BitSetCollector extends Collector {
  133.59 +
  133.60 +        private int docBase;
  133.61 +        public final BitSet bits;
  133.62 +
  133.63 +        public BitSetCollector(final BitSet bitSet) {
  133.64 +            assert bitSet != null;
  133.65 +            bits = bitSet;
  133.66 +        }
  133.67 +
  133.68 +        // ignore scorer
  133.69 +        public void setScorer(Scorer scorer) {
  133.70 +        }
  133.71 +
  133.72 +        // accept docs out of order (for a BitSet it doesn't matter)
  133.73 +        public boolean acceptsDocsOutOfOrder() {
  133.74 +          return true;
  133.75 +        }
  133.76 +
  133.77 +        public void collect(int doc) {
  133.78 +          bits.set(doc + docBase);
  133.79 +        }
  133.80 +
  133.81 +        public void setNextReader(IndexReader reader, int docBase) {
  133.82 +          this.docBase = docBase;
  133.83 +        }
  133.84 +
  133.85 +    }
  133.86 +    
  133.87 +}
   134.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   134.2 +++ b/remoting/common/borrowedtests/build.xml	Sat Feb 11 18:35:10 2012 +0100
   134.3 @@ -0,0 +1,13 @@
   134.4 +<?xml version="1.0" encoding="UTF-8"?>
   134.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   134.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   134.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   134.8 +<project name="org.netbeans.modules.jackpot30.test.borrowed" default="netbeans" basedir=".">
   134.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.test.borrowed.</description>
  134.10 +    <import file="nbproject/build-impl.xml"/>
  134.11 +<!--    <import file="../findbugs-import.xml"/>-->
  134.12 +
  134.13 +<!--    <target name="test" />
  134.14 +    <target name="test-coverage" />
  134.15 +    <target name="coverage-report" />-->
  134.16 +</project>
   135.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   135.2 +++ b/remoting/common/borrowedtests/manifest.mf	Sat Feb 11 18:35:10 2012 +0100
   135.3 @@ -0,0 +1,6 @@
   135.4 +Manifest-Version: 1.0
   135.5 +AutoUpdate-Show-In-Client: false
   135.6 +OpenIDE-Module: org.netbeans.modules.jackpot30.test.borrowed
   135.7 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties
   135.8 +OpenIDE-Module-Specification-Version: 1.16
   135.9 +
   136.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   136.2 +++ b/remoting/common/borrowedtests/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   136.3 @@ -0,0 +1,45 @@
   136.4 +<?xml version="1.0" encoding="UTF-8"?>
   136.5 +<!--
   136.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   136.7 +***         EDIT ../build.xml INSTEAD         ***
   136.8 +-->
   136.9 +<project name="org.netbeans.modules.jackpot30.test.borrowed-impl" basedir="..">
  136.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  136.11 +        <condition>
  136.12 +            <not>
  136.13 +                <antversion atleast="1.7.1"/>
  136.14 +            </not>
  136.15 +        </condition>
  136.16 +    </fail>
  136.17 +    <property file="nbproject/private/suite-private.properties"/>
  136.18 +    <property file="nbproject/suite.properties"/>
  136.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
  136.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
  136.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
  136.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
  136.23 +        <attribute name="name"/>
  136.24 +        <attribute name="value"/>
  136.25 +        <sequential>
  136.26 +            <property name="@{name}" value="${@{value}}"/>
  136.27 +        </sequential>
  136.28 +    </macrodef>
  136.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
  136.30 +        <attribute name="property"/>
  136.31 +        <attribute name="value"/>
  136.32 +        <sequential>
  136.33 +            <property name="@{property}" value="@{value}"/>
  136.34 +        </sequential>
  136.35 +    </macrodef>
  136.36 +    <property file="${user.properties.file}"/>
  136.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  136.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  136.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  136.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  136.41 +        <condition>
  136.42 +            <not>
  136.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  136.44 +            </not>
  136.45 +        </condition>
  136.46 +    </fail>
  136.47 +    <import file="${harness.dir}/build.xml"/>
  136.48 +</project>
   137.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.2 +++ b/remoting/common/borrowedtests/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   137.3 @@ -0,0 +1,8 @@
   137.4 +build.xml.data.CRC32=a4393221
   137.5 +build.xml.script.CRC32=3cb17d2d
   137.6 +build.xml.stylesheet.CRC32=79c3b980@1.28.0.7
   137.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   137.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   137.9 +nbproject/build-impl.xml.data.CRC32=6ddec023
  137.10 +nbproject/build-impl.xml.script.CRC32=cb5fccc2
  137.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
   138.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   138.2 +++ b/remoting/common/borrowedtests/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
   138.3 @@ -0,0 +1,21 @@
   138.4 +cluster.path=\
   138.5 +    ${nbplatform.active.dir}/identity:\
   138.6 +    ${nbplatform.active.dir}/enterprise:\
   138.7 +    ${nbplatform.active.dir}/webcommon:\
   138.8 +    ${nbplatform.active.dir}/mobility:\
   138.9 +    ${nbplatform.active.dir}/php:\
  138.10 +    ${nbplatform.active.dir}/harness:\
  138.11 +    ${nbplatform.active.dir}/dlight:\
  138.12 +    ${nbplatform.active.dir}/profiler:\
  138.13 +    ${nbplatform.active.dir}/platform:\
  138.14 +    ${nbplatform.active.dir}/websvccommon:\
  138.15 +    ${nbplatform.active.dir}/nb:\
  138.16 +    ${nbplatform.active.dir}/apisupport:\
  138.17 +    ${nbplatform.active.dir}/cnd:\
  138.18 +    ${nbplatform.active.dir}/ergonomics:\
  138.19 +    ${nbplatform.active.dir}/java:\
  138.20 +    ${nbplatform.active.dir}/groovy:\
  138.21 +    ${nbplatform.active.dir}/ruby:\
  138.22 +    ${nbplatform.active.dir}/extra:\
  138.23 +    ${nbplatform.active.dir}/ide
  138.24 +nbplatform.active=default
   139.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   139.2 +++ b/remoting/common/borrowedtests/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   139.3 @@ -0,0 +1,3 @@
   139.4 +is.autoload=true
   139.5 +javac.source=1.5
   139.6 +javac.compilerargs=-Xlint -Xlint:-serial
   140.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   140.2 +++ b/remoting/common/borrowedtests/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   140.3 @@ -0,0 +1,328 @@
   140.4 +<?xml version="1.0" encoding="UTF-8"?>
   140.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   140.6 +    <type>org.netbeans.modules.apisupport.project</type>
   140.7 +    <configuration>
   140.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
   140.9 +            <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
  140.10 +            <suite-component/>
  140.11 +            <module-dependencies>
  140.12 +                <dependency>
  140.13 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
  140.14 +                    <build-prerequisite/>
  140.15 +                    <compile-dependency/>
  140.16 +                    <run-dependency>
  140.17 +                        <release-version>1</release-version>
  140.18 +                        <specification-version>1.13</specification-version>
  140.19 +                    </run-dependency>
  140.20 +                </dependency>
  140.21 +                <dependency>
  140.22 +                    <code-name-base>org.netbeans.api.java</code-name-base>
  140.23 +                    <build-prerequisite/>
  140.24 +                    <compile-dependency/>
  140.25 +                    <run-dependency>
  140.26 +                        <release-version>1</release-version>
  140.27 +                        <specification-version>1.31</specification-version>
  140.28 +                    </run-dependency>
  140.29 +                </dependency>
  140.30 +                <dependency>
  140.31 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
  140.32 +                    <build-prerequisite/>
  140.33 +                    <compile-dependency/>
  140.34 +                    <run-dependency>
  140.35 +                        <release-version>1</release-version>
  140.36 +                        <specification-version>1.27</specification-version>
  140.37 +                    </run-dependency>
  140.38 +                </dependency>
  140.39 +                <dependency>
  140.40 +                    <code-name-base>org.netbeans.api.progress</code-name-base>
  140.41 +                    <build-prerequisite/>
  140.42 +                    <compile-dependency/>
  140.43 +                    <run-dependency>
  140.44 +                        <release-version>1</release-version>
  140.45 +                        <specification-version>1.22</specification-version>
  140.46 +                    </run-dependency>
  140.47 +                </dependency>
  140.48 +                <dependency>
  140.49 +                    <code-name-base>org.netbeans.insane</code-name-base>
  140.50 +                    <build-prerequisite/>
  140.51 +                    <compile-dependency/>
  140.52 +                    <run-dependency>
  140.53 +                        <release-version>1</release-version>
  140.54 +                        <implementation-version/>
  140.55 +                    </run-dependency>
  140.56 +                </dependency>
  140.57 +                <dependency>
  140.58 +                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
  140.59 +                    <build-prerequisite/>
  140.60 +                    <compile-dependency/>
  140.61 +                    <run-dependency>
  140.62 +                        <specification-version>7.1.0.2</specification-version>
  140.63 +                    </run-dependency>
  140.64 +                </dependency>
  140.65 +                <dependency>
  140.66 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
  140.67 +                    <build-prerequisite/>
  140.68 +                    <compile-dependency/>
  140.69 +                    <run-dependency>
  140.70 +                        <release-version>1</release-version>
  140.71 +                        <implementation-version/>
  140.72 +                    </run-dependency>
  140.73 +                </dependency>
  140.74 +                <dependency>
  140.75 +                    <code-name-base>org.netbeans.libs.junit4</code-name-base>
  140.76 +                    <build-prerequisite/>
  140.77 +                    <compile-dependency/>
  140.78 +                    <run-dependency>
  140.79 +                        <specification-version>1.12</specification-version>
  140.80 +                    </run-dependency>
  140.81 +                </dependency>
  140.82 +                <dependency>
  140.83 +                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
  140.84 +                    <build-prerequisite/>
  140.85 +                    <compile-dependency/>
  140.86 +                    <run-dependency>
  140.87 +                        <release-version>1-3</release-version>
  140.88 +                        <specification-version>2.13</specification-version>
  140.89 +                    </run-dependency>
  140.90 +                </dependency>
  140.91 +                <dependency>
  140.92 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
  140.93 +                    <build-prerequisite/>
  140.94 +                    <compile-dependency/>
  140.95 +                    <run-dependency>
  140.96 +                        <release-version>1</release-version>
  140.97 +                        <specification-version>1.35.0.5</specification-version>
  140.98 +                    </run-dependency>
  140.99 +                </dependency>
 140.100 +                <dependency>
 140.101 +                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
 140.102 +                    <build-prerequisite/>
 140.103 +                    <compile-dependency/>
 140.104 +                    <run-dependency>
 140.105 +                        <release-version>1</release-version>
 140.106 +                        <specification-version>1.20</specification-version>
 140.107 +                    </run-dependency>
 140.108 +                </dependency>
 140.109 +                <dependency>
 140.110 +                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
 140.111 +                    <build-prerequisite/>
 140.112 +                    <compile-dependency/>
 140.113 +                    <run-dependency>
 140.114 +                        <release-version>1</release-version>
 140.115 +                        <specification-version>1.39</specification-version>
 140.116 +                    </run-dependency>
 140.117 +                </dependency>
 140.118 +                <dependency>
 140.119 +                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
 140.120 +                    <build-prerequisite/>
 140.121 +                    <compile-dependency/>
 140.122 +                    <run-dependency>
 140.123 +                        <release-version>1</release-version>
 140.124 +                        <implementation-version/>
 140.125 +                    </run-dependency>
 140.126 +                </dependency>
 140.127 +                <dependency>
 140.128 +                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
 140.129 +                    <build-prerequisite/>
 140.130 +                    <compile-dependency/>
 140.131 +                    <run-dependency>
 140.132 +                        <release-version>1</release-version>
 140.133 +                        <specification-version>1.12</specification-version>
 140.134 +                    </run-dependency>
 140.135 +                </dependency>
 140.136 +                <dependency>
 140.137 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
 140.138 +                    <build-prerequisite/>
 140.139 +                    <compile-dependency/>
 140.140 +                    <run-dependency>
 140.141 +                        <implementation-version/>
 140.142 +                    </run-dependency>
 140.143 +                </dependency>
 140.144 +                <dependency>
 140.145 +                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
 140.146 +                    <build-prerequisite/>
 140.147 +                    <compile-dependency/>
 140.148 +                    <run-dependency>
 140.149 +                        <release-version>2</release-version>
 140.150 +                        <specification-version>1.37.0.1</specification-version>
 140.151 +                    </run-dependency>
 140.152 +                </dependency>
 140.153 +                <dependency>
 140.154 +                    <code-name-base>org.netbeans.modules.masterfs</code-name-base>
 140.155 +                    <build-prerequisite/>
 140.156 +                    <compile-dependency/>
 140.157 +                    <run-dependency>
 140.158 +                        <release-version>2</release-version>
 140.159 +                        <implementation-version/>
 140.160 +                    </run-dependency>
 140.161 +                </dependency>
 140.162 +                <dependency>
 140.163 +                    <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
 140.164 +                    <build-prerequisite/>
 140.165 +                    <compile-dependency/>
 140.166 +                    <run-dependency>
 140.167 +                        <release-version>1</release-version>
 140.168 +                        <specification-version>1.65</specification-version>
 140.169 +                    </run-dependency>
 140.170 +                </dependency>
 140.171 +                <dependency>
 140.172 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
 140.173 +                    <build-prerequisite/>
 140.174 +                    <compile-dependency/>
 140.175 +                    <run-dependency>
 140.176 +                        <release-version>1</release-version>
 140.177 +                        <implementation-version/>
 140.178 +                    </run-dependency>
 140.179 +                </dependency>
 140.180 +                <dependency>
 140.181 +                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
 140.182 +                    <build-prerequisite/>
 140.183 +                    <compile-dependency/>
 140.184 +                    <run-dependency>
 140.185 +                        <release-version>1</release-version>
 140.186 +                        <specification-version>1.34</specification-version>
 140.187 +                    </run-dependency>
 140.188 +                </dependency>
 140.189 +                <dependency>
 140.190 +                    <code-name-base>org.netbeans.modules.projectui</code-name-base>
 140.191 +                    <build-prerequisite/>
 140.192 +                    <compile-dependency/>
 140.193 +                    <run-dependency>
 140.194 +                        <implementation-version/>
 140.195 +                    </run-dependency>
 140.196 +                </dependency>
 140.197 +                <dependency>
 140.198 +                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
 140.199 +                    <build-prerequisite/>
 140.200 +                    <compile-dependency/>
 140.201 +                    <run-dependency>
 140.202 +                        <release-version>1</release-version>
 140.203 +                        <specification-version>1.49.0.8</specification-version>
 140.204 +                    </run-dependency>
 140.205 +                </dependency>
 140.206 +                <dependency>
 140.207 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
 140.208 +                    <build-prerequisite/>
 140.209 +                    <compile-dependency/>
 140.210 +                    <run-dependency>
 140.211 +                        <release-version>1</release-version>
 140.212 +                        <specification-version>1.21</specification-version>
 140.213 +                    </run-dependency>
 140.214 +                </dependency>
 140.215 +                <dependency>
 140.216 +                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
 140.217 +                    <build-prerequisite/>
 140.218 +                    <compile-dependency/>
 140.219 +                    <run-dependency>
 140.220 +                        <release-version>0-1</release-version>
 140.221 +                        <specification-version>1.16.0.7.5</specification-version>
 140.222 +                    </run-dependency>
 140.223 +                </dependency>
 140.224 +                <dependency>
 140.225 +                    <code-name-base>org.openide.actions</code-name-base>
 140.226 +                    <build-prerequisite/>
 140.227 +                    <compile-dependency/>
 140.228 +                    <run-dependency>
 140.229 +                        <specification-version>6.19</specification-version>
 140.230 +                    </run-dependency>
 140.231 +                </dependency>
 140.232 +                <dependency>
 140.233 +                    <code-name-base>org.openide.awt</code-name-base>
 140.234 +                    <build-prerequisite/>
 140.235 +                    <compile-dependency/>
 140.236 +                    <run-dependency>
 140.237 +                        <specification-version>7.29</specification-version>
 140.238 +                    </run-dependency>
 140.239 +                </dependency>
 140.240 +                <dependency>
 140.241 +                    <code-name-base>org.openide.dialogs</code-name-base>
 140.242 +                    <build-prerequisite/>
 140.243 +                    <compile-dependency/>
 140.244 +                    <run-dependency>
 140.245 +                        <specification-version>7.17</specification-version>
 140.246 +                    </run-dependency>
 140.247 +                </dependency>
 140.248 +                <dependency>
 140.249 +                    <code-name-base>org.openide.filesystems</code-name-base>
 140.250 +                    <build-prerequisite/>
 140.251 +                    <compile-dependency/>
 140.252 +                    <run-dependency>
 140.253 +                        <specification-version>7.43</specification-version>
 140.254 +                    </run-dependency>
 140.255 +                </dependency>
 140.256 +                <dependency>
 140.257 +                    <code-name-base>org.openide.loaders</code-name-base>
 140.258 +                    <build-prerequisite/>
 140.259 +                    <compile-dependency/>
 140.260 +                    <run-dependency>
 140.261 +                        <specification-version>7.19</specification-version>
 140.262 +                    </run-dependency>
 140.263 +                </dependency>
 140.264 +                <dependency>
 140.265 +                    <code-name-base>org.openide.nodes</code-name-base>
 140.266 +                    <build-prerequisite/>
 140.267 +                    <compile-dependency/>
 140.268 +                    <run-dependency>
 140.269 +                        <specification-version>7.19</specification-version>
 140.270 +                    </run-dependency>
 140.271 +                </dependency>
 140.272 +                <dependency>
 140.273 +                    <code-name-base>org.openide.text</code-name-base>
 140.274 +                    <build-prerequisite/>
 140.275 +                    <compile-dependency/>
 140.276 +                    <run-dependency>
 140.277 +                        <specification-version>6.34</specification-version>
 140.278 +                    </run-dependency>
 140.279 +                </dependency>
 140.280 +                <dependency>
 140.281 +                    <code-name-base>org.openide.util</code-name-base>
 140.282 +                    <build-prerequisite/>
 140.283 +                    <compile-dependency/>
 140.284 +                    <run-dependency>
 140.285 +                        <specification-version>8.9</specification-version>
 140.286 +                    </run-dependency>
 140.287 +                </dependency>
 140.288 +                <dependency>
 140.289 +                    <code-name-base>org.openide.util.lookup</code-name-base>
 140.290 +                    <build-prerequisite/>
 140.291 +                    <compile-dependency/>
 140.292 +                    <run-dependency>
 140.293 +                        <specification-version>8.5</specification-version>
 140.294 +                    </run-dependency>
 140.295 +                </dependency>
 140.296 +                <dependency>
 140.297 +                    <code-name-base>org.openide.windows</code-name-base>
 140.298 +                    <build-prerequisite/>
 140.299 +                    <compile-dependency/>
 140.300 +                    <run-dependency>
 140.301 +                        <specification-version>6.37</specification-version>
 140.302 +                    </run-dependency>
 140.303 +                </dependency>
 140.304 +                <dependency>
 140.305 +                    <code-name-base>org.openidex.util</code-name-base>
 140.306 +                    <build-prerequisite/>
 140.307 +                    <compile-dependency/>
 140.308 +                    <run-dependency>
 140.309 +                        <release-version>3</release-version>
 140.310 +                        <specification-version>3.27</specification-version>
 140.311 +                    </run-dependency>
 140.312 +                </dependency>
 140.313 +            </module-dependencies>
 140.314 +            <test-dependencies>
 140.315 +                <test-type>
 140.316 +                    <name>unit</name>
 140.317 +                    <test-dependency>
 140.318 +                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
 140.319 +                        <compile-dependency/>
 140.320 +                    </test-dependency>
 140.321 +                    <test-dependency>
 140.322 +                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
 140.323 +                        <recursive/>
 140.324 +                        <compile-dependency/>
 140.325 +                    </test-dependency>
 140.326 +                </test-type>
 140.327 +            </test-dependencies>
 140.328 +            <public-packages/>
 140.329 +        </data>
 140.330 +    </configuration>
 140.331 +</project>
   141.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   141.2 +++ b/remoting/common/borrowedtests/nbproject/suite.properties	Sat Feb 11 18:35:10 2012 +0100
   141.3 @@ -0,0 +1,1 @@
   141.4 +suite.dir=${basedir}/..
   142.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   142.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java	Sat Feb 11 18:35:10 2012 +0100
   142.3 @@ -0,0 +1,441 @@
   142.4 +/*
   142.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   142.6 + *
   142.7 + * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
   142.8 + *
   142.9 + * The contents of this file are subject to the terms of either the GNU
  142.10 + * General Public License Version 2 only ("GPL") or the Common
  142.11 + * Development and Distribution License("CDDL") (collectively, the
  142.12 + * "License"). You may not use this file except in compliance with the
  142.13 + * License. You can obtain a copy of the License at
  142.14 + * http://www.netbeans.org/cddl-gplv2.html
  142.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  142.16 + * specific language governing permissions and limitations under the
  142.17 + * License.  When distributing the software, include this License Header
  142.18 + * Notice in each file and include the License file at
  142.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  142.20 + * particular file as subject to the "Classpath" exception as provided
  142.21 + * by Sun in the GPL Version 2 section of the License file that
  142.22 + * accompanied this code. If applicable, add the following below the
  142.23 + * License Header, with the fields enclosed by brackets [] replaced by
  142.24 + * your own identifying information:
  142.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  142.26 + *
  142.27 + * Contributor(s):
  142.28 + *
  142.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  142.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  142.31 + * Microsystems, Inc. All Rights Reserved.
  142.32 + *
  142.33 + * If you wish your version of this file to be governed by only the CDDL
  142.34 + * or only the GPL Version 2, indicate your decision by adding
  142.35 + * "[Contributor] elects to include this software in this distribution
  142.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  142.37 + * single choice of license, a recipient has the option to distribute
  142.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  142.39 + * to extend the choice of license to its licensees as provided above.
  142.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  142.41 + * Version 2 license, then the option applies only if the new code is
  142.42 + * made subject to such option by the copyright holder.
  142.43 + */
  142.44 +package org.netbeans.api.java.source;
  142.45 +
  142.46 +import com.sun.source.util.JavacTask;
  142.47 +import java.beans.PropertyVetoException;
  142.48 +import java.io.File;
  142.49 +import java.io.IOException;
  142.50 +import java.net.URL;
  142.51 +import java.util.ArrayList;
  142.52 +import java.util.Enumeration;
  142.53 +import java.util.HashSet;
  142.54 +import java.util.LinkedList;
  142.55 +import java.util.List;
  142.56 +import java.util.Map;
  142.57 +import java.util.Set;
  142.58 +import java.util.WeakHashMap;
  142.59 +import java.util.logging.Logger;
  142.60 +import java.util.logging.Level;
  142.61 +import java.util.regex.Pattern;
  142.62 +import javax.swing.event.ChangeListener;
  142.63 +import junit.framework.Assert;
  142.64 +import org.netbeans.api.editor.mimelookup.MimePath;
  142.65 +import org.netbeans.api.java.classpath.ClassPath;
  142.66 +import org.netbeans.api.java.queries.SourceForBinaryQuery;
  142.67 +import org.netbeans.api.java.source.JavaSource.Phase;
  142.68 +import org.netbeans.junit.NbTestCase;
  142.69 +import org.netbeans.modules.java.JavaDataLoader;
  142.70 +import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
  142.71 +import org.netbeans.modules.java.source.parsing.JavacParser;
  142.72 +import org.netbeans.modules.java.source.parsing.JavacParserFactory;
  142.73 +import org.netbeans.modules.java.source.usages.IndexUtil;
  142.74 +import org.netbeans.modules.parsing.api.indexing.IndexingManager;
  142.75 +import org.netbeans.modules.parsing.impl.indexing.MimeTypes;
  142.76 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
  142.77 +import org.netbeans.spi.java.classpath.ClassPathProvider;
  142.78 +import org.netbeans.spi.java.classpath.support.ClassPathSupport;
  142.79 +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
  142.80 +import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
  142.81 +import org.openide.filesystems.FileObject;
  142.82 +import org.openide.filesystems.FileStateInvalidException;
  142.83 +import org.openide.filesystems.FileSystem;
  142.84 +import org.openide.filesystems.FileUtil;
  142.85 +import org.openide.filesystems.LocalFileSystem;
  142.86 +import org.openide.filesystems.MIMEResolver;
  142.87 +import org.openide.filesystems.MultiFileSystem;
  142.88 +import org.openide.filesystems.Repository;
  142.89 +import org.openide.filesystems.URLMapper;
  142.90 +import org.openide.filesystems.XMLFileSystem;
  142.91 +import org.openide.util.Lookup;
  142.92 +import org.openide.util.lookup.Lookups;
  142.93 +import org.openide.util.lookup.ProxyLookup;
  142.94 +import org.openide.util.lookup.ServiceProvider;
  142.95 +import org.xml.sax.SAXException;
  142.96 +
  142.97 +/**
  142.98 + *
  142.99 + * @author Jan Lahoda
 142.100 + */
 142.101 +public final class SourceUtilsTestUtil extends ProxyLookup {
 142.102 +    
 142.103 +    private static SourceUtilsTestUtil DEFAULT_LOOKUP = null;
 142.104 +    
 142.105 +    public SourceUtilsTestUtil() {
 142.106 +//        Assert.assertNull(DEFAULT_LOOKUP);
 142.107 +        DEFAULT_LOOKUP = this;
 142.108 +    }
 142.109 +    
 142.110 +    /**
 142.111 +     * Set the global default lookup with some fixed instances including META-INF/services/*.
 142.112 +     */
 142.113 +    /**
 142.114 +     * Set the global default lookup with some fixed instances including META-INF/services/*.
 142.115 +     */
 142.116 +    public static void setLookup(Object[] instances, ClassLoader cl) {
 142.117 +        DEFAULT_LOOKUP.setLookups(new Lookup[] {
 142.118 +            Lookups.fixed(instances),
 142.119 +            Lookups.metaInfServices(cl),
 142.120 +            Lookups.singleton(cl),
 142.121 +        });
 142.122 +    }
 142.123 +    
 142.124 +    private static Object[] extraLookupContent = null;
 142.125 +    
 142.126 +    public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
 142.127 +        List<URL> layers = new LinkedList<URL>();
 142.128 +        
 142.129 +        for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
 142.130 +            boolean found = false;
 142.131 +
 142.132 +            for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(additionalLayers[cntr]); en.hasMoreElements(); ) {
 142.133 +                found = true;
 142.134 +                layers.add(en.nextElement());
 142.135 +            }
 142.136 +
 142.137 +            Assert.assertTrue(additionalLayers[cntr], found);
 142.138 +        }
 142.139 +        
 142.140 +        XMLFileSystem xmlFS = new XMLFileSystem();
 142.141 +        xmlFS.setXmlUrls(layers.toArray(new URL[0]));
 142.142 +        
 142.143 +        FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});
 142.144 +        
 142.145 +        Repository repository = new Repository(system);
 142.146 +        extraLookupContent = new Object[additionalLookupContent.length + 1];
 142.147 +        
 142.148 +        System.arraycopy(additionalLookupContent, 0, extraLookupContent, 1, additionalLookupContent.length);
 142.149 +        
 142.150 +        extraLookupContent[0] = repository;
 142.151 +        
 142.152 +        SourceUtilsTestUtil.setLookup(extraLookupContent, SourceUtilsTestUtil.class.getClassLoader());
 142.153 +        
 142.154 +        SourceUtilsTestUtil2.disableLocks();
 142.155 +
 142.156 +        Set<String> mimeTypes = MimeTypes.getAllMimeTypes();
 142.157 +
 142.158 +        if (mimeTypes == null) {
 142.159 +            mimeTypes = new HashSet<String>();
 142.160 +        } else {
 142.161 +            mimeTypes = new HashSet<String>(mimeTypes);
 142.162 +        }
 142.163 +
 142.164 +        mimeTypes.add("text/x-java");
 142.165 +
 142.166 +        MimeTypes.setAllMimeTypes(mimeTypes);
 142.167 +        org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
 142.168 +    }
 142.169 +    
 142.170 +    static {
 142.171 +        SourceUtilsTestUtil.class.getClassLoader().setDefaultAssertionStatus(true);
 142.172 +        System.setProperty("org.openide.util.Lookup", SourceUtilsTestUtil.class.getName());
 142.173 +        Assert.assertEquals(SourceUtilsTestUtil.class, Lookup.getDefault().getClass());
 142.174 +    }
 142.175 +    
 142.176 +    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache) throws Exception {
 142.177 +        prepareTest(sourceRoot, buildRoot, cache, new FileObject[0]);
 142.178 +    }
 142.179 +    
 142.180 +    public static void prepareTest(FileObject sourceRoot, FileObject buildRoot, FileObject cache, FileObject[] classPathElements) throws Exception {
 142.181 +        if (extraLookupContent == null)
 142.182 +            prepareTest(new String[0], new Object[0]);
 142.183 +        
 142.184 +        Object[] lookupContent = new Object[extraLookupContent.length + 4];
 142.185 +        
 142.186 +        System.arraycopy(extraLookupContent, 0, lookupContent, 4, extraLookupContent.length);
 142.187 +        
 142.188 +        lookupContent[0] = new TestProxyClassPathProvider(sourceRoot, buildRoot, classPathElements);
 142.189 +        lookupContent[1] = new TestSourceForBinaryQuery(sourceRoot, buildRoot);
 142.190 +        lookupContent[2] = new TestSourceLevelQueryImplementation();
 142.191 +        lookupContent[3] = JavaDataLoader.findObject(JavaDataLoader.class, true);
 142.192 +        
 142.193 +        setLookup(lookupContent, SourceUtilsTestUtil.class.getClassLoader());
 142.194 +
 142.195 +        IndexUtil.setCacheFolder(FileUtil.toFile(cache));
 142.196 +    }
 142.197 +
 142.198 +    private static Map<FileObject,  String> file2SourceLevel = new WeakHashMap<FileObject, String>();
 142.199 +    
 142.200 +    public static void setSourceLevel(FileObject file, String level) {
 142.201 +        file2SourceLevel.put(file, level);
 142.202 +    }
 142.203 +
 142.204 +    /**This method assures that all java classes under sourceRoot are compiled,
 142.205 +     * and the caches are created for them.
 142.206 +     */
 142.207 +    public static void compileRecursively(FileObject sourceRoot) throws Exception {
 142.208 +        IndexingManager.getDefault().refreshIndexAndWait(sourceRoot.getURL(), null);
 142.209 +    }
 142.210 +
 142.211 +    private static List<URL> bootClassPath;
 142.212 +
 142.213 +    private static Logger log = Logger.getLogger(SourceUtilsTestUtil.class.getName());
 142.214 +    
 142.215 +    public static synchronized List<URL> getBootClassPath() {
 142.216 +        if (bootClassPath == null) {
 142.217 +            try {
 142.218 +                String cp = System.getProperty("sun.boot.class.path");
 142.219 +                List<URL> urls = new ArrayList<URL>();
 142.220 +                String[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
 142.221 +                
 142.222 +                for (String path : paths) {
 142.223 +                    File f = new File(path);
 142.224 +                    
 142.225 +                    if (!f.canRead())
 142.226 +                        continue;
 142.227 +                    
 142.228 +                    FileObject fo = FileUtil.toFileObject(f);
 142.229 +                    
 142.230 +                    if (FileUtil.isArchiveFile(fo)) {
 142.231 +                        fo = FileUtil.getArchiveRoot(fo);
 142.232 +                    }
 142.233 +                    
 142.234 +                    if (fo != null) {
 142.235 +                        urls.add(fo.getURL());
 142.236 +                    }
 142.237 +                }
 142.238 +                
 142.239 +                bootClassPath = urls;
 142.240 +            } catch (FileStateInvalidException e) {
 142.241 +                if (log.isLoggable(Level.SEVERE))
 142.242 +                    log.log(Level.SEVERE, e.getMessage(), e);
 142.243 +            }
 142.244 +        }
 142.245 +
 142.246 +        return bootClassPath;
 142.247 +    }
 142.248 +
 142.249 +    private static class TestSourceForBinaryQuery implements SourceForBinaryQueryImplementation {
 142.250 +        
 142.251 +        private final FileObject sourceRoot;
 142.252 +        private final FileObject buildRoot;
 142.253 +        
 142.254 +        public TestSourceForBinaryQuery(FileObject sourceRoot, FileObject buildRoot) {
 142.255 +            this.sourceRoot = sourceRoot;
 142.256 +            this.buildRoot = buildRoot;
 142.257 +        }
 142.258 +        
 142.259 +        public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
 142.260 +            FileObject f = URLMapper.findFileObject(binaryRoot);
 142.261 +
 142.262 +            if (buildRoot.equals(f)) {
 142.263 +                return new SourceForBinaryQuery.Result() {
 142.264 +                    public FileObject[] getRoots() {
 142.265 +                        return new FileObject[] {
 142.266 +                            sourceRoot,
 142.267 +                        };
 142.268 +                    }
 142.269 +
 142.270 +                    public void addChangeListener(ChangeListener l) {
 142.271 +                    }
 142.272 +
 142.273 +                    public void removeChangeListener(ChangeListener l) {
 142.274 +                    }
 142.275 +                };
 142.276 +            }
 142.277 +
 142.278 +            return null;
 142.279 +        }
 142.280 +        
 142.281 +    }
 142.282 +    
 142.283 +    private static class TestProxyClassPathProvider implements ClassPathProvider {
 142.284 +        
 142.285 +        private FileObject sourceRoot;
 142.286 +        private FileObject buildRoot;
 142.287 +        private FileObject[] classPathElements;
 142.288 +        
 142.289 +        public TestProxyClassPathProvider(FileObject sourceRoot, FileObject buildRoot, FileObject[] classPathElements) {
 142.290 +            this.sourceRoot = sourceRoot;
 142.291 +            this.buildRoot = buildRoot;
 142.292 +            this.classPathElements = classPathElements;
 142.293 +        }
 142.294 +        
 142.295 +        public ClassPath findClassPath(FileObject file, String type) {
 142.296 +            try {
 142.297 +            if (ClassPath.BOOT == type) {
 142.298 +                return ClassPathSupport.createClassPath(getBootClassPath().toArray(new URL[0]));
 142.299 +            }
 142.300 +            
 142.301 +            if (ClassPath.SOURCE == type) {
 142.302 +                return ClassPathSupport.createClassPath(new FileObject[] {
 142.303 +                    sourceRoot
 142.304 +                });
 142.305 +            }
 142.306 +            
 142.307 +            if (ClassPath.COMPILE == type) {
 142.308 +                return ClassPathSupport.createClassPath(classPathElements);
 142.309 +            }
 142.310 +            
 142.311 +            if (ClassPath.EXECUTE == type) {
 142.312 +                return ClassPathSupport.createClassPath(new FileObject[] {
 142.313 +                    buildRoot
 142.314 +                });
 142.315 +            }
 142.316 +            } catch (Exception e) {
 142.317 +                e.printStackTrace();
 142.318 +            }
 142.319 +            return null;
 142.320 +        }
 142.321 +        
 142.322 +    }
 142.323 +
 142.324 +    public static class TestSourceLevelQueryImplementation implements SourceLevelQueryImplementation {
 142.325 +        
 142.326 +        public String getSourceLevel(FileObject javaFile) {
 142.327 +            String level = file2SourceLevel.get(javaFile);
 142.328 +            
 142.329 +            if (level == null) {
 142.330 +                if (javaFile.isFolder()) {
 142.331 +                    for (FileObject data : file2SourceLevel.keySet()) {
 142.332 +                        if (FileUtil.isParentOf(javaFile, data)) {
 142.333 +                            return file2SourceLevel.get(data);
 142.334 +                        }
 142.335 +                    }
 142.336 +                }
 142.337 +                return "1.5";
 142.338 +            } else
 142.339 +                return level;
 142.340 +        }
 142.341 +        
 142.342 +    }
 142.343 +
 142.344 +    /**Copied from org.netbeans.api.project.
 142.345 +     * Create a scratch directory for tests.
 142.346 +     * Will be in /tmp or whatever, and will be empty.
 142.347 +     * If you just need a java.io.File use clearWorkDir + getWorkDir.
 142.348 +     */
 142.349 +    public static FileObject makeScratchDir(NbTestCase test) throws IOException {
 142.350 +        test.clearWorkDir();
 142.351 +        File root = test.getWorkDir();
 142.352 +        assert root.isDirectory() && root.list().length == 0;
 142.353 +        FileObject fo = FileUtil.toFileObject(root);
 142.354 +        if (fo != null) {
 142.355 +            // Presumably using masterfs.
 142.356 +            return fo;
 142.357 +        } else {
 142.358 +            // For the benefit of those not using masterfs.
 142.359 +            LocalFileSystem lfs = new LocalFileSystem();
 142.360 +            try {
 142.361 +                lfs.setRootDirectory(root);
 142.362 +            } catch (PropertyVetoException e) {
 142.363 +                assert false : e;
 142.364 +            }
 142.365 +            Repository.getDefault().addFileSystem(lfs);
 142.366 +            return lfs.getRoot();
 142.367 +        }
 142.368 +    }
 142.369 +    
 142.370 +    public static JavacTask getJavacTaskFor(CompilationInfo info) {
 142.371 +        return info.impl.getJavacTask();
 142.372 +    }
 142.373 +    
 142.374 +    /** Blocking call for CompilationInfo after given phase is reached.
 142.375 +     *  @param phase to be reached
 142.376 +     *  @return CompilationInfo or null
 142.377 +     *  XXX: REMOVE ME!!!!!!!
 142.378 +     */
 142.379 +    public static CompilationInfo getCompilationInfo(JavaSource js, Phase phase ) throws IOException {        
 142.380 +        if (phase == null || phase == Phase.MODIFIED) { 
 142.381 +            throw new IllegalArgumentException (String.format("The %s is not a legal value of phase",phase));   //NOI18N
 142.382 +        }
 142.383 +        final DeadlockTask bt = new DeadlockTask(phase);
 142.384 +        js.runUserActionTask(bt,true);
 142.385 +        return bt.info;
 142.386 +    }
 142.387 +    
 142.388 +    
 142.389 +    private static class DeadlockTask implements Task<CompilationController> {
 142.390 +        
 142.391 +        private final Phase phase;
 142.392 +        private CompilationInfo info;
 142.393 +        
 142.394 +        public DeadlockTask(Phase phase) {
 142.395 +            assert phase != null;
 142.396 +            this.phase = phase;
 142.397 +        }
 142.398 +        
 142.399 +        public void run( CompilationController info ) {
 142.400 +            try {
 142.401 +                info.toPhase(this.phase);
 142.402 +                this.info = info;
 142.403 +            } catch (IOException ioe) {
 142.404 +                if (log.isLoggable(Level.SEVERE))
 142.405 +                    log.log(Level.SEVERE, ioe.getMessage(), ioe);
 142.406 +            }
 142.407 +        }                
 142.408 +        
 142.409 +    }
 142.410 +
 142.411 +    @ServiceProvider(service=MimeDataProvider.class)
 142.412 +    public static final class JavacParserProvider implements MimeDataProvider {
 142.413 +
 142.414 +        private Lookup javaLookup = Lookups.fixed(new JavacParserFactory(), new JavaCustomIndexer.Factory());
 142.415 +
 142.416 +        public Lookup getLookup(MimePath mimePath) {
 142.417 +            if (mimePath.getPath().endsWith(JavacParser.MIME_TYPE)) {
 142.418 +                return javaLookup;
 142.419 +            }
 142.420 +
 142.421 +            return Lookup.EMPTY;
 142.422 +        }
 142.423 +        
 142.424 +    }
 142.425 +
 142.426 +    @ServiceProvider(service=MIMEResolver.class)
 142.427 +    public static final class JavaMimeResolver extends MIMEResolver {
 142.428 +
 142.429 +        public JavaMimeResolver() {
 142.430 +            super(JavacParser.MIME_TYPE);
 142.431 +        }
 142.432 +
 142.433 +        @Override
 142.434 +        public String findMIMEType(FileObject fo) {
 142.435 +            if ("java".equals(fo.getExt())) {
 142.436 +                return JavacParser.MIME_TYPE;
 142.437 +            }
 142.438 +
 142.439 +            return null;
 142.440 +        }
 142.441 +
 142.442 +    }
 142.443 +    
 142.444 +}
   143.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   143.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/api/java/source/SourceUtilsTestUtil2.java	Sat Feb 11 18:35:10 2012 +0100
   143.3 @@ -0,0 +1,80 @@
   143.4 +/*
   143.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   143.6 + *
   143.7 + * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
   143.8 + *
   143.9 + * The contents of this file are subject to the terms of either the GNU
  143.10 + * General Public License Version 2 only ("GPL") or the Common
  143.11 + * Development and Distribution License("CDDL") (collectively, the
  143.12 + * "License"). You may not use this file except in compliance with the
  143.13 + * License. You can obtain a copy of the License at
  143.14 + * http://www.netbeans.org/cddl-gplv2.html
  143.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  143.16 + * specific language governing permissions and limitations under the
  143.17 + * License.  When distributing the software, include this License Header
  143.18 + * Notice in each file and include the License file at
  143.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  143.20 + * particular file as subject to the "Classpath" exception as provided
  143.21 + * by Sun in the GPL Version 2 section of the License file that
  143.22 + * accompanied this code. If applicable, add the following below the
  143.23 + * License Header, with the fields enclosed by brackets [] replaced by
  143.24 + * your own identifying information:
  143.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  143.26 + *
  143.27 + * Contributor(s):
  143.28 + *
  143.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  143.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  143.31 + * Microsystems, Inc. All Rights Reserved.
  143.32 + *
  143.33 + * If you wish your version of this file to be governed by only the CDDL
  143.34 + * or only the GPL Version 2, indicate your decision by adding
  143.35 + * "[Contributor] elects to include this software in this distribution
  143.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  143.37 + * single choice of license, a recipient has the option to distribute
  143.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  143.39 + * to extend the choice of license to its licensees as provided above.
  143.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  143.41 + * Version 2 license, then the option applies only if the new code is
  143.42 + * made subject to such option by the copyright holder.
  143.43 + */
  143.44 +package org.netbeans.api.java.source;
  143.45 +
  143.46 +import com.sun.source.tree.Tree;
  143.47 +import org.apache.lucene.store.FSDirectory;
  143.48 +import org.netbeans.modules.java.source.transform.Transformer;
  143.49 +
  143.50 +/**
  143.51 + *
  143.52 + * @author Jan Lahoda
  143.53 + */
  143.54 +public final class SourceUtilsTestUtil2 {
  143.55 +
  143.56 +    private SourceUtilsTestUtil2() {
  143.57 +    }
  143.58 +
  143.59 +    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t) {
  143.60 +//        if (afterCommit)
  143.61 +//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
  143.62 +        t.init();
  143.63 +        t.attach(wc.impl.getJavacTask().getContext(), wc);
  143.64 +        t.apply(wc.getCompilationUnit());
  143.65 +        t.release();
  143.66 +        t.destroy();
  143.67 +    }
  143.68 +    
  143.69 +    public static <R, P> void run(WorkingCopy wc, Transformer<R, P> t, Tree tree) {
  143.70 +//        if (afterCommit)
  143.71 +//            throw new IllegalStateException ("The run method can't be called on a WorkingCopy instance after the commit");   //NOI18N
  143.72 +        t.init();
  143.73 +        t.attach(wc.impl.getJavacTask().getContext(), wc);
  143.74 +        t.apply(tree);
  143.75 +        t.release();
  143.76 +        t.destroy();
  143.77 +    }
  143.78 +    
  143.79 +    public static void disableLocks() {
  143.80 +//        FSDirectory.setDisableLocks(true);
  143.81 +    }
  143.82 +    
  143.83 +}
   144.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   144.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/api/java/source/TestUtilities.java	Sat Feb 11 18:35:10 2012 +0100
   144.3 @@ -0,0 +1,263 @@
   144.4 +/*
   144.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   144.6 + *
   144.7 + * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
   144.8 + *
   144.9 + * The contents of this file are subject to the terms of either the GNU
  144.10 + * General Public License Version 2 only ("GPL") or the Common
  144.11 + * Development and Distribution License("CDDL") (collectively, the
  144.12 + * "License"). You may not use this file except in compliance with the
  144.13 + * License. You can obtain a copy of the License at
  144.14 + * http://www.netbeans.org/cddl-gplv2.html
  144.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  144.16 + * specific language governing permissions and limitations under the
  144.17 + * License.  When distributing the software, include this License Header
  144.18 + * Notice in each file and include the License file at
  144.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  144.20 + * particular file as subject to the "Classpath" exception as provided
  144.21 + * by Sun in the GPL Version 2 section of the License file that
  144.22 + * accompanied this code. If applicable, add the following below the
  144.23 + * License Header, with the fields enclosed by brackets [] replaced by
  144.24 + * your own identifying information:
  144.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  144.26 + *
  144.27 + * Contributor(s):
  144.28 + *
  144.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  144.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  144.31 + * Microsystems, Inc. All Rights Reserved.
  144.32 + *
  144.33 + * If you wish your version of this file to be governed by only the CDDL
  144.34 + * or only the GPL Version 2, indicate your decision by adding
  144.35 + * "[Contributor] elects to include this software in this distribution
  144.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  144.37 + * single choice of license, a recipient has the option to distribute
  144.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  144.39 + * to extend the choice of license to its licensees as provided above.
  144.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  144.41 + * Version 2 license, then the option applies only if the new code is
  144.42 + * made subject to such option by the copyright holder.
  144.43 + */
  144.44 +
  144.45 +package org.netbeans.api.java.source;
  144.46 +
  144.47 +import java.io.ByteArrayInputStream;
  144.48 +import java.io.EOFException;
  144.49 +import java.io.File;
  144.50 +import java.io.FileInputStream;
  144.51 +import java.io.FileOutputStream;
  144.52 +import java.io.IOException;
  144.53 +import java.io.InputStream;
  144.54 +import java.io.OutputStream;
  144.55 +import java.net.URL;
  144.56 +import java.util.ArrayList;
  144.57 +import java.util.Collection;
  144.58 +import java.util.List;
  144.59 +import java.util.concurrent.ExecutionException;
  144.60 +import java.util.concurrent.Future;
  144.61 +import java.util.concurrent.TimeUnit;
  144.62 +import java.util.concurrent.TimeoutException;
  144.63 +import java.util.concurrent.atomic.AtomicBoolean;
  144.64 +import java.util.zip.GZIPInputStream;
  144.65 +
  144.66 +import org.netbeans.api.java.classpath.ClassPath;
  144.67 +import org.netbeans.modules.java.source.usages.BinaryAnalyser;
  144.68 +import org.netbeans.modules.java.source.usages.ClassIndexImpl;
  144.69 +import org.netbeans.modules.java.source.usages.ClassIndexManager;
  144.70 +import org.netbeans.modules.java.source.usages.IndexUtil;
  144.71 +//import org.netbeans.modules.parsing.lucene.support.IndexManager.Action;
  144.72 +import org.netbeans.spi.java.classpath.support.ClassPathSupport;
  144.73 +import org.openide.filesystems.FileObject;
  144.74 +import org.openide.filesystems.FileUtil;
  144.75 +
  144.76 +/**
  144.77 + * Utilities to aid unit testing java.source module.
  144.78 + *
  144.79 + * @author Jaroslav Tulach
  144.80 + * @author Tom Ball
  144.81 + * @author Tomas Zezula
  144.82 + */
  144.83 +public final class TestUtilities {
  144.84 +    
  144.85 +    // do not instantiate
  144.86 +    private TestUtilities() {}
  144.87 +    
  144.88 +    /**
  144.89 +     * Waits for the end of the background scan, this helper method 
  144.90 +     * is designed for tests which require to wait for the end of initial scan.
  144.91 +     * The method can be used as a barrier but it is not guaranteed that the
  144.92 +     * background scan will not start again after return from this method, the
  144.93 +     * test is responsible for it itself. In general it's safer to use {@link JavaSource#runWhenScanFinished}
  144.94 +     * method and do the critical action inside the run method.
  144.95 +     * @param timeout the maximum time to wait
  144.96 +     * @param unit the time unit of the timeout argument
  144.97 +     * @return true if the scan finished, false when the timeout elapsed before the end of the scan.
  144.98 +     * @throws InterruptedException is thrown when the waiting thread is interrupted.
  144.99 +     */
 144.100 +    public static boolean waitScanFinished (final long timeout, final TimeUnit unit) throws InterruptedException {
 144.101 +        assert unit != null;
 144.102 +        final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(new URL[0]),
 144.103 +                ClassPathSupport.createClassPath(new URL[0]), null);
 144.104 +        assert cpInfo != null;
 144.105 +        final JavaSource js = JavaSource.create(cpInfo);
 144.106 +        assert js != null;
 144.107 +        try {
 144.108 +            Future<Void> future = js.runWhenScanFinished(new Task<CompilationController>() {
 144.109 +                public void run(CompilationController parameter) throws Exception {
 144.110 +                }
 144.111 +            }, true);
 144.112 +            future.get(timeout,unit);
 144.113 +            return true;
 144.114 +        } catch (IOException ioe) {
 144.115 +            //Actually never thrown
 144.116 +        }
 144.117 +        catch (ExecutionException ee) {
 144.118 +            //Actually never thrown
 144.119 +        }
 144.120 +        catch (TimeoutException timeoutEx) {
 144.121 +        }
 144.122 +        return false;
 144.123 +    }
 144.124 +    
 144.125 +//    /**
 144.126 +//     * Disables use of {@link LibraryManager} in the {@link GlobalSourcePath}. The tests
 144.127 +//     * which don't register {@link LibraryProvider} or {@link LibraryTypeProvider} may
 144.128 +//     * use this method to disable use of {@link LibraryManager} in the {@link GlobalSourcePath}.
 144.129 +//     * @param use false value disables use of {@link LibraryManager}
 144.130 +//     */
 144.131 +//    public static void setUseLibraries (final boolean use) {
 144.132 +//        //GlobalSourcePathTestUtil.setUseLibraries(use);
 144.133 +//        // IMO this in fact did nothing... If your tests are failing due to this
 144.134 +//        // please file a defect on editor/parsing & indexing and we will try to help.
 144.135 +//    }
 144.136 +    
 144.137 +    /**
 144.138 +     * Sets a root folder of the java source caches. This method may be used by tests
 144.139 +     * which need to do an initial compilation, they require either {@link ClassIndex} or
 144.140 +     * need to work with a group of related java files.
 144.141 +     * @param cacheFolder the folder used by java infrastructure as a cache,
 144.142 +     * has to exist and must be a folder.
 144.143 +     */
 144.144 +    public static void setCacheFolder (final File cacheFolder) {
 144.145 +        IndexUtil.setCacheFolder(cacheFolder);
 144.146 +    }
 144.147 +    
 144.148 +    /**
 144.149 +     * Creates boot {@link ClassPath} for platform the test is running on,
 144.150 +     * it uses the sun.boot.class.path property to find out the boot path roots.
 144.151 +     * @return ClassPath
 144.152 +     * @throws java.io.IOException when boot path property contains non valid path
 144.153 +     */
 144.154 +    public static ClassPath createBootClassPath () throws IOException {
 144.155 +        String bootPath = System.getProperty ("sun.boot.class.path");
 144.156 +        String[] paths = bootPath.split(File.pathSeparator);
 144.157 +        List<URL>roots = new ArrayList<URL> (paths.length);
 144.158 +        for (String path : paths) {
 144.159 +            File f = new File (path);            
 144.160 +            if (!f.exists()) {
 144.161 +                continue;
 144.162 +            }
 144.163 +            URL url = f.toURI().toURL();
 144.164 +            if (FileUtil.isArchiveFile(url)) {
 144.165 +                url = FileUtil.getArchiveRoot(url);
 144.166 +            }
 144.167 +            roots.add (url);
 144.168 +        }
 144.169 +        return ClassPathSupport.createClassPath(roots.toArray(new URL[roots.size()]));
 144.170 +    }
 144.171 +    /**
 144.172 +     * Returns a string which contains the contents of a file.
 144.173 +     *
 144.174 +     * @param f the file to be read
 144.175 +     * @return the contents of the file(s).
 144.176 +     */
 144.177 +    public final static String copyFileToString (java.io.File f) throws java.io.IOException {
 144.178 +        int s = (int)f.length ();
 144.179 +        byte[] data = new byte[s];
 144.180 +        int len = new FileInputStream (f).read (data);
 144.181 +        if (len != s)
 144.182 +            throw new EOFException("truncated file");
 144.183 +        return new String (data);
 144.184 +    }
 144.185 +    
 144.186 +    /**
 144.187 +     * Returns a string which contains the contents of a GZIP compressed file.
 144.188 +     *
 144.189 +     * @param f the file to be read
 144.190 +     * @return the contents of the file(s).
 144.191 +     */
 144.192 +    public final static String copyGZipFileToString (java.io.File f) throws java.io.IOException {
 144.193 +        GZIPInputStream is = new GZIPInputStream(new FileInputStream(f));
 144.194 +        byte[] arr = new byte[256 * 256];
 144.195 +        int first = 0;
 144.196 +        for(;;) {
 144.197 +            int len = is.read(arr, first, arr.length - first);
 144.198 +            if (first + len < arr.length) {
 144.199 +                return new String(arr, 0, first + len);
 144.200 +            }
 144.201 +        }
 144.202 +    }
 144.203 +    
 144.204 +    /**
 144.205 +     * Copies a string to a specified file.
 144.206 +     *
 144.207 +     * @param f the file to use.
 144.208 +     * @param content the contents of the returned file.
 144.209 +     * @return the created file
 144.210 +     */
 144.211 +    public final static File copyStringToFile (File f, String content) throws Exception {
 144.212 +        FileOutputStream os = new FileOutputStream(f);
 144.213 +        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
 144.214 +        FileUtil.copy(is, os);
 144.215 +        os.close ();
 144.216 +        is.close();
 144.217 +            
 144.218 +        return f;
 144.219 +    }
 144.220 +    
 144.221 +    /**
 144.222 +     * Copies a string to a specified file.
 144.223 +     *
 144.224 +     * @param f the {@link FilObject} to use.
 144.225 +     * @param content the contents of the returned file.
 144.226 +     * @return the created file
 144.227 +     */
 144.228 +    public final static FileObject copyStringToFile (FileObject f, String content) throws Exception {
 144.229 +        OutputStream os = f.getOutputStream();
 144.230 +        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
 144.231 +        FileUtil.copy(is, os);
 144.232 +        os.close ();
 144.233 +        is.close();
 144.234 +            
 144.235 +        return f;
 144.236 +    }   
 144.237 +
 144.238 +    private static final ClassPath EMPTY = ClassPathSupport.createClassPath(new URL[0]);
 144.239 +    
 144.240 +//    /**
 144.241 +//     * Prepare Java caches for given binary roots.
 144.242 +//     *
 144.243 +//     * @param urls to analyze
 144.244 +//     */
 144.245 +//    public final static void analyzeBinaries(final Collection<URL> urls) throws IOException {
 144.246 +//        final ClasspathInfo cpInfo = ClasspathInfo.create(EMPTY, EMPTY, EMPTY);
 144.247 +//        final ClassIndexManager mgr  = ClassIndexManager.getDefault();
 144.248 +//        final JavaSource js = JavaSource.create(cpInfo);
 144.249 +//        js.runUserActionTask(new Task<CompilationController>() {
 144.250 +//            public void run(CompilationController parameter) throws Exception {
 144.251 +//                for (final URL url : urls) {
 144.252 +//                    final ClassIndexImpl cii = mgr.createUsagesQuery(url, false);
 144.253 +//                    ClassIndexManager.getDefault().writeLock(new Action<Void>() {
 144.254 +//                        public Void run() throws IOException, InterruptedException {
 144.255 +//                            BinaryAnalyser ba = cii.getBinaryAnalyser();
 144.256 +//                            ba.start(url, new AtomicBoolean(false), new AtomicBoolean(false));
 144.257 +//                            ba.finish();
 144.258 +//                            return null;
 144.259 +//                        }
 144.260 +//                    });
 144.261 +//                }
 144.262 +//            }
 144.263 +//        }, true);
 144.264 +//    }
 144.265 +    
 144.266 +}
   145.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   145.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/jackpot30/impl/TestUtils.java	Sat Feb 11 18:35:10 2012 +0100
   145.3 @@ -0,0 +1,116 @@
   145.4 +/*
   145.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   145.6 + *
   145.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   145.8 + *
   145.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  145.10 + * Other names may be trademarks of their respective owners.
  145.11 + *
  145.12 + * The contents of this file are subject to the terms of either the GNU
  145.13 + * General Public License Version 2 only ("GPL") or the Common
  145.14 + * Development and Distribution License("CDDL") (collectively, the
  145.15 + * "License"). You may not use this file except in compliance with the
  145.16 + * License. You can obtain a copy of the License at
  145.17 + * http://www.netbeans.org/cddl-gplv2.html
  145.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  145.19 + * specific language governing permissions and limitations under the
  145.20 + * License.  When distributing the software, include this License Header
  145.21 + * Notice in each file and include the License file at
  145.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  145.23 + * particular file as subject to the "Classpath" exception as provided
  145.24 + * by Oracle in the GPL Version 2 section of the License file that
  145.25 + * accompanied this code. If applicable, add the following below the
  145.26 + * License Header, with the fields enclosed by brackets [] replaced by
  145.27 + * your own identifying information:
  145.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  145.29 + *
  145.30 + * If you wish your version of this file to be governed by only the CDDL
  145.31 + * or only the GPL Version 2, indicate your decision by adding
  145.32 + * "[Contributor] elects to include this software in this distribution
  145.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  145.34 + * single choice of license, a recipient has the option to distribute
  145.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  145.36 + * to extend the choice of license to its licensees as provided above.
  145.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  145.38 + * Version 2 license, then the option applies only if the new code is
  145.39 + * made subject to such option by the copyright holder.
  145.40 + *
  145.41 + * Contributor(s):
  145.42 + *
  145.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
  145.44 + */
  145.45 +package org.netbeans.modules.jackpot30.impl;
  145.46 +
  145.47 +import java.io.ByteArrayInputStream;
  145.48 +import java.io.IOException;
  145.49 +import java.net.URL;
  145.50 +import java.net.URLConnection;
  145.51 +import java.net.URLStreamHandler;
  145.52 +import java.net.URLStreamHandlerFactory;
  145.53 +import java.util.HashMap;
  145.54 +import java.util.Map;
  145.55 +import junit.framework.Assert;
  145.56 +import org.openide.util.lookup.ServiceProvider;
  145.57 +
  145.58 +/**
  145.59 + *
  145.60 + * @author lahvac
  145.61 + */
  145.62 +public class TestUtils {
  145.63 +
  145.64 +    public static void clearRemoteContent() {
  145.65 +        content.clear();
  145.66 +    }
  145.67 +
  145.68 +    public static void addRemoteContent(URL url, String content) {
  145.69 +        TestUtils.content.put(url, content);
  145.70 +    }
  145.71 +
  145.72 +    private static final Map<URL, String> content = new HashMap<URL, String>();
  145.73 +
  145.74 +    @ServiceProvider(service=URLStreamHandlerFactory.class)
  145.75 +    public static final class URLStreamHandlerFactoryImpl implements URLStreamHandlerFactory {
  145.76 +
  145.77 +        public URLStreamHandler createURLStreamHandler(String protocol) {
  145.78 +            if ("test".equals(protocol)) {
  145.79 +                return new URLStreamHandlerImpl();
  145.80 +            }
  145.81 +
  145.82 +            return null;
  145.83 +        }
  145.84 +
  145.85 +    }
  145.86 +
  145.87 +    private static final class URLStreamHandlerImpl extends URLStreamHandler {
  145.88 +
  145.89 +        @Override
  145.90 +        protected URLConnection openConnection(URL u) throws IOException {
  145.91 +            String str = content.get(u);
  145.92 +
  145.93 +            Assert.assertNotNull(u.toExternalForm(), str);
  145.94 +
  145.95 +            return new TestURLConnection(u, str);
  145.96 +        }
  145.97 +
  145.98 +    }
  145.99 +
 145.100 +    private static final class TestURLConnection extends URLConnection {
 145.101 +
 145.102 +        private final String content;
 145.103 +
 145.104 +        public TestURLConnection(URL url, String content) {
 145.105 +            super(url);
 145.106 +            this.content = content;
 145.107 +        }
 145.108 +
 145.109 +        @Override
 145.110 +        public void connect() throws IOException {
 145.111 +        }
 145.112 +
 145.113 +        @Override
 145.114 +        public Object getContent() throws IOException {
 145.115 +            return new ByteArrayInputStream(content.getBytes("ASCII")); //XXX
 145.116 +        }
 145.117 +
 145.118 +    }
 145.119 +}
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/jackpot30/test/borrowed/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
   146.3 @@ -0,0 +1,38 @@
   146.4 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   146.5 +#
   146.6 +# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
   146.7 +#
   146.8 +# The contents of this file are subject to the terms of either the GNU
   146.9 +# General Public License Version 2 only ("GPL") or the Common
  146.10 +# Development and Distribution License("CDDL") (collectively, the
  146.11 +# "License"). You may not use this file except in compliance with the
  146.12 +# License. You can obtain a copy of the License at
  146.13 +# http://www.netbeans.org/cddl-gplv2.html
  146.14 +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  146.15 +# specific language governing permissions and limitations under the
  146.16 +# License.  When distributing the software, include this License Header
  146.17 +# Notice in each file and include the License file at
  146.18 +# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  146.19 +# particular file as subject to the "Classpath" exception as provided
  146.20 +# by Sun in the GPL Version 2 section of the License file that
  146.21 +# accompanied this code. If applicable, add the following below the
  146.22 +# License Header, with the fields enclosed by brackets [] replaced by
  146.23 +# your own identifying information:
  146.24 +# "Portions Copyrighted [year] [name of copyright owner]"
  146.25 +#
  146.26 +# If you wish your version of this file to be governed by only the CDDL
  146.27 +# or only the GPL Version 2, indicate your decision by adding
  146.28 +# "[Contributor] elects to include this software in this distribution
  146.29 +# under the [CDDL or GPL Version 2] license." If you do not indicate a
  146.30 +# single choice of license, a recipient has the option to distribute
  146.31 +# your version of this file under either the CDDL, the GPL Version 2 or
  146.32 +# to extend the choice of license to its licensees as provided above.
  146.33 +# However, if you add GPL Version 2 code and therefore, elected the GPL
  146.34 +# Version 2 license, then the option applies only if the new code is
  146.35 +# made subject to such option by the copyright holder.
  146.36 +#
  146.37 +# Contributor(s):
  146.38 +#
  146.39 +# Portions Copyrighted 2009 Sun Microsystems, Inc.
  146.40 +
  146.41 +OpenIDE-Module-Name=Borrowed Test Infra
   147.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   147.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/TestUtilities.java	Sat Feb 11 18:35:10 2012 +0100
   147.3 @@ -0,0 +1,60 @@
   147.4 +/*
   147.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   147.6 + *
   147.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   147.8 + *
   147.9 + * The contents of this file are subject to the terms of either the GNU
  147.10 + * General Public License Version 2 only ("GPL") or the Common
  147.11 + * Development and Distribution License("CDDL") (collectively, the
  147.12 + * "License"). You may not use this file except in compliance with the
  147.13 + * License. You can obtain a copy of the License at
  147.14 + * http://www.netbeans.org/cddl-gplv2.html
  147.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  147.16 + * specific language governing permissions and limitations under the
  147.17 + * License.  When distributing the software, include this License Header
  147.18 + * Notice in each file and include the License file at
  147.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  147.20 + * particular file as subject to the "Classpath" exception as provided
  147.21 + * by Sun in the GPL Version 2 section of the License file that
  147.22 + * accompanied this code. If applicable, add the following below the
  147.23 + * License Header, with the fields enclosed by brackets [] replaced by
  147.24 + * your own identifying information:
  147.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  147.26 + *
  147.27 + * Contributor(s):
  147.28 + *
  147.29 + * Portions Copyrighted 2007 Sun Microsystems, Inc.
  147.30 + */
  147.31 +package org.netbeans.modules.java.hints;
  147.32 +
  147.33 +import junit.framework.Assert;
  147.34 +
  147.35 +/**
  147.36 + *
  147.37 + * @author Jan Lahoda
  147.38 + */
  147.39 +public class TestUtilities {
  147.40 +
  147.41 +    private TestUtilities() {
  147.42 +    }
  147.43 +
  147.44 +    public static String detectOffsets(String source, int[] positionOrSpan) {
  147.45 +        //for now, the position/span delimiter is '|', without possibility of escaping:
  147.46 +        String[] split = source.split("\\|");
  147.47 +        
  147.48 +        Assert.assertTrue("incorrect number of position markers (|)", positionOrSpan.length == split.length - 1);
  147.49 +        
  147.50 +        StringBuilder sb = new StringBuilder();
  147.51 +        int index = 0;
  147.52 +        int offset = 0;
  147.53 +        
  147.54 +        for (String s : split) {
  147.55 +            sb.append(s);
  147.56 +            if (index < positionOrSpan.length)
  147.57 +                positionOrSpan[index++] = (offset += s.length());
  147.58 +        }
  147.59 +        
  147.60 +        return sb.toString();
  147.61 +    }
  147.62 +
  147.63 +}
   148.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/infrastructure/TreeRuleTestBase.java	Sat Feb 11 18:35:10 2012 +0100
   148.3 @@ -0,0 +1,303 @@
   148.4 +/*
   148.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   148.6 + *
   148.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   148.8 + *
   148.9 + * The contents of this file are subject to the terms of either the GNU
  148.10 + * General Public License Version 2 only ("GPL") or the Common
  148.11 + * Development and Distribution License("CDDL") (collectively, the
  148.12 + * "License"). You may not use this file except in compliance with the
  148.13 + * License. You can obtain a copy of the License at
  148.14 + * http://www.netbeans.org/cddl-gplv2.html
  148.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  148.16 + * specific language governing permissions and limitations under the
  148.17 + * License.  When distributing the software, include this License Header
  148.18 + * Notice in each file and include the License file at
  148.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  148.20 + * particular file as subject to the "Classpath" exception as provided
  148.21 + * by Sun in the GPL Version 2 section of the License file that
  148.22 + * accompanied this code. If applicable, add the following below the
  148.23 + * License Header, with the fields enclosed by brackets [] replaced by
  148.24 + * your own identifying information:
  148.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  148.26 + *
  148.27 + * Contributor(s):
  148.28 + *
  148.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  148.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  148.31 + * Microsystems, Inc. All Rights Reserved.
  148.32 + *
  148.33 + * If you wish your version of this file to be governed by only the CDDL
  148.34 + * or only the GPL Version 2, indicate your decision by adding
  148.35 + * "[Contributor] elects to include this software in this distribution
  148.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  148.37 + * single choice of license, a recipient has the option to distribute
  148.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  148.39 + * to extend the choice of license to its licensees as provided above.
  148.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  148.41 + * Version 2 license, then the option applies only if the new code is
  148.42 + * made subject to such option by the copyright holder.
  148.43 + */
  148.44 +package org.netbeans.modules.java.hints.infrastructure;
  148.45 +
  148.46 +import com.sun.source.util.TreePath;
  148.47 +import java.io.File;
  148.48 +import java.util.Arrays;
  148.49 +import java.util.Collections;
  148.50 +import java.util.LinkedList;
  148.51 +import java.util.List;
  148.52 +import java.util.logging.Level;
  148.53 +import java.util.logging.Logger;
  148.54 +import javax.swing.text.Document;
  148.55 +import org.netbeans.api.java.lexer.JavaTokenId;
  148.56 +import org.netbeans.api.java.source.CompilationInfo;
  148.57 +import org.netbeans.api.java.source.JavaSource;
  148.58 +import org.netbeans.api.java.source.JavaSource.Phase;
  148.59 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
  148.60 +import org.netbeans.api.java.source.TestUtilities;
  148.61 +import org.netbeans.api.lexer.Language;
  148.62 +import org.netbeans.junit.NbTestCase;
  148.63 +import org.netbeans.modules.java.source.TreeLoader;
  148.64 +import org.netbeans.spi.editor.hints.ErrorDescription;
  148.65 +import org.netbeans.spi.editor.hints.Fix;
  148.66 +import org.openide.LifecycleManager;
  148.67 +import org.openide.cookies.EditorCookie;
  148.68 +import org.openide.filesystems.FileObject;
  148.69 +import org.openide.filesystems.FileUtil;
  148.70 +import org.openide.loaders.DataObject;
  148.71 +
  148.72 +/**
  148.73 + * @author Jan Lahoda
  148.74 + */
  148.75 +public abstract class TreeRuleTestBase extends NbTestCase {
  148.76 +    protected final Logger LOG;
  148.77 +    
  148.78 +    public TreeRuleTestBase(String name) {
  148.79 +        super(name);
  148.80 +        LOG = Logger.getLogger("test." + name);
  148.81 +    }
  148.82 +    
  148.83 +    @Override
  148.84 +    protected Level logLevel() {
  148.85 +        return Level.INFO;
  148.86 +    }
  148.87 +
  148.88 +    @Override
  148.89 +    protected void setUp() throws Exception {
  148.90 +        super.setUp();
  148.91 +        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[0]);
  148.92 +        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
  148.93 +    }
  148.94 +
  148.95 +    private void prepareTest(String fileName, String code) throws Exception {
  148.96 +        clearWorkDir();
  148.97 +        File wdFile = getWorkDir();
  148.98 +        FileUtil.refreshFor(wdFile);
  148.99 +
 148.100 +        FileObject wd = FileUtil.toFileObject(wdFile);
 148.101 +        assertNotNull(wd);
 148.102 +        sourceRoot = FileUtil.createFolder(wd, "src");
 148.103 +        FileObject buildRoot = FileUtil.createFolder(wd, "build");
 148.104 +        FileObject cache = FileUtil.createFolder(wd, "cache");
 148.105 +
 148.106 +        FileObject data = FileUtil.createData(sourceRoot, fileName);
 148.107 +        File dataFile = FileUtil.toFile(data);
 148.108 +        
 148.109 +        assertNotNull(dataFile);
 148.110 +        
 148.111 +        TestUtilities.copyStringToFile(dataFile, code);
 148.112 +        
 148.113 +        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache, extraClassPath());
 148.114 +        
 148.115 +        DataObject od = DataObject.find(data);
 148.116 +        EditorCookie ec = od.getCookie(EditorCookie.class);
 148.117 +        
 148.118 +        assertNotNull(ec);
 148.119 +        
 148.120 +        doc = ec.openDocument();
 148.121 +        doc.putProperty(Language.class, JavaTokenId.language());
 148.122 +        doc.putProperty("mimeType", "text/x-java");
 148.123 +        
 148.124 +        JavaSource js = JavaSource.forFileObject(data);
 148.125 +        
 148.126 +        assertNotNull(js);
 148.127 +        
 148.128 +        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
 148.129 +        
 148.130 +        assertNotNull(info);
 148.131 +    }
 148.132 +    
 148.133 +    private FileObject sourceRoot;
 148.134 +    private CompilationInfo info;
 148.135 +    private Document doc;
 148.136 +    
 148.137 +    protected abstract List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path);
 148.138 +    
 148.139 +    protected List<ErrorDescription> computeErrors(CompilationInfo info, TreePath path, int offset) {
 148.140 +        return computeErrors(info, path);
 148.141 +    }
 148.142 +    
 148.143 +    protected String toDebugString(CompilationInfo info, Fix f) {
 148.144 +        return f.toString();
 148.145 +    }
 148.146 +    
 148.147 +    protected void performAnalysisTest(String fileName, String code, String... golden) throws Exception {
 148.148 +        int[] offset = new int[1];
 148.149 +        
 148.150 +        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
 148.151 +        
 148.152 +        performAnalysisTest(fileName, code, offset[0], golden);
 148.153 +    }
 148.154 +    
 148.155 +    protected void performAnalysisTest(String fileName, String code, int pos, String... golden) throws Exception {
 148.156 +        prepareTest(fileName, code);
 148.157 +        
 148.158 +        TreePath path = info.getTreeUtilities().pathFor(pos);
 148.159 +        
 148.160 +        List<ErrorDescription> errors = computeErrors(info, path, pos);
 148.161 +        List<String> errorsNames = new LinkedList<String>();
 148.162 +        
 148.163 +        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
 148.164 +        
 148.165 +        for (ErrorDescription e : errors) {
 148.166 +            errorsNames.add(e.toString());
 148.167 +        }
 148.168 +        
 148.169 +        assertTrue("The warnings provided by the hint do not match expected warnings. Provided warnings: " + errorsNames.toString(), Arrays.equals(golden, errorsNames.toArray(new String[0])));
 148.170 +    }
 148.171 +    
 148.172 +    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
 148.173 +        int[] offset = new int[1];
 148.174 +
 148.175 +        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
 148.176 +        
 148.177 +        return performFixTest(fileName, code, offset[0], errorDescriptionToString, fixDebugString, golden);
 148.178 +    }
 148.179 +    
 148.180 +    protected String performFixTest(String fileName, String code, int pos, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
 148.181 +        return performFixTest(fileName, code, pos, errorDescriptionToString, fixDebugString, fileName, golden);
 148.182 +    }
 148.183 +    
 148.184 +    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
 148.185 +        int[] offset = new int[1];
 148.186 +
 148.187 +        code = org.netbeans.modules.java.hints.TestUtilities.detectOffsets(code, offset);
 148.188 +
 148.189 +        return performFixTest(fileName, code, offset[0], errorDescriptionToString, fixDebugString, goldenFileName, golden);
 148.190 +    }
 148.191 +    
 148.192 +    protected String performFixTest(String fileName, String code, int pos, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
 148.193 +        prepareTest(fileName, code);
 148.194 +        
 148.195 +        TreePath path = info.getTreeUtilities().pathFor(pos);
 148.196 +        
 148.197 +        List<ErrorDescription> errors = computeErrors(info, path, pos);
 148.198 +        
 148.199 +        ErrorDescription toFix = null;
 148.200 +        
 148.201 +        for (ErrorDescription d : errors) {
 148.202 +            if (errorDescriptionToString.equals(d.toString())) {
 148.203 +                toFix = d;
 148.204 +                break;
 148.205 +            }
 148.206 +        }
 148.207 +        
 148.208 +        assertNotNull("Error: \"" + errorDescriptionToString + "\" not found. All ErrorDescriptions: " + errors.toString(), toFix);
 148.209 +        
 148.210 +        assertTrue("Must be computed", toFix.getFixes().isComputed());
 148.211 +        
 148.212 +        List<Fix> fixes = toFix.getFixes().getFixes();
 148.213 +        List<String> fixNames = new LinkedList<String>();
 148.214 +        Fix toApply = null;
 148.215 +        
 148.216 +        for (Fix f : fixes) {
 148.217 +            if (fixDebugString.equals(toDebugString(info, f))) {
 148.218 +                toApply = f;
 148.219 +            }
 148.220 +            
 148.221 +            fixNames.add(toDebugString(info, f));
 148.222 +        }
 148.223 +        
 148.224 +        assertNotNull("Cannot find fix to invoke: " + fixNames.toString(), toApply);
 148.225 +        
 148.226 +        toApply.implement();
 148.227 +        
 148.228 +        FileObject toCheck = sourceRoot.getFileObject(goldenFileName);
 148.229 +        
 148.230 +        assertNotNull(toCheck);
 148.231 +        
 148.232 +        DataObject toCheckDO = DataObject.find(toCheck);
 148.233 +        EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
 148.234 +        Document toCheckDocument = ec.openDocument();
 148.235 +        
 148.236 +        String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());
 148.237 +        
 148.238 +        //ignore whitespaces:
 148.239 +        realCode = realCode.replaceAll("[ \t\n]+", " ");
 148.240 +
 148.241 +        if (golden != null) {
 148.242 +            assertEquals("The output code does not match the expected code.", golden, realCode);
 148.243 +        }
 148.244 +        
 148.245 +        LifecycleManager.getDefault().saveAll();
 148.246 +
 148.247 +        return realCode;
 148.248 +    }
 148.249 +    
 148.250 +    protected FileObject[] extraClassPath() {
 148.251 +        return new FileObject[0];
 148.252 +    }
 148.253 +
 148.254 +    // common tests to check nothing is reported
 148.255 +    public void testIssue105979() throws Exception {
 148.256 +        String before = "package test; class Test {" +
 148.257 +                "  return b;" +
 148.258 +                "}\n";
 148.259 +
 148.260 +        for (int i = 0; i < before.length(); i++) {
 148.261 +            LOG.info("testing position " + i + " at " + before.charAt(i));
 148.262 +            clearWorkDir();
 148.263 +            performAnalysisTest("test/Test.java", before, i);
 148.264 +}
 148.265 +    }
 148.266 +    public void testIssue108246() throws Exception {
 148.267 +
 148.268 +        String before = "package test; class Test {" +
 148.269 +            "  Integer ii = new Integer(0);" +
 148.270 +            "  String s = ii.toString();" +
 148.271 +            "\n}\n";
 148.272 +
 148.273 +        for (int i = 0; i < before.length(); i++) {
 148.274 +            LOG.info("testing position " + i + " at " + before.charAt(i));
 148.275 +            clearWorkDir();
 148.276 +            performAnalysisTest("test/Test.java", before, i);
 148.277 +        }
 148.278 +    }
 148.279 +
 148.280 +    public void testNoHintsForSimpleInitialize() throws Exception {
 148.281 +
 148.282 +        String before = "package test; class Test {" +
 148.283 +            " { java.lang.System.out.println(); } " +
 148.284 +            "}\n";
 148.285 +
 148.286 +        for (int i = 0; i < before.length(); i++) {
 148.287 +            LOG.info("testing position " + i + " at " + before.charAt(i));
 148.288 +            clearWorkDir();
 148.289 +            performAnalysisTest("test/Test.java", before, i);
 148.290 +        }
 148.291 +    }
 148.292 +
 148.293 +    public void testIssue113933() throws Exception {
 148.294 +
 148.295 +        String before = "package test; class Test {" +
 148.296 +            "  public void test() {" +
 148.297 +            "  super.A();" +
 148.298 +            "\n}\n}\n";
 148.299 +
 148.300 +        for (int i = 0; i < before.length(); i++) {
 148.301 +            LOG.info("testing position " + i + " at " + before.charAt(i));
 148.302 +            clearWorkDir();
 148.303 +            performAnalysisTest("test/Test.java", before, i);
 148.304 +        }
 148.305 +    }
 148.306 +}
   149.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/code/spi/TestBase.java	Sat Feb 11 18:35:10 2012 +0100
   149.3 @@ -0,0 +1,341 @@
   149.4 +/*
   149.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   149.6 + *
   149.7 + * Copyright 2009-2010 Oracle and/or its affiliates. All rights reserved.
   149.8 + *
   149.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  149.10 + * Other names may be trademarks of their respective owners.
  149.11 + *
  149.12 + * The contents of this file are subject to the terms of either the GNU
  149.13 + * General Public License Version 2 only ("GPL") or the Common
  149.14 + * Development and Distribution License("CDDL") (collectively, the
  149.15 + * "License"). You may not use this file except in compliance with the
  149.16 + * License. You can obtain a copy of the License at
  149.17 + * http://www.netbeans.org/cddl-gplv2.html
  149.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  149.19 + * specific language governing permissions and limitations under the
  149.20 + * License.  When distributing the software, include this License Header
  149.21 + * Notice in each file and include the License file at
  149.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  149.23 + * particular file as subject to the "Classpath" exception as provided
  149.24 + * by Oracle in the GPL Version 2 section of the License file that
  149.25 + * accompanied this code. If applicable, add the following below the
  149.26 + * License Header, with the fields enclosed by brackets [] replaced by
  149.27 + * your own identifying information:
  149.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  149.29 + *
  149.30 + * If you wish your version of this file to be governed by only the CDDL
  149.31 + * or only the GPL Version 2, indicate your decision by adding
  149.32 + * "[Contributor] elects to include this software in this distribution
  149.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  149.34 + * single choice of license, a recipient has the option to distribute
  149.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  149.36 + * to extend the choice of license to its licensees as provided above.
  149.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  149.38 + * Version 2 license, then the option applies only if the new code is
  149.39 + * made subject to such option by the copyright holder.
  149.40 + *
  149.41 + * Contributor(s):
  149.42 + *
  149.43 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
  149.44 + */
  149.45 +
  149.46 +package org.netbeans.modules.java.hints.jackpot.code.spi;
  149.47 +
  149.48 +import java.io.File;
  149.49 +import java.lang.reflect.Method;
  149.50 +import java.util.ArrayList;
  149.51 +import java.util.Arrays;
  149.52 +import java.util.Collection;
  149.53 +import java.util.Collections;
  149.54 +import java.util.Comparator;
  149.55 +import java.util.HashMap;
  149.56 +import java.util.HashSet;
  149.57 +import java.util.LinkedList;
  149.58 +import java.util.List;
  149.59 +import java.util.Map;
  149.60 +import java.util.Map.Entry;
  149.61 +import java.util.Set;
  149.62 +import java.util.concurrent.atomic.AtomicBoolean;
  149.63 +import java.util.logging.Level;
  149.64 +import java.util.logging.Logger;
  149.65 +import javax.swing.text.Document;
  149.66 +import org.netbeans.api.java.lexer.JavaTokenId;
  149.67 +import org.netbeans.api.java.source.CompilationInfo;
  149.68 +import org.netbeans.api.java.source.JavaSource;
  149.69 +import org.netbeans.api.java.source.JavaSource.Phase;
  149.70 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
  149.71 +import org.netbeans.api.java.source.TestUtilities;
  149.72 +import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory;
  149.73 +import org.netbeans.api.lexer.Language;
  149.74 +import org.netbeans.junit.NbTestCase;
  149.75 +import org.netbeans.modules.java.hints.jackpot.code.CodeHintProviderImpl;
  149.76 +import org.netbeans.modules.java.hints.jackpot.code.FSWrapper;
  149.77 +import org.netbeans.modules.java.hints.jackpot.code.FSWrapper.ClassWrapper;
  149.78 +import org.netbeans.modules.java.hints.jackpot.spi.HintDescription;
  149.79 +import org.netbeans.modules.java.hints.jackpot.spi.HintMetadata;
  149.80 +import org.netbeans.modules.java.hints.jackpot.spi.HintsRunner;
  149.81 +import org.netbeans.modules.java.source.TreeLoader;
  149.82 +import org.netbeans.spi.editor.hints.ErrorDescription;
  149.83 +import org.netbeans.spi.editor.hints.Fix;
  149.84 +import org.openide.LifecycleManager;
  149.85 +import org.openide.cookies.EditorCookie;
  149.86 +import org.openide.filesystems.FileObject;
  149.87 +import org.openide.filesystems.FileUtil;
  149.88 +import org.openide.loaders.DataObject;
  149.89 +import org.openide.util.NbBundle;
  149.90 +
  149.91 +/**
  149.92 + *
  149.93 + * @author lahvac
  149.94 + */
  149.95 +public abstract class TestBase extends NbTestCase {
  149.96 +    private final Class<?> hintClass;
  149.97 +    protected final Logger LOG;
  149.98 +
  149.99 +    public TestBase(String name, Class<?> hintClass) {
 149.100 +        super(name);
 149.101 +        this.hintClass = hintClass;
 149.102 +        LOG = Logger.getLogger("test." + name);
 149.103 +    }
 149.104 +
 149.105 +    @Override
 149.106 +    protected Level logLevel() {
 149.107 +        return Level.INFO;
 149.108 +    }
 149.109 +
 149.110 +    @Override
 149.111 +    protected void setUp() throws Exception {
 149.112 +        super.setUp();
 149.113 +        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml", "META-INF/generated-layer.xml"}, new Object[0]);
 149.114 +        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
 149.115 +    }
 149.116 +
 149.117 +    private String sourceLevel = "1.5";
 149.118 +
 149.119 +    protected void setSourceLevel(String sourceLevel) {
 149.120 +        this.sourceLevel = sourceLevel;
 149.121 +    }
 149.122 +    
 149.123 +    protected void prepareTest(String fileName, String code) throws Exception {
 149.124 +        clearWorkDir();
 149.125 +        File wdFile = getWorkDir();
 149.126 +        FileUtil.refreshFor(wdFile);
 149.127 +
 149.128 +        FileObject wd = FileUtil.toFileObject(wdFile);
 149.129 +        assertNotNull(wd);
 149.130 +        sourceRoot = FileUtil.createFolder(wd, "src");
 149.131 +        FileObject buildRoot = FileUtil.createFolder(wd, "build");
 149.132 +        FileObject cache = FileUtil.createFolder(wd, "cache");
 149.133 +
 149.134 +        FileObject data = FileUtil.createData(sourceRoot, fileName);
 149.135 +        File dataFile = FileUtil.toFile(data);
 149.136 +
 149.137 +        assertNotNull(dataFile);
 149.138 +
 149.139 +        TestUtilities.copyStringToFile(dataFile, code);
 149.140 +
 149.141 +        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache, extraClassPath());
 149.142 +
 149.143 +        SourceUtilsTestUtil.setSourceLevel(data, sourceLevel);
 149.144 +
 149.145 +        DataObject od = DataObject.find(data);
 149.146 +        EditorCookie ec = od.getCookie(EditorCookie.class);
 149.147 +
 149.148 +        assertNotNull(ec);
 149.149 +
 149.150 +        doc = ec.openDocument();
 149.151 +        doc.putProperty(Language.class, JavaTokenId.language());
 149.152 +        doc.putProperty("mimeType", "text/x-java");
 149.153 +
 149.154 +        JavaSource js = JavaSource.forFileObject(data);
 149.155 +
 149.156 +        assertNotNull(js);
 149.157 +
 149.158 +        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
 149.159 +
 149.160 +        assertNotNull(info);
 149.161 +    }
 149.162 +
 149.163 +    private FileObject sourceRoot;
 149.164 +    private CompilationInfo info;
 149.165 +    private Document doc;
 149.166 +
 149.167 +    protected final void setTestFileCaretLocation(int pos) throws Exception {
 149.168 +        Method m = CaretAwareJavaSourceTaskFactory.class.getDeclaredMethod("setLastPosition", FileObject.class, int.class);
 149.169 +
 149.170 +        m.setAccessible(true);
 149.171 +        m.invoke(null, info.getFileObject(), pos);
 149.172 +    }
 149.173 +
 149.174 +    private List<ErrorDescription> computeErrors(CompilationInfo info) {
 149.175 +        Map<HintMetadata, Collection<HintDescription>> hints = new HashMap<HintMetadata, Collection<HintDescription>>();
 149.176 +
 149.177 +        ClassWrapper found = null;
 149.178 +
 149.179 +        for (ClassWrapper w : FSWrapper.listClasses()) {
 149.180 +            if (w.getName().equals(hintClass.getName())) {
 149.181 +                found = w;
 149.182 +                break;
 149.183 +            }
 149.184 +        }
 149.185 +
 149.186 +        assertNotNull(found);
 149.187 +        
 149.188 +        CodeHintProviderImpl.processClass(found, hints);
 149.189 +
 149.190 +        List<HintDescription> total = new LinkedList<HintDescription>();
 149.191 +
 149.192 +        for (Collection<? extends HintDescription> l : hints.values()) {
 149.193 +            total.addAll(l);
 149.194 +        }
 149.195 +
 149.196 +        List<ErrorDescription> result = new ArrayList<ErrorDescription>();
 149.197 +        
 149.198 +        for (Entry<HintDescription, List<ErrorDescription>> e : HintsRunner.computeErrors(info, total, new AtomicBoolean()).entrySet()) {
 149.199 +            result.addAll(e.getValue());
 149.200 +        }
 149.201 +
 149.202 +        return result;
 149.203 +    }
 149.204 +
 149.205 +    protected String toDebugString(CompilationInfo info, Fix f) {
 149.206 +        return "FixImpl";
 149.207 +    }
 149.208 +
 149.209 +    protected void performAnalysisTest(String fileName, String code, String... golden) throws Exception {
 149.210 +        prepareTest(fileName, code);
 149.211 +
 149.212 +        List<ErrorDescription> errors = computeErrors(info);
 149.213 +        Collections.sort (errors, ERRORS_COMPARATOR);
 149.214 +        List<String> errorsNames = new LinkedList<String>();
 149.215 +
 149.216 +        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
 149.217 +
 149.218 +        for (ErrorDescription e : errors) {
 149.219 +            errorsNames.add(e.toString());
 149.220 +        }
 149.221 +
 149.222 +        assertTrue("The warnings provided by the hint do not match expected warnings. Provided warnings: " + errorsNames.toString(), Arrays.equals(golden, errorsNames.toArray(new String[0])));
 149.223 +    }
 149.224 +
 149.225 +    protected void performAnalysisContainsTest(String fileName, String code, String... golden) throws Exception {
 149.226 +        prepareTest(fileName, code);
 149.227 +
 149.228 +        Set<String> goldenSet = new HashSet<String>();
 149.229 +        for (String s : golden) {
 149.230 +            goldenSet.add(s);
 149.231 +        }
 149.232 +
 149.233 +        List<ErrorDescription> errors = computeErrors(info);
 149.234 +        Collections.sort (errors, ERRORS_COMPARATOR);
 149.235 +        List<String> errorsNames = new LinkedList<String>();
 149.236 +
 149.237 +        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
 149.238 +
 149.239 +        for (ErrorDescription d : errors) {
 149.240 +            goldenSet.remove(d.toString());
 149.241 +            errorsNames.add(d.toString());
 149.242 +        }
 149.243 +        assertTrue("The warnings provided by the hint do not contain expected warnings. Provided warnings: " + errorsNames.toString(), goldenSet.isEmpty());
 149.244 +    }
 149.245 +
 149.246 +    protected void performAnalysisExcludesTest(String fileName, String code, String... golden) throws Exception {
 149.247 +        prepareTest(fileName, code);
 149.248 +
 149.249 +        Set<String> goldenSet = new HashSet<String>();
 149.250 +        for (String s : golden) {
 149.251 +            goldenSet.add(s);
 149.252 +        }
 149.253 +
 149.254 +        List<ErrorDescription> errors = computeErrors(info);
 149.255 +        Collections.sort (errors, ERRORS_COMPARATOR);
 149.256 +        List<String> errorsNames = new LinkedList<String>();
 149.257 +
 149.258 +        errors = errors != null ? errors : Collections.<ErrorDescription>emptyList();
 149.259 +
 149.260 +        boolean fail = false;
 149.261 +        for (ErrorDescription d : errors) {
 149.262 +            if (goldenSet.remove(d.getDescription()))
 149.263 +                fail = true;
 149.264 +            errorsNames.add(d.toString());
 149.265 +        }
 149.266 +        assertFalse("The warnings provided by the hint do not exclude expected warnings. Provided warnings: " + errorsNames.toString(), fail);
 149.267 +    }
 149.268 +
 149.269 +    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String golden) throws Exception {
 149.270 +        return performFixTest(fileName, code, errorDescriptionToString, fixDebugString, fileName, golden);
 149.271 +    }
 149.272 +
 149.273 +    protected String performFixTest(String fileName, String code, String errorDescriptionToString, String fixDebugString, String goldenFileName, String golden) throws Exception {
 149.274 +        prepareTest(fileName, code);
 149.275 +
 149.276 +        List<ErrorDescription> errors = computeErrors(info);
 149.277 +        Collections.sort (errors, ERRORS_COMPARATOR);
 149.278 +
 149.279 +        ErrorDescription toFix = null;
 149.280 +
 149.281 +        for (ErrorDescription d : errors) {
 149.282 +            if (errorDescriptionToString.equals(d.toString())) {
 149.283 +                toFix = d;
 149.284 +                break;
 149.285 +            }
 149.286 +        }
 149.287 +
 149.288 +        assertNotNull("Error: \"" + errorDescriptionToString + "\" not found. All ErrorDescriptions: " + errors.toString(), toFix);
 149.289 +
 149.290 +        assertTrue("Must be computed", toFix.getFixes().isComputed());
 149.291 +
 149.292 +        List<Fix> fixes = toFix.getFixes().getFixes();
 149.293 +        List<String> fixNames = new LinkedList<String>();
 149.294 +        Fix toApply = null;
 149.295 +
 149.296 +        for (Fix f : fixes) {
 149.297 +            if (fixDebugString.equals(toDebugString(info, f))) {
 149.298 +                toApply = f;
 149.299 +            }
 149.300 +
 149.301 +            fixNames.add(toDebugString(info, f));
 149.302 +        }
 149.303 +
 149.304 +        assertNotNull("Cannot find fix to invoke: " + fixNames.toString(), toApply);
 149.305 +
 149.306 +        toApply.implement();
 149.307 +
 149.308 +        FileObject toCheck = sourceRoot.getFileObject(goldenFileName);
 149.309 +
 149.310 +        assertNotNull(toCheck);
 149.311 +
 149.312 +        DataObject toCheckDO = DataObject.find(toCheck);
 149.313 +        EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
 149.314 +        Document toCheckDocument = ec.openDocument();
 149.315 +
 149.316 +        String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());
 149.317 +
 149.318 +        //ignore whitespaces:
 149.319 +        realCode = realCode.replaceAll("[ \t\n]+", " ");
 149.320 +
 149.321 +        if (golden != null) {
 149.322 +            assertEquals("The output code does not match the expected code.", golden, realCode);
 149.323 +        }
 149.324 +
 149.325 +        LifecycleManager.getDefault().saveAll();
 149.326 +
 149.327 +        return realCode;
 149.328 +    }
 149.329 +
 149.330 +    protected FileObject[] extraClassPath() {
 149.331 +        return new FileObject[0];
 149.332 +    }
 149.333 +
 149.334 +    static {
 149.335 +        NbBundle.setBranding("test");
 149.336 +    }
 149.337 +
 149.338 +    private static final Comparator<ErrorDescription> ERRORS_COMPARATOR = new Comparator<ErrorDescription> () {
 149.339 +
 149.340 +        public int compare (ErrorDescription e1, ErrorDescription e2) {
 149.341 +            return e1.getRange ().getBegin ().getOffset () - e2.getRange ().getBegin ().getOffset ();
 149.342 +        }
 149.343 +    };
 149.344 +}
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/hints/jackpot/impl/pm/BulkSearchTestPerformer.java	Sat Feb 11 18:35:10 2012 +0100
   150.3 @@ -0,0 +1,664 @@
   150.4 +/*
   150.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   150.6 + *
   150.7 + * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
   150.8 + *
   150.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  150.10 + * Other names may be trademarks of their respective owners.
  150.11 + *
  150.12 + * The contents of this file are subject to the terms of either the GNU
  150.13 + * General Public License Version 2 only ("GPL") or the Common
  150.14 + * Development and Distribution License("CDDL") (collectively, the
  150.15 + * "License"). You may not use this file except in compliance with the
  150.16 + * License. You can obtain a copy of the License at
  150.17 + * http://www.netbeans.org/cddl-gplv2.html
  150.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  150.19 + * specific language governing permissions and limitations under the
  150.20 + * License.  When distributing the software, include this License Header
  150.21 + * Notice in each file and include the License file at
  150.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  150.23 + * particular file as subject to the "Classpath" exception as provided
  150.24 + * by Oracle in the GPL Version 2 section of the License file that
  150.25 + * accompanied this code. If applicable, add the following below the
  150.26 + * License Header, with the fields enclosed by brackets [] replaced by
  150.27 + * your own identifying information:
  150.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  150.29 + *
  150.30 + * If you wish your version of this file to be governed by only the CDDL
  150.31 + * or only the GPL Version 2, indicate your decision by adding
  150.32 + * "[Contributor] elects to include this software in this distribution
  150.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  150.34 + * single choice of license, a recipient has the option to distribute
  150.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  150.36 + * to extend the choice of license to its licensees as provided above.
  150.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  150.38 + * Version 2 license, then the option applies only if the new code is
  150.39 + * made subject to such option by the copyright holder.
  150.40 + *
  150.41 + * Contributor(s):
  150.42 + *
  150.43 + * Portions Copyrighted 2009 Sun Microsystems, Inc.
  150.44 + */
  150.45 +
  150.46 +package org.netbeans.modules.java.hints.jackpot.impl.pm;
  150.47 +
  150.48 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
  150.49 +import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
  150.50 +import com.sun.source.util.TreePath;
  150.51 +import java.io.ByteArrayInputStream;
  150.52 +import java.io.ByteArrayOutputStream;
  150.53 +import java.io.File;
  150.54 +import java.util.Arrays;
  150.55 +import java.util.Collection;
  150.56 +import java.util.Collections;
  150.57 +import java.util.HashMap;
  150.58 +import java.util.HashSet;
  150.59 +import java.util.LinkedList;
  150.60 +import java.util.List;
  150.61 +import java.util.Map;
  150.62 +import java.util.Map.Entry;
  150.63 +import java.util.Set;
  150.64 +import java.util.regex.Pattern;
  150.65 +import javax.swing.text.Document;
  150.66 +import org.netbeans.api.java.lexer.JavaTokenId;
  150.67 +import org.netbeans.api.java.source.CompilationInfo;
  150.68 +import org.netbeans.api.java.source.JavaSource;
  150.69 +import org.netbeans.api.java.source.JavaSource.Phase;
  150.70 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
  150.71 +import org.netbeans.api.java.source.TestUtilities;
  150.72 +import org.netbeans.api.java.source.TreePathHandle;
  150.73 +import org.netbeans.api.lexer.Language;
  150.74 +import org.netbeans.junit.NbTestCase;
  150.75 +import org.netbeans.modules.java.source.TreeLoader;
  150.76 +import org.openide.cookies.EditorCookie;
  150.77 +import org.openide.filesystems.FileObject;
  150.78 +import org.openide.filesystems.FileUtil;
  150.79 +import org.openide.loaders.DataObject;
  150.80 +import static org.junit.Assert.*;
  150.81 +
  150.82 +/**
  150.83 + *
  150.84 + * @author lahvac
  150.85 + */
  150.86 +public abstract class BulkSearchTestPerformer extends NbTestCase {
  150.87 +
  150.88 +    public BulkSearchTestPerformer(String name) {
  150.89 +        super(name);
  150.90 +    }
  150.91 +
  150.92 +    @Override
  150.93 +    protected void setUp() throws Exception {
  150.94 +        super.setUp();
  150.95 +        SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/editor/resources/layer.xml"}, new Object[0]);
  150.96 +        TreeLoader.DISABLE_CONFINEMENT_TEST = true;
  150.97 +    }
  150.98 +
  150.99 +//    public static TestSuite suite() {
 150.100 +//        NbTestSuite s = new NbTestSuite();
 150.101 +//
 150.102 +//        s.addTestSuite(NFABasedBulkSearchTest.class);
 150.103 +//
 150.104 +//        return s;
 150.105 +//    }
 150.106 +
 150.107 +    public void testSimple1() throws Exception {
 150.108 +        performTest("package test; public class Test { private void test() { System.err./**/println(\"\");}}",
 150.109 +                    Collections.singletonMap("System.err.println(\"\")", Arrays.asList("System.err./**/println(\"\")")),
 150.110 +                    Arrays.asList("System.err.println(\"\" + \"\")"));
 150.111 +    }
 150.112 +
 150.113 +    public void testDontCare() throws Exception {
 150.114 +        performTest("package test; public class Test { private void test() { System.err./**/println(\"\" + \"\");}}",
 150.115 +                    Collections.singletonMap("System.err.println($1)", Arrays.asList("System.err./**/println(\"\" + \"\")")),
 150.116 +                    Collections.<String>emptyList());
 150.117 +    }
 150.118 +
 150.119 +    public void testMemberSelectAndIdentifier() throws Exception {
 150.120 +        performTest("package test; public class Test { private static void test() { test();}}",
 150.121 +                    Collections.singletonMap("test.Test.test()", Arrays.asList("test()")),
 150.122 +                    Collections.<String>emptyList());
 150.123 +    }
 150.124 +
 150.125 +    public void testUnpureMemberSelect() throws Exception {
 150.126 +        performTest("package test; public class Test { private static void test() { new StringBuilder().append(\"\");}}",
 150.127 +                    Collections.<String, List<String>>emptyMap(),
 150.128 +                    Arrays.asList("test.append(\"\")"));
 150.129 +    }
 150.130 +
 150.131 +    public void testMemberSelectWithVariables1() throws Exception {
 150.132 +        performTest("package test; public class Test { private static void test() { new StringBuilder().append(\"\");}}",
 150.133 +                    Collections.singletonMap("$0.append(\"\")", Arrays.asList("new StringBuilder().append(\"\")")),
 150.134 +                    Collections.<String>emptyList());
 150.135 +    }
 150.136 +
 150.137 +    public void testMemberSelectWithVariables2() throws Exception {
 150.138 +        performTest("package test; public class Test { private void append(char c) { append(\"\");}}",
 150.139 +                    Collections.singletonMap("$0.append(\"\")", Arrays.asList("append(\"\")")),
 150.140 +                    Collections.<String>emptyList());
 150.141 +    }
 150.142 +
 150.143 +    public void testLocalVariables() throws Exception {
 150.144 +        performTest("package test; public class Test { private void test() { { int y; y = 1; } }}",
 150.145 +                    Collections.singletonMap("{ int $1; $1 = 1; }", Arrays.asList("{ int y; y = 1; }")),
 150.146 +                    Collections.<String>emptyList());
 150.147 +    }
 150.148 +
 150.149 +    public void testAssert() throws Exception {
 150.150 +        performTest("package test; public class Test { private void test() { assert true : \"\"; }}",
 150.151 +                    Collections.singletonMap("assert $1 : $2;", Arrays.asList("assert true : \"\";")),
 150.152 +                    Collections.<String>emptyList());
 150.153 +    }
 150.154 +
 150.155 +    public void testStatementAndSingleBlockStatementAreSame1() throws Exception {
 150.156 +        performTest("package test; public class Test { private void test() { { int y; { y = 1; } } }}",
 150.157 +                    Collections.singletonMap("{ int $1; $1 = 1; }", Arrays.asList("{ int y; { y = 1; } }")),
 150.158 +                    Collections.<String>emptyList());
 150.159 +    }
 150.160 +
 150.161 +    public void testStatementAndSingleBlockStatementAreSame2() throws Exception {
 150.162 +        performTest("package test; public class Test { private void test() { { int y; y = 1; } }}",
 150.163 +                    Collections.singletonMap("{ int $1; { $1 = 1; } }", Arrays.asList("{ int y; y = 1; }")),
 150.164 +                    Collections.<String>emptyList());
 150.165 +    }
 150.166 +
 150.167 +    public void testStatementVariables1() throws Exception {
 150.168 +        performTest("package test; public class Test { public int test1() { if (true) return 1; else return 2; } }",
 150.169 +                    Collections.singletonMap("if ($1) $2; else $3;", Arrays.asList("if (true) return 1; else return 2;")),
 150.170 +                    Collections.<String>emptyList());
 150.171 +    }
 150.172 +
 150.173 +    public void testMultiStatementVariables1() throws Exception {
 150.174 +        performTest("package test; public class Test { public int test1(int i) { System.err.println(i); System.err.println(i); i = 3; System.err.println(i); System.err.println(i); return i; } }",
 150.175 +                    Collections.singletonMap("{ $s1$; i = 3; $s2$; return i; }", Arrays.asList("{ System.err.println(i); System.err.println(i); i = 3; System.err.println(i); System.err.println(i); return i; }")),
 150.176 +                    Collections.<String>emptyList());
 150.177 +    }
 150.178 +
 150.179 +    public void testMultiStatementVariables2() throws Exception {
 150.180 +        performTest("package test; public class Test { public int test1(int i) { i = 3; return i; } }",
 150.181 +                    Collections.singletonMap("{ $s1$; i = 3; $s2$; return i; }", Arrays.asList("{ i = 3; return i; }")),
 150.182 +                    Collections.<String>emptyList());
 150.183 +    }
 150.184 +
 150.185 +    public void testMultiStatementVariablesAndBlocks1() throws Exception {
 150.186 +        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
 150.187 +                    Collections.singletonMap("if ($c) {$s1$; System.err.println(); $s2$; }", Arrays.asList("if (true) System.err.println();")),
 150.188 +                    Collections.<String>emptyList());
 150.189 +    }
 150.190 +
 150.191 +    public void testMultiStatementVariablesAndBlocks2() throws Exception {
 150.192 +        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
 150.193 +                    Collections.singletonMap("if ($c) {$s1$; System.err.println(); }", Arrays.asList("if (true) System.err.println();")),
 150.194 +                    Collections.<String>emptyList());
 150.195 +    }
 150.196 +
 150.197 +    public void testMultiStatementVariablesAndBlocks3() throws Exception {
 150.198 +        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
 150.199 +                    Collections.singletonMap("if ($c) {System.err.println(); $s2$; }", Arrays.asList("if (true) System.err.println();")),
 150.200 +                    Collections.<String>emptyList());
 150.201 +    }
 150.202 +
 150.203 +    public void testMultiStatementVariablesAndBlocks4() throws Exception {
 150.204 +        performTest("package test; public class Test { public void test1() { if (true) System.err.println(); } }",
 150.205 +                    Collections.singletonMap("{ $s1$; System.err.println(); $s2$; }", Arrays.asList("System.err.println();")),
 150.206 +                    Collections.<String>emptyList());
 150.207 +    }
 150.208 +
 150.209 +    public void testTwoPatterns() throws Exception {
 150.210 +        Map<String, List<String>> contained = new HashMap<String, List<String>>();
 150.211 +
 150.212 +        contained.put("if ($a) $ret = $b; else $ret = $c;", Arrays.asList("if (b) q = 2; else q = 3;"));
 150.213 +        contained.put("{ $p$; $T $v; if($a) $v = $b; else $v = $c; $q$; }", Arrays.asList("{ int q; if (b) q = 2; else q = 3; }"));
 150.214 +
 150.215 +        performTest("package test; public class Test { public void test1(boolean b) { int q; if (b) q = 2; else q = 3; } }",
 150.216 +                    contained,
 150.217 +                    Collections.<String>emptyList());
 150.218 +    }
 150.219 +
 150.220 +    public void testEffectiveNewClass() throws Exception {
 150.221 +        performTest("package test; import javax.swing.ImageIcon; public class Test { public void test1(java.awt.Image i) { new ImageIcon(i); new String(i); } }",
 150.222 +                    Collections.singletonMap("new javax.swing.ImageIcon($1)", Arrays.asList("new ImageIcon(i)")),
 150.223 +                    Collections.<String>emptyList());
 150.224 +    }
 150.225 +
 150.226 +    public void testSynchronizedAndMultiStatementVariables() throws Exception {
 150.227 +        performTest("package test; public class Test {public void test() { Object o = null; int i = 0; synchronized (o) {} } }",
 150.228 +                    Collections.singletonMap("synchronized($var) {$stmts$;}", Arrays.asList("synchronized (o) {}")),
 150.229 +                    Collections.<String>emptyList());
 150.230 +    }
 150.231 +
 150.232 +    public void testJackpot30_2() throws Exception {
 150.233 +        String code = "package test;\n" +
 150.234 +                      "public class Test {\n" +
 150.235 +                      "    private void m() {\n" +
 150.236 +                      "        a(c.i().getFileObject());\n" +
 150.237 +                      "        if (span != null && span[0] != (-1) && span[1] != (-1));\n" +
 150.238 +                      "    }\n" +
 150.239 +                      "}\n";
 150.240 +
 150.241 +        performTest(code,
 150.242 +                    Collections.<String, List<String>>emptyMap(),
 150.243 +                    Arrays.asList("$0.getFileObject($1)"));
 150.244 +    }
 150.245 +
 150.246 +    public void testIdentifierInPureMemberSelect() throws Exception {
 150.247 +        String code = "package test;\n" +
 150.248 +                       "public class Test {\n" +
 150.249 +                       "     public Test test;\n" +
 150.250 +                       "     public String name;\n" +
 150.251 +                       "     private void test() {\n" +
 150.252 +                       "         Test t = null;\n" +
 150.253 +                       "         String s = t.test.name;\n" +
 150.254 +                       "     }\n" +
 150.255 +                       "}\n";
 150.256 +
 150.257 +        performTest(code,
 150.258 +                    Collections.singletonMap("$Test.test", Arrays.asList("test", "t.test")),
 150.259 +                    Collections.<String>emptyList());
 150.260 +    }
 150.261 +
 150.262 +    public void testNoExponentialTimeComplexity() throws Exception {
 150.263 +        try {
 150.264 +        String code = "package test;\n" +
 150.265 +                      "public class Test {\n" +
 150.266 +                      "    private void test() {\n" +
 150.267 +                      "        Object o;\n" +
 150.268 +                      "        if(o == null) {\n" +
 150.269 +                      "            f(\"\");\n" +
 150.270 +                      "        }|\n" +
 150.271 +                      "    }\n" +
 150.272 +                      "}";
 150.273 +        String pattern = "{ $p$; $T $v; if($a) $v = $b; else $v = $c; }";
 150.274 +
 150.275 +        measure(code, "\na(\"\");", 5, pattern); //to load needed classes, etc.
 150.276 +
 150.277 +        int rep = 1;
 150.278 +        long baseline;
 150.279 +
 150.280 +        while (true) {
 150.281 +            baseline = measure(code, "\na(\"\");", rep, pattern);
 150.282 +
 150.283 +            if (baseline >= 2000) {
 150.284 +                break;
 150.285 +            }
 150.286 +
 150.287 +            rep *= 2;
 150.288 +        }
 150.289 +
 150.290 +        long doubleSize = measure(code, "\na(\"\");", 2 * rep, pattern);
 150.291 +
 150.292 +        assertTrue("baseline=" + baseline + ", actual=" + String.valueOf(doubleSize), doubleSize <= 4 * baseline);
 150.293 +        } catch (OutOfMemoryError oome) {
 150.294 +            //OK
 150.295 +        }
 150.296 +    }
 150.297 +
 150.298 +    public void testMultiParameter1() throws Exception {
 150.299 +        performTest("package test; public class Test { { java.util.Arrays.asList(\"a\", \"b\", \"c\"); } }",
 150.300 +                    Collections.singletonMap("java.util.Arrays.asList($params$)", Arrays.asList("java.util.Arrays.asList(\"a\", \"b\", \"c\")")),
 150.301 +                    Collections.<String>emptyList());
 150.302 +    }
 150.303 +
 150.304 +    public void testMultiParameter2() throws Exception {
 150.305 +        performTest("package test; public class Test { { java.util.Arrays.asList(); } }",
 150.306 +                    Collections.singletonMap("java.util.Arrays.asList($params$)", Arrays.asList("java.util.Arrays.asList()")),
 150.307 +                    Collections.<String>emptyList());
 150.308 +    }
 150.309 +
 150.310 +    public void testTypeParameter() throws Exception {
 150.311 +        performTest("package test; public class Test { { java.util.Arrays.<String>asList(); } }",
 150.312 +                    Collections.singletonMap("java.util.Arrays.<$1>asList($params$)", Arrays.asList("java.util.Arrays.<String>asList()")),
 150.313 +                    Collections.<String>emptyList());
 150.314 +    }
 150.315 +
 150.316 +    public void testField1() throws Exception {
 150.317 +        String code = "package test;\n" +
 150.318 +                       "public class Test {\n" +
 150.319 +                       "     String name = null;\n" +
 150.320 +                       "}\n";
 150.321 +
 150.322 +        performTest(code,
 150.323 +                    Collections.singletonMap("$modifiers$ java.lang.String $name = $initializer;", Arrays.asList("String name = null;")),
 150.324 +                    Collections.<String>emptyList());
 150.325 +    }
 150.326 +
 150.327 +    public void testField2() throws Exception {
 150.328 +        String code = "package test;\n" +
 150.329 +                       "public class Test {\n" +
 150.330 +                       "     private String name = null;\n" +
 150.331 +                       "}\n";
 150.332 +
 150.333 +        performTest(code,
 150.334 +                    Collections.singletonMap("$modifiers$ java.lang.String $name = $initializer;", Arrays.asList("private String name = null;")),
 150.335 +                    Collections.<String>emptyList());
 150.336 +    }
 150.337 +
 150.338 +    public void testMemberSelectWithVariable() throws Exception {
 150.339 +        String code = "package test;\n" +
 150.340 +                      "import java.util.Arrays;\n" +
 150.341 +                      "public class Test {" +
 150.342 +                      "     {\n" +
 150.343 +                      "          foo.bar(0, 3, 4);\n" +
 150.344 +                      "     }\n" +
 150.345 +                      "}\n";
 150.346 +
 150.347 +        performTest(code,
 150.348 +                    Collections.singletonMap("$foo.$bar($p1, $p2$)", Arrays.asList("foo.bar(0, 3, 4)")),
 150.349 +                    Collections.<String>emptyList());
 150.350 +    }
 150.351 +
 150.352 +    public void testCheckIdentifiers1() throws Exception {
 150.353 +        String code = "package test;\n" +
 150.354 +                      "import static java.util.Arrays.*;\n" +
 150.355 +                      "public class Test {" +
 150.356 +                      "     {\n" +
 150.357 +                      "          toString(new int[] {0, 3, 4});\n" +
 150.358 +                      "     }\n" +
 150.359 +                      "}\n";
 150.360 +
 150.361 +        performTest(code,
 150.362 +                    Collections.singletonMap("java.util.Arrays.toString($x)", Arrays.asList("toString(new int[] {0, 3, 4})")),
 150.363 +                    Collections.<String>emptyList());
 150.364 +    }
 150.365 +
 150.366 +    public void testCheckIdentifiers2() throws Exception {
 150.367 +        String code = "package test;\n" +
 150.368 +                      "public class Test {" +
 150.369 +                      "     {\n" +
 150.370 +                      "          toString(new int[] {0, 3, 4});\n" +
 150.371 +                      "     }\n" +
 150.372 +                      "}\n";
 150.373 +
 150.374 +        performTest(code,
 150.375 +                    Collections.<String, List<String>>emptyMap(),
 150.376 +                    Collections.singletonList("java.util.Arrays.toString($x)"));
 150.377 +    }
 150.378 +
 150.379 +    public void testCheckIdentifiers3() throws Exception {
 150.380 +        String code = "package test;\n" +
 150.381 +                      "import static java.util.Arrays.*;\n" +
 150.382 +                      "public class Test {" +
 150.383 +                      "     {\n" +
 150.384 +                      "          Foo.toString(new int[] {0, 3, 4});\n" +
 150.385 +                      "     }\n" +
 150.386 +                      "}\n";
 150.387 +
 150.388 +        performTest(code,
 150.389 +                    Collections.<String, List<String>>emptyMap(),
 150.390 +                    Collections.singletonList("java.util.Arrays.toString($x)"));
 150.391 +    }
 150.392 +
 150.393 +    public void testCheckIdentifiers4() throws Exception {
 150.394 +        String code = "package test;\n" +
 150.395 +                      "public class Test {" +
 150.396 +                      "     {\n" +
 150.397 +                      "          java.util.Arrays.toString(new int[] {0, 3, 4});\n" +
 150.398 +                      "     }\n" +
 150.399 +                      "}\n";
 150.400 +
 150.401 +        performTest(code,
 150.402 +                    Collections.singletonMap("Arrays", Arrays.asList("java.util.Arrays")), //could be imported in the input pattern
 150.403 +                    Collections.<String>emptyList());
 150.404 +    }
 150.405 +
 150.406 +    public void testLambdaInput() throws Exception {
 150.407 +        String code = "package test; public class Test {public void test() { new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { return true; } }; } }";
 150.408 +
 150.409 +        performTest(code,
 150.410 +                    Collections.singletonMap("new $type() {public $retType $name($params$) { $body$; } }", Arrays.asList("new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { return true; } }")),
 150.411 +
 150.412 +                    Collections.<String>emptyList());
 150.413 +    }
 150.414 +
 150.415 +    public void testDoubleCheckedLockingWithVariable() throws Exception {
 150.416 +        String dcl =  "if (o == null) {\n" +
 150.417 +                      "              Object o1 = new Object();\n" +
 150.418 +                      "              synchronized (Test.class) {\n" +
 150.419 +                      "                  if (o == null) {\n" +
 150.420 +                      "                      o = o1;\n" +
 150.421 +                      "                  }\n" +
 150.422 +                      "              }\n" +
 150.423 +                      "          }";
 150.424 +        String code = "package test;\n" +
 150.425 +                      "public class Test {\n" +
 150.426 +                      "     private Object o;\n" +
 150.427 +                      "     private void t() {\n" +
 150.428 +                      "          " + dcl + "\n" +
 150.429 +                      "     }\n" +
 150.430 +                      "}\n";
 150.431 +
 150.432 +        performTest(code,
 150.433 +                    Collections.singletonMap("if ($var == null) {$pref$; synchronized ($lock) { if ($var == null) { $init$; } } }", Arrays.asList(dcl)),
 150.434 +                    Collections.<String>emptyList());
 150.435 +    }
 150.436 +
 150.437 +    public void testMethodName1() throws Exception {
 150.438 +        String code = "package test; public class Test {public void test() { clone(); } }";
 150.439 +
 150.440 +        performTest(code,
 150.441 +                    Collections.<String, List<String>>emptyMap(),
 150.442 +                    Collections.<String>singletonList("public void clone() {$stmts$;}"));
 150.443 +    }
 150.444 +
 150.445 +    public void testMethodName2() throws Exception {
 150.446 +        String code = "package test; public class Test {public void test() { clone(); } }";
 150.447 +
 150.448 +        performTest(code,
 150.449 +                    Collections.singletonMap("public void test() {$stmts$;}", Arrays.asList("public void test() { clone(); }")),
 150.450 +                    Collections.<String>emptyList());
 150.451 +    }
 150.452 +
 150.453 +    private long measure(String baseCode, String toInsert, int repetitions, String pattern) throws Exception {
 150.454 +        int pos = baseCode.indexOf('|');
 150.455 +
 150.456 +        assertTrue(pos != (-1));
 150.457 +
 150.458 +        baseCode = baseCode.replaceAll(Pattern.quote("|"), "");
 150.459 +        
 150.460 +        StringBuilder code = new StringBuilder(baseCode.length() + repetitions * toInsert.length());
 150.461 +
 150.462 +        code.append(baseCode);
 150.463 +        
 150.464 +        while (repetitions-- > 0) {
 150.465 +            code.insert(pos, toInsert);
 150.466 +        }
 150.467 +
 150.468 +        long startTime = System.currentTimeMillis();
 150.469 +
 150.470 +        performTest(code.toString(),
 150.471 +                    Collections.<String, List<String>>emptyMap(),
 150.472 +                    Arrays.asList(pattern));
 150.473 +
 150.474 +        long endTime = System.currentTimeMillis();
 150.475 +
 150.476 +        return endTime - startTime;
 150.477 +    }
 150.478 +
 150.479 +    public void XtestMeasureTime() throws Exception {
 150.480 +        String code = TestUtilities.copyFileToString(new File("/usr/local/home/lahvac/src/nb//outgoing/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java"));
 150.481 +        List<String> patterns = new LinkedList<String>();
 150.482 +
 150.483 +        for (int cntr = 0; cntr < 1000; cntr++) {
 150.484 +            patterns.add("System.err.println($1)");
 150.485 +        }
 150.486 +
 150.487 +        performTest(code,
 150.488 +                    Collections.<String, List<String>>emptyMap(),
 150.489 +                    patterns);
 150.490 +    }
 150.491 +
 150.492 +    public void testMatches1() throws Exception {
 150.493 +        performMatchesTest("package test; public class Test { private void test() { f.isDirectory(); } }", Arrays.asList("$1.isDirectory()", "new ImageIcon($1)"), true);
 150.494 +    }
 150.495 +
 150.496 +    public void testSerialization() throws Exception {
 150.497 +        String text = "package test; public class Test { public void test1(boolean b) { int q; if (b) q = 2; else q = 3; } }";
 150.498 +
 150.499 +        prepareTest("test/Test.java", text);
 150.500 +
 150.501 +        ByteArrayOutputStream out = new ByteArrayOutputStream();
 150.502 +        EncodingContext ec = new EncodingContext(out, false);
 150.503 +
 150.504 +        createSearch().encode(info.getCompilationUnit(), ec);
 150.505 +        
 150.506 +        boolean matches = createSearch().matches(new ByteArrayInputStream(out.toByteArray()), createSearch().create(info, "{ $p$; $T $v; if($a) $v = $b; else $v = $c; $q$; }"));
 150.507 +
 150.508 +        assertTrue(matches);
 150.509 +    }
 150.510 +
 150.511 +    public void testFrequencies() throws Exception {
 150.512 +        String text = "package test; public class Test { public void test1(boolean b) { java.io.File f = null; f.isDirectory(); f.isDirectory(); new javax.swing.ImageIcon(null); } }";
 150.513 +
 150.514 +        prepareTest("test/Test.java", text);
 150.515 +
 150.516 +        ByteArrayOutputStream out = new ByteArrayOutputStream();
 150.517 +        EncodingContext ec = new EncodingContext(out, false);
 150.518 +
 150.519 +        createSearch().encode(info.getCompilationUnit(), ec);
 150.520 +        
 150.521 +        Map<String, Integer> actual = createSearch().matchesWithFrequencies(new ByteArrayInputStream(out.toByteArray()), createSearch().create(info, "$1.isDirectory()", "new ImageIcon($1)"));
 150.522 +        Map<String, Integer> golden = new HashMap<String, Integer>();
 150.523 +
 150.524 +        golden.put("$1.isDirectory()", 2);
 150.525 +        golden.put("new ImageIcon($1)", 1);
 150.526 +
 150.527 +        assertEquals(golden, actual);
 150.528 +    }
 150.529 +
 150.530 +    public void testPatternEncodingAndIdentifiers() throws Exception {
 150.531 +        String text = "package test; public class Test { }";
 150.532 +
 150.533 +        prepareTest("test/Test.java", text);
 150.534 +
 150.535 +        BulkPattern bp = createSearch().create(info, "$0.isDirectory()");
 150.536 +
 150.537 +        assertEquals(Arrays.asList(new HashSet<String>(Arrays.asList("isDirectory"))), bp.getIdentifiers());
 150.538 +        //TODO: the actual code for kinds differs for NFABased search and REBased search:
 150.539 +//        assertEquals(Arrays.asList(new HashSet<String>(Arrays.asList(Kind.METHOD_INVOCATION.name()))), bp.getKinds());
 150.540 +    }
 150.541 +
 150.542 +    protected abstract BulkSearch createSearch();
 150.543 +    
 150.544 +    private void performMatchesTest(String text, List<String> patterns, boolean golden) throws Exception {
 150.545 +        prepareTest("test/Test.java", text);
 150.546 +
 150.547 +        BulkPattern p = createSearch().create(info, patterns);
 150.548 +
 150.549 +        boolean result = createSearch().matches(info, new TreePath(info.getCompilationUnit()), p);
 150.550 +
 150.551 +        assertEquals(golden, result);
 150.552 +    }
 150.553 +    
 150.554 +    private void performTest(String text, Map<String, List<String>> containedPatterns, Collection<String> notContainedPatterns) throws Exception {
 150.555 +        prepareTest("test/Test.java", text);
 150.556 +
 150.557 +        List<String> patterns = new LinkedList<String>();
 150.558 +
 150.559 +        patterns.addAll(containedPatterns.keySet());
 150.560 +        patterns.addAll(notContainedPatterns);
 150.561 +
 150.562 +        long s1 = System.currentTimeMillis();
 150.563 +        BulkPattern p = createSearch().create(info, patterns);
 150.564 +        long e1 = System.currentTimeMillis();
 150.565 +
 150.566 +//        System.err.println("create: " + (e1 - s1));
 150.567 +
 150.568 +        long s2 = System.currentTimeMillis();
 150.569 +        Map<String, Collection<TreePath>> result = createSearch().match(info, new TreePath(info.getCompilationUnit()), p);
 150.570 +        long e2 = System.currentTimeMillis();
 150.571 +
 150.572 +//        System.err.println("match: " + (e2 - s2));
 150.573 +
 150.574 +        assertTrue(result.toString(), result.keySet().containsAll(containedPatterns.keySet()));
 150.575 +
 150.576 +        for (Entry<String, Collection<TreePath>> e : result.entrySet()) {
 150.577 +            List<String> actual = new LinkedList<String>();
 150.578 +
 150.579 +            for (TreePath tp : e.getValue()) {
 150.580 +                assertNotNull(TreePathHandle.create(tp, info).resolve(info));
 150.581 +                
 150.582 +                int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tp.getLeaf());
 150.583 +                int end   = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), tp.getLeaf());
 150.584 +
 150.585 +                actual.add(info.getText().substring(start, end));
 150.586 +            }
 150.587 +
 150.588 +            assertEquals(e.getKey(), containedPatterns.get(e.getKey()), actual);
 150.589 +        }
 150.590 +
 150.591 +
 150.592 +        Set<String> none = new HashSet<String>(result.keySet());
 150.593 +
 150.594 +        none.retainAll(notContainedPatterns);
 150.595 +
 150.596 +        assertTrue(none.isEmpty());
 150.597 +
 150.598 +        if (!verifyIndexingData())
 150.599 +            return ;
 150.600 +        
 150.601 +        //ensure the returned identifiers/treeKinds are correct:
 150.602 +        ByteArrayOutputStream data = new ByteArrayOutputStream();
 150.603 +        EncodingContext ec = new EncodingContext(data, false);
 150.604 +        
 150.605 +        createSearch().encode(info.getCompilationUnit(), ec);
 150.606 +
 150.607 +        for (int i = 0; i < containedPatterns.size(); i++) {
 150.608 +            assertTrue("expected: " + p.getIdentifiers().get(i) + ", but exist only: " + ec.getIdentifiers(), ec.getIdentifiers().containsAll(p.getIdentifiers().get(i)));
 150.609 +            
 150.610 +            for (List<String> phrase : p.getRequiredContent().get(i)) {
 150.611 +                assertTrue("expected: " + phrase + ", but exist only: " + ec.getContent() + "(all phrases: " + p.getRequiredContent().get(i) + ")", Collections.indexOfSubList(ec.getContent(), phrase) != (-1));
 150.612 +            }
 150.613 +        }
 150.614 +
 150.615 +        data.close();
 150.616 +        assertEquals(!containedPatterns.isEmpty(), createSearch().matches(new ByteArrayInputStream(data.toByteArray()), p));
 150.617 +    }
 150.618 +    
 150.619 +    private void prepareTest(String fileName, String code) throws Exception {
 150.620 +        clearWorkDir();
 150.621 +
 150.622 +        FileUtil.refreshFor(File.listRoots());
 150.623 +
 150.624 +        FileObject workFO = FileUtil.toFileObject(getWorkDir());
 150.625 +
 150.626 +        assertNotNull(workFO);
 150.627 +
 150.628 +        workFO.refresh();
 150.629 +
 150.630 +        sourceRoot = workFO.createFolder("src");
 150.631 +        FileObject buildRoot  = workFO.createFolder("build");
 150.632 +        FileObject cache = workFO.createFolder("cache");
 150.633 +
 150.634 +        FileObject data = FileUtil.createData(sourceRoot, fileName);
 150.635 +        File dataFile = FileUtil.toFile(data);
 150.636 +
 150.637 +        assertNotNull(dataFile);
 150.638 +
 150.639 +        TestUtilities.copyStringToFile(dataFile, code);
 150.640 +
 150.641 +        SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache);
 150.642 +
 150.643 +        DataObject od = DataObject.find(data);
 150.644 +        EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
 150.645 +
 150.646 +        assertNotNull(ec);
 150.647 +
 150.648 +        doc = ec.openDocument();
 150.649 +        doc.putProperty(Language.class, JavaTokenId.language());
 150.650 +
 150.651 +        JavaSource js = JavaSource.forFileObject(data);
 150.652 +
 150.653 +        assertNotNull(js);
 150.654 +
 150.655 +        info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
 150.656 +
 150.657 +        assertNotNull(info);
 150.658 +    }
 150.659 +
 150.660 +    private FileObject sourceRoot;
 150.661 +    private CompilationInfo info;
 150.662 +    private Document doc;
 150.663 +
 150.664 +    protected boolean verifyIndexingData() {
 150.665 +        return true;
 150.666 +    }
 150.667 +}
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/source/transform/Transformer.java	Sat Feb 11 18:35:10 2012 +0100
   151.3 @@ -0,0 +1,133 @@
   151.4 +/*
   151.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   151.6 + *
   151.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   151.8 + *
   151.9 + * The contents of this file are subject to the terms of either the GNU
  151.10 + * General Public License Version 2 only ("GPL") or the Common
  151.11 + * Development and Distribution License("CDDL") (collectively, the
  151.12 + * "License"). You may not use this file except in compliance with the
  151.13 + * License. You can obtain a copy of the License at
  151.14 + * http://www.netbeans.org/cddl-gplv2.html
  151.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  151.16 + * specific language governing permissions and limitations under the
  151.17 + * License.  When distributing the software, include this License Header
  151.18 + * Notice in each file and include the License file at
  151.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  151.20 + * particular file as subject to the "Classpath" exception as provided
  151.21 + * by Sun in the GPL Version 2 section of the License file that
  151.22 + * accompanied this code. If applicable, add the following below the
  151.23 + * License Header, with the fields enclosed by brackets [] replaced by
  151.24 + * your own identifying information:
  151.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  151.26 + *
  151.27 + * Contributor(s):
  151.28 + *
  151.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  151.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  151.31 + * Microsystems, Inc. All Rights Reserved.
  151.32 + *
  151.33 + * If you wish your version of this file to be governed by only the CDDL
  151.34 + * or only the GPL Version 2, indicate your decision by adding
  151.35 + * "[Contributor] elects to include this software in this distribution
  151.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  151.37 + * single choice of license, a recipient has the option to distribute
  151.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  151.39 + * to extend the choice of license to its licensees as provided above.
  151.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  151.41 + * Version 2 license, then the option applies only if the new code is
  151.42 + * made subject to such option by the copyright holder.
  151.43 + */
  151.44 +
  151.45 +package org.netbeans.modules.java.source.transform;
  151.46 +
  151.47 +import org.netbeans.modules.java.source.query.CommentHandler;
  151.48 +import org.openide.util.NbBundle;
  151.49 +import com.sun.source.tree.*;
  151.50 +import com.sun.source.util.TreeScanner;
  151.51 +import com.sun.tools.javac.model.JavacTypes;
  151.52 +import com.sun.tools.javac.util.Context;
  151.53 +import java.util.List;
  151.54 +import java.util.logging.*;
  151.55 +import javax.lang.model.util.Types;
  151.56 +import org.netbeans.api.java.source.WorkingCopy;
  151.57 +import org.netbeans.modules.java.source.builder.ASTService;
  151.58 +import org.netbeans.modules.java.source.builder.CommentHandlerService;
  151.59 +import org.netbeans.modules.java.source.builder.TreeFactory;
  151.60 +
  151.61 +/**
  151.62 + * A Transformer is an Query that modifies the model.  Model transformation
  151.63 + * is done by a supplied ImmutableTreeTranslator implementation.  A new context
  151.64 + * is set upon successful completion of this Transformer.
  151.65 + */
  151.66 +public abstract class Transformer<R, P> extends TreeScanner<R,P> {
  151.67 +
  151.68 +    CommentHandler commentHandler;
  151.69 +    public TreeFactory make;
  151.70 +    protected WorkingCopy copy;
  151.71 +    protected String refactoringDescription;
  151.72 +    protected Types types; // used by tests
  151.73 +    private String failureMessage;
  151.74 +    protected ASTService model;
  151.75 +
  151.76 +    static final Logger logger = Logger.getLogger("org.netbeans.modules.java.source");
  151.77 +
  151.78 +    public void init() {
  151.79 +    }
  151.80 +
  151.81 +    /**
  151.82 +     * Initialize and associate this Query instance with the
  151.83 +     * specified QueryEnvironment.
  151.84 +     */
  151.85 +    public void attach(Context context, WorkingCopy copy) {
  151.86 +        make = TreeFactory.instance(context);
  151.87 +        types = JavacTypes.instance(context);
  151.88 +        commentHandler = CommentHandlerService.instance(context);
  151.89 +        model = ASTService.instance(context);
  151.90 +        this.copy = copy;
  151.91 +    }
  151.92 +
  151.93 +    /**
  151.94 +     * Release any instance data created during attach() invocation.  This
  151.95 +     * is necessary because the Java reflection support may cache created
  151.96 +     * instances, preventing the session data from being garbage-collected.
  151.97 +     */
  151.98 +    public void release() {
  151.99 +        //changes.release();  // enable when async results are supported
 151.100 +        //result.release()
 151.101 +        make = null;
 151.102 +        types = null;
 151.103 +        this.copy = null;
 151.104 +    }
 151.105 +
 151.106 +    public void destroy() {}
 151.107 +    
 151.108 +    public String getRefactoringDescription() {
 151.109 +        return refactoringDescription != null ? refactoringDescription : "Unnamed Refactoring";
 151.110 +    }
 151.111 +
 151.112 +    public void setRefactoringDescription(String description) {
 151.113 +        refactoringDescription = description;
 151.114 +    }
 151.115 +
 151.116 +    public void apply(Tree t) {
 151.117 +        t.accept(this, null);
 151.118 +    }
 151.119 +
 151.120 +    String getString(String key) {
 151.121 +        return NbBundle.getBundle(Transformer.class).getString(key); //NOI18N
 151.122 +    }
 151.123 +
 151.124 +    /**
 151.125 +     * True if no translation failures occurred.
 151.126 +     */
 151.127 +    protected boolean translationSuccessful() {
 151.128 +        return failureMessage == null;
 151.129 +    }
 151.130 +
 151.131 +    public final void copyCommentTo(Tree from, Tree to) {
 151.132 +        if (from != null && to != null) {
 151.133 +            commentHandler.copyComments(from, to);
 151.134 +        }
 151.135 +    }
 151.136 +}
   152.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/java/source/usages/IndexUtil.java	Sat Feb 11 18:35:10 2012 +0100
   152.3 @@ -0,0 +1,58 @@
   152.4 +/*
   152.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   152.6 + *
   152.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   152.8 + *
   152.9 + * The contents of this file are subject to the terms of either the GNU
  152.10 + * General Public License Version 2 only ("GPL") or the Common
  152.11 + * Development and Distribution License("CDDL") (collectively, the
  152.12 + * "License"). You may not use this file except in compliance with the
  152.13 + * License. You can obtain a copy of the License at
  152.14 + * http://www.netbeans.org/cddl-gplv2.html
  152.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  152.16 + * specific language governing permissions and limitations under the
  152.17 + * License.  When distributing the software, include this License Header
  152.18 + * Notice in each file and include the License file at
  152.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  152.20 + * particular file as subject to the "Classpath" exception as provided
  152.21 + * by Sun in the GPL Version 2 section of the License file that
  152.22 + * accompanied this code. If applicable, add the following below the
  152.23 + * License Header, with the fields enclosed by brackets [] replaced by
  152.24 + * your own identifying information:
  152.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  152.26 + *
  152.27 + * Contributor(s):
  152.28 + *
  152.29 + * The Original Software is NetBeans. The Initial Developer of the Original
  152.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  152.31 + * Microsystems, Inc. All Rights Reserved.
  152.32 + *
  152.33 + * If you wish your version of this file to be governed by only the CDDL
  152.34 + * or only the GPL Version 2, indicate your decision by adding
  152.35 + * "[Contributor] elects to include this software in this distribution
  152.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  152.37 + * single choice of license, a recipient has the option to distribute
  152.38 + * your version of this file under either the CDDL, the GPL Version 2 or
  152.39 + * to extend the choice of license to its licensees as provided above.
  152.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  152.41 + * Version 2 license, then the option applies only if the new code is
  152.42 + * made subject to such option by the copyright holder.
  152.43 + */
  152.44 +
  152.45 +package org.netbeans.modules.java.source.usages;
  152.46 +
  152.47 +import java.io.File;
  152.48 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
  152.49 +import org.openide.filesystems.FileUtil;
  152.50 +
  152.51 +/**
  152.52 + *
  152.53 + * @author Tomas Zezula
  152.54 + */
  152.55 +public class IndexUtil {
  152.56 +
  152.57 +    public static void setCacheFolder (final File cacheFolder) {
  152.58 +        CacheFolder.setCacheFolder(FileUtil.toFileObject(cacheFolder));
  152.59 +    }
  152.60 +
  152.61 +}
   153.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.2 +++ b/remoting/common/borrowedtests/src/org/netbeans/modules/parsing/impl/indexing/MimeTypes.java	Sat Feb 11 18:35:10 2012 +0100
   153.3 @@ -0,0 +1,66 @@
   153.4 +/*
   153.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   153.6 + *
   153.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   153.8 + *
   153.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  153.10 + * Other names may be trademarks of their respective owners.
  153.11 + *
  153.12 + * The contents of this file are subject to the terms of either the GNU
  153.13 + * General Public License Version 2 only ("GPL") or the Common
  153.14 + * Development and Distribution License("CDDL") (collectively, the
  153.15 + * "License"). You may not use this file except in compliance with the
  153.16 + * License. You can obtain a copy of the License at
  153.17 + * http://www.netbeans.org/cddl-gplv2.html
  153.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  153.19 + * specific language governing permissions and limitations under the
  153.20 + * License.  When distributing the software, include this License Header
  153.21 + * Notice in each file and include the License file at
  153.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  153.23 + * particular file as subject to the "Classpath" exception as provided
  153.24 + * by Oracle in the GPL Version 2 section of the License file that
  153.25 + * accompanied this code. If applicable, add the following below the
  153.26 + * License Header, with the fields enclosed by brackets [] replaced by
  153.27 + * your own identifying information:
  153.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  153.29 + *
  153.30 + * If you wish your version of this file to be governed by only the CDDL
  153.31 + * or only the GPL Version 2, indicate your decision by adding
  153.32 + * "[Contributor] elects to include this software in this distribution
  153.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  153.34 + * single choice of license, a recipient has the option to distribute
  153.35 + * your version of this file under either the CDDL, the GPL Version 2 or
  153.36 + * to extend the choice of license to its licensees as provided above.
  153.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  153.38 + * Version 2 license, then the option applies only if the new code is
  153.39 + * made subject to such option by the copyright holder.
  153.40 + *
  153.41 + * Contributor(s):
  153.42 + *
  153.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
  153.44 + */
  153.45 +package org.netbeans.modules.parsing.impl.indexing;
  153.46 +
  153.47 +import java.util.Set;
  153.48 +import org.netbeans.api.annotations.common.CheckForNull;
  153.49 +import org.netbeans.api.annotations.common.NonNull;
  153.50 +import org.openide.util.Parameters;
  153.51 +
  153.52 +/**
  153.53 + *
  153.54 + * @author Tomas Zezula
  153.55 + */
  153.56 +public class MimeTypes {
  153.57 +
  153.58 +    private MimeTypes() {}
  153.59 +
  153.60 +    public static void setAllMimeTypes(@NonNull final Set<String> allMimeTypes) {
  153.61 +        Parameters.notNull("allMimeTypes", allMimeTypes);   //NOI18N
  153.62 +        Util.allMimeTypes = allMimeTypes;
  153.63 +    }
  153.64 +
  153.65 +    @CheckForNull
  153.66 +    public static Set<String> getAllMimeTypes() {
  153.67 +        return Util.allMimeTypes;
  153.68 +    }
  153.69 +}
   154.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.2 +++ b/remoting/common/borrowedtests/src/org/openide/util/test/AnnotationProcessorTestUtils.java	Sat Feb 11 18:35:10 2012 +0100
   154.3 @@ -0,0 +1,139 @@
   154.4 +/*
   154.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   154.6 + *
   154.7 + * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
   154.8 + *
   154.9 + * The contents of this file are subject to the terms of either the GNU
  154.10 + * General Public License Version 2 only ("GPL") or the Common
  154.11 + * Development and Distribution License("CDDL") (collectively, the
  154.12 + * "License"). You may not use this file except in compliance with the
  154.13 + * License. You can obtain a copy of the License at
  154.14 + * http://www.netbeans.org/cddl-gplv2.html
  154.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  154.16 + * specific language governing permissions and limitations under the
  154.17 + * License.  When distributing the software, include this License Header
  154.18 + * Notice in each file and include the License file at
  154.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  154.20 + * particular file as subject to the "Classpath" exception as provided
  154.21 + * by Sun in the GPL Version 2 section of the License file that
  154.22 + * accompanied this code. If applicable, add the following below the
  154.23 + * License Header, with the fields enclosed by brackets [] replaced by
  154.24 + * your own identifying information:
  154.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  154.26 + *
  154.27 + * If you wish your version of this file to be governed by only the CDDL
  154.28 + * or only the GPL Version 2, indicate your decision by adding
  154.29 + * "[Contributor] elects to include this software in this distribution
  154.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  154.31 + * single choice of license, a recipient has the option to distribute
  154.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  154.33 + * to extend the choice of license to its licensees as provided above.
  154.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  154.35 + * Version 2 license, then the option applies only if the new code is
  154.36 + * made subject to such option by the copyright holder.
  154.37 + *
  154.38 + * Contributor(s):
  154.39 + *
  154.40 + * Portions Copyrighted 2008 Sun Microsystems, Inc.
  154.41 + */
  154.42 +
  154.43 +package org.openide.util.test;
  154.44 +
  154.45 +import java.io.File;
  154.46 +import java.io.FileWriter;
  154.47 +import java.io.IOException;
  154.48 +import java.io.OutputStream;
  154.49 +import java.io.PrintWriter;
  154.50 +import java.io.Writer;
  154.51 +import java.util.ArrayList;
  154.52 +import java.util.List;
  154.53 +import java.util.regex.Pattern;
  154.54 +import javax.tools.JavaCompiler;
  154.55 +import javax.tools.ToolProvider;
  154.56 +import junit.framework.Assert;
  154.57 +
  154.58 +/**
  154.59 + * Utilities useful to those testing JSR 269 annotation processors.
  154.60 + * <p>If you just want to test that the output of the processor is correct,
  154.61 + * you do not need to do anything special:
  154.62 + * just use the annotation on some sample classes nested inside your unit test.
  154.63 + * They will be processed, and you check that your SPI loads them correctly.
  154.64 + * These utilities are useful mainly in case you want to check that the processor
  154.65 + * rejects erroneous sources, and that any messages it prints are reasonable;
  154.66 + * that it behaves correctly on incremental compilations; etc.
  154.67 + */
  154.68 +public class AnnotationProcessorTestUtils {
  154.69 +
  154.70 +    private AnnotationProcessorTestUtils() {}
  154.71 +
  154.72 +    /**
  154.73 +     * Create a source file.
  154.74 +     * @param dir source root
  154.75 +     * @param clazz a fully-qualified class name
  154.76 +     * @param content lines of text (skip package decl)
  154.77 +     */
  154.78 +    public static void makeSource(File dir, String clazz, String... content) throws IOException {
  154.79 +        File f = new File(dir, clazz.replace('.', File.separatorChar) + ".java");
  154.80 +        f.getParentFile().mkdirs();
  154.81 +        Writer w = new FileWriter(f);
  154.82 +        try {
  154.83 +            PrintWriter pw = new PrintWriter(w);
  154.84 +            String pkg = clazz.replaceFirst("\\.[^.]+$", "");
  154.85 +            if (!pkg.equals(clazz)) {
  154.86 +                pw.println("package " + pkg + ";");
  154.87 +            }
  154.88 +            for (String line : content) {
  154.89 +                pw.println(line);
  154.90 +            }
  154.91 +            pw.flush();
  154.92 +        } finally {
  154.93 +            w.close();
  154.94 +        }
  154.95 +    }
  154.96 +
  154.97 +    /**
  154.98 +     * Run the Java compiler.
  154.99 +     * (A JSR 199 implementation must be available.)
 154.100 +     * @param src a source root (runs javac on all *.java it finds matching {@code srcIncludes})
 154.101 +     * @param srcIncludes a pattern of source files names without path to compile (useful for testing incremental compiles), or null for all
 154.102 +     * @param dest a dest dir to compile classes to
 154.103 +     * @param cp classpath entries; if null, use Java classpath of test
 154.104 +     * @param stderr output stream to print messages to, or null for test console (i.e. do not capture)
 154.105 +     * @return true if compilation succeeded, false if it failed
 154.106 +     */
 154.107 +    public static boolean runJavac(File src, String srcIncludes, File dest, File[] cp, OutputStream stderr) {
 154.108 +        List<String> args = new ArrayList<String>();
 154.109 +        args.add("-classpath");
 154.110 +        if (cp != null) {
 154.111 +            StringBuffer b = new StringBuffer();
 154.112 +            for (File entry : cp) {
 154.113 +                b.append(File.pathSeparatorChar);
 154.114 +                b.append(entry.getAbsolutePath());
 154.115 +            }
 154.116 +            args.add(b.toString());
 154.117 +        } else {
 154.118 +            args.add(System.getProperty("java.class.path"));
 154.119 +        }
 154.120 +        args.add("-d");
 154.121 +        args.add(dest.getAbsolutePath());
 154.122 +        args.add("-sourcepath");
 154.123 +        args.add(src.getAbsolutePath());
 154.124 +        dest.mkdirs();
 154.125 +        scan(args, src, srcIncludes);
 154.126 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 154.127 +        Assert.assertNotNull("no JSR 199 compiler impl found; try e.g.: " +
 154.128 +                "test.unit.run.cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar", compiler);
 154.129 +        //System.err.println("running javac with args: " + args);
 154.130 +        return compiler.run(null, null, stderr, args.toArray(new String[args.size()])) == 0;
 154.131 +    }
 154.132 +    private static void scan(List<String> names, File f, String includes) {
 154.133 +        if (f.isDirectory()) {
 154.134 +            for (File kid : f.listFiles()) {
 154.135 +                scan(names, kid, includes);
 154.136 +            }
 154.137 +        } else if (f.getName().endsWith(".java") && (includes == null || Pattern.compile(includes).matcher(f.getName()).find())) {
 154.138 +            names.add(f.getAbsolutePath());
 154.139 +        }
 154.140 +    }
 154.141 +
 154.142 +}
   155.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.2 +++ b/remoting/common/build.xml	Sat Feb 11 18:35:10 2012 +0100
   155.3 @@ -0,0 +1,8 @@
   155.4 +<?xml version="1.0" encoding="UTF-8"?>
   155.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   155.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   155.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   155.8 +<project name="base" basedir=".">
   155.9 +    <description>Builds the module suite base.</description>
  155.10 +    <import file="nbproject/build-impl.xml"/>
  155.11 +</project>
   156.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.2 +++ b/remoting/common/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   156.3 @@ -0,0 +1,50 @@
   156.4 +<?xml version="1.0" encoding="UTF-8"?>
   156.5 +<!--
   156.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   156.7 +***         EDIT ../build.xml INSTEAD         ***
   156.8 +-->
   156.9 +<project name="base-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
  156.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  156.11 +        <condition>
  156.12 +            <not>
  156.13 +                <antversion atleast="1.7.1"/>
  156.14 +            </not>
  156.15 +        </condition>
  156.16 +    </fail>
  156.17 +    <property file="nbproject/private/platform-private.properties"/>
  156.18 +    <property file="nbproject/platform.properties"/>
  156.19 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
  156.20 +        <attribute name="name"/>
  156.21 +        <attribute name="value"/>
  156.22 +        <sequential>
  156.23 +            <property name="@{name}" value="${@{value}}"/>
  156.24 +        </sequential>
  156.25 +    </macrodef>
  156.26 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-suite-project/1">
  156.27 +        <attribute name="property"/>
  156.28 +        <attribute name="value"/>
  156.29 +        <sequential>
  156.30 +            <property name="@{property}" value="@{value}"/>
  156.31 +        </sequential>
  156.32 +    </macrodef>
  156.33 +    <property file="${user.properties.file}"/>
  156.34 +    <sproject:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir"/>
  156.35 +    <sproject:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir"/>
  156.36 +    <sproject:evalprops property="cluster.path.evaluated" value="${cluster.path}"/>
  156.37 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  156.38 +        <condition>
  156.39 +            <not>
  156.40 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  156.41 +            </not>
  156.42 +        </condition>
  156.43 +    </fail>
  156.44 +    <ant antfile="nbproject/platform.xml"/>
  156.45 +    <fail message="Cannot find NetBeans build harness. ${line.separator}Check that nbplatform.${nbplatform.active}.netbeans.dest.dir and nbplatform.${nbplatform.active}.harness.dir are defined. ${line.separator}On a developer machine these are normally defined in ${user.properties.file}=${netbeans.user}/build.properties ${line.separator}but for automated builds you should pass these properties to Ant explicitly. ${line.separator}You may instead download the harness and platform: -Dbootstrap.url=.../tasks.jar -Dautoupdate.catalog.url=.../updates.xml">
  156.46 +        <condition>
  156.47 +            <not>
  156.48 +                <available file="${harness.dir}/suite.xml"/>
  156.49 +            </not>
  156.50 +        </condition>
  156.51 +    </fail>
  156.52 +    <import file="${harness.dir}/suite.xml"/>
  156.53 +</project>
   157.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.2 +++ b/remoting/common/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   157.3 @@ -0,0 +1,11 @@
   157.4 +build.xml.data.CRC32=8c462dad
   157.5 +build.xml.script.CRC32=263c4f10
   157.6 +build.xml.stylesheet.CRC32=eaf9f76a@2.49
   157.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   157.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   157.9 +nbproject/build-impl.xml.data.CRC32=8c462dad
  157.10 +nbproject/build-impl.xml.script.CRC32=64b5d2e4
  157.11 +nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.49
  157.12 +nbproject/platform.xml.data.CRC32=8c462dad
  157.13 +nbproject/platform.xml.script.CRC32=db9e1f43
  157.14 +nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.49
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/remoting/common/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
   158.3 @@ -0,0 +1,12 @@
   158.4 +cluster.path=\
   158.5 +    ${nbplatform.active.dir}/apisupport:\
   158.6 +    ${nbplatform.active.dir}/profiler:\
   158.7 +    ${nbplatform.active.dir}/ide:\
   158.8 +    ${nbplatform.active.dir}/nb:\
   158.9 +    ${nbplatform.active.dir}/java:\
  158.10 +    ${nbplatform.active.dir}/harness:\
  158.11 +    ${nbplatform.active.dir}/javafx:\
  158.12 +    ${nbplatform.active.dir}/websvccommon:\
  158.13 +    ${nbplatform.active.dir}/platform:\
  158.14 +    ${nbplatform.active.dir}/extra
  158.15 +nbplatform.active=default
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/remoting/common/nbproject/platform.xml	Sat Feb 11 18:35:10 2012 +0100
   159.3 @@ -0,0 +1,34 @@
   159.4 +<?xml version="1.0" encoding="UTF-8"?>
   159.5 +<project name="platform" default="download" basedir="..">
   159.6 +    <condition property="download.required">
   159.7 +        <and>
   159.8 +            <not>
   159.9 +                <available file="${harness.dir}/suite.xml"/>
  159.10 +            </not>
  159.11 +            <isset property="bootstrap.url"/>
  159.12 +            <isset property="autoupdate.catalog.url"/>
  159.13 +        </and>
  159.14 +    </condition>
  159.15 +    <target name="download" if="download.required">
  159.16 +        <mkdir dir="${harness.dir}"/>
  159.17 +        <pathconvert pathsep="|" property="download.clusters">
  159.18 +            <mapper type="flatten"/>
  159.19 +            <path path="${cluster.path}"/>
  159.20 +        </pathconvert>
  159.21 +        <property name="disabled.modules" value=""/>
  159.22 +        <pathconvert property="module.includes" pathsep="">
  159.23 +            <mapper type="glob" from="${basedir}${file.separator}*" to="(?!\Q*\E)"/>
  159.24 +            <path>
  159.25 +                <filelist files="${disabled.modules}" dir="."/>
  159.26 +            </path>
  159.27 +        </pathconvert>
  159.28 +        <echo message="Downloading clusters ${download.clusters}"/>
  159.29 +        <property name="tasks.jar" location="${java.io.tmpdir}/tasks.jar"/>
  159.30 +        <get src="${bootstrap.url}" dest="${tasks.jar}" usetimestamp="true" verbose="true"/>
  159.31 +        <taskdef name="autoupdate" classname="org.netbeans.nbbuild.AutoUpdate" classpath="${tasks.jar}"/>
  159.32 +        <autoupdate installdir="${nbplatform.active.dir}" updatecenter="${autoupdate.catalog.url}">
  159.33 +            <modules includes="${module.includes}.*" clusters="${download.clusters}"/>
  159.34 +            <modules includes="org[.]netbeans[.]modules[.]apisupport[.]harness" clusters="harness"/>
  159.35 +        </autoupdate>
  159.36 +    </target>
  159.37 +</project>
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/remoting/common/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   160.3 @@ -0,0 +1,8 @@
   160.4 +app.title=common
   160.5 +modules=\
   160.6 +    ${project.org.netbeans.modules.jackpot30.common}:\
   160.7 +    ${project.org.netbeans.modules.jackpot30.test.borrowed}:\
   160.8 +    ${project.org.netbeans.modules.jackpot30.common.test}
   160.9 +project.org.netbeans.modules.jackpot30.common=api
  160.10 +project.org.netbeans.modules.jackpot30.common.test=test
  160.11 +project.org.netbeans.modules.jackpot30.test.borrowed=borrowedtests
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/remoting/common/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   161.3 @@ -0,0 +1,9 @@
   161.4 +<?xml version="1.0" encoding="UTF-8"?>
   161.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   161.6 +    <type>org.netbeans.modules.apisupport.project.suite</type>
   161.7 +    <configuration>
   161.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-suite-project/1">
   161.9 +            <name>base</name>
  161.10 +        </data>
  161.11 +    </configuration>
  161.12 +</project>
   162.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   162.2 +++ b/remoting/common/test/build.xml	Sat Feb 11 18:35:10 2012 +0100
   162.3 @@ -0,0 +1,8 @@
   162.4 +<?xml version="1.0" encoding="UTF-8"?>
   162.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   162.6 +<!-- for some information on what you could do (e.g. targets to override). -->
   162.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
   162.8 +<project name="org.netbeans.modules.jackpot30.common.test" default="netbeans" basedir=".">
   162.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.common.test.</description>
  162.10 +    <import file="nbproject/build-impl.xml"/>
  162.11 +</project>
   163.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.2 +++ b/remoting/common/test/manifest.mf	Sat Feb 11 18:35:10 2012 +0100
   163.3 @@ -0,0 +1,5 @@
   163.4 +Manifest-Version: 1.0
   163.5 +OpenIDE-Module: org.netbeans.modules.jackpot30.common.test
   163.6 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/common/test/Bundle.properties
   163.7 +OpenIDE-Module-Specification-Version: 1.0
   163.8 +
   164.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   164.2 +++ b/remoting/common/test/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   164.3 @@ -0,0 +1,45 @@
   164.4 +<?xml version="1.0" encoding="UTF-8"?>
   164.5 +<!--
   164.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
   164.7 +***         EDIT ../build.xml INSTEAD         ***
   164.8 +-->
   164.9 +<project name="org.netbeans.modules.jackpot30.common.test-impl" basedir="..">
  164.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
  164.11 +        <condition>
  164.12 +            <not>
  164.13 +                <antversion atleast="1.7.1"/>
  164.14 +            </not>
  164.15 +        </condition>
  164.16 +    </fail>
  164.17 +    <property file="nbproject/private/suite-private.properties"/>
  164.18 +    <property file="nbproject/suite.properties"/>
  164.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
  164.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
  164.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
  164.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
  164.23 +        <attribute name="name"/>
  164.24 +        <attribute name="value"/>
  164.25 +        <sequential>
  164.26 +            <property name="@{name}" value="${@{value}}"/>
  164.27 +        </sequential>
  164.28 +    </macrodef>
  164.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
  164.30 +        <attribute name="property"/>
  164.31 +        <attribute name="value"/>
  164.32 +        <sequential>
  164.33 +            <property name="@{property}" value="@{value}"/>
  164.34 +        </sequential>
  164.35 +    </macrodef>
  164.36 +    <property file="${user.properties.file}"/>
  164.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  164.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  164.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
  164.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
  164.41 +        <condition>
  164.42 +            <not>
  164.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
  164.44 +            </not>
  164.45 +        </condition>
  164.46 +    </fail>
  164.47 +    <import file="${harness.dir}/build.xml"/>
  164.48 +</project>
   165.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   165.2 +++ b/remoting/common/test/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   165.3 @@ -0,0 +1,8 @@
   165.4 +build.xml.data.CRC32=4735325c
   165.5 +build.xml.script.CRC32=b3a2b248
   165.6 +build.xml.stylesheet.CRC32=a56c6a5b@2.49
   165.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   165.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   165.9 +nbproject/build-impl.xml.data.CRC32=4735325c
  165.10 +nbproject/build-impl.xml.script.CRC32=4e8c4baf
  165.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
   166.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   166.2 +++ b/remoting/common/test/nbproject/project.properties	Sat Feb 11 18:35:10 2012 +0100
   166.3 @@ -0,0 +1,2 @@
   166.4 +javac.source=1.6
   166.5 +javac.compilerargs=-Xlint -Xlint:-serial
   167.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   167.2 +++ b/remoting/common/test/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   167.3 @@ -0,0 +1,339 @@
   167.4 +<?xml version="1.0" encoding="UTF-8"?>
   167.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
   167.6 +    <type>org.netbeans.modules.apisupport.project</type>
   167.7 +    <configuration>
   167.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
   167.9 +            <code-name-base>org.netbeans.modules.jackpot30.common.test</code-name-base>
  167.10 +            <suite-component/>
  167.11 +            <module-dependencies>
  167.12 +                <dependency>
  167.13 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
  167.14 +                    <build-prerequisite/>
  167.15 +                    <compile-dependency/>
  167.16 +                    <run-dependency>
  167.17 +                        <release-version>1</release-version>
  167.18 +                        <specification-version>1.13</specification-version>
  167.19 +                    </run-dependency>
  167.20 +                </dependency>
  167.21 +                <dependency>
  167.22 +                    <code-name-base>org.netbeans.api.java</code-name-base>
  167.23 +                    <build-prerequisite/>
  167.24 +                    <compile-dependency/>
  167.25 +                    <run-dependency>
  167.26 +                        <release-version>1</release-version>
  167.27 +                        <specification-version>1.31</specification-version>
  167.28 +                    </run-dependency>
  167.29 +                </dependency>
  167.30 +                <dependency>
  167.31 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
  167.32 +                    <build-prerequisite/>
  167.33 +                    <compile-dependency/>
  167.34 +                    <run-dependency>
  167.35 +                        <release-version>1</release-version>
  167.36 +                        <specification-version>1.27</specification-version>
  167.37 +                    </run-dependency>
  167.38 +                </dependency>
  167.39 +                <dependency>
  167.40 +                    <code-name-base>org.netbeans.api.progress</code-name-base>
  167.41 +                    <build-prerequisite/>
  167.42 +                    <compile-dependency/>
  167.43 +                    <run-dependency>
  167.44 +                        <release-version>1</release-version>
  167.45 +                        <specification-version>1.22</specification-version>
  167.46 +                    </run-dependency>
  167.47 +                </dependency>
  167.48 +                <dependency>
  167.49 +                    <code-name-base>org.netbeans.core.startup</code-name-base>
  167.50 +                    <build-prerequisite/>
  167.51 +                    <compile-dependency/>
  167.52 +                    <run-dependency>
  167.53 +                        <release-version>1</release-version>
  167.54 +                        <implementation-version/>
  167.55 +                    </run-dependency>
  167.56 +                </dependency>
  167.57 +                <dependency>
  167.58 +                    <code-name-base>org.netbeans.insane</code-name-base>
  167.59 +                    <build-prerequisite/>
  167.60 +                    <compile-dependency/>
  167.61 +                    <run-dependency>
  167.62 +                        <release-version>1</release-version>
  167.63 +                        <implementation-version/>
  167.64 +                    </run-dependency>
  167.65 +                </dependency>
  167.66 +                <dependency>
  167.67 +                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
  167.68 +                    <build-prerequisite/>
  167.69 +                    <compile-dependency/>
  167.70 +                    <run-dependency>
  167.71 +                        <specification-version>7.1.0.2</specification-version>
  167.72 +                    </run-dependency>
  167.73 +                </dependency>
  167.74 +                <dependency>
  167.75 +                    <code-name-base>org.netbeans.libs.javacimpl</code-name-base>
  167.76 +                    <build-prerequisite/>
  167.77 +                    <compile-dependency/>
  167.78 +                    <run-dependency>
  167.79 +                        <release-version>1</release-version>
  167.80 +                        <implementation-version/>
  167.81 +                    </run-dependency>
  167.82 +                </dependency>
  167.83 +                <dependency>
  167.84 +                    <code-name-base>org.netbeans.libs.junit4</code-name-base>
  167.85 +                    <build-prerequisite/>
  167.86 +                    <compile-dependency/>
  167.87 +                    <run-dependency>
  167.88 +                        <specification-version>1.12</specification-version>
  167.89 +                    </run-dependency>
  167.90 +                </dependency>
  167.91 +                <dependency>
  167.92 +                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
  167.93 +                    <build-prerequisite/>
  167.94 +                    <compile-dependency/>
  167.95 +                    <run-dependency>
  167.96 +                        <release-version>1-3</release-version>
  167.97 +                        <specification-version>2.13</specification-version>
  167.98 +                    </run-dependency>
  167.99 +                </dependency>
 167.100 +                <dependency>
 167.101 +                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
 167.102 +                    <build-prerequisite/>
 167.103 +                    <compile-dependency/>
 167.104 +                    <run-dependency>
 167.105 +                        <release-version>1</release-version>
 167.106 +                        <specification-version>1.35.0.5</specification-version>
 167.107 +                    </run-dependency>
 167.108 +                </dependency>
 167.109 +                <dependency>
 167.110 +                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
 167.111 +                    <build-prerequisite/>
 167.112 +                    <compile-dependency/>
 167.113 +                    <run-dependency>
 167.114 +                        <release-version>1</release-version>
 167.115 +                        <specification-version>1.20</specification-version>
 167.116 +                    </run-dependency>
 167.117 +                </dependency>
 167.118 +                <dependency>
 167.119 +                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
 167.120 +                    <build-prerequisite/>
 167.121 +                    <compile-dependency/>
 167.122 +                    <run-dependency>
 167.123 +                        <release-version>1</release-version>
 167.124 +                        <specification-version>1.39</specification-version>
 167.125 +                    </run-dependency>
 167.126 +                </dependency>
 167.127 +                <dependency>
 167.128 +                    <code-name-base>org.netbeans.modules.jackpot30.test.borrowed</code-name-base>
 167.129 +                    <build-prerequisite/>
 167.130 +                    <compile-dependency/>
 167.131 +                    <run-dependency>
 167.132 +                        <implementation-version/>
 167.133 +                    </run-dependency>
 167.134 +                </dependency>
 167.135 +                <dependency>
 167.136 +                    <code-name-base>org.netbeans.modules.java.hints</code-name-base>
 167.137 +                    <build-prerequisite/>
 167.138 +                    <compile-dependency/>
 167.139 +                    <run-dependency>
 167.140 +                        <release-version>1</release-version>
 167.141 +                        <implementation-version/>
 167.142 +                    </run-dependency>
 167.143 +                </dependency>
 167.144 +                <dependency>
 167.145 +                    <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
 167.146 +                    <build-prerequisite/>
 167.147 +                    <compile-dependency/>
 167.148 +                    <run-dependency>
 167.149 +                        <release-version>1</release-version>
 167.150 +                        <specification-version>1.12</specification-version>
 167.151 +                    </run-dependency>
 167.152 +                </dependency>
 167.153 +                <dependency>
 167.154 +                    <code-name-base>org.netbeans.modules.java.preprocessorbridge</code-name-base>
 167.155 +                    <build-prerequisite/>
 167.156 +                    <compile-dependency/>
 167.157 +                    <run-dependency>
 167.158 +                        <implementation-version/>
 167.159 +                    </run-dependency>
 167.160 +                </dependency>
 167.161 +                <dependency>
 167.162 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
 167.163 +                    <build-prerequisite/>
 167.164 +                    <compile-dependency/>
 167.165 +                    <run-dependency>
 167.166 +                        <implementation-version/>
 167.167 +                    </run-dependency>
 167.168 +                </dependency>
 167.169 +                <dependency>
 167.170 +                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
 167.171 +                    <build-prerequisite/>
 167.172 +                    <compile-dependency/>
 167.173 +                    <run-dependency>
 167.174 +                        <release-version>2</release-version>
 167.175 +                        <specification-version>1.37.0.1</specification-version>
 167.176 +                    </run-dependency>
 167.177 +                </dependency>
 167.178 +                <dependency>
 167.179 +                    <code-name-base>org.netbeans.modules.masterfs</code-name-base>
 167.180 +                    <build-prerequisite/>
 167.181 +                    <compile-dependency/>
 167.182 +                    <run-dependency>
 167.183 +                        <release-version>2</release-version>
 167.184 +                        <implementation-version/>
 167.185 +                    </run-dependency>
 167.186 +                </dependency>
 167.187 +                <dependency>
 167.188 +                    <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
 167.189 +                    <build-prerequisite/>
 167.190 +                    <compile-dependency/>
 167.191 +                    <run-dependency>
 167.192 +                        <release-version>1</release-version>
 167.193 +                        <specification-version>1.65</specification-version>
 167.194 +                    </run-dependency>
 167.195 +                </dependency>
 167.196 +                <dependency>
 167.197 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
 167.198 +                    <build-prerequisite/>
 167.199 +                    <compile-dependency/>
 167.200 +                    <run-dependency>
 167.201 +                        <release-version>1</release-version>
 167.202 +                        <implementation-version/>
 167.203 +                    </run-dependency>
 167.204 +                </dependency>
 167.205 +                <dependency>
 167.206 +                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
 167.207 +                    <build-prerequisite/>
 167.208 +                    <compile-dependency/>
 167.209 +                    <run-dependency>
 167.210 +                        <release-version>1</release-version>
 167.211 +                        <specification-version>1.34</specification-version>
 167.212 +                    </run-dependency>
 167.213 +                </dependency>
 167.214 +                <dependency>
 167.215 +                    <code-name-base>org.netbeans.modules.projectui</code-name-base>
 167.216 +                    <build-prerequisite/>
 167.217 +                    <compile-dependency/>
 167.218 +                    <run-dependency>
 167.219 +                        <implementation-version/>
 167.220 +                    </run-dependency>
 167.221 +                </dependency>
 167.222 +                <dependency>
 167.223 +                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
 167.224 +                    <build-prerequisite/>
 167.225 +                    <compile-dependency/>
 167.226 +                    <run-dependency>
 167.227 +                        <release-version>1</release-version>
 167.228 +                        <specification-version>1.49.0.8</specification-version>
 167.229 +                    </run-dependency>
 167.230 +                </dependency>
 167.231 +                <dependency>
 167.232 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
 167.233 +                    <build-prerequisite/>
 167.234 +                    <compile-dependency/>
 167.235 +                    <run-dependency>
 167.236 +                        <release-version>1</release-version>
 167.237 +                        <specification-version>1.21</specification-version>
 167.238 +                    </run-dependency>
 167.239 +                </dependency>
 167.240 +                <dependency>
 167.241 +                    <code-name-base>org.netbeans.spi.editor.hints</code-name-base>
 167.242 +                    <build-prerequisite/>
 167.243 +                    <compile-dependency/>
 167.244 +                    <run-dependency>
 167.245 +                        <release-version>0-1</release-version>
 167.246 +                        <specification-version>1.16.0.7.5</specification-version>
 167.247 +                    </run-dependency>
 167.248 +                </dependency>
 167.249 +                <dependency>
 167.250 +                    <code-name-base>org.openide.actions</code-name-base>
 167.251 +                    <build-prerequisite/>
 167.252 +                    <compile-dependency/>
 167.253 +                    <run-dependency>
 167.254 +                        <specification-version>6.19</specification-version>
 167.255 +                    </run-dependency>
 167.256 +                </dependency>
 167.257 +                <dependency>
 167.258 +                    <code-name-base>org.openide.awt</code-name-base>
 167.259 +                    <build-prerequisite/>
 167.260 +                    <compile-dependency/>
 167.261 +                    <run-dependency>
 167.262 +                        <specification-version>7.29</specification-version>
 167.263 +                    </run-dependency>
 167.264 +                </dependency>
 167.265 +                <dependency>
 167.266 +                    <code-name-base>org.openide.dialogs</code-name-base>
 167.267 +                    <build-prerequisite/>
 167.268 +                    <compile-dependency/>
 167.269 +                    <run-dependency>
 167.270 +                        <specification-version>7.17</specification-version>
 167.271 +                    </run-dependency>
 167.272 +                </dependency>
 167.273 +                <dependency>
 167.274 +                    <code-name-base>org.openide.filesystems</code-name-base>
 167.275 +                    <build-prerequisite/>
 167.276 +                    <compile-dependency/>
 167.277 +                    <run-dependency>
 167.278 +                        <specification-version>7.43</specification-version>
 167.279 +                    </run-dependency>
 167.280 +                </dependency>
 167.281 +                <dependency>
 167.282 +                    <code-name-base>org.openide.loaders</code-name-base>
 167.283 +                    <build-prerequisite/>
 167.284 +                    <compile-dependency/>
 167.285 +                    <run-dependency>
 167.286 +                        <specification-version>7.19</specification-version>
 167.287 +                    </run-dependency>
 167.288 +                </dependency>
 167.289 +                <dependency>
 167.290 +                    <code-name-base>org.openide.nodes</code-name-base>
 167.291 +                    <build-prerequisite/>
 167.292 +                    <compile-dependency/>
 167.293 +                    <run-dependency>
 167.294 +                        <specification-version>7.19</specification-version>
 167.295 +                    </run-dependency>
 167.296 +                </dependency>
 167.297 +                <dependency>
 167.298 +                    <code-name-base>org.openide.text</code-name-base>
 167.299 +                    <build-prerequisite/>
 167.300 +                    <compile-dependency/>
 167.301 +                    <run-dependency>
 167.302 +                        <specification-version>6.34</specification-version>
 167.303 +                    </run-dependency>
 167.304 +                </dependency>
 167.305 +                <dependency>
 167.306 +                    <code-name-base>org.openide.util</code-name-base>
 167.307 +                    <build-prerequisite/>
 167.308 +                    <compile-dependency/>
 167.309 +                    <run-dependency>
 167.310 +                        <specification-version>8.9</specification-version>
 167.311 +                    </run-dependency>
 167.312 +                </dependency>
 167.313 +                <dependency>
 167.314 +                    <code-name-base>org.openide.util.lookup</code-name-base>
 167.315 +                    <build-prerequisite/>
 167.316 +                    <compile-dependency/>
 167.317 +                    <run-dependency>
 167.318 +                        <specification-version>8.5</specification-version>
 167.319 +                    </run-dependency>
 167.320 +                </dependency>
 167.321 +                <dependency>
 167.322 +                    <code-name-base>org.openide.windows</code-name-base>
 167.323 +                    <build-prerequisite/>
 167.324 +                    <compile-dependency/>
 167.325 +                    <run-dependency>
 167.326 +                        <specification-version>6.37</specification-version>
 167.327 +                    </run-dependency>
 167.328 +                </dependency>
 167.329 +                <dependency>
 167.330 +                    <code-name-base>org.openidex.util</code-name-base>
 167.331 +                    <build-prerequisite/>
 167.332 +                    <compile-dependency/>
 167.333 +                    <run-dependency>
 167.334 +                        <release-version>3</release-version>
 167.335 +                        <specification-version>3.27</specification-version>
 167.336 +                    </run-dependency>
 167.337 +                </dependency>
 167.338 +            </module-dependencies>
 167.339 +            <public-packages/>
 167.340 +        </data>
 167.341 +    </configuration>
 167.342 +</project>
   168.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   168.2 +++ b/remoting/common/test/nbproject/suite.properties	Sat Feb 11 18:35:10 2012 +0100
   168.3 @@ -0,0 +1,1 @@
   168.4 +suite.dir=${basedir}/..
   169.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   169.2 +++ b/remoting/common/test/src/org/netbeans/modules/jackpot30/common/test/Bundle.properties	Sat Feb 11 18:35:10 2012 +0100
   169.3 @@ -0,0 +1,1 @@
   169.4 +OpenIDE-Module-Name=Jackpot 3.0 Common Test APIs
   170.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   170.2 +++ b/remoting/common/test/src/org/netbeans/modules/jackpot30/common/test/IndexTestBase.java	Sat Feb 11 18:35:10 2012 +0100
   170.3 @@ -0,0 +1,192 @@
   170.4 +/*
   170.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   170.6 + *
   170.7 + * Copyright 2009-2010 Sun Microsystems, Inc. All rights reserved.
   170.8 + *
   170.9 + * The contents of this file are subject to the terms of either the GNU
  170.10 + * General Public License Version 2 only ("GPL") or the Common
  170.11 + * Development and Distribution License("CDDL") (collectively, the
  170.12 + * "License"). You may not use this file except in compliance with the
  170.13 + * License. You can obtain a copy of the License at
  170.14 + * http://www.netbeans.org/cddl-gplv2.html
  170.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  170.16 + * specific language governing permissions and limitations under the
  170.17 + * License.  When distributing the software, include this License Header
  170.18 + * Notice in each file and include the License file at
  170.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  170.20 + * particular file as subject to the "Classpath" exception as provided
  170.21 + * by Sun in the GPL Version 2 section of the License file that
  170.22 + * accompanied this code. If applicable, add the following below the
  170.23 + * License Header, with the fields enclosed by brackets [] replaced by
  170.24 + * your own identifying information:
  170.25 + * "Portions Copyrighted [year] [name of copyright owner]"
  170.26 + *
  170.27 + * If you wish your version of this file to be governed by only the CDDL
  170.28 + * or only the GPL Version 2, indicate your decision by adding
  170.29 + * "[Contributor] elects to include this software in this distribution
  170.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
  170.31 + * single choice of license, a recipient has the option to distribute
  170.32 + * your version of this file under either the CDDL, the GPL Version 2 or
  170.33 + * to extend the choice of license to its licensees as provided above.
  170.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
  170.35 + * Version 2 license, then the option applies only if the new code is
  170.36 + * made subject to such option by the copyright holder.
  170.37 + *
  170.38 + * Contributor(s):
  170.39 + *
  170.40 + * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
  170.41 + */
  170.42 +
  170.43 +package org.netbeans.modules.jackpot30.common.test;
  170.44 +
  170.45 +import java.net.URL;
  170.46 +import java.util.Collections;
  170.47 +import org.netbeans.api.editor.mimelookup.MimePath;
  170.48 +import org.netbeans.api.java.classpath.ClassPath;
  170.49 +import org.netbeans.api.java.classpath.GlobalPathRegistry;
  170.50 +import org.netbeans.api.java.source.SourceUtils;
  170.51 +import org.netbeans.api.java.source.SourceUtilsTestUtil;
  170.52 +import org.netbeans.api.java.source.TestUtilities;
  170.53 +import org.netbeans.core.startup.Main;
  170.54 +import org.netbeans.junit.NbTestCase;
  170.55 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaIndexerPlugin;
  170.56 +import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
  170.57 +import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
  170.58 +import org.netbeans.modules.parsing.impl.indexing.MimeTypes;
  170.59 +import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
  170.60 +import org.netbeans.modules.parsing.spi.indexing.Context;
  170.61 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
  170.62 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
  170.63 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
  170.64 +import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
  170.65 +import org.netbeans.spi.java.classpath.ClassPathProvider;
  170.66 +import org.netbeans.spi.java.classpath.support.ClassPathSupport;
  170.67 +import org.openide.filesystems.FileObject;
  170.68 +import org.openide.filesystems.FileUtil;
  170.69 +import org.openide.util.Lookup;
  170.70 +import org.openide.util.lookup.Lookups;
  170.71 +import org.openide.util.lookup.ServiceProvider;
  170.72 +
  170.73 +/**
  170.74 + *
  170.75 + * @author lahvac
  170.76 + */
  170.77 +public abstract class IndexTestBase extends NbTestCase {
  170.78 +
  170.79 +    public IndexTestBase(String name) {
  170.80 +        super(name);
  170.81 +    }
  170.82 +
  170.83 +    @Override
  170.84 +    protected void setUp() throws Exception {
  170.85 +        SourceUtilsTestUtil.prepareTest(new String[0], new Object[] {new TestClassPathProvider()});
  170.86 +        Main.initializeURLFactory();
  170.87 +        org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
  170.88 +        prepareTest();
  170.89 +        MimeTypes.setAllMimeTypes(Collections.singleton("text/x-java"));
  170.90 +        GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {sourceCP});
  170.91 +        RepositoryUpdater.getDefault().start(true);
  170.92 +        super.setUp();
  170.93 +    }
  170.94 +
  170.95 +    @Override
  170.96 +    protected void tearDown() throws Exception {
  170.97 +        super.tearDown();
  170.98 +        GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, new ClassPath[] {sourceCP});
  170.99 +    }
 170.100 +
 170.101 +    protected FileObject sources;
 170.102 +    protected FileObject src;
 170.103 +    protected FileObject src2;
 170.104 +    protected FileObject build;
 170.105 +    protected FileObject cache;
 170.106 +
 170.107 +    private ClassPath sourceCP;
 170.108 +
 170.109 +    private void prepareTest() throws Exception {
 170.110 +        FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);
 170.111 +
 170.112 +        sources = FileUtil.createFolder(workdir, "sources");
 170.113 +        src = FileUtil.createFolder(sources, "src");
 170.114 +        src2 = FileUtil.createFolder(sources, "src2");
 170.115 +        build = FileUtil.createFolder(workdir, "build");
 170.116 +        cache = FileUtil.createFolder(workdir, "cache");
 170.117 +
 170.118 +        sourceCP = ClassPathSupport.createClassPath(src, src2);
 170.119 +        
 170.120 +        SourceUtilsTestUtil.prepareTest(src, build, cache);
 170.121 +    }
 170.122 +
 170.123 +    public static void writeFiles(FileObject sourceRoot, File... files) throws Exception {
 170.124 +        for (FileObject c : sourceRoot.getChildren()) {
 170.125 +            c.delete();
 170.126 +        }
 170.127 +
 170.128 +        for (File f : files) {
 170.129 +            FileObject fo = FileUtil.createData(sourceRoot, f.filename);
 170.130 +            TestUtilities.copyStringToFile(fo, f.content);
 170.131 +        }
 170.132 +    }
 170.133 +
 170.134 +    public static void writeFilesAndWaitForScan(FileObject sourceRoot, File... files) throws Exception {
 170.135 +        writeFiles(sourceRoot, files);
 170.136 +        SourceUtils.waitScanFinished();
 170.137 +    }
 170.138 +
 170.139 +    public static final class File {
 170.140 +        public final String filename;
 170.141 +        public final String content;
 170.142 +
 170.143 +        public File(String filename, String content) {
 170.144 +            this.filename = filename;
 170.145 +            this.content = content;
 170.146 +        }
 170.147 +    }
 170.148 +
 170.149 +    @ServiceProvider(service=MimeDataProvider.class)
 170.150 +    public static final class MimeDataProviderImpl implements MimeDataProvider {
 170.151 +
 170.152 +        private static final Lookup L = Lookups.fixed(new JavaCustomIndexer.Factory());
 170.153 +        
 170.154 +        @Override
 170.155 +        public Lookup getLookup(MimePath mp) {
 170.156 +            if ("text/x-java".equals(mp.getPath())) {
 170.157 +                return L;
 170.158 +            }
 170.159 +            return Lookup.EMPTY;
 170.160 +        }
 170.161 +        
 170.162 +    }
 170.163 +
 170.164 +    private class TestClassPathProvider implements ClassPathProvider {
 170.165 +        
 170.166 +        public TestClassPathProvider() {
 170.167 +        }
 170.168 +        
 170.169 +        public ClassPath findClassPath(FileObject file, String type) {
 170.170 +            try {
 170.171 +            if (ClassPath.BOOT == type) {
 170.172 +                return ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0]));
 170.173 +            }
 170.174 +            
 170.175 +            if (ClassPath.SOURCE == type) {
 170.176 +                return sourceCP;
 170.177 +            }
 170.178 +            
 170.179 +            if (ClassPath.COMPILE == type) {
 170.180 +                return ClassPathSupport.createClassPath(new URL[0]);
 170.181 +            }
 170.182 +            
 170.183 +            if (ClassPath.EXECUTE == type) {
 170.184 +                return ClassPathSupport.createClassPath(new FileObject[] {
 170.185 +                    build
 170.186 +                });
 170.187 +            }
 170.188 +            } catch (Exception e) {
 170.189 +                e.printStackTrace();
 170.190 +            }
 170.191 +            return null;
 170.192 +        }
 170.193 +        
 170.194 +    }
 170.195 +}
   171.1 --- a/remoting/ide/build.xml	Fri Jan 27 13:35:56 2012 +0100
   171.2 +++ b/remoting/ide/build.xml	Sat Feb 11 18:35:10 2012 +0100
   171.3 @@ -2,7 +2,7 @@
   171.4  <!-- You may freely edit this file. See harness/README in the NetBeans platform -->
   171.5  <!-- for some information on what you could do (e.g. targets to override). -->
   171.6  <!-- If you delete this file and reopen the project it will be recreated. -->
   171.7 -<project name="ide" basedir=".">
   171.8 +<project name="remoting-ide" basedir=".">
   171.9      <description>Builds the module suite ide.</description>
  171.10      <import file="nbproject/build-impl.xml"/>
  171.11  </project>
   172.1 --- a/remoting/ide/nbproject/build-impl.xml	Fri Jan 27 13:35:56 2012 +0100
   172.2 +++ b/remoting/ide/nbproject/build-impl.xml	Sat Feb 11 18:35:10 2012 +0100
   172.3 @@ -3,7 +3,7 @@
   172.4  *** GENERATED FROM project.xml - DO NOT EDIT  ***
   172.5  ***         EDIT ../build.xml INSTEAD         ***
   172.6  -->
   172.7 -<project name="ide-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
   172.8 +<project name="remoting-ide-impl" basedir=".." xmlns:sproject="http://www.netbeans.org/ns/nb-module-suite-project/1">
   172.9      <fail message="Please build using Ant 1.7.1 or higher.">
  172.10          <condition>
  172.11              <not>
   173.1 --- a/remoting/ide/nbproject/genfiles.properties	Fri Jan 27 13:35:56 2012 +0100
   173.2 +++ b/remoting/ide/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   173.3 @@ -3,9 +3,9 @@
   173.4  build.xml.stylesheet.CRC32=eaf9f76a@1.47
   173.5  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   173.6  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   173.7 -nbproject/build-impl.xml.data.CRC32=891734f5
   173.8 -nbproject/build-impl.xml.script.CRC32=f4643aa8
   173.9 -nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.46
  173.10 -nbproject/platform.xml.data.CRC32=891734f5
  173.11 +nbproject/build-impl.xml.data.CRC32=fa6e1472
  173.12 +nbproject/build-impl.xml.script.CRC32=c2d6d7d2
  173.13 +nbproject/build-impl.xml.stylesheet.CRC32=0f381476@2.49
  173.14 +nbproject/platform.xml.data.CRC32=fa6e1472
  173.15  nbproject/platform.xml.script.CRC32=db9e1f43
  173.16 -nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.46
  173.17 +nbproject/platform.xml.stylesheet.CRC32=df8ac4dd@2.49
   174.1 --- a/remoting/ide/nbproject/platform.properties	Fri Jan 27 13:35:56 2012 +0100
   174.2 +++ b/remoting/ide/nbproject/platform.properties	Sat Feb 11 18:35:10 2012 +0100
   174.3 @@ -10,5 +10,7 @@
   174.4      ${nbplatform.active.dir}/platform:\
   174.5      ${nbplatform.active.dir}/profiler:\
   174.6      ${nbplatform.active.dir}/websvccommon:\
   174.7 -    ../../borrowedtests/build/cluster
   174.8 +    ../common/build/cluster
   174.9 +extcluster.../common/build/cluster.javadoc=
  174.10 +extcluster.../common/build/cluster.sources=../common
  174.11  nbplatform.active=default
   175.1 --- a/remoting/ide/nbproject/project.xml	Fri Jan 27 13:35:56 2012 +0100
   175.2 +++ b/remoting/ide/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   175.3 @@ -3,7 +3,7 @@
   175.4      <type>org.netbeans.modules.apisupport.project.suite</type>
   175.5      <configuration>
   175.6          <data xmlns="http://www.netbeans.org/ns/nb-module-suite-project/1">
   175.7 -            <name>ide</name>
   175.8 +            <name>remoting-ide</name>
   175.9          </data>
  175.10      </configuration>
  175.11  </project>
   176.1 --- a/remoting/ide/usages/nbproject/genfiles.properties	Fri Jan 27 13:35:56 2012 +0100
   176.2 +++ b/remoting/ide/usages/nbproject/genfiles.properties	Sat Feb 11 18:35:10 2012 +0100
   176.3 @@ -1,8 +1,8 @@
   176.4 -build.xml.data.CRC32=46c67808
   176.5 +build.xml.data.CRC32=e216ee19
   176.6  build.xml.script.CRC32=58a6b47a
   176.7 -build.xml.stylesheet.CRC32=a56c6a5b@2.46
   176.8 +build.xml.stylesheet.CRC32=a56c6a5b@2.49
   176.9  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
  176.10  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
  176.11 -nbproject/build-impl.xml.data.CRC32=46c67808
  176.12 +nbproject/build-impl.xml.data.CRC32=e216ee19
  176.13  nbproject/build-impl.xml.script.CRC32=583fd407
  176.14 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.46
  176.15 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49
   177.1 --- a/remoting/ide/usages/nbproject/project.xml	Fri Jan 27 13:35:56 2012 +0100
   177.2 +++ b/remoting/ide/usages/nbproject/project.xml	Sat Feb 11 18:35:10 2012 +0100
   177.3 @@ -7,6 +7,15 @@
   177.4              <suite-component/>
   177.5              <module-dependencies>
   177.6                  <dependency>
   177.7 +                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
   177.8 +                    <build-prerequisite/>
   177.9 +                    <compile-dependency/>
  177.10 +                    <run-dependency>
  177.11 +                        <release-version>1</release-version>
  177.12 +                        <specification-version>1.13</specification-version>
  177.13 +                    </run-dependency>
  177.14 +                </dependency>
  177.15 +                <dependency>
  177.16                      <code-name-base>org.netbeans.api.java.classpath</code-name-base>
  177.17                      <build-prerequisite/>
  177.18                      <compile-dependency/>
  177.19 @@ -42,6 +51,14 @@
  177.20                      </run-dependency>
  177.21                  </dependency>
  177.22                  <dependency>
  177.23 +                    <code-name-base>org.netbeans.modules.jackpot30.common</code-name-base>
  177.24 +                    <build-prerequisite/>
  177.25 +                    <compile-dependency/>
  177.26 +                    <run-dependency>
  177.27 +                        <specification-version>1.0</specification-version>
  177.28 +                    </run-dependency>
  177.29 +                </dependency>
  177.30 +                <dependency>
  177.31                      <code-name-base>org.netbeans.modules.jackpot30.remoting.api</code-name-base>
  177.32                      <build-prerequisite/>
  177.33                      <compile-dependency/>
   178.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Common.java	Fri Jan 27 13:35:56 2012 +0100
   178.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.3 @@ -1,76 +0,0 @@
   178.4 -/*
   178.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   178.6 - *
   178.7 - * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   178.8 - *
   178.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  178.10 - * Other names may be trademarks of their respective owners.
  178.11 - *
  178.12 - * The contents of this file are subject to the terms of either the GNU
  178.13 - * General Public License Version 2 only ("GPL") or the Common
  178.14 - * Development and Distribution License("CDDL") (collectively, the
  178.15 - * "License"). You may not use this file except in compliance with the
  178.16 - * License. You can obtain a copy of the License at
  178.17 - * http://www.netbeans.org/cddl-gplv2.html
  178.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  178.19 - * specific language governing permissions and limitations under the
  178.20 - * License.  When distributing the software, include this License Header
  178.21 - * Notice in each file and include the License file at
  178.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  178.23 - * particular file as subject to the "Classpath" exception as provided
  178.24 - * by Oracle in the GPL Version 2 section of the License file that
  178.25 - * accompanied this code. If applicable, add the following below the
  178.26 - * License Header, with the fields enclosed by brackets [] replaced by
  178.27 - * your own identifying information:
  178.28 - * "Portions Copyrighted [year] [name of copyright owner]"
  178.29 - *
  178.30 - * If you wish your version of this file to be governed by only the CDDL
  178.31 - * or only the GPL Version 2, indicate your decision by adding
  178.32 - * "[Contributor] elects to include this software in this distribution
  178.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
  178.34 - * single choice of license, a recipient has the option to distribute
  178.35 - * your version of this file under either the CDDL, the GPL Version 2 or
  178.36 - * to extend the choice of license to its licensees as provided above.
  178.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
  178.38 - * Version 2 license, then the option applies only if the new code is
  178.39 - * made subject to such option by the copyright holder.
  178.40 - *
  178.41 - * Contributor(s):
  178.42 - *
  178.43 - * Portions Copyrighted 2011 Sun Microsystems, Inc.
  178.44 - */
  178.45 -package org.netbeans.modules.jackpot30.ide.usages;
  178.46 -
  178.47 -import java.util.EnumSet;
  178.48 -import java.util.Set;
  178.49 -import javax.lang.model.element.ElementKind;
  178.50 -import org.netbeans.api.java.source.ElementHandle;
  178.51 -import org.netbeans.api.java.source.SourceUtils;
  178.52 -
  178.53 -/**XXX: Copied between indexing and ide!
  178.54 - *
  178.55 - * @author lahvac
  178.56 - */
  178.57 -public class Common {
  178.58 -
  178.59 -    public static final Set<ElementKind> SUPPORTED_KINDS = EnumSet.of(ElementKind.PACKAGE, ElementKind.CLASS,
  178.60 -            ElementKind.INTERFACE, ElementKind.ENUM, ElementKind.ANNOTATION_TYPE, ElementKind.METHOD,
  178.61 -            ElementKind.CONSTRUCTOR, ElementKind.INSTANCE_INIT, ElementKind.STATIC_INIT,
  178.62 -            ElementKind.FIELD, ElementKind.ENUM_CONSTANT);
  178.63 -    
  178.64 -    public static String serialize(ElementHandle<?> h) {
  178.65 -        StringBuilder result = new StringBuilder();
  178.66 -
  178.67 -        result.append(h.getKind());
  178.68 -
  178.69 -        String[] signatures = SourceUtils.getJVMSignature(h);
  178.70 -
  178.71 -        for (String sig : signatures) {
  178.72 -            result.append(":");
  178.73 -            result.append(sig);
  178.74 -        }
  178.75 -
  178.76 -        return result.toString();
  178.77 -    }
  178.78 -
  178.79 -}
   179.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Fri Jan 27 13:35:56 2012 +0100
   179.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Sat Feb 11 18:35:10 2012 +0100
   179.3 @@ -81,16 +81,17 @@
   179.4  import org.netbeans.api.java.source.ui.ElementHeaders;
   179.5  import org.netbeans.api.java.source.ui.ScanDialog;
   179.6  import org.netbeans.modules.editor.NbEditorUtilities;
   179.7 +import org.netbeans.modules.jackpot30.common.api.JavaUtils;
   179.8  import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   179.9  import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
  179.10  import org.openide.DialogDescriptor;
  179.11  import org.openide.DialogDisplayer;
  179.12  import org.openide.NotifyDescriptor;
  179.13  import org.openide.NotifyDescriptor.Message;
  179.14 -import org.openide.awt.ActionRegistration;
  179.15 +import org.openide.awt.ActionID;
  179.16  import org.openide.awt.ActionReference;
  179.17  import org.openide.awt.ActionReferences;
  179.18 -import org.openide.awt.ActionID;
  179.19 +import org.openide.awt.ActionRegistration;
  179.20  import org.openide.filesystems.FileObject;
  179.21  import org.openide.filesystems.URLMapper;
  179.22  import org.openide.nodes.Node;
  179.23 @@ -169,7 +170,7 @@
  179.24                              TreePath tp = parameter.getTreeUtilities().pathFor(pos);
  179.25                              Element el = parameter.getTrees().getElement(tp);
  179.26  
  179.27 -                            if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
  179.28 +                            if (el != null && JavaUtils.SUPPORTED_KINDS.contains(el.getKind())) {
  179.29                                  handle[0] = new ElementDescription(parameter, el);
  179.30                              }
  179.31                          }
  179.32 @@ -291,7 +292,7 @@
  179.33  
  179.34          @Override public void run() {
  179.35              try {
  179.36 -                final String serialized = Common.serialize(toSearch);
  179.37 +                final String serialized = JavaUtils.serialize(toSearch);
  179.38  
  179.39                  Set<FileObject> resultSet = new HashSet<FileObject>();
  179.40                  List<FileObject> result = new ArrayList<FileObject>();
   180.1 --- a/remoting/server/web/web.main/build.xml	Fri Jan 27 13:35:56 2012 +0100
   180.2 +++ b/remoting/server/web/web.main/build.xml	Sat Feb 11 18:35:10 2012 +0100
   180.3 @@ -71,4 +71,5 @@
   180.4      nbproject/build-impl.xml file. 
   180.5  
   180.6      -->
   180.7 +    <target name="build" depends="jar" />
   180.8  </project>