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 203806
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+14 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="PackageUsages">
112
             <api name="general"/>
113
             <summary>Added <code>ClassIndex.getResourcesForPackage</code> and <code>ClassIndex.getElementsForPackage</code>to allow to find package usages.</summary>
114
             <version major="0" minor="89"/>
115
             <date day="20" month="10" year="2011"/>
116
             <author login="tzezula"/>
117
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 Added <code>ClassIndex.getResourcesForPackage</code> and <code>ClassIndex.getElementsForPackage</code>to allow to find package usages.
120
                 Currently the client which needs to find usages of all types declared in the package has to list the package and query usages of each type
121
                 individually which is inefficient.
122
             </description>
123
             <issue number="131944"/>
124
        </change>
111
        <change id="OrganizeImports">
125
        <change id="OrganizeImports">
112
             <api name="general"/>
126
             <api name="general"/>
113
             <summary>Added <code>GeneratorUtilities.addImports</code> and several methods to <code>CodeStyle</code> to support organizing imports.</summary>
127
             <summary>Added <code>GeneratorUtilities.addImports</code> and several methods to <code>CodeStyle</code> to support organizing imports.</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.88.0
49
spec.version.base=0.89.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 (-46 / +103 lines)
Lines 61-67 Link Here
61
import java.util.concurrent.atomic.AtomicBoolean;
61
import java.util.concurrent.atomic.AtomicBoolean;
62
import java.util.logging.Level;
62
import java.util.logging.Level;
63
import java.util.logging.Logger;
63
import java.util.logging.Logger;
64
import javax.lang.model.element.Element;
64
import javax.lang.model.element.ElementKind;
65
import javax.lang.model.element.ElementKind;
66
import javax.lang.model.element.PackageElement;
65
import javax.lang.model.element.TypeElement;
67
import javax.lang.model.element.TypeElement;
66
import org.apache.lucene.document.Document;
68
import org.apache.lucene.document.Document;
67
import org.netbeans.api.annotations.common.CheckForNull;
69
import org.netbeans.api.annotations.common.CheckForNull;
Lines 325-332 Link Here
325
    
327
    
326
    
328
    
327
    /**
329
    /**
328
     * Returns a set of {@link ElementHandle}s containing reference(s) to given element.
330
     * Returns a set of {@link ElementHandle}s containing reference(s) to given type element.
329
     * @param element for which usages should be found
331
     * @param element the {@link ElementHandle} of a {@link TypeElement} for which usages should be found
330
     * @param searchKind type of reference, {@see SearchKind}
332
     * @param searchKind type of reference, {@see SearchKind}
331
     * @param scope to search in {@see SearchScope}
333
     * @param scope to search in {@see SearchScope}
332
     * @return set of {@link ElementHandle}s containing the reference(s)
334
     * @return set of {@link ElementHandle}s containing the reference(s)
Lines 337-375 Link Here
337
            final @NonNull ElementHandle<TypeElement> element,
339
            final @NonNull ElementHandle<TypeElement> element,
338
            final @NonNull Set<SearchKind> searchKind,
340
            final @NonNull Set<SearchKind> searchKind,
339
            final @NonNull Set<? extends SearchScopeType> scope) {
341
            final @NonNull Set<? extends SearchScopeType> scope) {
340
        assert element != null;
342
        return searchImpl(
341
        assert element.getSignature()[0] != null;
343
            element,
342
        assert searchKind != null;
344
            searchKind,
343
        final Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>> ();
345
            scope,
344
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
346
            new Convertor<ClassIndexImpl, Convertor<? super Document,ElementHandle<TypeElement>>>(){
345
        final Set<ClassIndexImpl.UsageType> ut =  encodeSearchKind(element.getKind(),searchKind);
347
                @NonNull
346
        final Convertor<? super Document, ElementHandle<TypeElement>> thConvertor = DocumentUtil.elementHandleConvertor();
348
                @Override
347
        try {
349
                public Convertor<? super Document, ElementHandle<TypeElement>> convert(@NonNull final ClassIndexImpl p) {
348
            if (!ut.isEmpty()) {
350
                    return DocumentUtil.elementHandleConvertor();
349
                for (ClassIndexImpl query : queries) {
350
                    try {
351
                        query.search(
352
                            element,
353
                            ut,
354
                            scope,
355
                            thConvertor,
356
                            result);
357
                    } catch (Index.IndexClosedException e) {
358
                        logClosedIndex (query);
359
                    } catch (IOException e) {
360
                        Exceptions.printStackTrace(e);
361
                    }
362
                }
351
                }
363
            }
352
            });
364
            return Collections.unmodifiableSet(result);
365
        } catch (InterruptedException e) {
366
            return null;
367
        }
368
    }
353
    }
369
    
354
370
    /**
355
    /**
371
     * Returns a set of source files containing reference(s) to given element.
356
     * Returns a set of {@link ElementHandle}s containing reference(s) to given package element.
372
     * @param element for which usages should be found
357
     * @param element the {@link ElementHandle} of a {@link PackageElement} for which usages should be found
358
     * @param searchKind type of reference, {@see SearchKind}
359
     * @param scope to search in {@see SearchScope}
360
     * @return set of {@link ElementHandle}s containing the reference(s)
361
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
362
     * inside call of this method.
363
     * @since 0.89
364
     */
