use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class WrongParameterPackage method describe.
public Description describe(MethodTree tree, VisitorState state) {
SuggestedFix.Builder builder = null;
MethodSymbol method = ASTHelpers.getSymbol(tree);
if (supermethod == null) {
throw new IllegalStateException("Matching supermethod was not found");
}
for (int x = 0; x < method.params().size(); x++) {
Type methodParamType = method.params().get(x).type;
Type supermethodParamType = supermethod.params().get(x).type;
if (methodParamType.tsym.name.contentEquals(supermethodParamType.tsym.name) && !state.getTypes().isSameType(methodParamType, supermethodParamType)) {
VariableTree param = tree.getParameters().get(x);
// TODO(user): Name is most likely more qualified than necessary.
Name replacement = supermethodParamType.tsym.getQualifiedName();
if (builder == null) {
builder = SuggestedFix.builder();
}
builder.replace(param, replacement + " " + param.getName());
}
}
return (builder != null) ? describeMatch(tree, builder.build()) : describeMatch(tree);
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class FragmentInjection method matchClass.
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
// Only examine classes that extend PreferenceActivity.
Type preferenceActivityType = state.getTypeFromString("android.preference.PreferenceActivity");
if (!isSubtype(getType(tree), preferenceActivityType, state)) {
return NO_MATCH;
}
// Examine each method in the class. Complain if isValidFragment not implemented.
TypeSymbol preferenceActivityTypeSymbol = preferenceActivityType.tsym;
boolean methodNotImplemented = true;
try {
MethodSymbol isValidFragmentMethodSymbol = resolveExistingMethod(state, getSymbol(tree), state.getName("isValidFragment"), ImmutableList.<Type>of(state.getTypeFromString("java.lang.String")), ImmutableList.<Type>of());
methodNotImplemented = isValidFragmentMethodSymbol.owner.equals(preferenceActivityTypeSymbol);
} catch (FatalError e) {
// If isValidFragment method symbol is not found, then we must be compiling against an old SDK
// version (< 19) in which isValidFragment is not yet implemented, and neither this class nor
// any of its super classes have implemented it.
}
// isValidFragment, and this is not an abstract class, emit warning.
if (methodNotImplemented && not(hasModifier(Modifier.ABSTRACT)).matches(tree, state)) {
return buildDescription(tree).setMessage("Class extending PreferenceActivity does not implement isValidFragment.").build();
}
// Check the implementation of isValidFragment. Complain if it always returns true.
MethodTree isValidFragmentMethodTree = getMethod(OVERRIDES_IS_VALID_FRAGMENT, tree, state);
if (isValidFragmentMethodTree != null) {
if (isValidFragmentMethodTree.accept(ALWAYS_RETURNS_TRUE, null)) {
return buildDescription(isValidFragmentMethodTree).setMessage("isValidFragment unconditionally returns true.").build();
}
}
return NO_MATCH;
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class WaitNotInLoop method matchMethodInvocation.
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (!matcher.matches(tree, state)) {
return Description.NO_MATCH;
}
Description.Builder description = buildDescription(tree);
MethodSymbol sym = ASTHelpers.getSymbol(tree);
if (sym != null) {
description.setMessage(String.format(MESSAGE_TEMPLATE, sym));
}
// mechanically, so we provide detailed instructions in the wiki content.
if (!waitMethodWithTimeout.matches(tree, state)) {
JCIf enclosingIf = ASTHelpers.findEnclosingNode(state.getPath().getParentPath(), JCIf.class);
if (enclosingIf != null && enclosingIf.getElseStatement() == null) {
CharSequence ifSource = state.getSourceForNode(enclosingIf);
if (ifSource == null) {
// Source isn't available, so we can't construct a fix
return description.build();
}
String replacement = ifSource.toString().replaceFirst("if", "while");
return description.addFix(SuggestedFix.replace(enclosingIf, replacement)).build();
}
}
return description.build();
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class ChainingConstructorIgnoresParameter method matchMethod.
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
MethodSymbol symbol = getSymbol(tree);
if (!symbol.isConstructor()) {
return NO_MATCH;
}
paramTypesForMethod.put(symbol, unmodifiableList(tree.getParameters()));
return evaluateCallers(symbol);
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project error-prone by google.
the class CheckReturnValue method checkEnclosingClasses.
private static Optional<Boolean> checkEnclosingClasses(MethodSymbol method, VisitorState state) {
Symbol enclosingClass = enclosingClass(method);
while (enclosingClass instanceof ClassSymbol) {
Optional<Boolean> result = shouldCheckReturnValue(enclosingClass, state);
if (result.isPresent()) {
return result;
}
enclosingClass = enclosingClass.owner;
}
return Optional.absent();
}
Aggregations