Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e6266aa
Test case for guardedbychecker bug.
Mar 15, 2019
3b45e8f
RELNOTES: Enable AnnotateFormatMethod by default, and add a strong wa…
graememorgan Mar 19, 2019
07f9c7f
Add fixes for incompatible/required modifiers checks
cushon Mar 20, 2019
c5f99f3
Delete DeprecatedThreadMethods in favour of general-purpose deprecati…
cushon Mar 20, 2019
55a9e0a
New error for reference equality on boxed primitives
cushon Mar 22, 2019
3269b66
Support renaming fields in renameVariable
cushon Mar 22, 2019
66cdb01
Add a defensive null-check
cushon Mar 27, 2019
13f2d76
Make IncompatibleModifiers an error
cushon Mar 28, 2019
885319a
Fix BadImport on ParameterizedType with TYPE_USE annotation
dx404 Mar 28, 2019
d055fdb
Add ModifySourceCollectionInStream check
dx404 Mar 30, 2019
eba27ed
Updated JavaTimeDefaultTimeZone to avoid NPE'ing when the function it
nick-someone Apr 2, 2019
95ebe6a
Add a check for local variables which are of boxed type but do not ne…
awturner Apr 3, 2019
8ef14ba
Provide suggestions for using Truth's Subject.check(...) in 3 cases:
cpovirk Apr 3, 2019
8aa3f18
Omit enclosing class names of constructors in diagnostics
cushon Apr 3, 2019
e66c65a
Add a refactoring to replace trivial lambdas with method references
cushon Apr 5, 2019
e1918bb
Clean up description creation
cushon Apr 5, 2019
b59a3fb
Use a prebuilt JDK 7 -> 8 API diff
cushon Apr 8, 2019
21a262c
New a check to simplify description creation
cushon Apr 8, 2019
427ccb4
Handle casts in SelfAssignment
cushon Apr 8, 2019
ac1b717
Don't complain about deprecated java.lang.Compiler API in JavaLangClash
cushon Apr 8, 2019
dd01c04
Clean up unnecessary lambdas
cushon Apr 8, 2019
45be640
Add a WARNING for using .valueOf(String) on lite proto buffer enums
sumitbhagwani Apr 9, 2019
69709fc
Return -> Returning
graememorgan Apr 9, 2019
b0218c1
Open-source @DoNotMock
Apr 9, 2019
8865ac4
Add Check for Leaking/Mutating an already-forked mutable instance (Bu…
dx404 Apr 10, 2019
c5d9072
Add EmptyBlockTag error-prone check
ash211 Apr 10, 2019
8be863d
Fix a crash in SelfAssignment
cushon Apr 10, 2019
94f0acc
Revert some unnecessary changes
cushon Apr 10, 2019
7fc1daf
Add java.time.temporal.ValueRange#checkValidValue as a method that
nick-someone Apr 11, 2019
ad16bb7
Recognize that it's safe to migrate from == to isEqualTo() for enums.
cpovirk Apr 11, 2019
bc9c078
In UnnecessaryLambda, don't refactor uses that call methods other tha…
cushon Apr 15, 2019
b717c49
Update Gradle plugin check example
tbroyer Apr 15, 2019
3f00c36
TypeParameterUnusedInFormals: Replace `.bound` by
don-vip Apr 15, 2019
6bbafbd
Fix for error-prone ImmutableEnumChecker warning
sumitbhagwani Apr 15, 2019
a902d79
Fix for error-prone AutoValueFinalMethods warning
sumitbhagwani Apr 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up description creation
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=242192393
  • Loading branch information
cushon authored and ronshapiro committed Apr 16, 2019
commit e1918bb39975db7d331ecb782e312026bd44d5be
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ protected Description describeMatch(Tree node, Fix fix) {
return buildDescription(node).addFix(fix).build();
}

/** Helper to create a Description for the common case where there is a fix. */
@CheckReturnValue
protected Description describeMatch(JCTree node, Fix fix) {
return describeMatch((Tree) node, fix);
}

/** Helper to create a Description for the common case where there is a fix. */
@CheckReturnValue
protected Description describeMatch(DiagnosticPosition position, Fix fix) {
return buildDescription(position).addFix(fix).build();
}

/** Helper to create a Description for the common case where there is no fix. */
@CheckReturnValue
protected Description describeMatch(Tree node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ private Description checkClosed(ExpressionTree tree, VisitorState state) {
}
// The caller method is not annotated, so the closing of the returned resource is not
// enforced. Suggest fixing this by annotating the caller method.
return buildDescription(tree)
.addFix(
SuggestedFix.builder()
.prefixWith(callerMethodTree, "@MustBeClosed\n")
.addImport(MustBeClosed.class.getCanonicalName())
.build())
.build();
return describeMatch(
tree,
SuggestedFix.builder()
.prefixWith(callerMethodTree, "@MustBeClosed\n")
.addImport(MustBeClosed.class.getCanonicalName())
.build());
}
break;
case CONDITIONAL_EXPRESSION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
boolean fixable =
formatParameter.get().equals(enclosingParameters.get(enclosingParameters.size() - 2));
if (fixable) {
return buildDescription(enclosingMethod)
.addFix(
SuggestedFix.builder()
.prefixWith(enclosingMethod, "@FormatMethod ")
.prefixWith(formatParameter.get(), "@FormatString ")
.addImport("com.google.errorprone.annotations.FormatMethod")
.addImport("com.google.errorprone.annotations.FormatString")
.build())
.build();
return describeMatch(
enclosingMethod,
SuggestedFix.builder()
.prefixWith(enclosingMethod, "@FormatMethod ")
.prefixWith(formatParameter.get(), "@FormatString ")
.addImport("com.google.errorprone.annotations.FormatMethod")
.addImport("com.google.errorprone.annotations.FormatString")
.build());
}
return buildDescription(enclosingMethod).setMessage(message() + REORDER).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ public Description matchTypeCast(TypeCastTree typeCastTree, VisitorState visitor
return Description.NO_MATCH;
}
if (castingMatcher.matches(typeCastTree, visitorState)) {
return buildDescription(typeCastTree)
.addFix(
SuggestedFix.replace(
castingMatcher.nodeToReplace,
visitorState.getSourceForNode(typeCastTree.getType())))
.build();
return describeMatch(
typeCastTree,
SuggestedFix.replace(
castingMatcher.nodeToReplace, visitorState.getSourceForNode(typeCastTree.getType())));
}
return Description.NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Description matchClass(ClassTree tree, VisitorState state) {
suggestedFix
.merge(fixClass(tree, state))
.postfixWith(getLast(members), String.format("\nprivate %s() {}", tree.getSimpleName()));
return buildDescription(tree).addFix(suggestedFix.build()).build();
return describeMatch(tree, suggestedFix.build());
}

private static SuggestedFix fixClass(ClassTree classTree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
private Description removeMathRoundCall(MethodInvocationTree tree, VisitorState state) {
if (ROUND_CALLS_WITH_INT_ARG.matches(tree, state)) {
if (ASTHelpers.requiresParentheses(Iterables.getOnlyElement(tree.getArguments()), state)) {
return buildDescription(tree)
.addFix(
SuggestedFix.builder()
.prefixWith(tree, "(")
.replace(tree, state.getSourceForNode(tree.getArguments().get(0)))
.postfixWith(tree, ")")
.build())
.build();
return describeMatch(
tree,
SuggestedFix.builder()
.prefixWith(tree, "(")
.replace(tree, state.getSourceForNode(tree.getArguments().get(0)))
.postfixWith(tree, ")")
.build());
}
return describeMatch(
tree, SuggestedFix.replace(tree, state.getSourceForNode(tree.getArguments().get(0))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public Description matchMethodInvocation(
return Description.NO_MATCH;
}
SuggestedFix fix = SuggestedFix.swap(expr, expectation);
return buildDescription(methodInvocationTree).addFix(fix).build();
return describeMatch(methodInvocationTree, fix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Description matchClass(ClassTree classTree, VisitorState state) {
if (batchFindings && !descriptions.isEmpty()) {
SuggestedFix.Builder fix = SuggestedFix.builder();
descriptions.forEach(d -> fix.merge((SuggestedFix) getOnlyElement(d.fixes)));
return buildDescription(descriptions.get(0).position).addFix(fix.build()).build();
return describeMatch(descriptions.get(0).position, fix.build());
}
descriptions.forEach(state::reportMatch);
return NO_MATCH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Description matchMethod(MethodTree methodTree, VisitorState state) {
replaceAssert(fix, foundAssert, state);
}

return buildDescription(methodTree).addFix(fix.build()).build();
return describeMatch(methodTree, fix.build());
}
return Description.NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public Description matchNewClass(NewClassTree tree, VisitorState state) {
return Description.NO_MATCH;
}

return buildDescription(invocationInfo.tree())
.addFix(changes.buildPermuteArgumentsFix(invocationInfo))
.build();
return describeMatch(invocationInfo.tree(), changes.buildPermuteArgumentsFix(invocationInfo));
}

private static Function<ParameterPair, Double> buildDistanceFunction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ private void handleMalformedTags(TextTree node) {
.replace(startOfCurly, startOfCurly + 1, " ")
.build();
state.reportMatch(
buildDescription(
getDiagnosticPosition(beforeAt, getCurrentPath().getTreePath().getLeaf()))
.addFix(fix)
.build());
describeMatch(
getDiagnosticPosition(beforeAt, getCurrentPath().getTreePath().getLeaf()), fix));
}
}

Expand Down Expand Up @@ -249,10 +247,8 @@ private void handleDanglingParams(TextTree node) {
SuggestedFix fix =
SuggestedFix.replace(startPos, endPos, String.format("{@code %s}", paramName));
state.reportMatch(
buildDescription(
getDiagnosticPosition(startPos, getCurrentPath().getTreePath().getLeaf()))
.addFix(fix)
.build());
describeMatch(
getDiagnosticPosition(startPos, getCurrentPath().getTreePath().getLeaf()), fix));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public Void visitThrows(ThrowsTree throwsTree, Void unused) {
if (type != null && isCheckedException(type)) {
if (methodTree.getThrows().stream().noneMatch(t -> isSubtype(type, getType(t), state))) {
state.reportMatch(
buildDescription(diagnosticPosition(getCurrentPath(), state))
.addFix(Utils.replace(throwsTree, "", state))
.build());
describeMatch(
diagnosticPosition(getCurrentPath(), state),
Utils.replace(throwsTree, "", state)));
}
}
return super.visitThrows(throwsTree, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ private VoidReturnTypeChecker(VisitorState state, MethodTree methodTree) {
public Void visitReturn(ReturnTree returnTree, Void unused) {
if (isSameType(getType(methodTree.getReturnType()), state.getSymtab().voidType, state)) {
state.reportMatch(
buildDescription(diagnosticPosition(getCurrentPath(), state))
.addFix(Utils.replace(returnTree, "", state))
.build());
describeMatch(
diagnosticPosition(getCurrentPath(), state), Utils.replace(returnTree, "", state)));
}
return super.visitReturn(returnTree, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ private Optional<Description> generateFix(String replacement) {
}

private Description replacementFix(String replacement) {
return buildDescription(diagnosticPosition(getCurrentPath(), state))
.addFix(replace(getCurrentPath().getLeaf(), replacement, state))
.build();
return describeMatch(
diagnosticPosition(getCurrentPath(), state),
replace(getCurrentPath().getLeaf(), replacement, state));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static class ImportArrayList extends BugChecker implements CompilationUni
@Override
public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) {
SuggestedFix fix = SuggestedFix.builder().addImport("java.util.ArrayList").build();
return buildDescription(tree).addFix(fix).build();
return describeMatch(tree, fix);
}
}
}