use of org.sonar.plugins.java.api.tree.TypeCastTree in project sonar-java by SonarSource.
the class RedundantTypeCastCheck method requiredForMemberAccess.
private static boolean requiredForMemberAccess(TypeCastTree typeCastTree) {
ExpressionTree expression = typeCastTree.expression();
if (!expression.is(Tree.Kind.METHOD_INVOCATION)) {
Tree parent = typeCastTree.parent();
return expression.is(Tree.Kind.METHOD_REFERENCE) && parent != null && skipParentheses(parent).is(Tree.Kind.MEMBER_SELECT);
}
Symbol symbol = ((MethodInvocationTree) expression).symbol();
if (!symbol.isMethodSymbol()) {
return false;
}
Type returnType = ((Symbol.MethodSymbol) symbol).returnType().type();
if (!(returnType instanceof TypeVariableJavaType) || ((TypeVariableJavaType) returnType).bounds().get(0).is("java.lang.Object")) {
return false;
}
// as the member accessed could have also been part of initial type
return skipParentheses(typeCastTree.parent()).is(Tree.Kind.MEMBER_SELECT);
}
Aggregations