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 227607
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="getSymbols">
112
             <api name="general"/>
113
             <summary>Added several methods to support Java 8 features.</summary>
114
             <version major="0" minor="114"/>
115
             <date day="25" month="2" year="2013"/>
116
             <author login="jlahoda"/>
117
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 Added <code>ClassIndex.getDeclaredSymbols</code>.
120
             </description>
121
             <class package="org.netbeans.api.java.source" name="ClassIndex"/>
122
             <issue number="227607"/>
123
        </change>
111
         <change id="LambdaEnhancements">
124
         <change id="LambdaEnhancements">
112
             <api name="general"/>
125
             <api name="general"/>
113
             <summary>Added several methods to support Java 8 features.</summary>
126
             <summary>Added several methods to support Java 8 features.</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.113
49
spec.version.base=0.114
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.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 (+86 lines)
Lines 48-61 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.ArrayList;
51
import java.util.Arrays;
52
import java.util.Arrays;
52
import java.util.Collection;
53
import java.util.Collection;
53
import java.util.Collections;
54
import java.util.Collections;
54
import java.util.EnumSet;
55
import java.util.EnumSet;
56
import java.util.HashMap;
55
import java.util.HashSet;
57
import java.util.HashSet;
56
import java.util.Iterator;
58
import java.util.Iterator;
57
import java.util.LinkedList;
59
import java.util.LinkedList;
58
import java.util.List;
60
import java.util.List;
61
import java.util.Map;
62
import java.util.Map.Entry;
59
import java.util.Set;
63
import java.util.Set;
60
import java.util.concurrent.ConcurrentLinkedQueue;
64
import java.util.concurrent.ConcurrentLinkedQueue;
61
import java.util.concurrent.atomic.AtomicBoolean;
65
import java.util.concurrent.atomic.AtomicBoolean;
Lines 510-515 Link Here
510
    }
514
    }
511
    
515
    
512
    /**
516
    /**
517
     * Returns descriptions of symbols found on the given classpath and matching the additional criteria.
518
     * @param name case sensitive prefix, case insensitive prefix, exact simple name,
519
     * camel case or regular expression depending on the kind parameter.
520
     * @param kind of the name {@see NameKind}
521
     * @param scope to search in {@see SearchScope}
522
     * @return iterable of {@link Symbols} describing found symbols matching the specified criteria.
523
     * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
524
     * inside call of this method.
525
     * @since 0.114
526
     */
527
    public @NullUnknown Iterable<Symbols> getDeclaredSymbols(
528
            final @NonNull String name,
529
            final @NonNull NameKind kind,
530
            final @NonNull Set<? extends SearchScopeType> scope) {
531
        Parameters.notNull("name", name);
532
        Parameters.notNull("kind", kind);
533
        final Map<ElementHandle<TypeElement>,Set<String>> result = new HashMap<ElementHandle<TypeElement>,Set<String>>();
534
        final Iterable<? extends ClassIndexImpl> queries = this.getQueries (scope);        
535
        final Convertor<Document, ElementHandle<TypeElement>> thConvertor = DocumentUtil.elementHandleConvertor();
536
        try {
537
            for (ClassIndexImpl query : queries) {
538
                try {
539
                    query.getDeclaredElements(
540
                        name,
541
                        kind,
542
                        thConvertor,
543
                        result);
544
                } catch (Index.IndexClosedException e) {
545
                    logClosedIndex (query);
546
                } catch (IOException e) {
547
                    Exceptions.printStackTrace(e);
548
                }
549
            }
550
            if (LOGGER.isLoggable(Level.FINE)) {
551
                LOGGER.log(
552
                        Level.FINE,
553
                        "ClassIndex.getDeclaredTypes returned {0} elements\n",  //NOI18N
554
                        result.size());
555
            }
556
            List<Symbols> finalResult = new ArrayList<Symbols>();
557
            for (Entry<ElementHandle<TypeElement>, Set<String>> e : result.entrySet()) {
558
                finalResult.add(new Symbols(e.getKey(), e.getValue()));
559
            }
560
            return Collections.unmodifiableList(finalResult);
561
        } catch (InterruptedException e) {
562
            return null;
563
        }
564
    }
565
    
566
    /**Description of found symbols (methods, constructors, fields) for one enclosing type.
567
     * Returned from {@link #getDeclaredSymbols(java.lang.String, org.netbeans.api.java.source.ClassIndex.NameKind, java.util.Set) }.
568
     * 
569
     * @since 0.114
570
     */
