diff -r 118122ec17fb java.source/apichanges.xml --- a/java.source/apichanges.xml Mon Mar 18 10:31:55 2013 +0100 +++ b/java.source/apichanges.xml Mon Mar 18 12:36:32 2013 +0100 @@ -108,6 +108,19 @@ + + + Added several methods to support Java 8 features. + + + + + + Added ClassIndex.getDeclaredSymbols. + + + + Added several methods to support Java 8 features. diff -r 118122ec17fb java.source/nbproject/project.properties --- a/java.source/nbproject/project.properties Mon Mar 18 10:31:55 2013 +0100 +++ b/java.source/nbproject/project.properties Mon Mar 18 12:36:32 2013 +0100 @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.113 +spec.version.base=0.114 test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\ ${o.n.core.dir}/lib/boot.jar:\ diff -r 118122ec17fb java.source/src/org/netbeans/api/java/source/ClassIndex.java --- a/java.source/src/org/netbeans/api/java/source/ClassIndex.java Mon Mar 18 10:31:55 2013 +0100 +++ b/java.source/src/org/netbeans/api/java/source/ClassIndex.java Mon Mar 18 12:36:32 2013 +0100 @@ -48,14 +48,18 @@ import java.beans.PropertyChangeListener; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; @@ -510,6 +514,88 @@ } /** + * Returns descriptions of symbols found on the given classpath and matching the additional criteria. + * @param name case sensitive prefix, case insensitive prefix, exact simple name, + * camel case or regular expression depending on the kind parameter. + * @param kind of the name {@see NameKind} + * @param scope to search in {@see SearchScope} + * @return iterable of {@link Symbols} describing found symbols matching the specified criteria. + * It may return null when the caller is a CancellableTask<CompilationInfo> and is cancelled + * inside call of this method. + * @since 0.114 + */ + public @NullUnknown Iterable getDeclaredSymbols( + final @NonNull String name, + final @NonNull NameKind kind, + final @NonNull Set scope) { + Parameters.notNull("name", name); + Parameters.notNull("kind", kind); + final Map,Set> result = new HashMap,Set>(); + final Iterable queries = this.getQueries (scope); + final Convertor> thConvertor = DocumentUtil.elementHandleConvertor(); + try { + for (ClassIndexImpl query : queries) { + try { + query.getDeclaredElements( + name, + kind, + thConvertor, + result); + } catch (Index.IndexClosedException e) { + logClosedIndex (query); + } catch (IOException e) { + Exceptions.printStackTrace(e); + } + } + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log( + Level.FINE, + "ClassIndex.getDeclaredTypes returned {0} elements\n", //NOI18N + result.size()); + } + List finalResult = new ArrayList(); + for (Entry, Set> e : result.entrySet()) { + finalResult.add(new Symbols(e.getKey(), e.getValue())); + } + return Collections.unmodifiableList(finalResult); + } catch (InterruptedException e) { + return null; + } + } + + /**Description of found symbols (methods, constructors, fields) for one enclosing type. + * Returned from {@link #getDeclaredSymbols(java.lang.String, org.netbeans.api.java.source.ClassIndex.NameKind, java.util.Set) }. + * + * @since 0.114 + */ + public static final class Symbols { + private final ElementHandle enclosingType; + private final Set symbols; + + Symbols(ElementHandle enclosingType, Set symbols) { + this.enclosingType = enclosingType; + this.symbols = symbols; + } + + /**The type that contains some symbols matching the required criterie. + * + * @return enclosing type + */ + public ElementHandle getEnclosingType() { + return enclosingType; + } + + /**The simple names of all symbols matching the criteria inside the given enclosing type. + * + * @return simple names of matching symbols + */ + public Set getSymbols() { + return symbols; + } + + } + + /** * Returns names af all packages in given classpath starting with prefix. * @param prefix of the package name * @param directOnly if true treats the packages as folders and returns only diff -r 118122ec17fb java.source/test/unit/src/org/netbeans/api/java/source/ClassIndexTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/ClassIndexTest.java Mon Mar 18 10:31:55 2013 +0100 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/ClassIndexTest.java Mon Mar 18 12:36:32 2013 +0100 @@ -60,6 +60,8 @@ import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.api.java.source.ClassIndex.NameKind; +import org.netbeans.api.java.source.ClassIndex.Symbols; import org.netbeans.junit.MockServices; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.java.source.parsing.FileObjects; @@ -551,6 +553,37 @@ assertTrue(testListener.getAdded().isEmpty()); } + public void testFindSymbols() throws Exception { + final FileObject wd = FileUtil.toFileObject(getWorkDir()); + final FileObject root = FileUtil.createFolder(wd,"src"); //NOI18N + sourcePath = ClassPathSupport.createClassPath(root); + compilePath = ClassPathSupport.createClassPath(new URL[0]); + bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(); + final FileObject t1 = createJavaFile( + root, + "test", //NOI18N + "Test", //NOI18N + "package test;\n"+ //NOI18N + "public class Test { private void foo() { } }"); //NOI18N + final FileObject t2 = createJavaFile( + root, + "test", //NOI18N + "foo", //NOI18N + "package test;\n"+ //NOI18N + "public class foo {\n"+ //NOI18N + "}"); //NOI18N + IndexingManager.getDefault().refreshIndexAndWait(root.toURL(), null); + final ClassIndex ci = ClasspathInfo.create(bootPath, compilePath, sourcePath).getClassIndex(); + assertNotNull(ci); + Iterable result = ci.getDeclaredSymbols("foo", NameKind.SIMPLE_NAME, + EnumSet.of(ClassIndex.SearchScope.SOURCE)); + Set actualResult = new HashSet(); + for (Symbols s : result) { + actualResult.add(s.getEnclosingType().getQualifiedName() + ":" + s.getSymbols().toString()); + } + assertEquals(new HashSet(Arrays.asList("test.foo:[foo]", "test.Test:[foo]")), actualResult); + } + private FileObject createJavaFile ( final FileObject root, final String pkg,