This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 199432
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+13 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="ClassIndex-package-scope">
112
             <api name="general"/>
113
             <summary>Added package search scope into <code>ClassIndex</code> to restrict search in given packages</summary>
114
             <version major="0" minor="82"/>
115
             <date day="17" month="6" year="2011"/>
116
             <author login="tzezula"/>
117
             <compatibility addition="yes"/>
118
             <description>
119
                 Added package search scope into <code>ClassIndex</code> to restrict search in given packages.
120
             </description>
121
             <class package="org.netbeans.api.java.source" name="ClassIndex"/>
122
             <issue number="197194"/>
123
        </change>
111
        <change id="TreeUtilities.findMethodParameterSpan">
124
        <change id="TreeUtilities.findMethodParameterSpan">
112
             <api name="general"/>
125
             <api name="general"/>
113
             <summary>Find span of the MethodTree#getParameters() parameter list in the source.</summary>
126
             <summary>Find span of the MethodTree#getParameters() parameter list in the source.</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.81.0
49
spec.version.base=0.82.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/ClassIndex.java (-25 / +128 lines)
Lines 48-53 Link Here
48
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.net.URL;
50
import java.net.URL;
51
import java.util.Arrays;
51
import java.util.Collection;
52
import java.util.Collection;
52
import java.util.Collections;
53
import java.util.Collections;
53
import java.util.EnumSet;
54
import java.util.EnumSet;
Lines 63-68 Link Here
63
import javax.lang.model.element.ElementKind;
64
import javax.lang.model.element.ElementKind;
64
import javax.lang.model.element.TypeElement;
65
import javax.lang.model.element.TypeElement;
65
import org.apache.lucene.document.Document;
66
import org.apache.lucene.document.Document;
67
import org.netbeans.api.annotations.common.CheckForNull;
66
import org.netbeans.api.annotations.common.NonNull;
68
import org.netbeans.api.annotations.common.NonNull;
67
import org.netbeans.api.annotations.common.NullUnknown;
69
import org.netbeans.api.annotations.common.NullUnknown;
68
import org.netbeans.api.java.classpath.ClassPath;
70
import org.netbeans.api.java.classpath.ClassPath;
Lines 212-230 Link Here
212
    };
214
    };
213
    
215
    
214
    /**
216
    /**
215
     * Scope used by {@link ClassIndex} to search in
217
     * Default predefined {@link SearchScopeType}s
216
     */
218
     */
217
    public enum SearchScope {
219
    public enum SearchScope implements SearchScopeType {
218
        /**
220
        /**
219
         * Search is done in source path
221
         * Search is done in source path
220
         */
222
         */
221
        SOURCE,
223
        SOURCE {
224
            @Override
225
            public boolean isSources() {return true;}
226
            @Override
227
            public boolean isDependencies() {return false;}
228
        },
222
        /**
229
        /**
223
         * Search is done in compile and boot path
230
         * Search is done in compile and boot path
224
         */
231
         */
225
        DEPENDENCIES
232
        DEPENDENCIES {
233
            @Override
234
            public boolean isSources() {return false;}
235
            @Override
236
            public boolean isDependencies() {return true;}
237
        };
238
239
        @Override
240
        @CheckForNull
241
        public Set<? extends String> getPackages() {
242
            return null;
243
        }
226
    };
244
    };
227
    
245
246
    /**
247
     * Scope used by {@link ClassIndex} to search in
248
     * @since 0.82.0
249
     */
250
    public static interface SearchScopeType {
251
        /**
252
         * Limits search only into given packages.
253
         * @return set of packages to search in or null which
254
         * means all packages
255
         */
256
        @CheckForNull
257
        Set<? extends String> getPackages();
258
259
        /**
260
         * Search in source path.
261
         * @return if true search in done in sources
262
         */
263
        boolean isSources();
264
265
        /**
266
         * Search in dependent libraries bootpath,  compilepath.
267
         * @return if true search in done in dependent libraries
268
         */
269
        boolean isDependencies();
270
    }
271
228
    static {
272
    static {
229
	ClassIndexImpl.FACTORY = new ClassIndexFactoryImpl();
273
	ClassIndexImpl.FACTORY = new ClassIndexFactoryImpl();
230
    }
274
    }
Lines 288-294 Link Here
288
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
332
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
289
     * inside call of this method.
