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

(-)a/java.source.base/apichanges.xml (+14 lines)
Lines 49-54 Link Here
49
    <apidef name="javasource_base">Java Source API</apidef>
49
    <apidef name="javasource_base">Java Source API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="classindex.searchkind.lambda">
53
        <api name="javasource_base"/>
54
        <summary>ClassIndex SearchKind extended by FUNCTIONAL_IMPLEMENTORS</summary>
55
        <version major="1" minor="2.9"/>
56
        <date day="23" month="9" year="2015"/>
57
        <author login="tzezula"/>
58
        <compatibility addition="yes" binary="compatible" source="compatible"/>
59
        <description>
60
            Added a possibility to <code>ClassIndex</code> to search a lambda
61
            implementations.
62
        </description>
63
        <class name="ClassIndex" package="org.netbeans.api.java.source"/>
64
        <issue number="255393"/>
65
    </change>
52
    <change id="classindex.resources.binaryroots">
66
    <change id="classindex.resources.binaryroots">
53
        <api name="javasource_base"/>
67
        <api name="javasource_base"/>
54
        <summary>ClassIndex returns resources from binaryroots</summary>
68
        <summary>ClassIndex returns resources from binaryroots</summary>
(-)a/java.source.base/nbproject/project.properties (-1 / +1 lines)
Lines 47-53 Link Here
47
javadoc.title=Java Source Base
47
javadoc.title=Java Source Base
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
50
spec.version.base=2.8.0
50
spec.version.base=2.9.0
51
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
51
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
52
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
53
    ${o.n.core.dir}/lib/boot.jar:\
53
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source.base/src/org/netbeans/api/java/source/ClassIndex.java (-3 / +14 lines)
Lines 198-203 Link Here
198
        
198
        
199
        /**
199
        /**
200
         * The returned class has to extend or implement given element
200
         * The returned class has to extend or implement given element
201
         *//**
202
         * The returned class has to extend or implement given element
201
         */
203
         */
202
        IMPLEMENTORS,
204
        IMPLEMENTORS,
203
        
205
        
Lines 214-220 Link Here
214
        /**
216
        /**
215
         * The returned class contains references to the element type
217
         * The returned class contains references to the element type
216
         */
218
         */
217
        TYPE_REFERENCES,        
219
        TYPE_REFERENCES,
220
221
        /**
222
         * The returned class contains a lambda implementation of given functional interface.
223
         * @since 2.9
224
         */
225
        FUNCTIONAL_IMPLEMENTORS;
218
    };
226
    };
219
    
227
    