365
    public @NullUnknown Set<ElementHandle<TypeElement>> getElementsForPackage (
366
            final @NonNull ElementHandle<PackageElement> element,
367
            final @NonNull Set<SearchKind> searchKind,
368
            final @NonNull Set<? extends SearchScopeType> scope) {
369
        return searchImpl(
370
            element,
371
            searchKind,
372
            scope,
373
            new Convertor<ClassIndexImpl, Convertor<? super Document,ElementHandle<TypeElement>>>(){
374
                @NonNull
375
                @Override
376
                public Convertor<? super Document, ElementHandle<TypeElement>> convert(@NonNull final ClassIndexImpl p) {
377
                    return DocumentUtil.elementHandleConvertor();
378
                }
379
            });
380
    }
381
382
    /**
383
     * Returns a set of source files containing reference(s) to given type element.
384
     * @param element the {@link ElementHandle} of a {@link TypeElement} for which usages should be found
373
     * @param searchKind type of reference, {@see SearchKind}
385
     * @param searchKind type of reference, {@see SearchKind}
374
     * @param scope to search in {@see SearchScope}
386
     * @param scope to search in {@see SearchScope}
375
     * @return set of {@link FileObject}s containing the reference(s)
387
     * @return set of {@link FileObject}s containing the reference(s)
Lines 380-401 Link Here
380
            final @NonNull ElementHandle<TypeElement> element,
392
            final @NonNull ElementHandle<TypeElement> element,
381
            final @NonNull Set<SearchKind> searchKind,
393
            final @NonNull Set<SearchKind> searchKind,
382
            final @NonNull Set<? extends SearchScopeType> scope) {
394
            final @NonNull Set<? extends SearchScopeType> scope) {
383
        assert element != null;
395
        return searchImpl(
384
        assert element.getSignature()[0] != null;
396
            element,
385
        assert searchKind != null;
397
            searchKind,
386
        final Set<FileObject> result = new HashSet<FileObject> ();
398
            scope,
387
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
399
            new Convertor<ClassIndexImpl, Convertor<? super Document,FileObject>>() {
400
                @NonNull
401
                @Override
402
                public Convertor<Document, FileObject> convert(@NonNull final ClassIndexImpl p) {
403
                    return DocumentUtil.fileObjectConvertor (p.getSourceRoots());
404
                }
405
            });
406
    }
407
408
    /**
409
     * Returns a set of source files containing reference(s) to given package element.
410
     * @param element the {@link ElementHandle} of a {@link PackageElement} for which usages should be found
411
     * @param searchKind type of reference, {@see SearchKind}
412
     * @param scope to search in {@see SearchScope}
413
     * @return set of {@link FileObject}s containing the reference(s)
414
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
415
     * inside call of this method.
416
     * @since 0.89
417
     */
