@Test void testClassCast() { MethodTree tree = buildSyntaxTree("public boolean equals(Object obj) {((String) obj).length();}"); BlockTree block = tree.block(); StatementTree statementTree = block.body().get(0); MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) statementTree).expression(); MemberSelectExpressionTree mse = (MemberSelectExpressionTree) mit.methodSelect(); assertThat(SyntaxTreeNameFinder.getName(mse)).isEqualTo("obj"); }
public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); }
SyntaxTreeNameFinder extends BaseTreeVisitor { public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); } }
SyntaxTreeNameFinder extends BaseTreeVisitor { public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); }  }
SyntaxTreeNameFinder extends BaseTreeVisitor { public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); }  static String getName(Tree syntaxNode); @Override void visitIdentifier(IdentifierTree tree); @Override void visitMemberSelectExpression(MemberSelectExpressionTree tree); @Override void visitSwitchStatement(SwitchStatementTree tree); @Override void visitParenthesized(ParenthesizedTree tree); @Override void visitTypeCast(TypeCastTree tree); @Override void visitMethodInvocation(MethodInvocationTree tree); @Override void visitVariable(VariableTree tree); }
SyntaxTreeNameFinder extends BaseTreeVisitor { public static String getName(Tree syntaxNode) { SyntaxTreeNameFinder finder = new SyntaxTreeNameFinder(); syntaxNode.accept(finder); return finder.getName(); }  static String getName(Tree syntaxNode); @Override void visitIdentifier(IdentifierTree tree); @Override void visitMemberSelectExpression(MemberSelectExpressionTree tree); @Override void visitSwitchStatement(SwitchStatementTree tree); @Override void visitParenthesized(ParenthesizedTree tree); @Override void visitTypeCast(TypeCastTree tree); @Override void visitMethodInvocation(MethodInvocationTree tree); @Override void visitVariable(VariableTree tree);  }