sandbox/old-modules/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/IndexBulkTest.java
branchdonation_review
changeset 1043 57843026e60b
parent 1027 205b7632914c
parent 1040 f7b6892fd754
child 1044 7feb751ba76b
     1.1 --- a/sandbox/old-modules/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/IndexBulkTest.java	Mon Dec 19 11:37:36 2016 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,182 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2009-2010 Oracle and/or its affiliates. All rights reserved.
     1.8 - *
     1.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    1.10 - * Other names may be trademarks of their respective owners.
    1.11 - *
    1.12 - * The contents of this file are subject to the terms of either the GNU
    1.13 - * General Public License Version 2 only ("GPL") or the Common
    1.14 - * Development and Distribution License("CDDL") (collectively, the
    1.15 - * "License"). You may not use this file except in compliance with the
    1.16 - * License. You can obtain a copy of the License at
    1.17 - * http://www.netbeans.org/cddl-gplv2.html
    1.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.19 - * specific language governing permissions and limitations under the
    1.20 - * License.  When distributing the software, include this License Header
    1.21 - * Notice in each file and include the License file at
    1.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    1.23 - * particular file as subject to the "Classpath" exception as provided
    1.24 - * by Oracle in the GPL Version 2 section of the License file that
    1.25 - * accompanied this code. If applicable, add the following below the
    1.26 - * License Header, with the fields enclosed by brackets [] replaced by
    1.27 - * your own identifying information:
    1.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    1.29 - *
    1.30 - * If you wish your version of this file to be governed by only the CDDL
    1.31 - * or only the GPL Version 2, indicate your decision by adding
    1.32 - * "[Contributor] elects to include this software in this distribution
    1.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    1.34 - * single choice of license, a recipient has the option to distribute
    1.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    1.36 - * to extend the choice of license to its licensees as provided above.
    1.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    1.38 - * Version 2 license, then the option applies only if the new code is
    1.39 - * made subject to such option by the copyright holder.
    1.40 - *
    1.41 - * Contributor(s):
    1.42 - *
    1.43 - * Portions Copyrighted 2009-2010 Sun Microsystems, Inc.
    1.44 - */
    1.45 -
    1.46 -package org.netbeans.modules.jackpot30.impl.pm;
    1.47 -
    1.48 -import com.sun.source.tree.Tree;
    1.49 -import com.sun.source.util.TreePath;
    1.50 -import java.io.IOException;
    1.51 -import java.io.InputStream;
    1.52 -import java.io.Reader;
    1.53 -import java.util.Collection;
    1.54 -import java.util.Collections;
    1.55 -import java.util.Map;
    1.56 -import org.apache.lucene.analysis.Analyzer;
    1.57 -import org.apache.lucene.analysis.TokenStream;
    1.58 -import org.apache.lucene.index.IndexReader;
    1.59 -import org.apache.lucene.index.IndexWriter.MaxFieldLength;
    1.60 -import org.apache.lucene.store.Directory;
    1.61 -import org.apache.lucene.store.RAMDirectory;
    1.62 -import org.netbeans.api.java.source.CompilationInfo;
    1.63 -import org.netbeans.modules.jackpot30.impl.indexing.AbstractLuceneIndex;
    1.64 -import org.netbeans.modules.jackpot30.impl.indexing.Index.IndexWriter;
    1.65 -import org.netbeans.modules.jackpot30.impl.indexing.IndexInfo;
    1.66 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch;
    1.67 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.BulkPattern;
    1.68 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearch.EncodingContext;
    1.69 -import org.netbeans.modules.java.hints.jackpot.impl.pm.BulkSearchTestPerformer;
    1.70 -import org.netbeans.modules.java.hints.jackpot.impl.pm.NFABasedBulkSearch;
    1.71 -import org.netbeans.modules.java.hints.jackpot.spi.HintDescription.AdditionalQueryConstraints;
    1.72 -
    1.73 -/**
    1.74 - *
    1.75 - * @author lahvac
    1.76 - */
    1.77 -public class IndexBulkTest extends BulkSearchTestPerformer {
    1.78 -
    1.79 -    public IndexBulkTest(String name) {
    1.80 -        super(name);
    1.81 -    }
    1.82 -
    1.83 -//    public static TestSuite suite() {
    1.84 -//        NbTestSuite r = new NbTestSuite();
    1.85 -//
    1.86 -//        r.addTest(new NFABasedBulkSearchTest("testField1"));
    1.87 -//        r.addTest(new NFABasedBulkSearchTest("testField2"));
    1.88 -//
    1.89 -//        return r;
    1.90 -//    }
    1.91 -
    1.92 -    @Override
    1.93 -    protected BulkSearch createSearch() {
    1.94 -        return new BulkSearchImpl(false);
    1.95 -    }
    1.96 -
    1.97 -    private static class BulkSearchImpl extends BulkSearch {
    1.98 -
    1.99 -        public BulkSearchImpl(boolean requiresLightweightVerification) {
   1.100 -            super(requiresLightweightVerification);
   1.101 -        }
   1.102 -
   1.103 -        @Override
   1.104 -        public Map<String, Collection<TreePath>> match(CompilationInfo info, TreePath toSearch, BulkPattern pattern, Map<String, Long> timeLog) {
   1.105 -            try {
   1.106 -                IndexImpl ii = new IndexImpl();
   1.107 -                IndexWriter writer = ii.openForWriting();
   1.108 -
   1.109 -                writer.record(toSearch.getCompilationUnit().getSourceFile().toUri().toURL(), toSearch.getCompilationUnit(), null);
   1.110 -                writer.close();
   1.111 -
   1.112 -                if (!ii.findCandidates(pattern).isEmpty()) {
   1.113 -                    return new NFABasedBulkSearch().match(info, toSearch, pattern, timeLog);
   1.114 -                } else {
   1.115 -                    assertTrue(new NFABasedBulkSearch().match(info, toSearch, pattern, timeLog).isEmpty());
   1.116 -                    return Collections.emptyMap();
   1.117 -                }
   1.118 -            } catch (IOException ex) {
   1.119 -                throw new IllegalStateException(ex);
   1.120 -            }
   1.121 -        }
   1.122 -
   1.123 -        @Override
   1.124 -        public boolean matches(InputStream encoded, BulkPattern pattern) {
   1.125 -            return new NFABasedBulkSearch().matches(encoded, pattern);
   1.126 -        }
   1.127 -
   1.128 -        @Override
   1.129 -        public boolean matches(CompilationInfo info, TreePath toSearch, BulkPattern pattern) {
   1.130 -            return new NFABasedBulkSearch().matches(info, toSearch, pattern);
   1.131 -        }
   1.132 -
   1.133 -        @Override
   1.134 -        public void encode(Tree tree, EncodingContext ctx) {
   1.135 -            new NFABasedBulkSearch().encode(tree, ctx);
   1.136 -        }
   1.137 -
   1.138 -        @Override
   1.139 -        public BulkPattern create(Collection<? extends String> code, Collection<? extends Tree> patterns, Collection<? extends AdditionalQueryConstraints> additionalConstraints) {
   1.140 -            return new NFABasedBulkSearch().create(code, patterns, additionalConstraints);
   1.141 -        }
   1.142 -
   1.143 -        @Override
   1.144 -        public Map<String, Integer> matchesWithFrequencies(InputStream encoded, BulkPattern pattern) {
   1.145 -            return new NFABasedBulkSearch().matchesWithFrequencies(encoded, pattern);
   1.146 -        }
   1.147 -    }
   1.148 -
   1.149 -    private static final class IndexImpl extends AbstractLuceneIndex {
   1.150 -
   1.151 -        private final Directory dir = new RAMDirectory();
   1.152 -
   1.153 -        public IndexImpl() {
   1.154 -            super(0, false, true);
   1.155 -        }
   1.156 -
   1.157 -        @Override
   1.158 -        protected IndexReader createReader() throws IOException {
   1.159 -            return IndexReader.open(dir, true);
   1.160 -        }
   1.161 -
   1.162 -        @Override
   1.163 -        protected org.apache.lucene.index.IndexWriter createWriter() throws IOException {
   1.164 -            return new org.apache.lucene.index.IndexWriter(dir, new NoAnalyzer(), MaxFieldLength.UNLIMITED);
   1.165 -        }
   1.166 -
   1.167 -        @Override
   1.168 -        public IndexInfo getIndexInfo() {
   1.169 -            return IndexInfo.empty();
   1.170 -        }
   1.171 -
   1.172 -        @Override
   1.173 -        protected void storeIndexInfo(IndexInfo info) throws IOException {}
   1.174 -    }
   1.175 -
   1.176 -    private static final class NoAnalyzer extends Analyzer {
   1.177 -
   1.178 -        @Override
   1.179 -        public TokenStream tokenStream(String string, Reader reader) {
   1.180 -            throw new UnsupportedOperationException("Should not be called");
   1.181 -        }
   1.182 -
   1.183 -    }
   1.184 -
   1.185 -}