ReferencedClassesParser { public static String getPackageOfJavaFile(String source) { return getPackageOfJavaFile(parseSource(source)); } 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 packageNameIsReturned() { String source = joiner.join("package com.company;", "class Bla { }"); ReferencedClassesParser parser = parse(source); assertThat(parser.packageName).isEqualTo("com.company"); assertThat(ReferencedClassesParser.getPackageOfJavaFile(source)).isEqualTo("com.company"); }