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