-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run https://errorprone.info/docs/inlineme over ErrorProne.
Swap `clazz.getName()` calls to string literals to prevent potential version skew issues w/ annotations. PiperOrigin-RevId: 698845521
- Loading branch information
Showing
28 changed files
with
199 additions
and
127 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
check_api/src/main/java/com/google/errorprone/util/AnnotationNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2024 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.util; | ||
|
||
/** Fully qualified names of common annotations used in ErrorProne checks. */ | ||
public final class AnnotationNames { | ||
|
||
// keep-sorted start | ||
|
||
public static final String AFTER_TEMPLATE_ANNOTATION = | ||
"com.google.errorprone.refaster.annotation.AfterTemplate"; | ||
public static final String BEFORE_TEMPLATE_ANNOTATION = | ||
"com.google.errorprone.refaster.annotation.BeforeTemplate"; | ||
public static final String BUG_PATTERN_ANNOTATION = "com.google.errorprone.BugPattern"; | ||
public static final String CAN_IGNORE_RETURN_VALUE_ANNOTATION = | ||
"com.google.errorprone.annotations.CanIgnoreReturnValue"; | ||
public static final String COMPATIBLE_WITH_ANNOTATION = | ||
"com.google.errorprone.annotations.CompatibleWith"; | ||
public static final String DO_NOT_CALL_ANNOTATION = "com.google.errorprone.annotations.DoNotCall"; | ||
public static final String FORMAT_METHOD_ANNOTATION = | ||
"com.google.errorprone.annotations.FormatMethod"; | ||
public static final String FORMAT_STRING_ANNOTATION = | ||
"com.google.errorprone.annotations.FormatString"; | ||
public static final String IMMUTABLE_ANNOTATION = "com.google.errorprone.annotations.Immutable"; | ||
public static final String LAZY_INIT_ANNOTATION = | ||
"com.google.errorprone.annotations.concurrent.LazyInit"; | ||
public static final String MUST_BE_CLOSED_ANNOTATION = | ||
"com.google.errorprone.annotations.MustBeClosed"; | ||
public static final String REPEATED_ANNOTATION = | ||
"com.google.errorprone.refaster.annotation.Repeated"; | ||
public static final String RESTRICTED_API_ANNOTATION = | ||
"com.google.errorprone.annotations.RestrictedApi"; | ||
public static final String THREAD_SAFE_ANNOTATION = | ||
"com.google.errorprone.annotations.ThreadSafe"; | ||
public static final String VAR_ANNOTATION = "com.google.errorprone.annotations.Var"; | ||
|
||
// keep-sorted end | ||
|
||
private AnnotationNames() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,11 @@ | |
import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod; | ||
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod; | ||
import static com.google.errorprone.util.ASTHelpers.getReceiver; | ||
import static com.google.errorprone.util.ASTHelpers.hasAnnotation; | ||
import static com.google.errorprone.util.AnnotationNames.FORMAT_METHOD_ANNOTATION; | ||
|
||
import com.google.errorprone.BugPattern; | ||
import com.google.errorprone.VisitorState; | ||
import com.google.errorprone.annotations.FormatMethod; | ||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; | ||
import com.google.errorprone.matchers.Description; | ||
import com.google.errorprone.matchers.Matcher; | ||
|
@@ -43,7 +44,7 @@ | |
|
||
/** | ||
* Detects occurrences of pairs of parameters being passed straight through to {@link String#format} | ||
* from a method not annotated with {@link FormatMethod}. | ||
* from a method not annotated with {@link com.google.errorprone.annotations.FormatMethod}. | ||
* | ||
* @author [email protected] (Graeme Morgan) | ||
*/ | ||
|
@@ -90,7 +91,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState | |
MethodTree enclosingMethod = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class); | ||
if (enclosingMethod == null | ||
|| !ASTHelpers.getSymbol(enclosingMethod).isVarArgs() | ||
|| ASTHelpers.hasAnnotation(enclosingMethod, FormatMethod.class, state)) { | ||
|| hasAnnotation(enclosingMethod, FORMAT_METHOD_ANNOTATION, state)) { | ||
return Description.NO_MATCH; | ||
} | ||
List<? extends VariableTree> enclosingParameters = enclosingMethod.getParameters(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.