use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class AbstractToString method checkToString.
/**
* Tests if the given expression is converted to a String by its parent (i.e. its parent is a
* string concat expression, {@code String.format}, or {@code println(Object)}).
*/
private Description checkToString(ExpressionTree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
if (!(sym instanceof VarSymbol || sym instanceof MethodSymbol)) {
return NO_MATCH;
}
Type type = ASTHelpers.getType(tree);
if (type instanceof MethodType) {
type = type.getReturnType();
}
Tree parent = state.getPath().getParentPath().getLeaf();
ToStringKind toStringKind = isToString(parent, tree, state);
if (toStringKind == ToStringKind.NONE) {
return NO_MATCH;
}
Optional<Fix> fix;
switch(toStringKind) {
case IMPLICIT:
fix = implicitToStringFix(tree, state);
break;
case EXPLICIT:
fix = toStringFix(parent, tree, state);
break;
default:
throw new AssertionError(toStringKind);
}
if (!typePredicate().apply(type, state)) {
return NO_MATCH;
}
return maybeFix(tree, fix);
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class ASTHelpersFindSuperMethodsTest method findSuperMethod_findsNothingForAbstractMethod.
@Test
public void findSuperMethod_findsNothingForAbstractMethod() {
MethodSymbol fooOfFoo = scanner.getMethod("Foo", "foo");
assertThat(findSuperMethod(fooOfFoo)).isEqualTo(Optional.empty());
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class ASTHelpersFindSuperMethodsTest method findSuperMethod_findsNormalSuperMethodForNonDirectSuperclass.
@Test
public void findSuperMethod_findsNormalSuperMethodForNonDirectSuperclass() {
MethodSymbol fooOfBaz = scanner.getMethod("Baz", "foo");
MethodSymbol fooOfNorf = scanner.getMethod("Norf", "foo");
assertThat(findSuperMethod(fooOfNorf)).isEqualTo(Optional.of(fooOfBaz));
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class ASTHelpersFindSuperMethodsTest method findSuperMethod_findsAbstractSuperMethod.
@Test
public void findSuperMethod_findsAbstractSuperMethod() {
MethodSymbol fooOfFoo = scanner.getMethod("Foo", "foo");
MethodSymbol fooOfBar = scanner.getMethod("Bar", "foo");
assertThat(findSuperMethod(fooOfBar)).isEqualTo(Optional.of(fooOfFoo));
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class ASTHelpersFindSuperMethodsTest method findSuperMethod_findsNothingForNewNonAbstractMethod.
@Test
public void findSuperMethod_findsNothingForNewNonAbstractMethod() {
MethodSymbol barOfQuux = scanner.getMethod("Quux", "bar");
assertThat(findSuperMethod(barOfQuux)).isEqualTo(Optional.empty());
}
Aggregations