220
    /**
228
    /**
Lines 831-838 Link Here
831
        final Set<ClassIndexImpl.UsageType> result = EnumSet.noneOf(ClassIndexImpl.UsageType.class);
839
        final Set<ClassIndexImpl.UsageType> result = EnumSet.noneOf(ClassIndexImpl.UsageType.class);
832
        for (ClassIndex.SearchKind sk : kind) {
840
        for (ClassIndex.SearchKind sk : kind) {
833
            switch (sk) {
841
            switch (sk) {
834
                case METHOD_REFERENCES:                    
842
                case METHOD_REFERENCES:
835
                    result.add(ClassIndexImpl.UsageType.METHOD_REFERENCE);                    
843
                    result.add(ClassIndexImpl.UsageType.METHOD_REFERENCE);
836
                    break;
844
                    break;
837
                case FIELD_REFERENCES:
845
                case FIELD_REFERENCES:
838
                    result.add(ClassIndexImpl.UsageType.FIELD_REFERENCE);
846
                    result.add(ClassIndexImpl.UsageType.FIELD_REFERENCE);
Lines 860-865 Link Here
860
                            throw new IllegalArgumentException ();                                        
868
                            throw new IllegalArgumentException ();                                        
861
                    }
869
                    }
862
                    break;
870
                    break;
871
                case FUNCTIONAL_IMPLEMENTORS:
872
                    result.add(ClassIndexImpl.UsageType.FUNCTIONAL_IMPLEMENTORS);
873
                    break;
863
                default:
874
                default:
864
                    throw new IllegalArgumentException ();                    
875
                    throw new IllegalArgumentException ();                    
865
            }
876
            }
(-)a/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaIndex.java (-1 / +1 lines)
Lines 81-87 Link Here
81
public final class JavaIndex {
81
public final class JavaIndex {
82
82
83
    public static final String NAME = "java"; //NOI18N
83
    public static final String NAME = "java"; //NOI18N
84
    public static final int VERSION = 14;
84
    public static final int VERSION = 15;
85
    static final Logger LOG = Logger.getLogger(JavaIndex.class.getName());
85
    static final Logger LOG = Logger.getLogger(JavaIndex.class.getName());
86
    private static final String CLASSES = "classes"; //NOI18N
86
    private static final String CLASSES = "classes"; //NOI18N
87
    private static final String APT_SOURCES = "sources";    //NOI18N
87
    private static final String APT_SOURCES = "sources";    //NOI18N
(-)a/java.source.base/src/org/netbeans/modules/java/source/usages/ClassIndexImpl.java (-1 / +2 lines)
Lines 87-93 Link Here
87
        SUPER_INTERFACE,
87
        SUPER_INTERFACE,
88
        FIELD_REFERENCE,
88
        FIELD_REFERENCE,
89
        METHOD_REFERENCE,
89
        METHOD_REFERENCE,
90
        TYPE_REFERENCE;
90
        TYPE_REFERENCE,
91
        FUNCTIONAL_IMPLEMENTORS;
91
    }
92
    }
92
93
93
    /**
94
    /**
(-)a/java.source.base/src/org/netbeans/modules/java/source/usages/SourceAnalyzerFactory.java (+19 lines)
Lines 778-783 Link Here
778
        }
778
        }
779
779
780
        @Override
780
        @Override
781
        public Void visitLambdaExpression(
782
                @NonNull final LambdaExpressionTree node,
783
                @NonNull final Map<Pair<String, String>, UsagesData<String>> p) {
784
            final Type type = ((JCTree.JCLambda)node).type;
785
            if (type != null) {
786
                final Symbol sym = type.tsym;
787
                if (sym != null) {
788
                    if (sym != null && sym.getKind().isInterface()) {
789
                        addUsage(sym,
790
                            activeClass.peek(),
791
                            p,
792
                            ClassIndexImpl.UsageType.FUNCTIONAL_IMPLEMENTORS);
793
                    }
794
                }
795
            }
796
            return super.visitLambdaExpression(node, p);
797
        }
798
799
        @Override
781
        @CheckForNull
800
        @CheckForNull
782
        public Void visitVariable(@NonNull final VariableTree node, @NonNull final Map<Pair<String, String>, UsagesData<String>> p) {
801
        public Void visitVariable(@NonNull final VariableTree node, @NonNull final Map<Pair<String, String>, UsagesData<String>> p) {
783
            Symbol s = ((JCTree.JCVariableDecl)node).sym;
802
            Symbol s = ((JCTree.JCVariableDecl)node).sym;
(-)a/refactoring.java/nbproject/project.xml (-1 / +1 lines)
Lines 177-183 Link Here
177
                    <build-prerequisite/>
177
                    <build-prerequisite/>
178
                    <compile-dependency/>
178
                    <compile-dependency/>
179
                    <run-dependency>
179
                    <run-dependency>
180
                        <specification-version>2.6</specification-version>
180
                        <specification-version>2.9</specification-version>
181
                    </run-dependency>
181
                    </run-dependency>
182
                </dependency>
182
                </dependency>
183
                <dependency>
183
                <dependency>
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaWhereUsedQueryPlugin.java (-3 / +33 lines)
Lines 56-61 Link Here
56
import javax.lang.model.element.ExecutableElement;
56
import javax.lang.model.element.ExecutableElement;
57
import javax.lang.model.element.Modifier;
57
import javax.lang.model.element.Modifier;
58
import javax.lang.model.element.TypeElement;
58
import javax.lang.model.element.TypeElement;
59
import org.netbeans.api.annotations.common.NonNull;
59
import org.netbeans.api.fileinfo.NonRecursiveFolder;
60
import org.netbeans.api.fileinfo.NonRecursiveFolder;
60
import org.netbeans.api.java.classpath.ClassPath;
61
import org.netbeans.api.java.classpath.ClassPath;
61
import org.netbeans.api.java.platform.JavaPlatform;
62
import org.netbeans.api.java.platform.JavaPlatform;
Lines 296-312 Link Here
296
                    }
297
                    }
297
                } else if (el.getKind().isClass() || el.getKind().isInterface()) {
298
                } else if (el.getKind().isClass() || el.getKind().isInterface()) {
298
                    if (isFindSubclasses || isFindDirectSubclassesOnly) {
299
                    if (isFindSubclasses || isFindDirectSubclassesOnly) {
299
                        EnumSet searchKind = EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS);
300
                        if (isFindDirectSubclassesOnly) {
300
                        if (isFindDirectSubclassesOnly) {
301
                            EnumSet searchKind = EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS);
302
                            if (el.getKind() == ElementKind.INTERFACE) {
303
                                searchKind.add(ClassIndex.SearchKind.FUNCTIONAL_IMPLEMENTORS);
304
                            }
301
                            //get direct implementors from index
305
                            //get direct implementors from index
302
                            sourceSet.addAll(idx.getResources(ElementHandle.create((TypeElement) el), searchKind, searchScopeType, resourceType));
306
                            sourceSet.addAll(idx.getResources(ElementHandle.create((TypeElement) el), searchKind, searchScopeType, resourceType));
303
                        } else {
307
                        } else {
304
                            Set<?> implementorsAsHandles = RefactoringUtils.getImplementorsAsHandles(idx, cpInfo, (TypeElement)el, cancel);
308
                            Set<ElementHandle<TypeElement>> implementorsAsHandles = RefactoringUtils.getImplementorsAsHandles(idx, cpInfo, (TypeElement)el, cancel);
305
                            if (cancel != null && cancel.get()) {
309
                            if (cancel != null && cancel.get()) {
306
                                sourceSet.clear();
310
                                sourceSet.clear();
307
                                return;
311
                                return;
308
                            }
312
                            }
309
                            sourceSet.addAll(SourceUtilsEx.getFiles((Collection<ElementHandle<? extends Element>>) implementorsAsHandles, cpInfo, cancel));
313
                            sourceSet.addAll(SourceUtilsEx.getFiles((Collection<ElementHandle<? extends Element>>)(Collection<?>)implementorsAsHandles, cpInfo, cancel));
314
                            if (el.getKind() == ElementKind.INTERFACE) {
315
                                sourceSet.addAll(getFunctionalSubtypes(
316
                                    ElementHandle.create((TypeElement)el),
317
                                    implementorsAsHandles,
318
                                    cpInfo,
319
                                    searchScopeType));
320
                            }
310
                        }
321
                        }
311
                    } else {
322
                    } else {
312
                        //get type references from index
323
                        //get type references from index
Lines 550-555 Link Here
550
        }
561
        }
551
    }
562
    }
552
563
564
    @NonNull
565
    private static Collection<? extends FileObject> getFunctionalSubtypes(
566
            @NonNull final ElementHandle<TypeElement> base,
567
            @NonNull final Collection<ElementHandle<TypeElement>> subtypes,
568
            @NonNull final ClasspathInfo cpInfo,
569
            @NonNull final Set<ClassIndex.SearchScopeType> scope) {
570
        assert base.getKind() == ElementKind.INTERFACE;
571
        final ClassIndex index = cpInfo.getClassIndex();
572
        final Set<ClassIndex.SearchKind> fncKind = EnumSet.of(ClassIndex.SearchKind.FUNCTIONAL_IMPLEMENTORS);
573
        final Set<FileObject> result = new HashSet<>();
574
        result.addAll(index.getResources(base, fncKind, scope));
575
        for (ElementHandle<TypeElement> e : subtypes) {
576
            if (e.getKind() == ElementKind.INTERFACE) {
577
                result.addAll(index.getResources(e, fncKind, scope));
578
            }
579
        }
580
        return result;
581
    }
582
553
    private class FindTask implements CancellableTask<CompilationController> {
583
    private class FindTask implements CancellableTask<CompilationController> {
554
584
555
        private final RefactoringElementsBag elements;
585
        private final RefactoringElementsBag elements;

Return to bug 255393