333
     * inside call of this method.
290
     */
334
     */
291
    public @NullUnknown Set<ElementHandle<TypeElement>> getElements (final @NonNull ElementHandle<TypeElement> element, final @NonNull Set<SearchKind> searchKind, final @NonNull Set<SearchScope> scope) {
335
    public @NullUnknown Set<ElementHandle<TypeElement>> getElements (
336
            final @NonNull ElementHandle<TypeElement> element,
337
            final @NonNull Set<SearchKind> searchKind,
338
            final @NonNull Set<? extends SearchScopeType> scope) {
292
        assert element != null;
339
        assert element != null;
293
        assert element.getSignature()[0] != null;
340
        assert element.getSignature()[0] != null;
294
        assert searchKind != null;
341
        assert searchKind != null;
Lines 301-307 Link Here
301
            if (!ut.isEmpty()) {
348
            if (!ut.isEmpty()) {
302
                for (ClassIndexImpl query : queries) {
349
                for (ClassIndexImpl query : queries) {
303
                    try {
350
                    try {
304
                        query.search(binaryName, ut, thConvertor, result);
351
                        query.search(
352
                            binaryName,
353
                            ut,
354
                            scope,
355
                            thConvertor,
356
                            result);
305
                    } catch (Index.IndexClosedException e) {
357
                    } catch (Index.IndexClosedException e) {
306
                        logClosedIndex (query);
358
                        logClosedIndex (query);
307
                    } catch (IOException e) {
359
                    } catch (IOException e) {
Lines 324-343 Link Here
324
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
376
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
325
     * inside call of this method.
377
     * inside call of this method.
326
     */
378
     */
327
    public @NullUnknown Set<FileObject> getResources (final @NonNull ElementHandle<TypeElement> element, final @NonNull Set<SearchKind> searchKind, final @NonNull Set<SearchScope> scope) {
379
    public @NullUnknown Set<FileObject> getResources (
380
            final @NonNull ElementHandle<TypeElement> element,
381
            final @NonNull Set<SearchKind> searchKind,
382
            final @NonNull Set<? extends SearchScopeType> scope) {
328
        assert element != null;
383
        assert element != null;
329
        assert element.getSignature()[0] != null;
384
        assert element.getSignature()[0] != null;
330
        assert searchKind != null;
385
        assert searchKind != null;
331
        final Set<FileObject> result = new HashSet<FileObject> ();
386
        final Set<FileObject> result = new HashSet<FileObject> ();
332
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
387
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
333
        final Set<ClassIndexImpl.UsageType> ut =  encodeSearchKind(element.getKind(),searchKind);
388
        final Set<ClassIndexImpl.UsageType> ut =  encodeSearchKind(element.getKind(),searchKind);
334
        final String binaryName = element.getSignature()[0];        
389
        final String binaryName = element.getSignature()[0];
335
        try {
390
        try {
336
            if (!ut.isEmpty()) {
391
            if (!ut.isEmpty()) {
337
                for (ClassIndexImpl query : queries) {
392
                for (ClassIndexImpl query : queries) {
338
                    final Convertor<? super Document, FileObject> foConvertor = DocumentUtil.fileObjectConvertor (query.getSourceRoots());
393
                    final Convertor<? super Document, FileObject> foConvertor = DocumentUtil.fileObjectConvertor (query.getSourceRoots());
339
                    try {
394
                    try {
340
                        query.search (binaryName, ut, foConvertor, result);
395
                        query.search(
396
                            binaryName,
397
                            ut,
398
                            scope,
399
                            foConvertor,
400
                            result);
341
                    } catch (Index.IndexClosedException e) {
401
                    } catch (Index.IndexClosedException e) {
342
                        logClosedIndex (query);
402
                        logClosedIndex (query);
343
                    } catch (IOException e) {
403
                    } catch (IOException e) {
Lines 349-355 Link Here
349
        } catch (InterruptedException e) {
409
        } catch (InterruptedException e) {
350
            return null;
410
            return null;
351
        }
411
        }
352
    }        
412
    }
353
    
413
    
354
    
414
    
355
    /**
415
    /**
Lines 362-368 Link Here
362
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
422
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
363
     * inside call of this method.
423
     * inside call of this method.
364
     */
424
     */
365
    public @NullUnknown Set<ElementHandle<TypeElement>> getDeclaredTypes (final @NonNull String name, final @NonNull NameKind kind, final @NonNull Set<SearchScope> scope) {
425
    public @NullUnknown Set<ElementHandle<TypeElement>> getDeclaredTypes (
426
            final @NonNull String name,
427
            final @NonNull NameKind kind,
428
            final @NonNull Set<? extends SearchScopeType> scope) {
366
        assert name != null;
429
        assert name != null;
367
        assert kind != null;
430
        assert kind != null;
368
        final Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();        
431
        final Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();        
Lines 400-406 Link Here
400
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
463
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
401
     * inside call of this method.
464
     * inside call of this method.
402
     */
465
     */
403
    public @NullUnknown Set<String> getPackageNames (final @NonNull String prefix, boolean directOnly, final @NonNull Set<SearchScope> scope) {
466
    public @NullUnknown Set<String> getPackageNames (
467
            final @NonNull String prefix,
468
            boolean directOnly,
469
            final @NonNull Set<? extends SearchScopeType> scope) {
404
        assert prefix != null;
470
        assert prefix != null;
405
        final Set<String> result = new HashSet<String> ();        
471
        final Set<String> result = new HashSet<String> ();        
406
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
472
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
Lines 419-427 Link Here
419
            return null;
485
            return null;
420
        }
486
        }
421
    }
487
    }
422
    
488
423
    // Private innerclasses ----------------------------------------------------
489
    /**
424
        
490
     * Creates a search scope limited to list of packages.
491
     * @param base the base search scope to restrict
492
     * @param pkgs a list of packages in which the search should be performed
493
     * @return a newly created search scope
494
     * @since 0.82.0
495
     */
496
    @NonNull
497
    public static SearchScopeType createPackageSearchScope(
498
            @NonNull final SearchScopeType base,
499
            @NonNull final String... pkgs) {
500
        final Set<String> pkgSet = new HashSet<String>(Arrays.asList(pkgs));
501
        final Set<? extends String> basePkgs = base.getPackages();
502
        if (basePkgs != null) {
503
            pkgSet.addAll(basePkgs);
504
        }
505
        final Set<String> newPkgs = Collections.unmodifiableSet(pkgSet);
506
        return new SearchScopeType() {
507
            @Override
508
            public Set<? extends String> getPackages() {
509
                return newPkgs;
510
            }
511
512
            @Override
513
            public boolean isSources() {
514
                return base.isSources();
515
            }
516
517
            @Override
518
            public boolean isDependencies() {
519
                return base.isDependencies();
520
            }
521
        };
522
    }
523
524
    // <editor-fold defaultstate="collapsed" desc="Private implementation">
425
    private static class ClassIndexFactoryImpl implements ClassIndexFactory {
525
    private static class ClassIndexFactoryImpl implements ClassIndexFactory {
426
        
526
        
427
	public ClassIndex create(final ClassPath bootPath, final ClassPath classPath, final ClassPath sourcePath) {            
527
	public ClassIndex create(final ClassPath bootPath, final ClassPath classPath, final ClassPath sourcePath) {            
Lines 465-479 Link Here
465
            }
565
            }
466
        });        
566
        });        
467
    }
567
    }
468
    
568
469
    private Iterable<? extends ClassIndexImpl> getQueries (final Set<SearchScope> scope) {
569
    private Iterable<? extends ClassIndexImpl> getQueries (final Set<? extends SearchScopeType> scope) {
470
        final Set<ClassIndexImpl> result = new HashSet<ClassIndexImpl> ();
570
        final Set<ClassIndexImpl> result = new HashSet<ClassIndexImpl> ();
471
        synchronized (this) {
571
        synchronized (this) {
472
            if (scope.contains(SearchScope.SOURCE)) {
572
            for (SearchScopeType s : scope) {
473
                result.addAll(this.sourceIndeces);
573
                if (s.isSources()) {
474
            }
574
                    result.addAll(this.sourceIndeces);
475
            if (scope.contains(SearchScope.DEPENDENCIES)) {
575
                }
476
                result.addAll(this.depsIndeces);
576
                if (s.isDependencies()) {
577
                    result.addAll(this.depsIndeces);
578
                }
477
            }
579
            }
478
        }
580
        }
479
        LOGGER.log(
581
        LOGGER.log(
Lines 487-494 Link Here
487
                    result
589
                    result
488
                });
590
                });
489
        return result;
591
        return result;
490
    }        
592
    }
491
    
593
492
    private void createQueriesForRoots (final ClassPath cp, final boolean sources, final Set<? super ClassIndexImpl> queries, final Set<? super URL> oldState) {
594
    private void createQueriesForRoots (final ClassPath cp, final boolean sources, final Set<? super ClassIndexImpl> queries, final Set<? super URL> oldState) {
493
        final PathRegistry preg = PathRegistry.getDefault();
595
        final PathRegistry preg = PathRegistry.getDefault();
494
        List<ClassPath.Entry> entries = cp.entries();
596
        List<ClassPath.Entry> entries = cp.entries();
Lines 820-823 Link Here
820
    private static void assertParserEventThread() {
922
    private static void assertParserEventThread() {
821
        assert Utilities.isTaskProcessorThread(Thread.currentThread());
923
        assert Utilities.isTaskProcessorThread(Thread.currentThread());
822
    }
924
    }
925
    //</editor-fold>
823
}
926
}
(-)a/java.source/src/org/netbeans/modules/java/source/usages/ClassIndexImpl.java (-3 / +9 lines)
Lines 59-64 Link Here
59
import java.util.logging.Logger;
59
import java.util.logging.Logger;
60
import javax.lang.model.element.TypeElement;
60
import javax.lang.model.element.TypeElement;
61
import org.apache.lucene.document.Document;
61
import org.apache.lucene.document.Document;
62
import org.netbeans.api.annotations.common.NonNull;
62
import org.netbeans.api.java.source.ClassIndex;
63
import org.netbeans.api.java.source.ClassIndex;
63
import org.netbeans.api.java.source.ElementHandle;
64
import org.netbeans.api.java.source.ElementHandle;
64
import org.netbeans.modules.parsing.lucene.support.Convertor;
65
import org.netbeans.modules.parsing.lucene.support.Convertor;
Lines 101-109 Link Here
101
    
102
    
102
    private State state = State.NEW;
103
    private State state = State.NEW;
103
    private final List<WeakReference<ClassIndexImplListener>> listeners = Collections.synchronizedList(new ArrayList<WeakReference<ClassIndexImplListener>> ());
104
    private final List<WeakReference<ClassIndexImplListener>> listeners = Collections.synchronizedList(new ArrayList<WeakReference<ClassIndexImplListener>> ());
104
    
105
105
    public abstract <T> void search (final String binaryName, final Set<UsageType> usageType, final Convertor<? super Document, T> convertor, final Set<? super T> result) throws IOException, InterruptedException;
106
    public abstract <T> void search (
106
    
107
            @NonNull final String binaryName,
108
            @NonNull final Set<? extends UsageType> usageType,
109
            @NonNull final Set<? extends ClassIndex.SearchScopeType> scope,
110
            @NonNull final Convertor<? super Document, T> convertor,
111
            @NonNull final Set<? super T> result) throws IOException, InterruptedException;
112
107
    public abstract <T> void getDeclaredTypes (String name, ClassIndex.NameKind kind, final Convertor<? super Document, T> convertor, final Set<? super T> result) throws IOException, InterruptedException;
113
    public abstract <T> void getDeclaredTypes (String name, ClassIndex.NameKind kind, final Convertor<? super Document, T> convertor, final Set<? super T> result) throws IOException, InterruptedException;
108
    
114
    
109
    public abstract <T> void getDeclaredElements (String ident, ClassIndex.NameKind kind, Convertor<? super Document, T> convertor, Map<T,Set<String>> result) throws IOException, InterruptedException;
115
    public abstract <T> void getDeclaredElements (String ident, ClassIndex.NameKind kind, Convertor<? super Document, T> convertor, Map<T,Set<String>> result) throws IOException, InterruptedException;
(-)a/java.source/src/org/netbeans/modules/java/source/usages/DocumentUtil.java (-2 / +2 lines)
Lines 217-223 Link Here
217
        return query;
217
        return query;
218
    }
218
    }
219
                                    
219
                                    
220
    static Term referencesTerm (String resourceName, final Set<ClassIndexImpl.UsageType> usageType) {
220
    static Term referencesTerm (String resourceName, final Set<? extends ClassIndexImpl.UsageType> usageType) {
221
        assert resourceName  != null;
221
        assert resourceName  != null;
222
        if (usageType != null) {
222
        if (usageType != null) {
223
            resourceName = encodeUsage (resourceName, usageType, WILDCARD).toString();
223
            resourceName = encodeUsage (resourceName, usageType, WILDCARD).toString();
Lines 291-297 Link Here
291
        return encodeUsage (className, usageTypes, NO).toString();
291
        return encodeUsage (className, usageTypes, NO).toString();
292
    }
292
    }
293
    
293
    
294
    private static StringBuilder encodeUsage (final String className, final Set<ClassIndexImpl.UsageType> usageTypes, char fill) {
294
    private static StringBuilder encodeUsage (final String className, final Set<? extends ClassIndexImpl.UsageType> usageTypes, char fill) {
295
        assert className != null;
295
        assert className != null;
296
        assert usageTypes != null;
296
        assert usageTypes != null;
297
        StringBuilder builder = new StringBuilder ();
297
        StringBuilder builder = new StringBuilder ();
(-)a/java.source/src/org/netbeans/modules/java/source/usages/PersistentClassIndex.java (-8 / +11 lines)
Lines 183-189 Link Here
183
    
183
    
184
    // Implementation of UsagesQueryImpl ---------------------------------------    
184
    // Implementation of UsagesQueryImpl ---------------------------------------    
185
    @Override
185
    @Override
186
    public <T> void search (final String binaryName, final Set<UsageType> usageType, final Convertor<? super Document, T> convertor, final Set<? super T> result) throws InterruptedException, IOException {
186
    public <T> void search (
187
            @NonNull final String binaryName,
188
            @NonNull final Set<? extends UsageType> usageType,
189
            @NonNull final Set<? extends ClassIndex.SearchScopeType> scope,
190
            @NonNull final Convertor<? super Document, T> convertor,
191
            @NonNull final Set<? super T> result) throws InterruptedException, IOException {
187
        updateDirty();
192
        updateDirty();
188
        try {
193
        try {
189
            if (BinaryAnalyser.OBJECT.equals(binaryName)) {
194
            if (BinaryAnalyser.OBJECT.equals(binaryName)) {
Lines 194-200 Link Here
194
            IndexManager.readAccess(new IndexManager.Action<Void> () {
199
            IndexManager.readAccess(new IndexManager.Action<Void> () {
195
                @Override
200
                @Override
196
                public Void run () throws IOException, InterruptedException {
201
                public Void run () throws IOException, InterruptedException {
197
                    usages(binaryName, usageType, convertor, result);
202
                    Query usagesQuery = QueryUtil.scopeFilter(
203
                            QueryUtil.createUsagesQuery(binaryName, usageType, Occur.SHOULD),
204
                            scope);
205
                    index.query(result, convertor, DocumentUtil.declaredTypesFieldSelector(), cancel.get(), usagesQuery);
198
                    return null;
206
                    return null;
199
                }
207
                }
200
            });
208
            });
Lines 393-404 Link Here
393
            }
401
            }
394
        }
402
        }
395
    }
403
    }
396
    
404
397
    private <T> void usages (final String binaryName, final Set<UsageType> usageType, Convertor<? super Document, T> convertor, Set<? super T> result) throws InterruptedException, IOException {
398
        final Query usagesQuery = QueryUtil.createUsagesQuery(binaryName, usageType, Occur.SHOULD);
399
        this.index.query(result, convertor, DocumentUtil.declaredTypesFieldSelector(), cancel.get(), usagesQuery);
400
    }
401
    
402
    private synchronized void resetPkgCache() {        
405
    private synchronized void resetPkgCache() {        
403
        rootPkgCache = null;
406
        rootPkgCache = null;
404
    }
407
    }
(-)a/java.source/src/org/netbeans/modules/java/source/usages/QueryUtil.java (-6 / +51 lines)
Lines 43-57 Link Here
43
package org.netbeans.modules.java.source.usages;
43
package org.netbeans.modules.java.source.usages;
44
44
45
import java.util.EnumSet;
45
import java.util.EnumSet;
46
import java.util.HashSet;
46
import java.util.Set;
47
import java.util.Set;
47
import org.apache.lucene.index.Term;
48
import org.apache.lucene.index.Term;
48
import org.apache.lucene.search.BooleanClause.Occur;
49
import org.apache.lucene.search.BooleanClause.Occur;
49
import org.apache.lucene.search.BooleanQuery;
50
import org.apache.lucene.search.BooleanQuery;
51
import org.apache.lucene.search.FilteredQuery;
52
import org.apache.lucene.search.PrefixFilter;
50
import org.apache.lucene.search.Query;
53
import org.apache.lucene.search.Query;
54
import org.apache.lucene.search.TermQuery;
51
import org.apache.lucene.search.WildcardQuery;
55
import org.apache.lucene.search.WildcardQuery;
52
import org.netbeans.api.annotations.common.NonNull;
56
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.api.annotations.common.NullAllowed;
57
import org.netbeans.api.annotations.common.NullAllowed;
54
import org.netbeans.modules.parsing.lucene.support.Convertor;
58
import org.netbeans.api.java.source.ClassIndex.SearchScopeType;
55
import org.netbeans.modules.parsing.lucene.support.StoppableConvertor;
59
import org.netbeans.modules.parsing.lucene.support.StoppableConvertor;
56
import org.openide.util.Parameters;
60
import org.openide.util.Parameters;
57
61
Lines 65-71 Link Here
65
    
69
    
66
    static Query createUsagesQuery(
70
    static Query createUsagesQuery(
67
            final @NonNull String resourceName,
71
            final @NonNull String resourceName,
68
            final @NonNull Set<ClassIndexImpl.UsageType> mask,
72
            final @NonNull Set<? extends ClassIndexImpl.UsageType> mask,
69
            final @NonNull Occur operator) {
73
            final @NonNull Occur operator) {
70
        Parameters.notNull("resourceName", resourceName);
74
        Parameters.notNull("resourceName", resourceName);
71
        Parameters.notNull("mask", mask);
75
        Parameters.notNull("mask", mask);
Lines 83-89 Link Here
83
            throw new IllegalArgumentException();
87
            throw new IllegalArgumentException();
84
        }
88
        }
85
    }
89
    }
86
        
90
    static Query scopeFilter (
91
            @NonNull final Query q,
92
            @NonNull final Set<? extends SearchScopeType> scope) {
93
        final Set<String> pkgs = new HashSet<String>();
94
        for (SearchScopeType s : scope) {
95
            Set<? extends String> sp = s.getPackages();
96
            if (sp != null) {
97
                pkgs.addAll(sp);
98
            }
99
        }
100
        switch (pkgs.size()) {
101
            case 0:
102
                return q;
103
            case 1:
104
            {
105
                //Todo perf: Use filter query
106
                final BooleanQuery qFiltered = new BooleanQuery();
107
                qFiltered.add(
108
                    new TermQuery(
109
                        new Term (
110
                            DocumentUtil.FIELD_PACKAGE_NAME,
111
                            pkgs.iterator().next())),
112
                    Occur.MUST);
113
                qFiltered.add(q, Occur.MUST);
114
                return qFiltered;
115
            }
116
            default:
117
            {
118
                final BooleanQuery qPkgs = new BooleanQuery();
119
                for (String pkg : pkgs) {
120
                    qPkgs.add(
121
                        new TermQuery(
122
                            new Term(
123
                                DocumentUtil.FIELD_PACKAGE_NAME,
124
                                pkg)),
125
                            Occur.SHOULD);
126
                }
127
                final BooleanQuery qFiltered = new BooleanQuery();
128
                qFiltered.add(q, Occur.MUST);
129
                qFiltered.add(qPkgs, Occur.MUST);
130
                return qFiltered;
131
            }
132
        }
133
    }
134
87
    static Pair<StoppableConvertor<Term,String>,Term> createPackageFilter(
135
    static Pair<StoppableConvertor<Term,String>,Term> createPackageFilter(
88
            final @NullAllowed String prefix,
136
            final @NullAllowed String prefix,
89
            final boolean directOnly) {
137
            final boolean directOnly) {
Lines 128-136 Link Here
128
            }
176
            }
129
            return null;
177
            return null;
130
        }
178
        }
131
        
132
    }
179
    }
133
    
134
    //</editor-fold>
180
    //</editor-fold>
135
            
136
}
181
}

Return to bug 199432