418
    public @NullUnknown Set<FileObject> getResourcesForPackage (
419
            final @NonNull ElementHandle<PackageElement> element,
420
            final @NonNull Set<SearchKind> searchKind,
421
            final @NonNull Set<? extends SearchScopeType> scope) {
422
        return searchImpl(
423
            element,
424
            searchKind,
425
            scope,
426
            new Convertor<ClassIndexImpl, Convertor<? super Document,FileObject>>() {
427
                @NonNull
428
                @Override
429
                public Convertor<Document, FileObject> convert(@NonNull final ClassIndexImpl p) {
430
                    return DocumentUtil.fileObjectConvertor (p.getSourceRoots());
431
                }
432
            });
433
    }
434
435
    @NullUnknown
436
    private <T> Set<T> searchImpl(
437
            @NonNull final ElementHandle<? extends Element> element,
438
            @NonNull final Set<SearchKind> searchKind,
439
            @NonNull final Set<? extends SearchScopeType> scope,
440
            @NonNull final Convertor<? super ClassIndexImpl,Convertor<? super Document, T>> convertor) {
441
        Parameters.notNull("element", element); //NOI18N
442
        Parameters.notNull("element.signatue", element.getSignature()[0]);  //NOI18N
443
        Parameters.notNull("searchKind", searchKind);   //NOI18N
444
        Parameters.notNull("scope", scope); //NOI18N
445
        Parameters.notNull("convertor", convertor); //NOI18N
446
        final Set<T> result = new HashSet<T> ();
388
        final Set<ClassIndexImpl.UsageType> ut =  encodeSearchKind(element.getKind(),searchKind);
447
        final Set<ClassIndexImpl.UsageType> ut =  encodeSearchKind(element.getKind(),searchKind);
389
        try {
448
        if (!ut.isEmpty()) {
390
            if (!ut.isEmpty()) {
449
            try {
450
                final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);
391
                for (ClassIndexImpl query : queries) {
451
                for (ClassIndexImpl query : queries) {
392
                    final Convertor<? super Document, FileObject> foConvertor = DocumentUtil.fileObjectConvertor (query.getSourceRoots());
393
                    try {
452
                    try {
394
                        query.search(
453
                        query.search(
395
                            element,
454
                            element,
396
                            ut,
455
                            ut,
397
                            scope,
456
                            scope,
398
                            foConvertor,
457
                            convertor.convert(query),
399
                            result);
458
                            result);
400
                    } catch (Index.IndexClosedException e) {
459
                    } catch (Index.IndexClosedException e) {
401
                        logClosedIndex (query);
460
                        logClosedIndex (query);
Lines 403-416 Link Here
403
                        Exceptions.printStackTrace(e);
462
                        Exceptions.printStackTrace(e);
404
                    }
463
                    }
405
                }
464
                }
465
            } catch (InterruptedException e) {
466
                return null;
406
            }
467
            }
407
            return Collections.unmodifiableSet(result);
408
        } catch (InterruptedException e) {
409
            return null;
410
        }
468
        }
469
        return Collections.unmodifiableSet(result);
411
    }
470
    }
412
    
413
    
414
    /**
471
    /**
415
     * Returns {@link ElementHandle}s for all declared types in given classpath corresponding to the name.
472
     * Returns {@link ElementHandle}s for all declared types in given classpath corresponding to the name.
416
     * @param name case sensitive prefix, case insensitive prefix, exact simple name,
473
     * @param name case sensitive prefix, case insensitive prefix, exact simple name,

Return to bug 203806