Federico Tomassetti | cf9d3fb | 2015-07-31 11:20:46 +0200 | [diff] [blame] | 1 | package me.tomassetti.symbolsolver.javaparser; |
| 2 | |
| 3 | import com.github.javaparser.ast.CompilationUnit; |
| 4 | import com.github.javaparser.ast.Node; |
| 5 | import com.github.javaparser.ast.body.BodyDeclaration; |
| 6 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; |
| 7 | import com.github.javaparser.ast.body.MethodDeclaration; |
| 8 | import com.github.javaparser.ast.body.TypeDeclaration; |
| 9 | import com.github.javaparser.ast.expr.NameExpr; |
| 10 | |
| 11 | import java.util.Optional; |
| 12 | |
| 13 | /** |
| 14 | * This class can be used to conveniently retrieve certain node from a JavaParser AST. |
| 15 | */ |
| 16 | public final class Navigator { |
| 17 | |
| 18 | private Navigator() { |
| 19 | // prevent instantiation |
| 20 | } |
| 21 | |
| 22 | public static Optional<TypeDeclaration> findType(CompilationUnit cu, String name) { |
| 23 | return cu.getTypes().stream().filter((t) -> t.getName().equals(name)).findFirst(); |
| 24 | } |
| 25 | |
| 26 | } |