@Test public void testExtractTypeNameWithoutGenerics() { AST ast = AST.newAST(AST.JLS4); org.eclipse.jdt.core.dom.SimpleName entry = ast.newSimpleName("Entry"); ParameterizedType map = ast.newParameterizedType(ast.newSimpleType(ast.newSimpleName("Map"))); map.typeArguments().add(ast.newSimpleType(ast.newSimpleName("Foo"))); QualifiedType type = ast.newQualifiedType(map, entry); assertThat(type.toString()).isEqualTo("Map<Foo>.Entry"); assertThat(ReferencedClassesParser.extractTypeNameWithoutGenerics(type)).isEqualTo("Map.Entry"); }
@VisibleForTesting static String extractTypeNameWithoutGenerics(QualifiedType type) { final StringBuilder sb = new StringBuilder(); type.accept( new ASTVisitor() { @Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { sb.append(node.getIdentifier()); sb.append("."); return true; } @Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } }); if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
ReferencedClassesParser { @VisibleForTesting static String extractTypeNameWithoutGenerics(QualifiedType type) { final StringBuilder sb = new StringBuilder(); type.accept( new ASTVisitor() { @Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { sb.append(node.getIdentifier()); sb.append("."); return true; } @Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } }); if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } }
ReferencedClassesParser { @VisibleForTesting static String extractTypeNameWithoutGenerics(QualifiedType type) { final StringBuilder sb = new StringBuilder(); type.accept( new ASTVisitor() { @Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { sb.append(node.getIdentifier()); sb.append("."); return true; } @Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } }); if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } ReferencedClassesParser(String filename, String source, Collection<Path> contentRoots); }
ReferencedClassesParser { @VisibleForTesting static String extractTypeNameWithoutGenerics(QualifiedType type) { final StringBuilder sb = new StringBuilder(); type.accept( new ASTVisitor() { @Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { sb.append(node.getIdentifier()); sb.append("."); return true; } @Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } }); if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } ReferencedClassesParser(String filename, String source, Collection<Path> contentRoots); static CompilationUnit parseSource(String source); static String getPackageOfJavaFile(String source); }
ReferencedClassesParser { @VisibleForTesting static String extractTypeNameWithoutGenerics(QualifiedType type) { final StringBuilder sb = new StringBuilder(); type.accept( new ASTVisitor() { @Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { sb.append(node.getIdentifier()); sb.append("."); return true; } @Override public boolean visit(ParameterizedType node) { node.getType().accept(this); return false; } }); if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } 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; }