ReferencedClassesParser { @VisibleForTesting static String extractClassNameFromQualifiedName(String s) { List<String> parts = Lists.newArrayList(Splitter.on(".").split(s)); for (int i = 0; i < parts.size(); i++) { String part = parts.get(i); if (isClassName.apply(part)) { return DOT_JOINER.join(parts.subList(0, i + 1)); } if (isLowerCase(part)) { continue; } return ""; } return ""; } ReferencedClassesParser(String filename, String source, Collection<Path> contentRoots); static CompilationUnit parseSource(String source); static String getPackageOfJavaFile(String source); final boolean isSuccessful; final Map<String, Metadata> symbols; final ImmutableSet<ImportDeclaration> importDeclarations; final String packageName; final List<String> compilationMessages; final String className; final String fullyQualifiedClassName; @Nullable final String superclass; final ImmutableSet<SimpleName> unresolvedClassNames; final ImmutableSet<QualifiedName> qualifiedTopLevelNames; final CompilationUnit compilationUnit; }
@Test public void testExtractClassNameFromQualifiedName() { assertThat( ReferencedClassesParser.extractClassNameFromQualifiedName( "ExternalClassA.ExternalAInnerClass")) .isEqualTo("ExternalClassA"); assertThat( ReferencedClassesParser.extractClassNameFromQualifiedName( "com.google.common.ExternalClassA.ExternalAInnerClass")) .isEqualTo("com.google.common.ExternalClassA"); assertThat(ReferencedClassesParser.extractClassNameFromQualifiedName("innerTemplate")) .isEqualTo(""); }