sandbox/java.hints/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/pm/BulkSearch.java
1.1 --- a/sandbox/java.hints/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/pm/BulkSearch.java Mon Dec 19 11:37:36 2016 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,190 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 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 Sun Microsystems, Inc.
1.44 - */
1.45 -
1.46 -package org.netbeans.modules.java.hints.spiimpl.pm;
1.47 -
1.48 -import com.sun.source.tree.Tree;
1.49 -import com.sun.source.util.TreePath;
1.50 -import java.io.InputStream;
1.51 -import java.io.OutputStream;
1.52 -import java.util.Arrays;
1.53 -import java.util.Collection;
1.54 -import java.util.LinkedList;
1.55 -import java.util.List;
1.56 -import java.util.Map;
1.57 -import java.util.Set;
1.58 -import java.util.concurrent.atomic.AtomicBoolean;
1.59 -import org.netbeans.api.annotations.common.CheckForNull;
1.60 -import org.netbeans.api.java.source.CompilationInfo;
1.61 -import org.netbeans.modules.java.hints.spiimpl.Utilities;
1.62 -import org.netbeans.modules.java.hints.providers.spi.HintDescription.AdditionalQueryConstraints;
1.63 -
1.64 -/**
1.65 - *
1.66 - * @author lahvac
1.67 - */
1.68 -public abstract class BulkSearch {
1.69 -
1.70 - private static final BulkSearch INSTANCE = new NFABasedBulkSearch();
1.71 -// private static final BulkSearch INSTANCE = new REBasedBulkSearch();
1.72 -
1.73 - public static BulkSearch getDefault() {
1.74 - return INSTANCE;
1.75 - }
1.76 -
1.77 - private final boolean requiresLightweightVerification;
1.78 -
1.79 - protected BulkSearch(boolean requiresLightweightVerification) {
1.80 - this.requiresLightweightVerification = requiresLightweightVerification;
1.81 - }
1.82 -
1.83 - public final Map<String, Collection<TreePath>> match(CompilationInfo info, AtomicBoolean cancel, TreePath toSearch, BulkPattern pattern) {
1.84 - return match(info, cancel, toSearch, pattern, null);
1.85 - }
1.86 -
1.87 - public final boolean requiresLightweightVerification() {
1.88 - return requiresLightweightVerification;
1.89 - }
1.90 -
1.91 - @CheckForNull
1.92 - public abstract Map<String, Collection<TreePath>> match(CompilationInfo info, AtomicBoolean cancel, TreePath toSearch, BulkPattern pattern, Map<String, Long> timeLog);
1.93 -
1.94 - public abstract boolean matches(InputStream encoded, AtomicBoolean cancel, BulkPattern pattern);
1.95 -
1.96 - @CheckForNull
1.97 - public abstract Map<String, Integer> matchesWithFrequencies(InputStream encoded, BulkPattern pattern, AtomicBoolean cancel);
1.98 -
1.99 - public abstract boolean matches(CompilationInfo info, AtomicBoolean cancel, TreePath toSearch, BulkPattern pattern);
1.100 -
1.101 - public abstract void encode(Tree tree, EncodingContext ctx, AtomicBoolean cancel);
1.102 -
1.103 - @CheckForNull
1.104 - public final BulkPattern create(CompilationInfo info, AtomicBoolean cancel, String... code) {
1.105 - return create(info, cancel, Arrays.asList(code));
1.106 - }
1.107 -
1.108 - @CheckForNull
1.109 - public final BulkPattern create(CompilationInfo info, AtomicBoolean cancel, Collection<? extends String> code) {
1.110 - List<Tree> patterns = new LinkedList<Tree>();
1.111 - List<AdditionalQueryConstraints> additionalConstraints = new LinkedList<AdditionalQueryConstraints>();
1.112 -
1.113 - for (String c : code) {
1.114 - patterns.add(Utilities.parseAndAttribute(info, c, null));
1.115 - additionalConstraints.add(AdditionalQueryConstraints.empty());
1.116 - }
1.117 -
1.118 - return create(code, patterns, additionalConstraints, cancel);
1.119 - }
1.120 -
1.121 - @CheckForNull
1.122 - public abstract BulkPattern create(Collection<? extends String> code, Collection<? extends Tree> patterns, Collection<? extends AdditionalQueryConstraints> additionalConstraints, AtomicBoolean cancel);
1.123 -
1.124 - public static abstract class BulkPattern {
1.125 -
1.126 - private final List<? extends String> patterns;
1.127 - private final List<? extends Set<? extends String>> identifiers;
1.128 - private final List<List<List<String>>> requiredContent;
1.129 - private final List<AdditionalQueryConstraints> additionalConstraints;
1.130 -
1.131 - public BulkPattern(List<? extends String> patterns, List<? extends Set<? extends String>> identifiers, List<List<List<String>>> requiredContent, List<AdditionalQueryConstraints> additionalConstraints) {
1.132 - this.patterns = patterns;
1.133 - this.identifiers = identifiers;//TODO: immutable, maybe clone
1.134 - this.requiredContent = requiredContent;
1.135 - this.additionalConstraints = additionalConstraints;
1.136 - }
1.137 -
1.138 - public List<? extends String> getPatterns() {
1.139 - return patterns;
1.140 - }
1.141 -
1.142 - public List<? extends Set<? extends String>> getIdentifiers() {
1.143 - return identifiers;
1.144 - }
1.145 -
1.146 - public List<List<List<String>>> getRequiredContent() {
1.147 - return requiredContent;
1.148 - }
1.149 -
1.150 - public List<AdditionalQueryConstraints> getAdditionalConstraints() {
1.151 - return additionalConstraints;
1.152 - }
1.153 -
1.154 - }
1.155 -
1.156 - public static final class EncodingContext {
1.157 -
1.158 - private final OutputStream out;
1.159 - private final boolean forDuplicates;
1.160 - private Set<? extends String> identifiers;
1.161 - private List<String> content;
1.162 -
1.163 - public EncodingContext(OutputStream out, boolean forDuplicates) {
1.164 - this.out = out;
1.165 - this.forDuplicates = forDuplicates;
1.166 - }
1.167 -
1.168 - public Set<? extends String> getIdentifiers() {
1.169 - return identifiers;
1.170 - }
1.171 -
1.172 - public OutputStream getOut() {
1.173 - return out;
1.174 - }
1.175 -
1.176 - public boolean isForDuplicates() {
1.177 - return forDuplicates;
1.178 - }
1.179 -
1.180 - public void setIdentifiers(Set<? extends String> identifiers) {
1.181 - this.identifiers = identifiers;
1.182 - }
1.183 -
1.184 - public void setContent(List<String> content) {
1.185 - this.content = content;
1.186 - }
1.187 -
1.188 - public List<String> getContent() {
1.189 - return content;
1.190 - }
1.191 -
1.192 - }
1.193 -}