ClasspathCache { synchronized ImmutableList<String> getMatchingClassNames(String partialClassName, int limit) { updateCache(); PartialClassNameMatcher matcher = new PartialClassNameMatcher(partialClassName); Set<String> fullMatchingClassNames = Sets.newLinkedHashSet(); Set<String> matchingClassNames = Sets.newLinkedHashSet(); Iterator<String> i = classNameLocations.keySet().iterator(); if (instrumentation != null) { List<String> loadedClassNames = Lists.newArrayList(); for (Class<?> clazz : instrumentation.getAllLoadedClasses()) { if (!clazz.getName().startsWith("[")) { loadedClassNames.add(clazz.getName()); } } i = Iterators.concat(i, loadedClassNames.iterator()); } while (i.hasNext()) { String className = i.next(); String classNameUpper = className.toUpperCase(Locale.ENGLISH); boolean potentialFullMatch = matcher.isPotentialFullMatch(classNameUpper); if (matchingClassNames.size() == limit && !potentialFullMatch) { continue; } if (fullMatchingClassNames.size() == limit) { break; } if (matcher.isPotentialMatch(classNameUpper)) { if (potentialFullMatch) { fullMatchingClassNames.add(className); } else { matchingClassNames.add(className); } } } return combineClassNamesWithLimit(fullMatchingClassNames, matchingClassNames, limit); } ClasspathCache(AnalyzedWorld analyzedWorld, @Nullable Instrumentation instrumentation);   }
@Test public void shouldRead() { List<String> classNames = classpathCache.getMatchingClassNames("google.common.base.str", 5); assertThat(classNames).contains("com.google.common.base.Strings"); }
@Test public void shouldReadFullClass() { List<String> classNames = classpathCache.getMatchingClassNames("ImmutableMap", 5); assertThat(classNames).contains("com.google.common.collect.ImmutableMap"); }
@Test public void shouldReadFullFullClass() { List<String> classNames = classpathCache.getMatchingClassNames("com.google.common.collect.ImmutableMap", 5); assertThat(classNames).contains("com.google.common.collect.ImmutableMap"); }
@Test public void shouldReadFullInnerClass() { List<String> classNames = classpathCache.getMatchingClassNames("OnePlusArrayList", 5); assertThat(classNames).contains("com.google.common.collect.Lists$OnePlusArrayList"); }
@Test public void shouldReadFullFullInnerClass() { List<String> classNames = classpathCache .getMatchingClassNames("com.google.common.collect.Lists$OnePlusArrayList", 5); assertThat(classNames).contains("com.google.common.collect.Lists$OnePlusArrayList"); }
@Test public void shouldHitFullMatchLimit() { List<String> classNames = classpathCache.getMatchingClassNames("Builder", 5); assertThat(classNames).hasSize(5); for (String className : classNames) { if (!className.endsWith("$Builder") && !className.endsWith(".Builder")) { throw new AssertionError(); } } }