diff options
author | Alexander Rookey | 2016-11-23 19:10:56 +0000 |
---|---|---|
committer | Stefan Xenos | 2016-12-09 17:36:14 +0000 |
commit | 62aeca6f35795240a37cab22b3a1ef7ecd44ddb1 (patch) | |
tree | ac689f99d276735fb901ef2ecec02d736ede0aa8 /org.eclipse.jdt.core.tests.model | |
parent | cdc18ff13cd7bb1632f65f1b57154df75a60549c (diff) | |
download | eclipse.jdt.core-62aeca6f35795240a37cab22b3a1ef7ecd44ddb1.tar.gz eclipse.jdt.core-62aeca6f35795240a37cab22b3a1ef7ecd44ddb1.tar.xz eclipse.jdt.core-62aeca6f35795240a37cab22b3a1ef7ecd44ddb1.zip |
Prefix search types by simple name.I20161211-2000I20161210-2000
Change-Id: I6e21c04ab774078194c2eb1d83b6ecaccc250398
Signed-off-by: Alexander Rookey <atrookey@google.com>
Diffstat (limited to 'org.eclipse.jdt.core.tests.model')
-rw-r--r-- | org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/indexer/IndexerTest.java | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/indexer/IndexerTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/indexer/IndexerTest.java index f378a33bc7..4940d07cba 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/indexer/IndexerTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/nd/indexer/IndexerTest.java @@ -11,9 +11,12 @@ package org.eclipse.jdt.core.tests.nd.indexer; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.Semaphore; +import java.util.function.Function; +import java.util.stream.Collectors; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -78,7 +81,7 @@ public class IndexerTest extends AbstractJavaModelTests { */ public void testInterruptedException() throws Exception { createJavaProject(PROJECT_NAME, new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8", true); - // Create an index + // Create an indexfa IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); Indexer indexer = new Indexer(index.getNd(), root); indexer.rescan(SubMonitor.convert(null)); @@ -140,7 +143,7 @@ public class IndexerTest extends AbstractJavaModelTests { int type = child.getElementType(); if (type == IJavaElement.CLASS_FILE) { - result.add((IClassFile)child); + result.add((IClassFile) child); } else if (child instanceof IParent) { IParent parent = (IParent) child; @@ -211,4 +214,69 @@ public class IndexerTest extends AbstractJavaModelTests { } assertTrue("No classes found in the index", foundAtLeastOneClass); } + + public void testFindTypesBySimpleName() throws CoreException { + createJavaProject(PROJECT_NAME, new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8", true); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + Indexer indexer = new Indexer(index.getNd(), root); + + indexer.rescan(SubMonitor.convert(null)); + + try (IReader reader = IndexerTest.index.getNd().acquireReadLock()) { + List<Object> javaUtilList = IndexerTest.index.findTypesBySimpleName("ArrayList".toCharArray()).stream() + .map(new Function<NdTypeId, String>() { + @Override + public String apply(NdTypeId typeId) { + return typeId.toString(); + } + }).collect(Collectors.toList()); + System.out.println(javaUtilList); + assertTrue("Test failed", javaUtilList.contains("Ljava/util/ArrayList;")); + } + } + + public void testFindTypesBySimpleNameFirstWord() throws CoreException { + createJavaProject(PROJECT_NAME, new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8", true); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + Indexer indexer = new Indexer(index.getNd(), root); + + indexer.rescan(SubMonitor.convert(null)); + + try (IReader reader = IndexerTest.index.getNd().acquireReadLock()) { + List<Object> javaUtilList = IndexerTest.index.findTypesBySimpleName("Array".toCharArray()).stream() + .map(new Function<NdTypeId, String>() { + @Override + public String apply(NdTypeId typeId) { + return typeId.toString(); + } + }).collect(Collectors.toList()); + System.out.println(javaUtilList); + assertTrue("Test failed", + javaUtilList.containsAll(Arrays.asList("Ljava/sql/Array;", "Ljava/lang/reflect/Array;", + "Ljava/util/concurrent/ArrayBlockingQueue;", "Ljava/util/ArrayDeque;", + "Ljava/lang/ArrayIndexOutOfBoundsException;", "Ljava/util/ArrayList;", + "Ljava/util/ArrayPrefixHelpers;", "Ljava/util/Arrays;", + "Ljava/util/ArraysParallelSortHelpers;", "Ljava/lang/ArrayStoreException;"))); + } + } + + public void testFindTypesBySimpleNameFirstLetterCount10() throws CoreException { + createJavaProject(PROJECT_NAME, new String[] {"src"}, new String[] {"JCL18_FULL"}, "bin", "1.8", true); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + Indexer indexer = new Indexer(index.getNd(), root); + + indexer.rescan(SubMonitor.convert(null)); + + try (IReader reader = IndexerTest.index.getNd().acquireReadLock()) { + List<Object> javaUtilList = IndexerTest.index.findTypesBySimpleName("A".toCharArray(), 10).stream() + .map(new Function<NdTypeId, String>() { + @Override + public String apply(NdTypeId typeId) { + return typeId.toString(); + } + }).collect(Collectors.toList()); + System.out.println(javaUtilList); + assertTrue("Test failed", javaUtilList.size() == 10); + } + } } |