571
    public static final class Symbols {
572
        private final ElementHandle<TypeElement> enclosingType;
573
        private final Set<String> symbols;
574
575
        Symbols(ElementHandle<TypeElement> enclosingType, Set<String> symbols) {
576
            this.enclosingType = enclosingType;
577
            this.symbols = symbols;
578
        }
579
580
        /**The type that contains some symbols matching the required criterie.
581
         * 
582
         * @return enclosing type
583
         */
584
        public ElementHandle<TypeElement> getEnclosingType() {
585
            return enclosingType;
586
        }
587
588
        /**The simple names of all symbols matching the criteria inside the given enclosing type.
589
         * 
590
         * @return simple names of matching symbols
591
         */
592
        public Set<String> getSymbols() {
593
            return symbols;
594
        }
595
        
596
    }
597
    
598
    /**
513
     * Returns names af all packages in given classpath starting with prefix.
599
     * Returns names af all packages in given classpath starting with prefix.
514
     * @param prefix of the package name
600
     * @param prefix of the package name
515
     * @param directOnly if true treats the packages as folders and returns only
601
     * @param directOnly if true treats the packages as folders and returns only
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/ClassIndexTest.java (+33 lines)
Lines 60-65 Link Here
60
import org.netbeans.api.java.classpath.GlobalPathRegistry;
60
import org.netbeans.api.java.classpath.GlobalPathRegistry;
61
import org.netbeans.api.java.platform.JavaPlatformManager;
61
import org.netbeans.api.java.platform.JavaPlatformManager;
62
import org.netbeans.api.java.queries.SourceForBinaryQuery;
62
import org.netbeans.api.java.queries.SourceForBinaryQuery;
63
import org.netbeans.api.java.source.ClassIndex.NameKind;
64
import org.netbeans.api.java.source.ClassIndex.Symbols;
63
import org.netbeans.junit.MockServices;
65
import org.netbeans.junit.MockServices;
64
import org.netbeans.junit.NbTestCase;
66
import org.netbeans.junit.NbTestCase;
65
import org.netbeans.modules.java.source.parsing.FileObjects;
67
import org.netbeans.modules.java.source.parsing.FileObjects;
Lines 551-556 Link Here
551
        assertTrue(testListener.getAdded().isEmpty());
553
        assertTrue(testListener.getAdded().isEmpty());
552
    }
554
    }
553
555
556
    public void testFindSymbols() throws Exception {
557
        final FileObject wd = FileUtil.toFileObject(getWorkDir());
558
        final FileObject root = FileUtil.createFolder(wd,"src");    //NOI18N
559
        sourcePath = ClassPathSupport.createClassPath(root);
560
        compilePath = ClassPathSupport.createClassPath(new URL[0]);
561
        bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
562
        final FileObject t1 = createJavaFile(
563
                root,
564
                "test",                                          //NOI18N
565
                "Test",                                          //NOI18N
566
                "package test;\n"+                               //NOI18N
567
                "public class Test { private void foo() { } }"); //NOI18N
568
        final FileObject t2 = createJavaFile(
569
                root,
570
                "test",                                          //NOI18N
571
                "foo",                                           //NOI18N
572
                "package test;\n"+                               //NOI18N
573
                "public class foo {\n"+                          //NOI18N
574
                "}");                                            //NOI18N
575
        IndexingManager.getDefault().refreshIndexAndWait(root.toURL(), null);
576
        final ClassIndex ci = ClasspathInfo.create(bootPath, compilePath, sourcePath).getClassIndex();
577
        assertNotNull(ci);
578
        Iterable<Symbols> result = ci.getDeclaredSymbols("foo", NameKind.SIMPLE_NAME,
579
            EnumSet.<ClassIndex.SearchScope>of(ClassIndex.SearchScope.SOURCE));
580
        Set<String> actualResult = new HashSet<String>();
581
        for (Symbols s : result) {
582
            actualResult.add(s.getEnclosingType().getQualifiedName() + ":" + s.getSymbols().toString());
583
        }
584
        assertEquals(new HashSet<String>(Arrays.asList("test.foo:[foo]", "test.Test:[foo]")), actualResult);
585
    }
586
    
554
    private FileObject createJavaFile (
587
    private FileObject createJavaFile (
555
            final FileObject root,
588
            final FileObject root,
556
            final String pkg,
589
            final String pkg,

Return to bug 227607