mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Compare commits
71 Commits
sschroever
...
ibabiankou
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db3cf7d0b8 | ||
|
|
50db75df52 | ||
|
|
8ca6982154 | ||
|
|
b8962fdba6 | ||
|
|
3fd83852fb | ||
|
|
0ed60fe726 | ||
|
|
6fc4c8c43c | ||
|
|
3921884481 | ||
|
|
10369e2624 | ||
|
|
708c8affcf | ||
|
|
0fa9541db6 | ||
|
|
5b261045d1 | ||
|
|
8be8730fd4 | ||
|
|
b12b2e8ebc | ||
|
|
13567d23e4 | ||
|
|
78cabb58c1 | ||
|
|
812787544a | ||
|
|
f35a1fba53 | ||
|
|
78035644dc | ||
|
|
ef67d41512 | ||
|
|
4cecff923a | ||
|
|
38a57db994 | ||
|
|
336557cf8e | ||
|
|
9055dfff19 | ||
|
|
3712a15195 | ||
|
|
9d487e4a88 | ||
|
|
b2b086761c | ||
|
|
ff64247b6d | ||
|
|
bc7443c72d | ||
|
|
abf4d68fba | ||
|
|
5c5f7d849e | ||
|
|
65c4694936 | ||
|
|
a45291c7d8 | ||
|
|
71012f31ab | ||
|
|
6e0905c033 | ||
|
|
af5ac85428 | ||
|
|
0329c25f78 | ||
|
|
9e67e2b795 | ||
|
|
4bafea05f4 | ||
|
|
8ce9cab2dd | ||
|
|
ae30625524 | ||
|
|
dc0046ebfc | ||
|
|
ad6d774818 | ||
|
|
405f5874ac | ||
|
|
bf5199ea3d | ||
|
|
c500516bb4 | ||
|
|
85d68a4f34 | ||
|
|
46467951dd | ||
|
|
6f7ce2067f | ||
|
|
f30ba36d18 | ||
|
|
65736ce83f | ||
|
|
17d5805d5a | ||
|
|
ce01b62832 | ||
|
|
4ee555c62b | ||
|
|
a24bbbe99d | ||
|
|
679e83bc48 | ||
|
|
0bdc171613 | ||
|
|
9b05ec62c6 | ||
|
|
72866183f5 | ||
|
|
9d7f569be5 | ||
|
|
f72adca292 | ||
|
|
5148143ae5 | ||
|
|
3d7fbbf7a2 | ||
|
|
8b6864d8a0 | ||
|
|
a03017b5e6 | ||
|
|
a227436f19 | ||
|
|
3f6558b7c0 | ||
|
|
ce06396521 | ||
|
|
268766a32a | ||
|
|
5366effd74 | ||
|
|
0a63361500 |
38
.github/workflows/build.yaml
vendored
Normal file
38
.github/workflows/build.yaml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
name: Build and verify
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'ibabiankou/experiments'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
matrix:
|
||||
jdk: [ 11.0.16, 17.0.4 ]
|
||||
steps:
|
||||
# We run the build twice for each supported JDK: once against the
|
||||
# original Error Prone release, using only Error Prone checks available
|
||||
# on Maven Central, and once against the Picnic Error Prone fork,
|
||||
# additionally enabling all checks defined in this project and any
|
||||
# Error Prone checks available only from other artifact repositories.
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v3.0.2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v3.4.1
|
||||
with:
|
||||
java-version: ${{ matrix.jdk }}
|
||||
distribution: temurin
|
||||
cache: maven
|
||||
- name: Display build environment details
|
||||
run: mvn --version
|
||||
- name: Build project against vanilla Error Prone
|
||||
run: mvn -T1C install
|
||||
- name: Build project with self-check against Error Prone fork
|
||||
run: mvn -T1C clean verify -Perror-prone-fork -Pnon-maven-central -Pself-check -s settings.xml
|
||||
- name: Remove project snapshots
|
||||
run: mvn build-helper:remove-project-artifact
|
||||
|
||||
# XXX: Enable Codecov once we "go public".
|
||||
# XXX: Enable SonarCloud once we "go public".
|
||||
1
.mvn/maven.config
Normal file
1
.mvn/maven.config
Normal file
@@ -0,0 +1 @@
|
||||
--batch-mode --errors --strict-checksums
|
||||
22
.renovaterc.json
Normal file
22
.renovaterc.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"packageRules": [
|
||||
{
|
||||
"matchPackagePatterns": [
|
||||
"^org\\.springframework:spring-framework-bom$",
|
||||
"^org\\.springframework\\.boot:spring-boot[a-z-]*$"
|
||||
],
|
||||
"separateMinorPatch": true
|
||||
},
|
||||
{
|
||||
"matchPackagePatterns": [
|
||||
"^com\\.palantir\\.baseline:baseline-error-prone$"
|
||||
],
|
||||
"schedule": "* * 1 * *"
|
||||
}
|
||||
],
|
||||
"reviewers": [
|
||||
"rickie",
|
||||
"Stephan202"
|
||||
]
|
||||
}
|
||||
38
.travis.yml
38
.travis.yml
@@ -1,38 +0,0 @@
|
||||
---
|
||||
dist: bionic
|
||||
language: java
|
||||
jdk: openjdk11
|
||||
addons:
|
||||
sonarcloud:
|
||||
organization: picnic-technologies
|
||||
token: "${SONARCLOUD_TOKEN}"
|
||||
install:
|
||||
- mvn io.takari:maven:wrapper
|
||||
script:
|
||||
# We run the build twice: once against the original Error Prone release,
|
||||
# using only Error Prone checks available on Maven Central, and once against
|
||||
# the Picnic Error Prone fork, additionally enabling all checks defined in
|
||||
# this project and any Error Prone checks available only from other artifact
|
||||
# repositories.
|
||||
- ./mvnw clean install
|
||||
- ./mvnw clean install -Perror-prone-fork -Pnon-maven-central -Pself-check -s settings.xml
|
||||
# XXX: Enable SonarCloud once we "go public".
|
||||
# ./mvnw jacoco:prepare-agent surefire:test jacoco:report sonar:sonar
|
||||
- ./mvnw jacoco:prepare-agent surefire:test jacoco:report
|
||||
before_cache:
|
||||
# Don't cache the artifacts we just generated, for multiple reasons: (1) we
|
||||
# shouldn't need them next time around and (2) if we do, that indicates a
|
||||
# dependency issue which might otherwise go unnoticed until next time we bump
|
||||
# the project's version (i.e., when tagging).
|
||||
- find "${HOME}/.m2/repository" -depth -name '*-SNAPSHOT' -exec rm -r '{}' \;
|
||||
cache:
|
||||
directories:
|
||||
# The local Maven repository in which third party dependencies are stored.
|
||||
- ${HOME}/.m2/repository
|
||||
# The Takari Maven Wrapper's storage for downloaded Maven distributions.
|
||||
- ${HOME}/.m2/wrapper
|
||||
# The SonarQube analysis cache.
|
||||
- ${HOME}/.sonar/cache
|
||||
# XXX: Enable Codecov once we "go public".
|
||||
#after_success:
|
||||
# - bash <(curl -s https://codecov.io/bash)
|
||||
25
apply-error-prone-suggestions.sh
Executable file
25
apply-error-prone-suggestions.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Compiles the code using Error Prone and applies its suggestions. The set of
|
||||
# checks applied can optionally be restricted by name.
|
||||
#
|
||||
# As this script may modify the project's code, it is important to execute it
|
||||
# in a clean Git working directory.
|
||||
|
||||
set -e -u -o pipefail
|
||||
|
||||
if [ "${#}" -gt 1 ]; then
|
||||
echo "Usage: ./$(basename "${0}") [PatchChecks]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
patchChecks=${1:-}
|
||||
|
||||
mvn clean test-compile fmt:format \
|
||||
-T 1.0C \
|
||||
-Perror-prone \
|
||||
-Perror-prone-fork \
|
||||
-Ppatch \
|
||||
-Pself-check \
|
||||
-Derror-prone.patch-checks="${patchChecks}" \
|
||||
-Dverification.skip
|
||||
@@ -76,6 +76,10 @@
|
||||
<artifactId>javac</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.googlejavaformat</groupId>
|
||||
<artifactId>google-java-format</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
@@ -126,6 +130,11 @@
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
@@ -171,6 +180,11 @@
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webflux</artifactId>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.errorprone.BugPattern.LinkType.NONE;
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION;
|
||||
import static com.google.errorprone.matchers.Matchers.allOf;
|
||||
import static com.google.errorprone.matchers.Matchers.argument;
|
||||
import static com.google.errorprone.matchers.Matchers.argumentCount;
|
||||
import static com.google.errorprone.matchers.Matchers.instanceMethod;
|
||||
import static com.google.errorprone.matchers.Matchers.nullLiteral;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.errorprone.BugPattern;
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.bugpatterns.BugChecker;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
|
||||
import com.google.errorprone.fixes.SuggestedFix;
|
||||
import com.google.errorprone.fixes.SuggestedFixes;
|
||||
import com.google.errorprone.matchers.Description;
|
||||
import com.google.errorprone.matchers.Matcher;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} which flags AssertJ {@code isEqualTo(null)} checks for simplification.
|
||||
*
|
||||
* <p>This bug checker cannot be replaced with a simple Refaster template, as the Refaster approach
|
||||
* would require that all overloads of {@link org.assertj.core.api.Assert#isEqualTo(Object)} (such
|
||||
* as {@link org.assertj.core.api.AbstractStringAssert#isEqualTo(String)}) are explicitly
|
||||
* enumerated. This bug checker generically matches all such current and future overloads.
|
||||
*/
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
name = "AssertJIsNull",
|
||||
summary = "Prefer `.isNull()` over `.isEqualTo(null)`",
|
||||
linkType = NONE,
|
||||
severity = SUGGESTION,
|
||||
tags = SIMPLIFICATION)
|
||||
public final class AssertJIsNullCheck extends BugChecker implements MethodInvocationTreeMatcher {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Matcher<MethodInvocationTree> ASSERT_IS_EQUAL_TO_NULL =
|
||||
allOf(
|
||||
instanceMethod().onDescendantOf("org.assertj.core.api.Assert").named("isEqualTo"),
|
||||
argumentCount(1),
|
||||
argument(0, nullLiteral()));
|
||||
|
||||
@Override
|
||||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
|
||||
if (!ASSERT_IS_EQUAL_TO_NULL.matches(tree, state)) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
SuggestedFix.Builder fix =
|
||||
SuggestedFix.builder().merge(SuggestedFixes.renameMethodInvocation(tree, "isNull", state));
|
||||
tree.getArguments().forEach(arg -> fix.merge(SuggestedFix.delete(arg)));
|
||||
|
||||
return describeMatch(tree, fix.build());
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import static com.google.errorprone.matchers.Matchers.annotations;
|
||||
import static com.google.errorprone.matchers.Matchers.isType;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.errorprone.BugPattern;
|
||||
import com.google.errorprone.VisitorState;
|
||||
@@ -43,7 +44,7 @@ public final class AutowiredConstructorCheck extends BugChecker implements Class
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
List<AnnotationTree> annotations =
|
||||
ImmutableList<AnnotationTree> annotations =
|
||||
AUTOWIRED_ANNOTATION
|
||||
.multiMatchResult(Iterables.getOnlyElement(constructors), state)
|
||||
.matchingNodes();
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.errorprone.BugPattern.LinkType.NONE;
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE;
|
||||
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.errorprone.BugPattern;
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.bugpatterns.BugChecker;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
|
||||
import com.google.errorprone.fixes.SuggestedFix;
|
||||
import com.google.errorprone.fixes.SuggestedFixes;
|
||||
import com.google.errorprone.matchers.Description;
|
||||
import com.google.errorprone.matchers.Matcher;
|
||||
import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} which flags {@link Collector Collectors} that don't clearly express
|
||||
* (im)mutability.
|
||||
*
|
||||
* <p>Replacing such collectors with alternatives that produce immutable collections is preferred.
|
||||
* Do note that Guava's immutable collections are null-hostile.
|
||||
*/
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
name = "CollectorMutability",
|
||||
summary =
|
||||
"Avoid `Collectors.to{List,Map,Set}` in favour of alternatives that emphasize (im)mutability",
|
||||
linkType = NONE,
|
||||
severity = WARNING,
|
||||
tags = FRAGILE_CODE)
|
||||
public final class CollectorMutabilityCheck extends BugChecker
|
||||
implements MethodInvocationTreeMatcher {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Matcher<ExpressionTree> COLLECTOR_METHOD =
|
||||
staticMethod().onClass("java.util.stream.Collectors");
|
||||
private static final Matcher<ExpressionTree> LIST_COLLECTOR =
|
||||
staticMethod().anyClass().named("toList");
|
||||
private static final Matcher<ExpressionTree> MAP_COLLECTOR =
|
||||
staticMethod().anyClass().named("toMap");
|
||||
private static final Matcher<ExpressionTree> SET_COLLECTOR =
|
||||
staticMethod().anyClass().named("toSet");
|
||||
|
||||
@Override
|
||||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
|
||||
if (!COLLECTOR_METHOD.matches(tree, state)) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
if (LIST_COLLECTOR.matches(tree, state)) {
|
||||
return suggestToCollectionAlternatives(
|
||||
tree, "com.google.common.collect.ImmutableList.toImmutableList", "ArrayList", state);
|
||||
}
|
||||
|
||||
if (MAP_COLLECTOR.matches(tree, state)) {
|
||||
return suggestToMapAlternatives(tree, state);
|
||||
}
|
||||
|
||||
if (SET_COLLECTOR.matches(tree, state)) {
|
||||
return suggestToCollectionAlternatives(
|
||||
tree, "com.google.common.collect.ImmutableSet.toImmutableSet", "HashSet", state);
|
||||
}
|
||||
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
private Description suggestToCollectionAlternatives(
|
||||
MethodInvocationTree tree,
|
||||
String fullyQualifiedImmutableReplacement,
|
||||
String mutableReplacement,
|
||||
VisitorState state) {
|
||||
SuggestedFix.Builder mutableFix = SuggestedFix.builder();
|
||||
String toCollectionSelect =
|
||||
SuggestedFixes.qualifyStaticImport(
|
||||
"java.util.stream.Collectors.toCollection", mutableFix, state);
|
||||
|
||||
return buildDescription(tree)
|
||||
.addFix(replaceMethodInvocation(tree, fullyQualifiedImmutableReplacement, state))
|
||||
.addFix(
|
||||
mutableFix
|
||||
.addImport(String.format("java.util.%s", mutableReplacement))
|
||||
.replace(tree, String.format("%s(%s::new)", toCollectionSelect, mutableReplacement))
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private Description suggestToMapAlternatives(MethodInvocationTree tree, VisitorState state) {
|
||||
int argCount = tree.getArguments().size();
|
||||
if (argCount > 3) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
return buildDescription(tree)
|
||||
.addFix(
|
||||
replaceMethodInvocation(
|
||||
tree, "com.google.common.collect.ImmutableMap.toImmutableMap", state))
|
||||
.addFix(
|
||||
SuggestedFix.builder()
|
||||
.addImport("java.util.HashMap")
|
||||
.postfixWith(
|
||||
tree.getArguments().get(argCount - 1),
|
||||
(argCount == 2 ? ", (a, b) -> { throw new IllegalStateException(); }" : "")
|
||||
+ ", HashMap::new")
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static SuggestedFix replaceMethodInvocation(
|
||||
MethodInvocationTree tree, String fullyQualifiedReplacement, VisitorState state) {
|
||||
SuggestedFix.Builder fix = SuggestedFix.builder();
|
||||
String replacement = SuggestedFixes.qualifyStaticImport(fullyQualifiedReplacement, fix, state);
|
||||
fix.merge(SuggestedFix.replace(tree.getMethodSelect(), replacement));
|
||||
return fix.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.errorprone.BugPattern.LinkType.NONE;
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.STYLE;
|
||||
import static com.google.errorprone.matchers.Matchers.anyOf;
|
||||
import static com.google.errorprone.matchers.Matchers.instanceMethod;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.errorprone.BugPattern;
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.bugpatterns.BugChecker;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
|
||||
import com.google.errorprone.fixes.SuggestedFix;
|
||||
import com.google.errorprone.matchers.Description;
|
||||
import com.google.errorprone.matchers.Matcher;
|
||||
import com.google.errorprone.util.ASTHelpers;
|
||||
import com.google.googlejavaformat.java.Formatter;
|
||||
import com.google.googlejavaformat.java.FormatterException;
|
||||
import com.google.googlejavaformat.java.ImportOrderer;
|
||||
import com.google.googlejavaformat.java.JavaFormatterOptions.Style;
|
||||
import com.google.googlejavaformat.java.RemoveUnusedImports;
|
||||
import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} which flags improperly formatted Error Prone test code.
|
||||
*
|
||||
* <p>All test code should be formatted in accordance with Google Java Format's {@link Formatter}
|
||||
* output, and imports should be ordered according to the {@link Style#GOOGLE Google} style.
|
||||
*
|
||||
* <p>This checker inspects inline code passed to {@code
|
||||
* com.google.errorprone.CompilationTestHelper} and {@code
|
||||
* com.google.errorprone.BugCheckerRefactoringTestHelper}. It requires that this code is properly
|
||||
* formatted and that its imports are organized. Only code that represents the expected output of a
|
||||
* refactoring operation is allowed to have unused imports, as most {@link BugChecker}s do not (and
|
||||
* are not able to) remove imports that become obsolete as a result of applying their suggested
|
||||
* fix(es).
|
||||
*/
|
||||
// XXX: Once we target JDK 17 (optionally?) suggest text block fixes.
|
||||
// XXX: GJF guesses the line separator to be used by inspecting the source. When using text blocks
|
||||
// this may cause the current unconditional use of `\n` not to be sufficient when building on
|
||||
// Windows; TBD.
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
name = "ErrorProneTestHelperSourceFormat",
|
||||
summary = "Test code should follow the Google Java style",
|
||||
linkType = NONE,
|
||||
severity = SUGGESTION,
|
||||
tags = STYLE)
|
||||
public final class ErrorProneTestHelperSourceFormatCheck extends BugChecker
|
||||
implements MethodInvocationTreeMatcher {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Formatter FORMATTER = new Formatter();
|
||||
private static final Matcher<ExpressionTree> INPUT_SOURCE_ACCEPTING_METHOD =
|
||||
anyOf(
|
||||
instanceMethod()
|
||||
.onDescendantOf("com.google.errorprone.CompilationTestHelper")
|
||||
.named("addSourceLines"),
|
||||
instanceMethod()
|
||||
.onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper")
|
||||
.named("addInputLines"));
|
||||
private static final Matcher<ExpressionTree> OUTPUT_SOURCE_ACCEPTING_METHOD =
|
||||
instanceMethod()
|
||||
.onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput")
|
||||
.named("addOutputLines");
|
||||
|
||||
@Override
|
||||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
|
||||
boolean isOutputSource = OUTPUT_SOURCE_ACCEPTING_METHOD.matches(tree, state);
|
||||
if (!isOutputSource && !INPUT_SOURCE_ACCEPTING_METHOD.matches(tree, state)) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
List<? extends ExpressionTree> sourceLines =
|
||||
tree.getArguments().subList(1, tree.getArguments().size());
|
||||
if (sourceLines.isEmpty()) {
|
||||
return buildDescription(tree).setMessage("No source code provided").build();
|
||||
}
|
||||
|
||||
int startPos = ASTHelpers.getStartPosition(sourceLines.get(0));
|
||||
int endPos = state.getEndPosition(sourceLines.get(sourceLines.size() - 1));
|
||||
|
||||
/* Attempt to format the source code only if it fully consists of constant expressions. */
|
||||
return getConstantSourceCode(sourceLines)
|
||||
.map(source -> flagFormattingIssues(startPos, endPos, source, isOutputSource, state))
|
||||
.orElse(Description.NO_MATCH);
|
||||
}
|
||||
|
||||
private Description flagFormattingIssues(
|
||||
int startPos, int endPos, String source, boolean retainUnusedImports, VisitorState state) {
|
||||
Tree methodInvocation = state.getPath().getLeaf();
|
||||
|
||||
String formatted;
|
||||
try {
|
||||
formatted = formatSourceCode(source, retainUnusedImports).trim();
|
||||
} catch (FormatterException e) {
|
||||
return buildDescription(methodInvocation)
|
||||
.setMessage(String.format("Source code is malformed: %s", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
|
||||
if (source.trim().equals(formatted)) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
if (startPos == Position.NOPOS || endPos == Position.NOPOS) {
|
||||
/*
|
||||
* We have insufficient source information to emit a fix, so we only flag the fact that the
|
||||
* code isn't properly formatted.
|
||||
*/
|
||||
return describeMatch(methodInvocation);
|
||||
}
|
||||
|
||||
/*
|
||||
* The code isn't properly formatted; replace all lines with the properly formatted
|
||||
* alternatives.
|
||||
*/
|
||||
return describeMatch(
|
||||
methodInvocation,
|
||||
SuggestedFix.replace(
|
||||
startPos,
|
||||
endPos,
|
||||
Splitter.on('\n')
|
||||
.splitToStream(formatted)
|
||||
.map(state::getConstantExpression)
|
||||
.collect(joining(", "))));
|
||||
}
|
||||
|
||||
private static String formatSourceCode(String source, boolean retainUnusedImports)
|
||||
throws FormatterException {
|
||||
String withReorderedImports = ImportOrderer.reorderImports(source, Style.GOOGLE);
|
||||
String withOptionallyRemovedImports =
|
||||
retainUnusedImports
|
||||
? withReorderedImports
|
||||
: RemoveUnusedImports.removeUnusedImports(withReorderedImports);
|
||||
return FORMATTER.formatSource(withOptionallyRemovedImports);
|
||||
}
|
||||
|
||||
private static Optional<String> getConstantSourceCode(
|
||||
List<? extends ExpressionTree> sourceLines) {
|
||||
StringBuilder source = new StringBuilder();
|
||||
|
||||
for (ExpressionTree sourceLine : sourceLines) {
|
||||
Object value = ASTHelpers.constValue(sourceLine);
|
||||
if (value == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
source.append(value).append('\n');
|
||||
}
|
||||
|
||||
return Optional.of(source.toString());
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import com.sun.source.util.SimpleTreeVisitor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} which flags string concatenations that produce a format string; in such
|
||||
@@ -210,6 +211,7 @@ public final class FormatStringConcatenationCheck extends BugChecker
|
||||
this.formatSpecifier = formatSpecifier;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitBinary(BinaryTree tree, VisitorState state) {
|
||||
if (tree.getKind() == Kind.PLUS && isStringTyped(tree, state)) {
|
||||
@@ -222,11 +224,13 @@ public final class FormatStringConcatenationCheck extends BugChecker
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitParenthesized(ParenthesizedTree tree, VisitorState state) {
|
||||
return tree.getExpression().accept(this, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Void defaultAction(Tree tree, VisitorState state) {
|
||||
appendExpression(tree);
|
||||
|
||||
@@ -40,7 +40,7 @@ import javax.lang.model.element.Name;
|
||||
/** A {@link BugChecker} which flags non-canonical JUnit method declarations. */
|
||||
// XXX: Consider introducing a class-level check which enforces that test classes:
|
||||
// 1. Are named `*Test` or `Abstract*TestCase`.
|
||||
// 2. If not `abstract`, don't have public methods and subclasses.
|
||||
// 2. If not `abstract`, are package-private and don't have public methods and subclasses.
|
||||
// 3. Only have private fields.
|
||||
// XXX: If implemented, the current logic could flag only `private` JUnit methods.
|
||||
@AutoService(BugChecker.class)
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} which flags annotation array listings which aren't sorted lexicographically.
|
||||
@@ -171,18 +172,21 @@ public final class LexicographicalAnnotationAttributeListingCheck extends BugChe
|
||||
ImmutableList.Builder<ImmutableList<String>> nodes = ImmutableList.builder();
|
||||
|
||||
new TreeScanner<Void, Void>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitIdentifier(IdentifierTree node, Void ctx) {
|
||||
nodes.add(tokenize(node));
|
||||
return super.visitIdentifier(node, ctx);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitLiteral(LiteralTree node, Void ctx) {
|
||||
nodes.add(tokenize(node));
|
||||
return super.visitLiteral(node, ctx);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitPrimitiveType(PrimitiveTypeTree node, Void ctx) {
|
||||
nodes.add(tokenize(node));
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class LexicographicalAnnotationListingCheck extends BugChecker
|
||||
|
||||
Optional<Fix> fix = tryFixOrdering(originalOrdering, sortedAnnotations, state);
|
||||
|
||||
Description.Builder description = buildDescription(tree);
|
||||
Description.Builder description = buildDescription(originalOrdering.get(0));
|
||||
fix.ifPresent(description::addFix);
|
||||
return description.build();
|
||||
}
|
||||
|
||||
@@ -166,11 +166,12 @@ public final class RefasterCheck extends BugChecker implements CompilationUnitTr
|
||||
flags
|
||||
.get(INCLUDED_TEMPLATES_PATTERN_FLAG)
|
||||
.map(Pattern::compile)
|
||||
.map(nameFilter -> filterCodeTransformers(allTransformers, nameFilter))
|
||||
.<ImmutableCollection<CodeTransformer>>map(
|
||||
nameFilter -> filterCodeTransformers(allTransformers, nameFilter))
|
||||
.orElseGet(allTransformers::values));
|
||||
}
|
||||
|
||||
private static ImmutableCollection<CodeTransformer> filterCodeTransformers(
|
||||
private static ImmutableList<CodeTransformer> filterCodeTransformers(
|
||||
ImmutableListMultimap<String, CodeTransformer> transformers, Pattern nameFilter) {
|
||||
return transformers.entries().stream()
|
||||
.filter(e -> nameFilter.matcher(e.getKey()).matches())
|
||||
@@ -195,7 +196,7 @@ public final class RefasterCheck extends BugChecker implements CompilationUnitTr
|
||||
|
||||
private static ImmutableSet<ResourceInfo> getClassPathResources() {
|
||||
try {
|
||||
return ClassPath.from(ClassLoader.getSystemClassLoader()).getResources();
|
||||
return ClassPath.from(RefasterCheck.class.getClassLoader()).getResources();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to scan classpath for resources", e);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class ScheduledTransactionTraceCheck extends BugChecker implements
|
||||
return describeMatch(
|
||||
traceAnnotation,
|
||||
SuggestedFixes.updateAnnotationArgumentValues(
|
||||
traceAnnotation, "dispatcher", ImmutableList.of("true"))
|
||||
traceAnnotation, state, "dispatcher", ImmutableList.of("true"))
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class TimeZoneUsageCheck extends BugChecker implements MethodInvoca
|
||||
LocalDateTime.class.getName(),
|
||||
LocalTime.class.getName())
|
||||
.named("now"),
|
||||
staticMethod().onClassAny(Instant.class.getName()).named("now").withParameters());
|
||||
staticMethod().onClassAny(Instant.class.getName()).named("now").withNoParameters());
|
||||
|
||||
@Override
|
||||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
|
||||
|
||||
@@ -268,9 +268,9 @@ final class AssertJThrowingCallableTemplates {
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIOExceptionHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByIOException" /* Matches strictly more specific expressions. */)
|
||||
@BeforeTemplate
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatIOException().isThrownBy(throwingCallable).withMessage(message);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ final class ImmutableListMultimapTemplates {
|
||||
*/
|
||||
static final class EntryToImmutableListMultimap<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMultimap<K, V> before(Map.Entry<? extends K, ? extends V> entry) {
|
||||
ImmutableListMultimap<K, V> before(Map.Entry<? extends K, ? extends V> entry) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableListMultimap.<K, V>builder().put(entry).build(),
|
||||
Stream.of(entry)
|
||||
|
||||
@@ -6,8 +6,6 @@ import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -78,17 +76,11 @@ final class ImmutableListTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link ImmutableList#toImmutableList()} over the more verbose alternative. */
|
||||
// XXX: Once the code base has been sufficiently cleaned up, we might want to also rewrite
|
||||
// `Collectors.toList(`), with the caveat that it allows mutation (though this cannot be relied
|
||||
// upon) as well as nulls. Another option is to explicitly rewrite those variants to
|
||||
// `Collectors.toSet(ArrayList::new)`.
|
||||
/** Prefer {@link ImmutableList#toImmutableList()} over less idiomatic alternatives. */
|
||||
static final class StreamToImmutableList<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableList<T> before(Stream<T> stream) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableList.copyOf(stream.iterator()),
|
||||
stream.collect(collectingAndThen(toList(), ImmutableList::copyOf)));
|
||||
return ImmutableList.copyOf(stream.iterator());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset;
|
||||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
import com.google.common.collect.Streams;
|
||||
@@ -90,9 +88,7 @@ final class ImmutableMultisetTemplates {
|
||||
static final class StreamToImmutableMultiset<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableMultiset<T> before(Stream<T> stream) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableMultiset.copyOf(stream.iterator()),
|
||||
stream.collect(collectingAndThen(toList(), ImmutableMultiset::copyOf)));
|
||||
return ImmutableMultiset.copyOf(stream.iterator());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
|
||||
@@ -4,9 +4,6 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.singleton;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets.SetView;
|
||||
@@ -75,18 +72,11 @@ final class ImmutableSetTemplates {
|
||||
}
|
||||
|
||||
/** Prefer {@link ImmutableSet#toImmutableSet()} over less idiomatic alternatives. */
|
||||
// XXX: Once the code base has been sufficiently cleaned up, we might want to also rewrite
|
||||
// `Collectors.toSet(`), with the caveat that it allows mutation (though this cannot be relied
|
||||
// upon) as well as nulls. Another option is to explicitly rewrite those variants to
|
||||
// `Collectors.toSet(HashSet::new)`.
|
||||
static final class StreamToImmutableSet<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableSet<T> before(Stream<T> stream) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSet.copyOf(stream.iterator()),
|
||||
stream.distinct().collect(toImmutableSet()),
|
||||
stream.collect(collectingAndThen(toList(), ImmutableSet::copyOf)),
|
||||
stream.collect(collectingAndThen(toSet(), ImmutableSet::copyOf)));
|
||||
ImmutableSet.copyOf(stream.iterator()), stream.distinct().collect(toImmutableSet()));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
|
||||
@@ -3,10 +3,7 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset;
|
||||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
import com.google.common.collect.ImmutableSortedMultiset;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
@@ -93,14 +90,14 @@ final class ImmutableSortedMultisetTemplates {
|
||||
// `reverseOrder`.) Worth the hassle?
|
||||
static final class IterableToImmutableSortedMultiset<T extends Comparable<? super T>> {
|
||||
@BeforeTemplate
|
||||
ImmutableMultiset<T> before(T[] iterable) {
|
||||
ImmutableSortedMultiset<T> before(T[] iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMultiset.<T>naturalOrder().add(iterable).build(),
|
||||
Arrays.stream(iterable).collect(toImmutableSortedMultiset(naturalOrder())));
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
ImmutableMultiset<T> before(Iterator<T> iterable) {
|
||||
ImmutableSortedMultiset<T> before(Iterator<T> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMultiset.copyOf(naturalOrder(), iterable),
|
||||
ImmutableSortedMultiset.<T>naturalOrder().addAll(iterable).build(),
|
||||
@@ -108,7 +105,7 @@ final class ImmutableSortedMultisetTemplates {
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
ImmutableMultiset<T> before(Iterable<T> iterable) {
|
||||
ImmutableSortedMultiset<T> before(Iterable<T> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMultiset.copyOf(naturalOrder(), iterable),
|
||||
ImmutableSortedMultiset.<T>naturalOrder().addAll(iterable).build(),
|
||||
@@ -134,9 +131,7 @@ final class ImmutableSortedMultisetTemplates {
|
||||
static final class StreamToImmutableSortedMultiset<T extends Comparable<? super T>> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMultiset<T> before(Stream<T> stream) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedMultiset.copyOf(stream.iterator()),
|
||||
stream.collect(collectingAndThen(toList(), ImmutableSortedMultiset::copyOf)));
|
||||
return ImmutableSortedMultiset.copyOf(stream.iterator());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
|
||||
@@ -3,10 +3,7 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
||||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
@@ -91,14 +88,14 @@ final class ImmutableSortedSetTemplates {
|
||||
// `reverseOrder`.) Worth the hassle?
|
||||
static final class IterableToImmutableSortedSet<T extends Comparable<? super T>> {
|
||||
@BeforeTemplate
|
||||
ImmutableSet<T> before(T[] iterable) {
|
||||
ImmutableSortedSet<T> before(T[] iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedSet.<T>naturalOrder().add(iterable).build(),
|
||||
Arrays.stream(iterable).collect(toImmutableSortedSet(naturalOrder())));
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
ImmutableSet<T> before(Iterator<T> iterable) {
|
||||
ImmutableSortedSet<T> before(Iterator<T> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedSet.copyOf(naturalOrder(), iterable),
|
||||
ImmutableSortedSet.<T>naturalOrder().addAll(iterable).build(),
|
||||
@@ -106,7 +103,7 @@ final class ImmutableSortedSetTemplates {
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
ImmutableSet<T> before(Iterable<T> iterable) {
|
||||
ImmutableSortedSet<T> before(Iterable<T> iterable) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedSet.copyOf(naturalOrder(), iterable),
|
||||
ImmutableSortedSet.<T>naturalOrder().addAll(iterable).build(),
|
||||
@@ -134,9 +131,7 @@ final class ImmutableSortedSetTemplates {
|
||||
static final class StreamToImmutableSortedSet<T extends Comparable<? super T>> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedSet<T> before(Stream<T> stream) {
|
||||
return Refaster.anyOf(
|
||||
ImmutableSortedSet.copyOf(stream.iterator()),
|
||||
stream.collect(collectingAndThen(toList(), ImmutableSortedSet::copyOf)));
|
||||
return ImmutableSortedSet.copyOf(stream.iterator());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
|
||||
@@ -166,6 +166,11 @@ final class OptionalTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link Optional#map} over a {@link Optional#flatMap} which wraps the result of a
|
||||
* transformation in an {@link Optional}; the former operation transforms {@code null} to {@link
|
||||
* Optional#empty()}.
|
||||
*/
|
||||
abstract static class MapToNullable<T, S> {
|
||||
@Placeholder
|
||||
abstract S toNullableFunction(@MayOptionallyUse T element);
|
||||
|
||||
@@ -157,8 +157,8 @@ final class ReactorTemplates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link Flux#concatMapIterable(Function)} over {@link Flux#concatMapIterable(Function)},
|
||||
* as the former has equivalent semantics but a clearer name.
|
||||
* Prefer {@link Flux#concatMapIterable(Function)} over {@link Flux#flatMapIterable(Function)}, as
|
||||
* the former has equivalent semantics but a clearer name.
|
||||
*/
|
||||
static final class FluxConcatMapIterable<T, S> {
|
||||
@BeforeTemplate
|
||||
@@ -224,6 +224,32 @@ final class ReactorTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link Mono#cast(Class)} over {@link Mono#map(Function)} with a cast. */
|
||||
static final class MonoCast<T, S> {
|
||||
@BeforeTemplate
|
||||
Mono<S> before(Mono<T> mono) {
|
||||
return mono.map(Refaster.<S>clazz()::cast);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Mono<S> after(Mono<T> mono) {
|
||||
return mono.cast(Refaster.<S>clazz());
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link Flux#cast(Class)} over {@link Flux#map(Function)} with a cast. */
|
||||
static final class FluxCast<T, S> {
|
||||
@BeforeTemplate
|
||||
Flux<S> before(Flux<T> flux) {
|
||||
return flux.map(Refaster.<S>clazz()::cast);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Flux<S> after(Flux<T> flux) {
|
||||
return flux.cast(Refaster.<S>clazz());
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */
|
||||
static final class PublisherProbeEmpty<T> {
|
||||
@BeforeTemplate
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.HEAD;
|
||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||
import static org.springframework.http.HttpMethod.PATCH;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
import com.google.errorprone.refaster.annotation.AfterTemplate;
|
||||
import com.google.errorprone.refaster.annotation.BeforeTemplate;
|
||||
import com.google.errorprone.refaster.annotation.Repeated;
|
||||
import java.util.function.Function;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
|
||||
|
||||
/**
|
||||
* Refaster templates related to expressions dealing with {@link
|
||||
@@ -23,7 +36,7 @@ final class WebClientTemplates {
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestHeadersSpec<?> before2(
|
||||
WebTestClient.RequestHeadersSpec<?> before(
|
||||
WebTestClient.RequestBodySpec requestBodySpec, T value) {
|
||||
return requestBodySpec.body(fromValue(value));
|
||||
}
|
||||
@@ -33,4 +46,159 @@ final class WebClientTemplates {
|
||||
return requestBodySpec.bodyValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#get()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#GET}.
|
||||
*/
|
||||
static final class WebClientGet {
|
||||
@BeforeTemplate
|
||||
RequestHeadersSpec<?> before(WebClient webClient) {
|
||||
return webClient.method(GET);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestHeadersSpec<?> before(WebTestClient webClient) {
|
||||
return webClient.method(GET);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestHeadersSpec<?> after(WebClient webClient) {
|
||||
return webClient.get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#head()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#HEAD}.
|
||||
*/
|
||||
static final class WebClientHead {
|
||||
@BeforeTemplate
|
||||
RequestHeadersSpec<?> before(WebClient webClient) {
|
||||
return webClient.method(HEAD);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestHeadersSpec<?> before(WebTestClient webClient) {
|
||||
return webClient.method(HEAD);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestHeadersSpec<?> after(WebClient webClient) {
|
||||
return webClient.head();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#options()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#OPTIONS}.
|
||||
*/
|
||||
static final class WebClientOptions {
|
||||
@BeforeTemplate
|
||||
RequestHeadersSpec<?> before(WebClient webClient) {
|
||||
return webClient.method(OPTIONS);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestHeadersSpec<?> before(WebTestClient webClient) {
|
||||
return webClient.method(OPTIONS);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestHeadersSpec<?> after(WebClient webClient) {
|
||||
return webClient.options();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#patch()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#PATCH}.
|
||||
*/
|
||||
static final class WebClientPatch {
|
||||
@BeforeTemplate
|
||||
RequestBodyUriSpec before(WebClient webClient) {
|
||||
return webClient.method(PATCH);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestBodyUriSpec before(WebTestClient webClient) {
|
||||
return webClient.method(PATCH);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestBodyUriSpec after(WebClient webClient) {
|
||||
return webClient.patch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#post()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#POST}.
|
||||
*/
|
||||
static final class WebClientPost {
|
||||
@BeforeTemplate
|
||||
RequestBodyUriSpec before(WebClient webClient) {
|
||||
return webClient.method(POST);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestBodyUriSpec before(WebTestClient webClient) {
|
||||
return webClient.method(POST);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestBodyUriSpec after(WebClient webClient) {
|
||||
return webClient.post();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer {@link WebClient#put()} over {@link WebClient#method(HttpMethod)} with {@link
|
||||
* HttpMethod#PUT}.
|
||||
*/
|
||||
static final class WebClientPut {
|
||||
@BeforeTemplate
|
||||
RequestBodyUriSpec before(WebClient webClient) {
|
||||
return webClient.method(PUT);
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestBodyUriSpec before(WebTestClient webClient) {
|
||||
return webClient.method(PUT);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestBodyUriSpec after(WebClient webClient) {
|
||||
return webClient.put();
|
||||
}
|
||||
}
|
||||
|
||||
/** Don't unnecessarily use {@link RequestHeadersUriSpec#uri(Function)}. */
|
||||
abstract static class RequestHeadersUriSpecUri {
|
||||
@BeforeTemplate
|
||||
RequestHeadersSpec<?> before(
|
||||
RequestHeadersUriSpec<?> requestHeadersUriSpec,
|
||||
String path,
|
||||
@Repeated Object uriVariables) {
|
||||
return requestHeadersUriSpec.uri(
|
||||
uriBuilder -> uriBuilder.path(path).build(Refaster.asVarargs(uriVariables)));
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
WebTestClient.RequestHeadersSpec<?> before(
|
||||
WebTestClient.RequestHeadersUriSpec<?> requestHeadersUriSpec,
|
||||
String path,
|
||||
@Repeated Object uriVariables) {
|
||||
return requestHeadersUriSpec.uri(
|
||||
uriBuilder -> uriBuilder.path(path).build(Refaster.asVarargs(uriVariables)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
RequestHeadersSpec<?> after(
|
||||
RequestHeadersUriSpec<?> requestHeadersUriSpec,
|
||||
String path,
|
||||
@Repeated Object uriVariables) {
|
||||
return requestHeadersUriSpec.uri(path, Refaster.asVarargs(uriVariables));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,6 @@ final class AmbiguousJsonCreatorCheckTest {
|
||||
" return new F(s);",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class AnnotationAttributeMatcherTest {
|
||||
final class AnnotationAttributeMatcherTest {
|
||||
@Test
|
||||
void withoutListings() {
|
||||
AnnotationAttributeMatcher matcher =
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;
|
||||
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class AssertJIsNullCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(AssertJIsNullCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
BugCheckerRefactoringTestHelper.newInstance(AssertJIsNullCheck.class, getClass());
|
||||
|
||||
@Test
|
||||
void identification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" assertThat(1).isEqualTo(1);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" assertThat(1).isEqualTo(null);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" assertThat(\"foo\").isEqualTo(null);",
|
||||
" isEqualTo(null);",
|
||||
" }",
|
||||
"",
|
||||
" private boolean isEqualTo(Object value) {",
|
||||
" return value.equals(\"bar\");",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacement() {
|
||||
refactoringTestHelper
|
||||
.addInputLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" assertThat(1).isEqualTo(null);",
|
||||
" assertThat(\"foo\").isEqualTo(null);",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" assertThat(1).isNull();",
|
||||
" assertThat(\"foo\").isNull();",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TEXT_MATCH);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class AutowiredConstructorCheckTest {
|
||||
final class AutowiredConstructorCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(AutowiredConstructorCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -27,27 +27,34 @@ public final class AutowiredConstructorCheckTest {
|
||||
" }",
|
||||
"",
|
||||
" class B {",
|
||||
" @Autowired void setProperty(Object o) {}",
|
||||
" @Autowired",
|
||||
" void setProperty(Object o) {}",
|
||||
" }",
|
||||
"",
|
||||
" class C {",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Autowired C() {}",
|
||||
" @Autowired",
|
||||
" C() {}",
|
||||
" }",
|
||||
"",
|
||||
" class D {",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Autowired D(String x) {}",
|
||||
" @Autowired",
|
||||
" D(String x) {}",
|
||||
" }",
|
||||
"",
|
||||
" class E {",
|
||||
" @Autowired E() {}",
|
||||
" @Autowired",
|
||||
" E() {}",
|
||||
"",
|
||||
" E(String x) {}",
|
||||
" }",
|
||||
"",
|
||||
" class F {",
|
||||
" F() {}",
|
||||
" @Autowired F(String x) {}",
|
||||
"",
|
||||
" @Autowired",
|
||||
" F(String x) {}",
|
||||
" }",
|
||||
"",
|
||||
" class G {",
|
||||
@@ -55,7 +62,8 @@ public final class AutowiredConstructorCheckTest {
|
||||
" }",
|
||||
"",
|
||||
" class H {",
|
||||
" @SafeVarargs H(List<String>... lists) {}",
|
||||
" @SafeVarargs",
|
||||
" H(List<String>... lists) {}",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
@@ -70,11 +78,14 @@ public final class AutowiredConstructorCheckTest {
|
||||
"",
|
||||
"interface Container {",
|
||||
" class A {",
|
||||
" @Autowired @Deprecated A() {}",
|
||||
" @Autowired",
|
||||
" @Deprecated",
|
||||
" A() {}",
|
||||
" }",
|
||||
"",
|
||||
" class B {",
|
||||
" @Autowired B(String x) {}",
|
||||
" @Autowired",
|
||||
" B(String x) {}",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
@@ -83,10 +94,13 @@ public final class AutowiredConstructorCheckTest {
|
||||
"",
|
||||
"interface Container {",
|
||||
" class A {",
|
||||
" @Deprecated A() {}",
|
||||
"",
|
||||
" @Deprecated",
|
||||
" A() {}",
|
||||
" }",
|
||||
"",
|
||||
" class B {",
|
||||
"",
|
||||
" B(String x) {}",
|
||||
" }",
|
||||
"}")
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class CanonicalAnnotationSyntaxCheckTest {
|
||||
final class CanonicalAnnotationSyntaxCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(CanonicalAnnotationSyntaxCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -23,63 +23,110 @@ public final class CanonicalAnnotationSyntaxCheckTest {
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" int[] value() default {};",
|
||||
"",
|
||||
" int[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @pkg.A.Foo A minimal1();",
|
||||
" @A.Foo A minimal2();",
|
||||
" @Foo A minimal3();",
|
||||
" @pkg.A.Foo",
|
||||
" A minimal1();",
|
||||
"",
|
||||
" @A.Foo",
|
||||
" A minimal2();",
|
||||
"",
|
||||
" @Foo",
|
||||
" A minimal3();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @pkg.A.Foo() A functional1();",
|
||||
" @pkg.A.Foo()",
|
||||
" A functional1();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @A.Foo() A functional2();",
|
||||
" @A.Foo()",
|
||||
" A functional2();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo() A functional3();",
|
||||
" @Foo()",
|
||||
" A functional3();",
|
||||
"",
|
||||
" @pkg.A.Foo(1) A simple1();",
|
||||
" @A.Foo(1) A simple2();",
|
||||
" @Foo(1) A simple3();",
|
||||
" @pkg.A.Foo(1)",
|
||||
" A simple1();",
|
||||
"",
|
||||
" @A.Foo(1)",
|
||||
" A simple2();",
|
||||
"",
|
||||
" @Foo(1)",
|
||||
" A simple3();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @pkg.A.Foo({1}) A singleton1();",
|
||||
" @pkg.A.Foo({1})",
|
||||
" A singleton1();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @A.Foo({1}) A singleton2();",
|
||||
" @A.Foo({1})",
|
||||
" A singleton2();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({1}) A singleton3();",
|
||||
" @Foo({1})",
|
||||
" A singleton3();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @pkg.A.Foo(value = 1) A verbose1();",
|
||||
" @pkg.A.Foo(value = 1)",
|
||||
" A verbose1();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @A.Foo(value = 1) A verbose2();",
|
||||
" @A.Foo(value = 1)",
|
||||
" A verbose2();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(value = 1) A verbose3();",
|
||||
" @Foo(value = 1)",
|
||||
" A verbose3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value2 = 2) A custom1();",
|
||||
" @A.Foo(value2 = 2) A custom2();",
|
||||
" @Foo(value2 = 2) A custom3();",
|
||||
" @pkg.A.Foo(value2 = 2)",
|
||||
" A custom1();",
|
||||
"",
|
||||
" @A.Foo(value2 = 2)",
|
||||
" A custom2();",
|
||||
"",
|
||||
" @Foo(value2 = 2)",
|
||||
" A custom3();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @pkg.A.Foo(value2 = {2}) A customSingleton1();",
|
||||
" @pkg.A.Foo(value2 = {2})",
|
||||
" A customSingleton1();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @A.Foo(value2 = {2}) A customSingleton2();",
|
||||
" @A.Foo(value2 = {2})",
|
||||
" A customSingleton2();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(value2 = {2}) A customSingleton3();",
|
||||
" @Foo(value2 = {2})",
|
||||
" A customSingleton3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value2 = {2, 2}) A customPair1();",
|
||||
" @A.Foo(value2 = {2, 2}) A customPair2();",
|
||||
" @Foo(value2 = {2, 2}) A customPair3();",
|
||||
" @pkg.A.Foo(value2 = {2, 2})",
|
||||
" A customPair1();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = 1, value2 = 2) A extended1();",
|
||||
" @A.Foo(value = 1, value2 = 2) A extended2();",
|
||||
" @Foo(value = 1, value2 = 2) A extended3();",
|
||||
" @A.Foo(value2 = {2, 2})",
|
||||
" A customPair2();",
|
||||
"",
|
||||
" @Foo(value2 = {2, 2})",
|
||||
" A customPair3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = 1, value2 = 2)",
|
||||
" A extended1();",
|
||||
"",
|
||||
" @A.Foo(value = 1, value2 = 2)",
|
||||
" A extended2();",
|
||||
"",
|
||||
" @Foo(value = 1, value2 = 2)",
|
||||
" A extended3();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @pkg.A.Foo({1, 1,}) A trailingComma1();",
|
||||
" @pkg.A.Foo({",
|
||||
" 1, 1,",
|
||||
" })",
|
||||
" A trailingComma1();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @A.Foo({1, 1,}) A trailingComma2();",
|
||||
" @A.Foo({",
|
||||
" 1, 1,",
|
||||
" })",
|
||||
" A trailingComma2();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({1, 1,}) A trailingComma3();",
|
||||
" @Foo({",
|
||||
" 1, 1,",
|
||||
" })",
|
||||
" A trailingComma3();",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -96,28 +143,67 @@ public final class CanonicalAnnotationSyntaxCheckTest {
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @pkg.A.Foo() A functional1();",
|
||||
" @A.Foo() A functional2();",
|
||||
" @Foo() A functional3();",
|
||||
" @pkg.A.Foo()",
|
||||
" A functional1();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = \"foo\") A verbose1();",
|
||||
" @A.Foo(value = \"a'b\") A verbose2();",
|
||||
" @Foo(value = \"a\" + \"\\nb\") A verbose3();",
|
||||
" @A.Foo()",
|
||||
" A functional2();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = {\"foo\"}) A moreVerbose1();",
|
||||
" @A.Foo(value = {\"a'b\"}) A moreVerbose2();",
|
||||
" @Foo(value = {\"a\" + \"\\nb\"}) A moreVerbose3();",
|
||||
" @Foo()",
|
||||
" A functional3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = {\"foo\", \"bar\"}, value2 = {2}) A extended1();",
|
||||
" @A.Foo(value = {\"a'b\", \"c'd\"}, value2 = {2}) A extended2();",
|
||||
" @Foo(value = {\"a\" + \"\\nb\", \"c\" + \"\\nd\"}, value2 = {2}) A extended3();",
|
||||
" @pkg.A.Foo(value = \"foo\")",
|
||||
" A verbose1();",
|
||||
"",
|
||||
" @pkg.A.Foo({\"foo\", \"bar\",}) A trailingComma1();",
|
||||
" @A.Foo({\"a'b\", \"c'd\",}) A trailingComma2();",
|
||||
" @Foo({\"a\" + \"\\nb\", \"c\" + \"\\nd\",}) A trailingComma3();",
|
||||
" @A.Foo(value = \"a'b\")",
|
||||
" A verbose2();",
|
||||
"",
|
||||
" @Foo(value = \"a\" + \"\\nb\")",
|
||||
" A verbose3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = {\"foo\"})",
|
||||
" A moreVerbose1();",
|
||||
"",
|
||||
" @A.Foo(value = {\"a'b\"})",
|
||||
" A moreVerbose2();",
|
||||
"",
|
||||
" @Foo(value = {\"a\" + \"\\nb\"})",
|
||||
" A moreVerbose3();",
|
||||
"",
|
||||
" @pkg.A.Foo(",
|
||||
" value = {\"foo\", \"bar\"},",
|
||||
" value2 = {2})",
|
||||
" A extended1();",
|
||||
"",
|
||||
" @A.Foo(",
|
||||
" value = {\"a'b\", \"c'd\"},",
|
||||
" value2 = {2})",
|
||||
" A extended2();",
|
||||
"",
|
||||
" @Foo(",
|
||||
" value = {\"a\" + \"\\nb\", \"c\" + \"\\nd\"},",
|
||||
" value2 = {2})",
|
||||
" A extended3();",
|
||||
"",
|
||||
" @pkg.A.Foo({",
|
||||
" \"foo\", \"bar\",",
|
||||
" })",
|
||||
" A trailingComma1();",
|
||||
"",
|
||||
" @A.Foo({",
|
||||
" \"a'b\", \"c'd\",",
|
||||
" })",
|
||||
" A trailingComma2();",
|
||||
"",
|
||||
" @Foo({",
|
||||
" \"a\" + \"\\nb\",",
|
||||
" \"c\" + \"\\nd\",",
|
||||
" })",
|
||||
" A trailingComma3();",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/pkg/A.java",
|
||||
@@ -128,28 +214,60 @@ public final class CanonicalAnnotationSyntaxCheckTest {
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @pkg.A.Foo A functional1();",
|
||||
" @A.Foo A functional2();",
|
||||
" @Foo A functional3();",
|
||||
" @pkg.A.Foo",
|
||||
" A functional1();",
|
||||
"",
|
||||
" @pkg.A.Foo(\"foo\") A verbose1();",
|
||||
" @A.Foo(\"a'b\") A verbose2();",
|
||||
" @Foo(\"a\" + \"\\nb\") A verbose3();",
|
||||
" @A.Foo",
|
||||
" A functional2();",
|
||||
"",
|
||||
" @pkg.A.Foo(\"foo\") A moreVerbose1();",
|
||||
" @A.Foo(\"a'b\") A moreVerbose2();",
|
||||
" @Foo(\"a\" + \"\\nb\") A moreVerbose3();",
|
||||
" @Foo",
|
||||
" A functional3();",
|
||||
"",
|
||||
" @pkg.A.Foo(value = {\"foo\", \"bar\"}, value2 = 2) A extended1();",
|
||||
" @A.Foo(value = {\"a'b\", \"c'd\"}, value2 = 2) A extended2();",
|
||||
" @Foo(value = {\"a\" + \"\\nb\", \"c\" + \"\\nd\"}, value2 = 2) A extended3();",
|
||||
" @pkg.A.Foo(\"foo\")",
|
||||
" A verbose1();",
|
||||
"",
|
||||
" @pkg.A.Foo({\"foo\", \"bar\"}) A trailingComma1();",
|
||||
" @A.Foo({\"a'b\", \"c'd\"}) A trailingComma2();",
|
||||
" @Foo({\"a\" + \"\\nb\", \"c\" + \"\\nd\"}) A trailingComma3();",
|
||||
" @A.Foo(\"a'b\")",
|
||||
" A verbose2();",
|
||||
"",
|
||||
" @Foo(\"a\" + \"\\nb\")",
|
||||
" A verbose3();",
|
||||
"",
|
||||
" @pkg.A.Foo(\"foo\")",
|
||||
" A moreVerbose1();",
|
||||
"",
|
||||
" @A.Foo(\"a'b\")",
|
||||
" A moreVerbose2();",
|
||||
"",
|
||||
" @Foo(\"a\" + \"\\nb\")",
|
||||
" A moreVerbose3();",
|
||||
"",
|
||||
" @pkg.A.Foo(",
|
||||
" value = {\"foo\", \"bar\"},",
|
||||
" value2 = 2)",
|
||||
" A extended1();",
|
||||
"",
|
||||
" @A.Foo(",
|
||||
" value = {\"a'b\", \"c'd\"},",
|
||||
" value2 = 2)",
|
||||
" A extended2();",
|
||||
"",
|
||||
" @Foo(",
|
||||
" value = {\"a\" + \"\\nb\", \"c\" + \"\\nd\"},",
|
||||
" value2 = 2)",
|
||||
" A extended3();",
|
||||
"",
|
||||
" @pkg.A.Foo({\"foo\", \"bar\"})",
|
||||
" A trailingComma1();",
|
||||
"",
|
||||
" @A.Foo({\"a'b\", \"c'd\"})",
|
||||
" A trailingComma2();",
|
||||
"",
|
||||
" @Foo({\"a\" + \"\\nb\", \"c\" + \"\\nd\"})",
|
||||
" A trailingComma3();",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.SECOND;
|
||||
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class CollectorMutabilityCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(CollectorMutabilityCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
BugCheckerRefactoringTestHelper.newInstance(CollectorMutabilityCheck.class, getClass());
|
||||
|
||||
@Test
|
||||
void identification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.collect.ImmutableList.toImmutableList;",
|
||||
"import static com.google.common.collect.ImmutableMap.toImmutableMap;",
|
||||
"import static com.google.common.collect.ImmutableSet.toImmutableSet;",
|
||||
"import static java.util.stream.Collectors.toCollection;",
|
||||
"import static java.util.stream.Collectors.toList;",
|
||||
"import static java.util.stream.Collectors.toMap;",
|
||||
"import static java.util.stream.Collectors.toSet;",
|
||||
"",
|
||||
"import java.util.ArrayList;",
|
||||
"import java.util.HashMap;",
|
||||
"import java.util.HashSet;",
|
||||
"import java.util.stream.Collectors;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Flux.just(1).collect(Collectors.toList());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Flux.just(2).collect(toList());",
|
||||
" Flux.just(3).collect(toImmutableList());",
|
||||
" Flux.just(4).collect(toCollection(ArrayList::new));",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Flux.just(\"foo\").collect(Collectors.toMap(String::getBytes, String::length));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Flux.just(\"bar\").collect(toMap(String::getBytes, String::length));",
|
||||
" Flux.just(\"baz\").collect(toImmutableMap(String::getBytes, String::length));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Flux.just(\"qux\").collect(toMap(String::getBytes, String::length, (a, b) -> a));",
|
||||
" Flux.just(\"quux\").collect(toImmutableMap(String::getBytes, String::length, (a, b) -> a));",
|
||||
" Flux.just(\"quuz\").collect(toMap(String::getBytes, String::length, (a, b) -> a, HashMap::new));",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Stream.of(1).collect(Collectors.toSet());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Stream.of(2).collect(toSet());",
|
||||
" Stream.of(3).collect(toImmutableSet());",
|
||||
" Stream.of(4).collect(toCollection(HashSet::new));",
|
||||
"",
|
||||
" Flux.just(\"foo\").collect(Collectors.joining());",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementFirstSuggestedFix() {
|
||||
refactoringTestHelper
|
||||
.addInputLines(
|
||||
"A.java",
|
||||
"import static java.util.stream.Collectors.toList;",
|
||||
"import static java.util.stream.Collectors.toMap;",
|
||||
"import static java.util.stream.Collectors.toSet;",
|
||||
"",
|
||||
"import java.util.stream.Collectors;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" Flux.just(1).collect(Collectors.toList());",
|
||||
" Flux.just(2).collect(toList());",
|
||||
"",
|
||||
" Stream.of(\"foo\").collect(Collectors.toMap(String::getBytes, String::length));",
|
||||
" Stream.of(\"bar\").collect(toMap(String::getBytes, String::length));",
|
||||
" Flux.just(\"baz\").collect(Collectors.toMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
" Flux.just(\"qux\").collect(toMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
"",
|
||||
" Stream.of(1).collect(Collectors.toSet());",
|
||||
" Stream.of(2).collect(toSet());",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"A.java",
|
||||
"import static com.google.common.collect.ImmutableList.toImmutableList;",
|
||||
"import static com.google.common.collect.ImmutableMap.toImmutableMap;",
|
||||
"import static com.google.common.collect.ImmutableSet.toImmutableSet;",
|
||||
"import static java.util.stream.Collectors.toList;",
|
||||
"import static java.util.stream.Collectors.toMap;",
|
||||
"import static java.util.stream.Collectors.toSet;",
|
||||
"",
|
||||
"import java.util.stream.Collectors;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" Flux.just(1).collect(toImmutableList());",
|
||||
" Flux.just(2).collect(toImmutableList());",
|
||||
"",
|
||||
" Stream.of(\"foo\").collect(toImmutableMap(String::getBytes, String::length));",
|
||||
" Stream.of(\"bar\").collect(toImmutableMap(String::getBytes, String::length));",
|
||||
" Flux.just(\"baz\").collect(toImmutableMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
" Flux.just(\"qux\").collect(toImmutableMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
"",
|
||||
" Stream.of(1).collect(toImmutableSet());",
|
||||
" Stream.of(2).collect(toImmutableSet());",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementSecondSuggestedFix() {
|
||||
refactoringTestHelper
|
||||
.setFixChooser(SECOND)
|
||||
.addInputLines(
|
||||
"A.java",
|
||||
"import static java.util.stream.Collectors.toList;",
|
||||
"import static java.util.stream.Collectors.toMap;",
|
||||
"import static java.util.stream.Collectors.toSet;",
|
||||
"",
|
||||
"import java.util.stream.Collectors;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" Flux.just(1).collect(Collectors.toList());",
|
||||
" Flux.just(2).collect(toList());",
|
||||
"",
|
||||
" Stream.of(\"foo\").collect(Collectors.toMap(String::getBytes, String::length));",
|
||||
" Stream.of(\"bar\").collect(toMap(String::getBytes, String::length));",
|
||||
" Flux.just(\"baz\").collect(Collectors.toMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
" Flux.just(\"qux\").collect(toMap(String::getBytes, String::length, (a, b) -> b));",
|
||||
"",
|
||||
" Stream.of(1).collect(Collectors.toSet());",
|
||||
" Stream.of(2).collect(toSet());",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"A.java",
|
||||
"import static java.util.stream.Collectors.toCollection;",
|
||||
"import static java.util.stream.Collectors.toList;",
|
||||
"import static java.util.stream.Collectors.toMap;",
|
||||
"import static java.util.stream.Collectors.toSet;",
|
||||
"",
|
||||
"import java.util.ArrayList;",
|
||||
"import java.util.HashMap;",
|
||||
"import java.util.HashSet;",
|
||||
"import java.util.stream.Collectors;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" Flux.just(1).collect(toCollection(ArrayList::new));",
|
||||
" Flux.just(2).collect(toCollection(ArrayList::new));",
|
||||
"",
|
||||
" Stream.of(\"foo\")",
|
||||
" .collect(",
|
||||
" Collectors.toMap(",
|
||||
" String::getBytes,",
|
||||
" String::length,",
|
||||
" (a, b) -> {",
|
||||
" throw new IllegalStateException();",
|
||||
" },",
|
||||
" HashMap::new));",
|
||||
" Stream.of(\"bar\")",
|
||||
" .collect(",
|
||||
" toMap(",
|
||||
" String::getBytes,",
|
||||
" String::length,",
|
||||
" (a, b) -> {",
|
||||
" throw new IllegalStateException();",
|
||||
" },",
|
||||
" HashMap::new));",
|
||||
" Flux.just(\"baz\")",
|
||||
" .collect(Collectors.toMap(String::getBytes, String::length, (a, b) -> b, HashMap::new));",
|
||||
" Flux.just(\"qux\").collect(toMap(String::getBytes, String::length, (a, b) -> b, HashMap::new));",
|
||||
"",
|
||||
" Stream.of(1).collect(toCollection(HashSet::new));",
|
||||
" Stream.of(2).collect(toCollection(HashSet::new));",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class EmptyMethodCheckTest {
|
||||
final class EmptyMethodCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(EmptyMethodCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class ErrorProneTestHelperSourceFormatCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormatCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
BugCheckerRefactoringTestHelper.newInstance(
|
||||
ErrorProneTestHelperSourceFormatCheck.class, getClass());
|
||||
|
||||
@Test
|
||||
void identification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import tech.picnic.errorprone.bugpatterns.EmptyMethodCheck;",
|
||||
"",
|
||||
"class A {",
|
||||
" private final CompilationTestHelper compilationTestHelper =",
|
||||
" CompilationTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
" private final BugCheckerRefactoringTestHelper refactoringTestHelper =",
|
||||
" BugCheckerRefactoringTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
"",
|
||||
" void m() {",
|
||||
" compilationTestHelper",
|
||||
" // BUG: Diagnostic contains: No source code provided",
|
||||
" .addSourceLines(\"A.java\")",
|
||||
" // BUG: Diagnostic contains: Source code is malformed:",
|
||||
" .addSourceLines(\"B.java\", \"class B {\")",
|
||||
" // Well-formed code, so not flagged.",
|
||||
" .addSourceLines(\"C.java\", \"class C {}\")",
|
||||
" // Malformed code, but not compile-time constant, so not flagged.",
|
||||
" .addSourceLines(\"D.java\", \"class D {\" + getClass())",
|
||||
" // BUG: Diagnostic contains: Test code should follow the Google Java style",
|
||||
" .addSourceLines(\"E.java\", \"class E { }\")",
|
||||
" .doTest();",
|
||||
"",
|
||||
" refactoringTestHelper",
|
||||
" // BUG: Diagnostic contains: Test code should follow the Google Java style",
|
||||
" .addInputLines(\"in/A.java\", \"class A { }\")",
|
||||
" // BUG: Diagnostic contains: Test code should follow the Google Java style",
|
||||
" .addOutputLines(\"out/A.java\", \"class A { }\")",
|
||||
" // BUG: Diagnostic contains: Test code should follow the Google Java style",
|
||||
" .addInputLines(\"in/B.java\", \"import java.util.Map;\", \"\", \"class B {}\")",
|
||||
" // Unused import, but in an output file, so not flagged.",
|
||||
" .addOutputLines(\"out/B.java\", \"import java.util.Map;\", \"\", \"class B {}\")",
|
||||
" .doTest(TestMode.TEXT_MATCH);",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacement() {
|
||||
/*
|
||||
* Verifies that import sorting and code formatting is performed unconditionally, while unused
|
||||
* imports are removed unless part of a `BugCheckerRefactoringTestHelper` expected output file.
|
||||
*/
|
||||
refactoringTestHelper
|
||||
.addInputLines(
|
||||
"in/A.java",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import tech.picnic.errorprone.bugpatterns.EmptyMethodCheck;",
|
||||
"",
|
||||
"class A {",
|
||||
" private final CompilationTestHelper compilationTestHelper =",
|
||||
" CompilationTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
" private final BugCheckerRefactoringTestHelper refactoringTestHelper =",
|
||||
" BugCheckerRefactoringTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
"",
|
||||
" void m() {",
|
||||
" compilationTestHelper",
|
||||
" .addSourceLines(",
|
||||
" \"A.java\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"import java.util.Collection;\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A,A> { }\")",
|
||||
" .doTest();",
|
||||
"",
|
||||
" refactoringTestHelper",
|
||||
" .addInputLines(",
|
||||
" \"in/A.java\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"import java.util.Collection;\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A,A> { }\")",
|
||||
" .addOutputLines(",
|
||||
" \"out/A.java\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"import java.util.Collection;\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A,A> { }\")",
|
||||
" .doTest(TestMode.TEXT_MATCH);",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import tech.picnic.errorprone.bugpatterns.EmptyMethodCheck;",
|
||||
"",
|
||||
"class A {",
|
||||
" private final CompilationTestHelper compilationTestHelper =",
|
||||
" CompilationTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
" private final BugCheckerRefactoringTestHelper refactoringTestHelper =",
|
||||
" BugCheckerRefactoringTestHelper.newInstance(EmptyMethodCheck.class, getClass());",
|
||||
"",
|
||||
" void m() {",
|
||||
" compilationTestHelper",
|
||||
" .addSourceLines(",
|
||||
" \"A.java\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A, A> {}\")",
|
||||
" .doTest();",
|
||||
"",
|
||||
" refactoringTestHelper",
|
||||
" .addInputLines(",
|
||||
" \"in/A.java\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A, A> {}\")",
|
||||
" .addOutputLines(",
|
||||
" \"out/A.java\",",
|
||||
" \"import java.util.Collection;\",",
|
||||
" \"import java.util.List;\",",
|
||||
" \"import java.util.Map;\",",
|
||||
" \"\",",
|
||||
" \"interface A extends List<A>, Map<A, A> {}\")",
|
||||
" .doTest(TestMode.TEXT_MATCH);",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,14 @@ final class ExplicitEnumOrderingCheckTest {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static java.lang.annotation.RetentionPolicy.SOURCE;",
|
||||
"import static java.lang.annotation.RetentionPolicy.CLASS;",
|
||||
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
|
||||
"import static java.lang.annotation.RetentionPolicy.SOURCE;",
|
||||
"import static java.time.chrono.IsoEra.BCE;",
|
||||
"import static java.time.chrono.IsoEra.CE;",
|
||||
"",
|
||||
"import com.google.common.collect.Ordering;",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.Ordering;",
|
||||
"import java.lang.annotation.RetentionPolicy;",
|
||||
"import java.time.chrono.IsoEra;",
|
||||
"",
|
||||
|
||||
@@ -20,8 +20,8 @@ final class FluxFlatMapUsageCheckTest {
|
||||
"A.java",
|
||||
"import java.util.function.BiFunction;",
|
||||
"import java.util.function.Function;",
|
||||
"import reactor.core.publisher.Mono;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.core.publisher.Mono;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class FormatStringConcatenationCheckTest {
|
||||
final class FormatStringConcatenationCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(FormatStringConcatenationCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -23,8 +23,8 @@ public final class FormatStringConcatenationCheckTest {
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"import static org.assertj.core.api.SoftAssertions.assertSoftly;",
|
||||
"",
|
||||
"import java.util.Locale;",
|
||||
"import java.util.Formatter;",
|
||||
"import java.util.Locale;",
|
||||
"import org.assertj.core.api.Assertions;",
|
||||
"import org.assertj.core.api.BDDAssertions;",
|
||||
"import org.assertj.core.api.Fail;",
|
||||
@@ -269,9 +269,9 @@ public final class FormatStringConcatenationCheckTest {
|
||||
" LOG.error(\"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.error((Marker) null,\"str \" + toString());",
|
||||
" LOG.error((Marker) null, \"str \" + toString());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.error((Marker) null,\"{} \" + toString(), \"arg\");",
|
||||
" LOG.error((Marker) null, \"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.info(\"str \" + toString());",
|
||||
@@ -279,9 +279,9 @@ public final class FormatStringConcatenationCheckTest {
|
||||
" LOG.info(\"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.info((Marker) null,\"str \" + toString());",
|
||||
" LOG.info((Marker) null, \"str \" + toString());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.info((Marker) null,\"{} \" + toString(), \"arg\");",
|
||||
" LOG.info((Marker) null, \"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.trace(\"str \" + toString());",
|
||||
@@ -289,9 +289,9 @@ public final class FormatStringConcatenationCheckTest {
|
||||
" LOG.trace(\"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.trace((Marker) null,\"str \" + toString());",
|
||||
" LOG.trace((Marker) null, \"str \" + toString());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.trace((Marker) null,\"{} \" + toString(), \"arg\");",
|
||||
" LOG.trace((Marker) null, \"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.warn(\"str \" + toString());",
|
||||
@@ -299,9 +299,9 @@ public final class FormatStringConcatenationCheckTest {
|
||||
" LOG.warn(\"{} \" + toString(), \"arg\");",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.warn((Marker) null,\"str \" + toString());",
|
||||
" LOG.warn((Marker) null, \"str \" + toString());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.warn((Marker) null,\"{} \" + toString(), \"arg\");",
|
||||
" LOG.warn((Marker) null, \"{} \" + toString(), \"arg\");",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
@@ -316,7 +316,6 @@ public final class FormatStringConcatenationCheckTest {
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"import java.util.Locale;",
|
||||
"import java.util.Formatter;",
|
||||
"import org.slf4j.Logger;",
|
||||
"import org.slf4j.LoggerFactory;",
|
||||
"import org.slf4j.Marker;",
|
||||
@@ -366,7 +365,6 @@ public final class FormatStringConcatenationCheckTest {
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"import java.util.Locale;",
|
||||
"import java.util.Formatter;",
|
||||
"import org.slf4j.Logger;",
|
||||
"import org.slf4j.LoggerFactory;",
|
||||
"import org.slf4j.Marker;",
|
||||
@@ -400,6 +398,7 @@ public final class FormatStringConcatenationCheckTest {
|
||||
" String.format(\"{} \" + toString(), \"arg\");",
|
||||
" String.format(Locale.ROOT, \"{} \" + toString(), \"arg\");",
|
||||
" }",
|
||||
"",
|
||||
" void slf4j() {",
|
||||
" LOG.debug(\"str {}\", toString());",
|
||||
" LOG.debug((Marker) null, \"str {}\", toString());",
|
||||
|
||||
@@ -121,8 +121,9 @@ final class IdentityConversionCheckTest {
|
||||
" ImmutableBiMap<Object, Object> o1 = ImmutableBiMap.copyOf(ImmutableBiMap.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableList<Object> o2 = ImmutableList.copyOf(ImmutableList.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableListMultimap<Object, Object> o3 = ImmutableListMultimap.copyOf(ImmutableListMultimap.of());",
|
||||
" ImmutableListMultimap<Object, Object> o3 =",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableListMultimap.copyOf(ImmutableListMultimap.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableMap<Object, Object> o4 = ImmutableMap.copyOf(ImmutableMap.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
@@ -135,8 +136,9 @@ final class IdentityConversionCheckTest {
|
||||
" ImmutableRangeSet<String> o8 = ImmutableRangeSet.copyOf(ImmutableRangeSet.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableSet<Object> o9 = ImmutableSet.copyOf(ImmutableSet.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableSetMultimap<Object, Object> o10 = ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of());",
|
||||
" ImmutableSetMultimap<Object, Object> o10 =",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableSetMultimap.copyOf(ImmutableSetMultimap.of());",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" ImmutableTable<Object, Object, Object> o11 = ImmutableTable.copyOf(ImmutableTable.of());",
|
||||
"",
|
||||
@@ -171,8 +173,8 @@ final class IdentityConversionCheckTest {
|
||||
"import com.google.common.collect.ImmutableCollection;",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import java.util.Collection;",
|
||||
"import java.util.ArrayList;",
|
||||
"import java.util.Collection;",
|
||||
"import org.reactivestreams.Publisher;",
|
||||
"import reactor.adapter.rxjava.RxJava2Adapter;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
@@ -204,8 +206,7 @@ final class IdentityConversionCheckTest {
|
||||
" Object o1 = ImmutableSet.copyOf(ImmutableList.of());",
|
||||
" Object o2 = ImmutableSet.copyOf(ImmutableSet.of());",
|
||||
"",
|
||||
" when(\"foo\".contains(\"f\"))",
|
||||
" .thenAnswer(inv-> ImmutableSet.copyOf(ImmutableList.of(1)));",
|
||||
" when(\"foo\".contains(\"f\")).thenAnswer(inv -> ImmutableSet.copyOf(ImmutableList.of(1)));",
|
||||
" }",
|
||||
"",
|
||||
" void bar(Publisher<Integer> publisher) {}",
|
||||
@@ -217,8 +218,8 @@ final class IdentityConversionCheckTest {
|
||||
"import com.google.common.collect.ImmutableCollection;",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import java.util.Collection;",
|
||||
"import java.util.ArrayList;",
|
||||
"import java.util.Collection;",
|
||||
"import org.reactivestreams.Publisher;",
|
||||
"import reactor.adapter.rxjava.RxJava2Adapter;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
@@ -250,8 +251,7 @@ final class IdentityConversionCheckTest {
|
||||
" Object o1 = ImmutableSet.copyOf(ImmutableList.of());",
|
||||
" Object o2 = ImmutableSet.of();",
|
||||
"",
|
||||
" when(\"foo\".contains(\"f\"))",
|
||||
" .thenAnswer(inv-> ImmutableSet.copyOf(ImmutableList.of(1)));",
|
||||
" when(\"foo\".contains(\"f\")).thenAnswer(inv -> ImmutableSet.copyOf(ImmutableList.of(1)));",
|
||||
" }",
|
||||
"",
|
||||
" void bar(Publisher<Integer> publisher) {}",
|
||||
@@ -269,9 +269,6 @@ final class IdentityConversionCheckTest {
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import java.util.ArrayList;",
|
||||
"import reactor.adapter.rxjava.RxJava2Adapter;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.core.publisher.Mono;",
|
||||
"",
|
||||
"public final class Foo {",
|
||||
" public void foo() {",
|
||||
@@ -288,9 +285,6 @@ final class IdentityConversionCheckTest {
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import java.util.ArrayList;",
|
||||
"import reactor.adapter.rxjava.RxJava2Adapter;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.core.publisher.Mono;",
|
||||
"",
|
||||
"public final class Foo {",
|
||||
" public void foo() {",
|
||||
|
||||
@@ -26,71 +26,137 @@ final class JUnitMethodDeclarationCheckTest {
|
||||
"import org.junit.jupiter.params.ParameterizedTest;",
|
||||
"",
|
||||
"class A {",
|
||||
" @BeforeAll void setUp1() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeAll public void setUp2() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeAll protected void setUp3() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeAll private void setUp4() {}",
|
||||
" {",
|
||||
" arguments();",
|
||||
" }",
|
||||
"",
|
||||
" @BeforeEach void setup5() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeEach public void setUp6() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeEach protected void setUp7() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @BeforeEach private void setUp8() {}",
|
||||
" @BeforeAll",
|
||||
" void setUp1() {}",
|
||||
"",
|
||||
" @AfterEach void tearDown1() {}",
|
||||
" @BeforeAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterEach public void tearDown2() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterEach protected void tearDown3() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterEach private void tearDown4() {}",
|
||||
" public void setUp2() {}",
|
||||
"",
|
||||
" @AfterAll void tearDown5() {}",
|
||||
" @BeforeAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterAll public void tearDown6() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterAll protected void tearDown7() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterAll private void tearDown8() {}",
|
||||
" protected void setUp3() {}",
|
||||
"",
|
||||
" @Test void method1() {}",
|
||||
" @BeforeAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Test void testMethod2() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Test public void method3() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Test protected void method4() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Test private void method5() {}",
|
||||
" private void setUp4() {}",
|
||||
"",
|
||||
" @ParameterizedTest void method6() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @ParameterizedTest void testMethod7() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @ParameterizedTest public void method8() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @ParameterizedTest protected void method9() {}",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @ParameterizedTest private void method10() {}",
|
||||
" @BeforeEach",
|
||||
" void setup5() {}",
|
||||
"",
|
||||
" @BeforeEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" public void setUp6() {}",
|
||||
"",
|
||||
" @BeforeEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" protected void setUp7() {}",
|
||||
"",
|
||||
" @BeforeEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private void setUp8() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" void tearDown1() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" public void tearDown2() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" protected void tearDown3() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private void tearDown4() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" void tearDown5() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" public void tearDown6() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" protected void tearDown7() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private void tearDown8() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void method1() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" void testMethod2() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" public void method3() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" protected void method4() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private void method5() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" void method6() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" void testMethod7() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" public void method8() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" protected void method9() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private void method10() {}",
|
||||
"",
|
||||
" @BeforeEach",
|
||||
" @BeforeAll",
|
||||
" @AfterEach",
|
||||
" @AfterAll",
|
||||
" void testNonTestMethod1() {}",
|
||||
"",
|
||||
" @BeforeEach @BeforeAll @AfterEach @AfterAll void testNonTestMethod1() {}",
|
||||
" public void testNonTestMethod2() {}",
|
||||
" protected void testNonTestMethod3() {}",
|
||||
" private void testNonTestMethod4() {}",
|
||||
" @Test void test5() {}",
|
||||
"",
|
||||
" // BUG: Diagnostic contains: (but note that a method named `overload` already exists in this class)",
|
||||
" @Test void testOverload() {}",
|
||||
" protected void testNonTestMethod3() {}",
|
||||
"",
|
||||
" private void testNonTestMethod4() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void test5() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains: (but note that a method named `overload` already exists in this",
|
||||
" // class)",
|
||||
" void testOverload() {}",
|
||||
"",
|
||||
" void overload() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains: (but note that `arguments` is already statically imported)",
|
||||
" @Test void testArguments() {}",
|
||||
" void testArguments() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains: (but note that `public` is a reserved keyword)",
|
||||
" @Test void testPublic() {}",
|
||||
" void testPublic() {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
"B.java",
|
||||
@@ -102,41 +168,117 @@ final class JUnitMethodDeclarationCheckTest {
|
||||
"import org.junit.jupiter.params.ParameterizedTest;",
|
||||
"",
|
||||
"class B extends A {",
|
||||
" @Override @BeforeAll void setUp1() {}",
|
||||
" @Override @BeforeAll public void setUp2() {}",
|
||||
" @Override @BeforeAll protected void setUp3() {}",
|
||||
" @Override",
|
||||
" @BeforeAll",
|
||||
" void setUp1() {}",
|
||||
"",
|
||||
" @Override @BeforeEach void setup5() {}",
|
||||
" @Override @BeforeEach public void setUp6() {}",
|
||||
" @Override @BeforeEach protected void setUp7() {}",
|
||||
" @Override",
|
||||
" @BeforeAll",
|
||||
" public void setUp2() {}",
|
||||
"",
|
||||
" @Override @AfterEach void tearDown1() {}",
|
||||
" @Override @AfterEach public void tearDown2() {}",
|
||||
" @Override @AfterEach protected void tearDown3() {}",
|
||||
" @Override",
|
||||
" @BeforeAll",
|
||||
" protected void setUp3() {}",
|
||||
"",
|
||||
" @Override @AfterAll void tearDown5() {}",
|
||||
" @Override @AfterAll public void tearDown6() {}",
|
||||
" @Override @AfterAll protected void tearDown7() {}",
|
||||
" @Override",
|
||||
" @BeforeEach",
|
||||
" void setup5() {}",
|
||||
"",
|
||||
" @Override @Test void method1() {}",
|
||||
" @Override @Test void testMethod2() {}",
|
||||
" @Override @Test public void method3() {}",
|
||||
" @Override @Test protected void method4() {}",
|
||||
" @Override",
|
||||
" @BeforeEach",
|
||||
" public void setUp6() {}",
|
||||
"",
|
||||
" @Override @ParameterizedTest void method6() {}",
|
||||
" @Override @ParameterizedTest void testMethod7() {}",
|
||||
" @Override @ParameterizedTest public void method8() {}",
|
||||
" @Override @ParameterizedTest protected void method9() {}",
|
||||
" @Override",
|
||||
" @BeforeEach",
|
||||
" protected void setUp7() {}",
|
||||
"",
|
||||
" @Override @BeforeEach @BeforeAll @AfterEach @AfterAll void testNonTestMethod1() {}",
|
||||
" @Override public void testNonTestMethod2() {}",
|
||||
" @Override protected void testNonTestMethod3() {}",
|
||||
" @Override @Test void test5() {}",
|
||||
" @Override",
|
||||
" @AfterEach",
|
||||
" void tearDown1() {}",
|
||||
"",
|
||||
" @Override @Test void testOverload() {}",
|
||||
" @Override void overload() {}",
|
||||
" @Override @Test void testArguments() {}",
|
||||
" @Override @Test void testPublic() {}",
|
||||
" @Override",
|
||||
" @AfterEach",
|
||||
" public void tearDown2() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @AfterEach",
|
||||
" protected void tearDown3() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @AfterAll",
|
||||
" void tearDown5() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @AfterAll",
|
||||
" public void tearDown6() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @AfterAll",
|
||||
" protected void tearDown7() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void method1() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void testMethod2() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" public void method3() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" protected void method4() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @ParameterizedTest",
|
||||
" void method6() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @ParameterizedTest",
|
||||
" void testMethod7() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @ParameterizedTest",
|
||||
" public void method8() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @ParameterizedTest",
|
||||
" protected void method9() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @BeforeEach",
|
||||
" @BeforeAll",
|
||||
" @AfterEach",
|
||||
" @AfterAll",
|
||||
" void testNonTestMethod1() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" public void testNonTestMethod2() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" protected void testNonTestMethod3() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void test5() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void testOverload() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" void overload() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void testArguments() {}",
|
||||
"",
|
||||
" @Override",
|
||||
" @Test",
|
||||
" void testPublic() {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
"C.java",
|
||||
@@ -145,13 +287,19 @@ final class JUnitMethodDeclarationCheckTest {
|
||||
"import org.junit.jupiter.api.Test;",
|
||||
"",
|
||||
"abstract class C {",
|
||||
" @BeforeAll public void setUp() {}",
|
||||
" @Test void testMethod1() {}",
|
||||
" @BeforeAll",
|
||||
" public void setUp() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void testMethod1() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @AfterAll private void tearDown() {}",
|
||||
" private void tearDown() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Test final void testMethod2() {}",
|
||||
" final void testMethod2() {}",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -172,22 +320,47 @@ final class JUnitMethodDeclarationCheckTest {
|
||||
"import org.junit.jupiter.params.ParameterizedTest;",
|
||||
"",
|
||||
"class A {",
|
||||
" @BeforeAll public void setUp1() {}",
|
||||
" @BeforeEach protected void setUp2() {}",
|
||||
" @AfterEach private void setUp3() {}",
|
||||
" @AfterAll private void setUp4() {}",
|
||||
" {",
|
||||
" arguments();",
|
||||
" }",
|
||||
"",
|
||||
" @Test void testFoo() {}",
|
||||
" @ParameterizedTest void testBar() {}",
|
||||
" @BeforeAll",
|
||||
" public void setUp1() {}",
|
||||
"",
|
||||
" @Test public void baz() {}",
|
||||
" @RepeatedTest(2) private void qux() {}",
|
||||
" @ParameterizedTest protected void quux() {}",
|
||||
" @BeforeEach",
|
||||
" protected void setUp2() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" private void setUp3() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" private void setUp4() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void testFoo() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" void testBar() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" public void baz() {}",
|
||||
"",
|
||||
" @RepeatedTest(2)",
|
||||
" private void qux() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" protected void quux() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" public void testOverload() {}",
|
||||
"",
|
||||
" @Test public void testOverload() {}",
|
||||
" void overload() {}",
|
||||
" @Test protected void testArguments() {}",
|
||||
" @Test private void testClass() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" protected void testArguments() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" private void testClass() {}",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
@@ -202,22 +375,47 @@ final class JUnitMethodDeclarationCheckTest {
|
||||
"import org.junit.jupiter.params.ParameterizedTest;",
|
||||
"",
|
||||
"class A {",
|
||||
" @BeforeAll void setUp1() {}",
|
||||
" @BeforeEach void setUp2() {}",
|
||||
" @AfterEach void setUp3() {}",
|
||||
" @AfterAll void setUp4() {}",
|
||||
" {",
|
||||
" arguments();",
|
||||
" }",
|
||||
"",
|
||||
" @Test void foo() {}",
|
||||
" @ParameterizedTest void bar() {}",
|
||||
" @BeforeAll",
|
||||
" void setUp1() {}",
|
||||
"",
|
||||
" @Test void baz() {}",
|
||||
" @RepeatedTest(2) void qux() {}",
|
||||
" @ParameterizedTest void quux() {}",
|
||||
" @BeforeEach",
|
||||
" void setUp2() {}",
|
||||
"",
|
||||
" @AfterEach",
|
||||
" void setUp3() {}",
|
||||
"",
|
||||
" @AfterAll",
|
||||
" void setUp4() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void foo() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" void bar() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void baz() {}",
|
||||
"",
|
||||
" @RepeatedTest(2)",
|
||||
" void qux() {}",
|
||||
"",
|
||||
" @ParameterizedTest",
|
||||
" void quux() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void testOverload() {}",
|
||||
"",
|
||||
" @Test void testOverload() {}",
|
||||
" void overload() {}",
|
||||
" @Test void testArguments() {}",
|
||||
" @Test void testClass() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void testArguments() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" void testClass() {}",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(
|
||||
LexicographicalAnnotationAttributeListingCheck.class, getClass());
|
||||
@@ -26,8 +26,8 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"import static java.math.RoundingMode.DOWN;",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"",
|
||||
"import com.fasterxml.jackson.annotation.JsonPropertyOrder;",
|
||||
"import io.swagger.annotations.ApiImplicitParam;",
|
||||
@@ -40,9 +40,13 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] ints() default {};",
|
||||
"",
|
||||
" Class<?>[] cls() default {};",
|
||||
"",
|
||||
" RoundingMode[] enums() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -50,50 +54,95 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
" String[] value() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @Foo({}) A noString();",
|
||||
" @Foo({\"a\"}) A oneString();",
|
||||
" @Foo({\"a\", \"b\"}) A sortedStrings();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"b\", \"a\"}) A unsortedString();",
|
||||
" @Foo({\"ab\", \"Ac\"}) A sortedStringCaseInsensitive();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"ac\", \"Ab\"}) A unsortedStringCaseInsensitive();",
|
||||
" @Foo({\"A\", \"a\"}) A sortedStringCaseInsensitiveWithTotalOrderFallback();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"a\", \"A\"}) A unsortedStringCaseInsensitiveWithTotalOrderFallback();",
|
||||
" @Foo({})",
|
||||
" A noString();",
|
||||
"",
|
||||
" @Foo(ints = {}) A noInts();",
|
||||
" @Foo(ints = {0}) A oneInt();",
|
||||
" @Foo(ints = {0, 1}) A sortedInts();",
|
||||
" @Foo(ints = {1, 0}) A unsortedInts();",
|
||||
" @Foo({\"a\"})",
|
||||
" A oneString();",
|
||||
"",
|
||||
" @Foo(cls = {}) A noClasses();",
|
||||
" @Foo(cls = {int.class}) A oneClass();",
|
||||
" @Foo(cls = {int.class, long.class}) A sortedClasses();",
|
||||
" @Foo({\"a\", \"b\"})",
|
||||
" A sortedStrings();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(cls = {long.class, int.class}) A unsortedClasses();",
|
||||
" @Foo({\"b\", \"a\"})",
|
||||
" A unsortedString();",
|
||||
"",
|
||||
" @Foo(enums = {}) A noEnums();",
|
||||
" @Foo(enums = {DOWN}) A oneEnum();",
|
||||
" @Foo(enums = {DOWN, UP}) A sortedEnums();",
|
||||
" @Foo({\"ab\", \"Ac\"})",
|
||||
" A sortedStringCaseInsensitive();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(enums = {UP, DOWN}) A unsortedEnums();",
|
||||
" @Foo({\"ac\", \"Ab\"})",
|
||||
" A unsortedStringCaseInsensitive();",
|
||||
"",
|
||||
" @Foo(anns = {}) A noAnns();",
|
||||
" @Foo(anns = {@Bar(\"a\")}) A oneAnn();",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar(\"b\")}) A sortedAnns();",
|
||||
" @Foo({\"A\", \"a\"})",
|
||||
" A sortedStringCaseInsensitiveWithTotalOrderFallback();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) A unsortedAnns();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"b\", \"a\"})}) A unsortedInnderAnns();",
|
||||
" @Foo({\"a\", \"A\"})",
|
||||
" A unsortedStringCaseInsensitiveWithTotalOrderFallback();",
|
||||
"",
|
||||
" @Foo({\"a=foo\", \"a.b=bar\", \"a.c=baz\"}) A hierarchicallySorted();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"a.b=bar\", \"a.c=baz\", \"a=foo\"}) A hierarchicallyUnsorted();",
|
||||
" @Foo(ints = {})",
|
||||
" A noInts();",
|
||||
"",
|
||||
" @JsonPropertyOrder({\"field2\", \"field1\"}) A dto();",
|
||||
" @ApiImplicitParams({@ApiImplicitParam(\"p2\"), @ApiImplicitParam(\"p1\")}) A firstEndpoint();",
|
||||
" @Parameters({@Parameter(name = \"p2\"), @Parameter(name = \"p1\")}) A secondEndpoint();",
|
||||
" @Foo(ints = {0})",
|
||||
" A oneInt();",
|
||||
"",
|
||||
" @Foo(ints = {0, 1})",
|
||||
" A sortedInts();",
|
||||
"",
|
||||
" @Foo(ints = {1, 0})",
|
||||
" A unsortedInts();",
|
||||
"",
|
||||
" @Foo(cls = {})",
|
||||
" A noClasses();",
|
||||
"",
|
||||
" @Foo(cls = {int.class})",
|
||||
" A oneClass();",
|
||||
"",
|
||||
" @Foo(cls = {int.class, long.class})",
|
||||
" A sortedClasses();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(cls = {long.class, int.class})",
|
||||
" A unsortedClasses();",
|
||||
"",
|
||||
" @Foo(enums = {})",
|
||||
" A noEnums();",
|
||||
"",
|
||||
" @Foo(enums = {DOWN})",
|
||||
" A oneEnum();",
|
||||
"",
|
||||
" @Foo(enums = {DOWN, UP})",
|
||||
" A sortedEnums();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(enums = {UP, DOWN})",
|
||||
" A unsortedEnums();",
|
||||
"",
|
||||
" @Foo(anns = {})",
|
||||
" A noAnns();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"a\")})",
|
||||
" A oneAnn();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar(\"b\")})",
|
||||
" A sortedAnns();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" A unsortedAnns();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"b\", \"a\"})})",
|
||||
" A unsortedInnderAnns();",
|
||||
"",
|
||||
" @Foo({\"a=foo\", \"a.b=bar\", \"a.c=baz\"})",
|
||||
" A hierarchicallySorted();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"a.b=bar\", \"a.c=baz\", \"a=foo\"})",
|
||||
" A hierarchicallyUnsorted();",
|
||||
"",
|
||||
" @JsonPropertyOrder({\"field2\", \"field1\"})",
|
||||
" A dto();",
|
||||
"",
|
||||
" @ApiImplicitParams({@ApiImplicitParam(\"p2\"), @ApiImplicitParam(\"p1\")})",
|
||||
" A firstEndpoint();",
|
||||
"",
|
||||
" @Parameters({@Parameter(name = \"p2\"), @Parameter(name = \"p1\")})",
|
||||
" A secondEndpoint();",
|
||||
"",
|
||||
" @XmlType(propOrder = {\"field2\", \"field1\"})",
|
||||
" class Dummy {}",
|
||||
@@ -109,16 +158,19 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
refactoringTestHelper
|
||||
.addInputLines(
|
||||
"in/A.java",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"import static java.math.RoundingMode.DOWN;",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"",
|
||||
"import java.math.RoundingMode;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" Class<?>[] cls() default {};",
|
||||
"",
|
||||
" RoundingMode[] enums() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -126,24 +178,36 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
" String[] value() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @Foo({\"b\", \"a\"}) A unsortedString();",
|
||||
" @Foo(cls = {long.class, int.class}) A unsortedClasses();",
|
||||
" @Foo(enums = {UP, DOWN}) A unsortedEnums();",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) A unsortedAnns();",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"b\", \"a\"})}) A unsortedInnderAnns();",
|
||||
" @Foo({\"b\", \"a\"})",
|
||||
" A unsortedString();",
|
||||
"",
|
||||
" @Foo(cls = {long.class, int.class})",
|
||||
" A unsortedClasses();",
|
||||
"",
|
||||
" @Foo(enums = {UP, DOWN})",
|
||||
" A unsortedEnums();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" A unsortedAnns();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"b\", \"a\"})})",
|
||||
" A unsortedInnderAnns();",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"import static java.math.RoundingMode.DOWN;",
|
||||
"import static java.math.RoundingMode.UP;",
|
||||
"",
|
||||
"import java.math.RoundingMode;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" Class<?>[] cls() default {};",
|
||||
"",
|
||||
" RoundingMode[] enums() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -151,11 +215,20 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
" String[] value() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @Foo({\"a\", \"b\"}) A unsortedString();",
|
||||
" @Foo(cls = {int.class, long.class}) A unsortedClasses();",
|
||||
" @Foo(enums = {DOWN, UP}) A unsortedEnums();",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar(\"b\")}) A unsortedAnns();",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"a\", \"b\"})}) A unsortedInnderAnns();",
|
||||
" @Foo({\"a\", \"b\"})",
|
||||
" A unsortedString();",
|
||||
"",
|
||||
" @Foo(cls = {int.class, long.class})",
|
||||
" A unsortedClasses();",
|
||||
"",
|
||||
" @Foo(enums = {DOWN, UP})",
|
||||
" A unsortedEnums();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar(\"b\")})",
|
||||
" A unsortedAnns();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"a\"), @Bar({\"a\", \"b\"})})",
|
||||
" A unsortedInnderAnns();",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
@@ -171,28 +244,40 @@ public final class LexicographicalAnnotationAttributeListingCheckTest {
|
||||
"interface A {",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" String[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @interface Bar {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" String[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" @interface Baz {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" String[] value2() default {};",
|
||||
" }",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo({\"b\", \"a\"}) A fooValue();",
|
||||
" @Foo({\"b\", \"a\"})",
|
||||
" A fooValue();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Foo(value2 = {\"b\", \"a\"}) A fooValue2();",
|
||||
" @Bar({\"b\", \"a\"}) A barValue();",
|
||||
" @Foo(value2 = {\"b\", \"a\"})",
|
||||
" A fooValue2();",
|
||||
"",
|
||||
" @Bar({\"b\", \"a\"})",
|
||||
" A barValue();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @Bar(value2 = {\"b\", \"a\"}) A barValue2();",
|
||||
" @Baz({\"b\", \"a\"}) A bazValue();",
|
||||
" @Baz(value2 = {\"b\", \"a\"}) A bazValue2();",
|
||||
" @Bar(value2 = {\"b\", \"a\"})",
|
||||
" A barValue2();",
|
||||
"",
|
||||
" @Baz({\"b\", \"a\"})",
|
||||
" A bazValue();",
|
||||
"",
|
||||
" @Baz(value2 = {\"b\", \"a\"})",
|
||||
" A bazValue2();",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class LexicographicalAnnotationListingCheckTest {
|
||||
final class LexicographicalAnnotationListingCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(LexicographicalAnnotationListingCheck.class, getClass())
|
||||
.expectErrorMessage(
|
||||
@@ -27,7 +27,9 @@ public final class LexicographicalAnnotationListingCheckTest {
|
||||
" @Repeatable(Foos.class)",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] ints() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -40,33 +42,70 @@ public final class LexicographicalAnnotationListingCheckTest {
|
||||
" }",
|
||||
"",
|
||||
" @interface Foos {",
|
||||
" Foo[] value();",
|
||||
" Foo[] value();",
|
||||
" }",
|
||||
"",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Foo @Bar A unsortedSimpleCase();",
|
||||
" @Foo",
|
||||
" @Bar",
|
||||
" A unsortedSimpleCase();",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Foo() @Bar() A unsortedWithParens();",
|
||||
" @Foo() A onlyOneAnnotation();",
|
||||
" @Bar @Foo() A sortedAnnotationsOneWithParens();",
|
||||
" @Foo()",
|
||||
" @Bar()",
|
||||
" A unsortedWithParens();",
|
||||
"",
|
||||
" @Foo()",
|
||||
" A onlyOneAnnotation();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Foo()",
|
||||
" A sortedAnnotationsOneWithParens();",
|
||||
"",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Foo @Baz @Bar A threeUnsortedAnnotationsSameInitialLetter();",
|
||||
" @Foo",
|
||||
" @Baz",
|
||||
" @Bar",
|
||||
" A threeUnsortedAnnotationsSameInitialLetter();",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Bar @Foo() @Baz A firstOrderedWithTwoUnsortedAnnotations();",
|
||||
" @Bar @Baz @Foo() A threeSortedAnnotations();",
|
||||
" @Bar",
|
||||
" @Foo()",
|
||||
" @Baz",
|
||||
" A firstOrderedWithTwoUnsortedAnnotations();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Baz",
|
||||
" @Foo()",
|
||||
" A threeSortedAnnotations();",
|
||||
"",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Foo({\"b\"}) @Bar({\"a\"}) A unsortedWithStringAttributes();",
|
||||
" @Foo({\"b\"})",
|
||||
" @Bar({\"a\"})",
|
||||
" A unsortedWithStringAttributes();",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Baz(str = {\"a\", \"b\"}) @Foo(ints = {1, 0}) @Bar A unsortedWithAttributes();",
|
||||
" @Baz(str = {\"a\", \"b\"})",
|
||||
" @Foo(ints = {1, 0})",
|
||||
" @Bar",
|
||||
" A unsortedWithAttributes();",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Bar @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Baz A unsortedWithNestedBar();",
|
||||
" @Bar @Baz @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) A sortedWithNestedBar();",
|
||||
" @Bar",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Baz",
|
||||
" A unsortedWithNestedBar();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Foo(ints = {1, 2}) @Foo({\"b\"}) A sortedRepeatableAnnotation();",
|
||||
" @Bar",
|
||||
" @Baz",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" A sortedWithNestedBar();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" @Foo({\"b\"})",
|
||||
" A sortedRepeatableAnnotation();",
|
||||
" // BUG: Diagnostic matches: X",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Bar @Foo(ints = {1, 2}) A unsortedRepeatableAnnotation();",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Bar",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" A unsortedRepeatableAnnotation();",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -77,11 +116,14 @@ public final class LexicographicalAnnotationListingCheckTest {
|
||||
.addInputLines(
|
||||
"in/A.java",
|
||||
"import java.lang.annotation.Repeatable;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @Repeatable(Foos.class)",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] ints() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -94,29 +136,56 @@ public final class LexicographicalAnnotationListingCheckTest {
|
||||
" }",
|
||||
"",
|
||||
" @interface Foos {",
|
||||
" Foo[] value();",
|
||||
" Foo[] value();",
|
||||
" }",
|
||||
"",
|
||||
" @Bar A singleAnnotation();",
|
||||
" @Bar @Foo A sortedAnnotations();",
|
||||
" @Foo @Bar A unsortedAnnotations();",
|
||||
" @Foo() @Baz() @Bar A unsortedAnnotationsWithSomeParens();",
|
||||
" @Bar",
|
||||
" A singleAnnotation();",
|
||||
"",
|
||||
" @Bar @Baz(str = {\"a\", \"b\"}) @Foo() A unsortedAnnotationsOneContainingAttributes();",
|
||||
" @Baz(str = {\"a\", \"b\"}) @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Bar({\"b\"}) A unsortedAnnotationsWithAttributes();",
|
||||
" @Bar",
|
||||
" @Foo",
|
||||
" A sortedAnnotations();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Foo(ints = {1, 2}) @Foo({\"b\"}) A sortedRepeatableAnnotation();",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Bar @Foo(ints = {1, 2}) A unsortedRepeatableAnnotation();",
|
||||
" @Foo",
|
||||
" @Bar",
|
||||
" A unsortedAnnotations();",
|
||||
"",
|
||||
" @Foo()",
|
||||
" @Baz()",
|
||||
" @Bar",
|
||||
" A unsortedAnnotationsWithSomeParens();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Baz(str = {\"a\", \"b\"})",
|
||||
" @Foo()",
|
||||
" A unsortedAnnotationsOneContainingAttributes();",
|
||||
"",
|
||||
" @Baz(str = {\"a\", \"b\"})",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Bar({\"b\"})",
|
||||
" A unsortedAnnotationsWithAttributes();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" @Foo({\"b\"})",
|
||||
" A sortedRepeatableAnnotation();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Bar",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" A unsortedRepeatableAnnotation();",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
"import java.lang.annotation.Repeatable;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @Repeatable(Foos.class)",
|
||||
" @interface Foo {",
|
||||
" String[] value() default {};",
|
||||
"",
|
||||
" int[] ints() default {};",
|
||||
"",
|
||||
" Bar[] anns() default {};",
|
||||
" }",
|
||||
"",
|
||||
@@ -129,19 +198,44 @@ public final class LexicographicalAnnotationListingCheckTest {
|
||||
" }",
|
||||
"",
|
||||
" @interface Foos {",
|
||||
" Foo[] value();",
|
||||
" Foo[] value();",
|
||||
" }",
|
||||
" @Bar A singleAnnotation();",
|
||||
" @Bar @Foo A sortedAnnotations();",
|
||||
" @Bar @Foo A unsortedAnnotations();",
|
||||
" @Bar @Baz() @Foo() A unsortedAnnotationsWithSomeParens();",
|
||||
"",
|
||||
" @Bar @Baz(str = {\"a\", \"b\"}) @Foo() A unsortedAnnotationsOneContainingAttributes();",
|
||||
" @Bar({\"b\"}) @Baz(str = {\"a\", \"b\"}) @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) A unsortedAnnotationsWithAttributes();",
|
||||
" @Bar",
|
||||
" A singleAnnotation();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Foo(ints = {1, 2}) @Foo({\"b\"}) A sortedRepeatableAnnotation();",
|
||||
" @Bar @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")}) @Foo(ints = {1, 2}) A unsortedRepeatableAnnotation();",
|
||||
" @Bar",
|
||||
" @Foo",
|
||||
" A sortedAnnotations();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Foo",
|
||||
" A unsortedAnnotations();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Baz()",
|
||||
" @Foo()",
|
||||
" A unsortedAnnotationsWithSomeParens();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Baz(str = {\"a\", \"b\"})",
|
||||
" @Foo()",
|
||||
" A unsortedAnnotationsOneContainingAttributes();",
|
||||
"",
|
||||
" @Bar({\"b\"})",
|
||||
" @Baz(str = {\"a\", \"b\"})",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" A unsortedAnnotationsWithAttributes();",
|
||||
"",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" @Foo({\"b\"})",
|
||||
" A sortedRepeatableAnnotation();",
|
||||
"",
|
||||
" @Bar",
|
||||
" @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})",
|
||||
" @Foo(ints = {1, 2})",
|
||||
" A unsortedRepeatableAnnotation();",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class MethodMatcherFactoryTest {
|
||||
final class MethodMatcherFactoryTest {
|
||||
/** A {@link BugChecker} which flags method invocations matched by {@link #TEST_MATCHER}. */
|
||||
@BugPattern(
|
||||
name = "MatchedMethodsFlagger",
|
||||
@@ -68,13 +68,21 @@ public final class MethodMatcherFactoryTest {
|
||||
"",
|
||||
"public class A {",
|
||||
" public void m1() {}",
|
||||
"",
|
||||
" public void m1(String s) {}",
|
||||
"",
|
||||
" public void m1(int i, int j) {}",
|
||||
"",
|
||||
" public void m2() {}",
|
||||
"",
|
||||
" public void m2(String s) {}",
|
||||
"",
|
||||
" public void m2(int i, int j) {}",
|
||||
"",
|
||||
" public void m3() {}",
|
||||
"",
|
||||
" public void m3(String s) {}",
|
||||
"",
|
||||
" public void m3(int i, int j) {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
@@ -83,13 +91,21 @@ public final class MethodMatcherFactoryTest {
|
||||
"",
|
||||
"public class B {",
|
||||
" public void m1() {}",
|
||||
"",
|
||||
" public void m1(String s) {}",
|
||||
"",
|
||||
" public void m1(int i, int j) {}",
|
||||
"",
|
||||
" public void m2() {}",
|
||||
"",
|
||||
" public void m2(String s) {}",
|
||||
"",
|
||||
" public void m2(int i, int j) {}",
|
||||
"",
|
||||
" public void m3() {}",
|
||||
"",
|
||||
" public void m3(String s) {}",
|
||||
"",
|
||||
" public void m3(int i, int j) {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
@@ -98,13 +114,21 @@ public final class MethodMatcherFactoryTest {
|
||||
"",
|
||||
"public class A {",
|
||||
" public static void m1() {}",
|
||||
"",
|
||||
" public static void m1(String s) {}",
|
||||
"",
|
||||
" public static void m1(int i, int j) {}",
|
||||
"",
|
||||
" public static void m2() {}",
|
||||
"",
|
||||
" public static void m2(String s) {}",
|
||||
"",
|
||||
" public static void m2(int i, int j) {}",
|
||||
"",
|
||||
" public static void m3() {}",
|
||||
"",
|
||||
" public static void m3(String s) {}",
|
||||
"",
|
||||
" public static void m3(int i, int j) {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
@@ -113,13 +137,21 @@ public final class MethodMatcherFactoryTest {
|
||||
"",
|
||||
"public class B {",
|
||||
" public static void m1() {}",
|
||||
"",
|
||||
" public static void m1(String s) {}",
|
||||
"",
|
||||
" public static void m1(int i, int j) {}",
|
||||
"",
|
||||
" public static void m2() {}",
|
||||
"",
|
||||
" public static void m2(String s) {}",
|
||||
"",
|
||||
" public static void m2(int i, int j) {}",
|
||||
"",
|
||||
" public static void m3() {}",
|
||||
"",
|
||||
" public static void m3(String s) {}",
|
||||
"",
|
||||
" public static void m3(int i, int j) {}",
|
||||
"}")
|
||||
.addSourceLines(
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class MethodReferenceUsageCheckTest {
|
||||
final class MethodReferenceUsageCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(MethodReferenceUsageCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -17,37 +17,62 @@ public final class MethodReferenceUsageCheckTest {
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import com.google.common.collect.Streams;",
|
||||
"import java.util.Map;",
|
||||
"import java.util.HashMap;",
|
||||
"import java.util.stream.Stream;",
|
||||
"import java.util.Map;",
|
||||
"import java.util.function.IntConsumer;",
|
||||
"import java.util.function.IntFunction;",
|
||||
"import java.util.stream.Stream;",
|
||||
"",
|
||||
"class A {",
|
||||
" private final Stream<Integer> s = Stream.of(1);",
|
||||
" private final Map<Integer, Integer> m = new HashMap<>();",
|
||||
" private final Runnable thrower = () -> { throw new RuntimeException(); };",
|
||||
" private final Runnable thrower =",
|
||||
" () -> {",
|
||||
" throw new RuntimeException();",
|
||||
" };",
|
||||
"",
|
||||
" void unaryExternalStaticFunctionCalls() {",
|
||||
" s.forEach(String::valueOf);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> String.valueOf(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach((v) -> { String.valueOf(v); });",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach((Integer v) -> { { String.valueOf(v); } });",
|
||||
" s.forEach(v -> { String.valueOf(v); String.valueOf(v); });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (v) -> {",
|
||||
" String.valueOf(v);",
|
||||
" });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (Integer v) -> {",
|
||||
" {",
|
||||
" String.valueOf(v);",
|
||||
" }",
|
||||
" });",
|
||||
" s.forEach(",
|
||||
" v -> {",
|
||||
" String.valueOf(v);",
|
||||
" String.valueOf(v);",
|
||||
" });",
|
||||
"",
|
||||
" s.map(String::valueOf);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.map(v -> String.valueOf(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.map((v) -> (String.valueOf(v)));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.map((Integer v) -> { return String.valueOf(v); });",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.map((final Integer v) -> { return (String.valueOf(v)); });",
|
||||
" s.map(v -> { String.valueOf(v); return String.valueOf(v); });",
|
||||
" s.map(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (Integer v) -> {",
|
||||
" return String.valueOf(v);",
|
||||
" });",
|
||||
" s.map(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (final Integer v) -> {",
|
||||
" return (String.valueOf(v));",
|
||||
" });",
|
||||
" s.map(",
|
||||
" v -> {",
|
||||
" String.valueOf(v);",
|
||||
" return String.valueOf(v);",
|
||||
" });",
|
||||
"",
|
||||
" s.findFirst().orElseGet(() -> Integer.valueOf(\"0\"));",
|
||||
" m.forEach((k, v) -> String.valueOf(v));",
|
||||
@@ -59,14 +84,34 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> m.put(k, v));",
|
||||
" m.forEach((k, v) -> m.put(v, k));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((Integer k, Integer v) -> { m.put(k, v); });",
|
||||
" m.forEach((k, v) -> { m.put(k, k); });",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((final Integer k, final Integer v) -> { { m.put(k, v); } });",
|
||||
" m.forEach((k, v) -> { { m.put(v, v); } });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (Integer k, Integer v) -> {",
|
||||
" m.put(k, v);",
|
||||
" });",
|
||||
" m.forEach(",
|
||||
" (k, v) -> {",
|
||||
" m.put(k, k);",
|
||||
" });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (final Integer k, final Integer v) -> {",
|
||||
" {",
|
||||
" m.put(k, v);",
|
||||
" }",
|
||||
" });",
|
||||
" m.forEach(",
|
||||
" (k, v) -> {",
|
||||
" {",
|
||||
" m.put(v, v);",
|
||||
" }",
|
||||
" });",
|
||||
" m.forEach((k, v) -> new HashMap<Integer, Integer>().put(k, v));",
|
||||
" m.forEach((k, v) -> { m.put(k, v); m.put(k, v); });",
|
||||
" m.forEach(",
|
||||
" (k, v) -> {",
|
||||
" m.put(k, v);",
|
||||
" m.put(k, v);",
|
||||
" });",
|
||||
"",
|
||||
" Streams.zip(s, s, m::put);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
@@ -75,20 +120,45 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Streams.zip(s, s, (Integer a, Integer b) -> (m.put(a, b)));",
|
||||
" Streams.zip(s, s, (a, b) -> (m.put(a, a)));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Streams.zip(s, s, (final Integer a, final Integer b) -> { return m.put(a, b); });",
|
||||
" Streams.zip(s, s, (a, b) -> { return m.put(b, b); });",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Streams.zip(s, s, (a, b) -> { return (m.put(a, b)); });",
|
||||
" Streams.zip(s, s, (a, b) -> { return (m.put(b, a)); });",
|
||||
" Streams.zip(s, s, (a, b) -> { m.put(a, b); return m.put(a, b); });",
|
||||
" Streams.zip(",
|
||||
" s,",
|
||||
" s,",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (final Integer a, final Integer b) -> {",
|
||||
" return m.put(a, b);",
|
||||
" });",
|
||||
" Streams.zip(",
|
||||
" s,",
|
||||
" s,",
|
||||
" (a, b) -> {",
|
||||
" return m.put(b, b);",
|
||||
" });",
|
||||
" Streams.zip(",
|
||||
" s,",
|
||||
" s,",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (a, b) -> {",
|
||||
" return (m.put(a, b));",
|
||||
" });",
|
||||
" Streams.zip(",
|
||||
" s,",
|
||||
" s,",
|
||||
" (a, b) -> {",
|
||||
" return (m.put(b, a));",
|
||||
" });",
|
||||
" Streams.zip(",
|
||||
" s,",
|
||||
" s,",
|
||||
" (a, b) -> {",
|
||||
" m.put(a, b);",
|
||||
" return m.put(a, b);",
|
||||
" });",
|
||||
" }",
|
||||
"",
|
||||
" void nullaryExternalInstanceFunctionCalls() {",
|
||||
" s.map(Integer::doubleValue);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.map(i -> i.doubleValue());",
|
||||
// `s.map(Integer::toString)` is ambiguous
|
||||
" s.map(i -> i.toString());",
|
||||
" s.map(i -> s.toString());",
|
||||
"",
|
||||
@@ -108,24 +178,36 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" s.forEach(this::ivoid1);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> ivoid1(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> { ivoid1(v); });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" v -> {",
|
||||
" ivoid1(v);",
|
||||
" });",
|
||||
" s.forEach(this::iint1);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> iint1(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> { iint1(v); });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" v -> {",
|
||||
" iint1(v);",
|
||||
" });",
|
||||
"",
|
||||
" s.forEach(A::svoid1);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> svoid1(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> { svoid1(v); });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" v -> {",
|
||||
" svoid1(v);",
|
||||
" });",
|
||||
" s.forEach(A::sint1);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> sint1(v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" s.forEach(v -> { sint1(v); });",
|
||||
" s.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" v -> {",
|
||||
" sint1(v);",
|
||||
" });",
|
||||
"",
|
||||
" s.forEach(v -> ivoid2(v, v));",
|
||||
" s.forEach(v -> iint2(v, v));",
|
||||
@@ -140,28 +222,43 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" m.forEach(this::ivoid2);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> ivoid2(k, v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> { ivoid2(k, v); });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (k, v) -> {",
|
||||
" ivoid2(k, v);",
|
||||
" });",
|
||||
" m.forEach(this::iint2);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> iint2(k, v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> { iint2(k, v); });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (k, v) -> {",
|
||||
" iint2(k, v);",
|
||||
" });",
|
||||
"",
|
||||
" m.forEach(A::svoid2);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> svoid2(k, v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> { svoid2(k, v); });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (k, v) -> {",
|
||||
" svoid2(k, v);",
|
||||
" });",
|
||||
" m.forEach(A::sint2);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> sint2(k, v));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" m.forEach((k, v) -> { sint2(k, v); });",
|
||||
" m.forEach(",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" (k, v) -> {",
|
||||
" sint2(k, v);",
|
||||
" });",
|
||||
" }",
|
||||
"",
|
||||
" void functionCallsWhoseReplacementWouldBeAmbiguous() {",
|
||||
" receiver(i -> { Integer.toString(i); });",
|
||||
" receiver(",
|
||||
" i -> {",
|
||||
" Integer.toString(i);",
|
||||
" });",
|
||||
" }",
|
||||
"",
|
||||
" void assortedOtherEdgeCases() {",
|
||||
@@ -175,23 +272,47 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" TernaryOp o7 = (a, b, c) -> b.concat(c);",
|
||||
" }",
|
||||
"",
|
||||
" void receiver(IntFunction<?> op) { }",
|
||||
" void receiver(IntConsumer op) { }",
|
||||
" void receiver(IntFunction<?> op) {}",
|
||||
"",
|
||||
" void ivoid0() { }",
|
||||
" void ivoid1(int a) { }",
|
||||
" void ivoid2(int a, int b) { }",
|
||||
" int iint0() { return 0; }",
|
||||
" int iint1(int a) { return 0; }",
|
||||
" int iint2(int a, int b) { return 0; }",
|
||||
" void receiver(IntConsumer op) {}",
|
||||
"",
|
||||
" static void svoid0() { }",
|
||||
" static void svoid1(int a) { }",
|
||||
" static void svoid2(int a, int b) { }",
|
||||
" static void svoid3(int a, int b, int c) { }",
|
||||
" static int sint0() { return 0; }",
|
||||
" static int sint1(int a) { return 0; }",
|
||||
" static int sint2(int a, int b) { return 0; }",
|
||||
" void ivoid0() {}",
|
||||
"",
|
||||
" void ivoid1(int a) {}",
|
||||
"",
|
||||
" void ivoid2(int a, int b) {}",
|
||||
"",
|
||||
" int iint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" int iint1(int a) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" int iint2(int a, int b) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static void svoid0() {}",
|
||||
"",
|
||||
" static void svoid1(int a) {}",
|
||||
"",
|
||||
" static void svoid2(int a, int b) {}",
|
||||
"",
|
||||
" static void svoid3(int a, int b, int c) {}",
|
||||
"",
|
||||
" static int sint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static int sint1(int a) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static int sint2(int a, int b) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" interface TernaryOp {",
|
||||
" String collect(String a, String b, String c);",
|
||||
@@ -210,9 +331,6 @@ public final class MethodReferenceUsageCheckTest {
|
||||
"import java.util.Collections;",
|
||||
"import java.util.List;",
|
||||
"import java.util.Map;",
|
||||
// Don't import `java.util.Set`; it should be added.
|
||||
"import java.util.function.IntConsumer;",
|
||||
"import java.util.function.IntFunction;",
|
||||
"import java.util.function.IntSupplier;",
|
||||
"import java.util.function.Supplier;",
|
||||
"import java.util.stream.Stream;",
|
||||
@@ -245,12 +363,19 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" Stream.of((Map<?, ?>) null).map(Map::keySet).map(s -> s.size());",
|
||||
" }",
|
||||
"",
|
||||
" @Override int iint0() { return 0; }",
|
||||
" @Override",
|
||||
" int iint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" int iint0() { return 0; }",
|
||||
" int iint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static int sint0() { return 0; }",
|
||||
" static int sint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
@@ -260,8 +385,6 @@ public final class MethodReferenceUsageCheckTest {
|
||||
"import java.util.List;",
|
||||
"import java.util.Map;",
|
||||
"import java.util.Set;",
|
||||
"import java.util.function.IntConsumer;",
|
||||
"import java.util.function.IntFunction;",
|
||||
"import java.util.function.IntSupplier;",
|
||||
"import java.util.function.Supplier;",
|
||||
"import java.util.stream.Stream;",
|
||||
@@ -294,12 +417,19 @@ public final class MethodReferenceUsageCheckTest {
|
||||
" Stream.of((Map<?, ?>) null).map(Map::keySet).map(Set::size);",
|
||||
" }",
|
||||
"",
|
||||
" @Override int iint0() { return 0; }",
|
||||
" @Override",
|
||||
" int iint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" int iint0() { return 0; }",
|
||||
" int iint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static int sint0() { return 0; }",
|
||||
" static int sint0() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import static com.google.common.base.Predicates.containsPattern;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class MissingRefasterAnnotationCheckTest {
|
||||
final class MissingRefasterAnnotationCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(MissingRefasterAnnotationCheck.class, getClass())
|
||||
.expectErrorMessage(
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class MockitoStubbingCheckTest {
|
||||
final class MockitoStubbingCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(MockitoStubbingCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -42,8 +42,10 @@ public final class MockitoStubbingCheckTest {
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(0, \"foo\");",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(eq(0), notNull());",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(notNull(), eq(\"foo\"));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(ArgumentMatchers.eq(0), ArgumentMatchers.eq(\"foo\"));",
|
||||
" doAnswer(inv -> null)",
|
||||
" .when(biConsumer)",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .accept(ArgumentMatchers.eq(0), ArgumentMatchers.eq(\"foo\"));",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(eq(hashCode()), eq(toString()));",
|
||||
" }",
|
||||
@@ -71,7 +73,9 @@ public final class MockitoStubbingCheckTest {
|
||||
" doAnswer(inv -> null).when(consumer).accept(eq(toString()));",
|
||||
"",
|
||||
" BiConsumer<Integer, String> biConsumer = mock(BiConsumer.class);",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(ArgumentMatchers.eq(0), ArgumentMatchers.eq(\"foo\"));",
|
||||
" doAnswer(inv -> null)",
|
||||
" .when(biConsumer)",
|
||||
" .accept(ArgumentMatchers.eq(0), ArgumentMatchers.eq(\"foo\"));",
|
||||
" doAnswer(inv -> null).when(biConsumer).accept(eq(hashCode()), eq(toString()));",
|
||||
" }",
|
||||
"}")
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class PrimitiveComparisonCheckTest {
|
||||
final class PrimitiveComparisonCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(PrimitiveComparisonCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -99,10 +99,21 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparingDouble(o -> Byte.valueOf((byte) 0));",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private byte toPrimitive(Object o) { return 0; }",
|
||||
" private Byte toBoxed(Object o) { return 0; }",
|
||||
" private Function<Object, Byte> toBoxed() { return o -> 0; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private byte toPrimitive(Object o) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" private Byte toBoxed(Object o) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, Byte> toBoxed() {",
|
||||
" return o -> 0;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -191,11 +202,25 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparingDouble(o -> Integer.valueOf(0));",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private int toPrimitive(Object o) { return 0; }",
|
||||
" private Integer toBoxed(Object o) { return 0; }",
|
||||
" private Function<Object, Integer> toBoxed() { return o -> 0; }",
|
||||
" private ToIntFunction<Object> toPrimitive() { return o -> 0; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private int toPrimitive(Object o) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" private Integer toBoxed(Object o) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, Integer> toBoxed() {",
|
||||
" return o -> 0;",
|
||||
" }",
|
||||
"",
|
||||
" private ToIntFunction<Object> toPrimitive() {",
|
||||
" return o -> 0;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -268,11 +293,25 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparingDouble(o -> Long.valueOf(0));",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private long toPrimitive(Object o) { return 0L; }",
|
||||
" private Long toBoxed(Object o) { return 0L; }",
|
||||
" private Function<Object, Long> toBoxed() { return o -> 0L; }",
|
||||
" private ToLongFunction<Object> toPrimitive() { return o -> 0L; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private long toPrimitive(Object o) {",
|
||||
" return 0L;",
|
||||
" }",
|
||||
"",
|
||||
" private Long toBoxed(Object o) {",
|
||||
" return 0L;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, Long> toBoxed() {",
|
||||
" return o -> 0L;",
|
||||
" }",
|
||||
"",
|
||||
" private ToLongFunction<Object> toPrimitive() {",
|
||||
" return o -> 0L;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -326,10 +365,21 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparingDouble(o -> Float.valueOf(0));",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private float toPrimitive(Object o) { return 0.0f; }",
|
||||
" private Float toBoxed(Object o) { return 0.0f; }",
|
||||
" private Function<Object, Float> toBoxed() { return o -> 0.0f; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private float toPrimitive(Object o) {",
|
||||
" return 0.0f;",
|
||||
" }",
|
||||
"",
|
||||
" private Float toBoxed(Object o) {",
|
||||
" return 0.0f;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, Float> toBoxed() {",
|
||||
" return o -> 0.0f;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -386,11 +436,25 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparingDouble(o -> Double.valueOf(0));",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private double toPrimitive(Object o) { return 0.0; }",
|
||||
" private Double toBoxed(Object o) { return 0.0; }",
|
||||
" private Function<Object, Double> toBoxed() { return o -> 0.0; }",
|
||||
" private ToDoubleFunction<Object> toPrimitive() { return o -> 0.0; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private double toPrimitive(Object o) {",
|
||||
" return 0.0;",
|
||||
" }",
|
||||
"",
|
||||
" private Double toBoxed(Object o) {",
|
||||
" return 0.0;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, Double> toBoxed() {",
|
||||
" return o -> 0.0;",
|
||||
" }",
|
||||
"",
|
||||
" private ToDoubleFunction<Object> toPrimitive() {",
|
||||
" return o -> 0.0;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -420,8 +484,13 @@ public final class PrimitiveComparisonCheckTest {
|
||||
" cmp().thenComparing(toStr(), cmp());",
|
||||
" }",
|
||||
"",
|
||||
" private Comparator<Object> cmp() { return null; }",
|
||||
" private Function<Object, String> toStr() { return String::valueOf; }",
|
||||
" private Comparator<Object> cmp() {",
|
||||
" return null;",
|
||||
" }",
|
||||
"",
|
||||
" private Function<Object, String> toStr() {",
|
||||
" return String::valueOf;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -692,22 +761,30 @@ public final class PrimitiveComparisonCheckTest {
|
||||
"import java.util.Comparator;",
|
||||
"",
|
||||
"interface A extends Comparable<A> {",
|
||||
" Comparator<A> bCmp = Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Byte.valueOf((byte) 0));",
|
||||
" Comparator<A> cCmp = Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Character.valueOf((char) 0));",
|
||||
" Comparator<A> sCmp = Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Short.valueOf((short) 0));",
|
||||
" Comparator<A> bCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Byte.valueOf((byte) 0));",
|
||||
" Comparator<A> cCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Character.valueOf((char) 0));",
|
||||
" Comparator<A> sCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Short.valueOf((short) 0));",
|
||||
" Comparator<A> iCmp = Comparator.<A, A>comparing(o -> o).thenComparingInt(o -> Integer.valueOf(0));",
|
||||
" Comparator<A> lCmp = Comparator.<A, A>comparing(o -> o).thenComparingLong(o -> Long.valueOf(0));",
|
||||
" Comparator<A> fCmp = Comparator.<A, A>comparing(o -> o).thenComparingDouble(o -> Float.valueOf(0));",
|
||||
" Comparator<A> dCmp = Comparator.<A, A>comparing(o -> o).thenComparingDouble(o -> Double.valueOf(0));",
|
||||
" Comparator<A> fCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparingDouble(o -> Float.valueOf(0));",
|
||||
" Comparator<A> dCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparingDouble(o -> Double.valueOf(0));",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
"import java.util.Comparator;",
|
||||
"",
|
||||
"interface A extends Comparable<A> {",
|
||||
" Comparator<A> bCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Byte.valueOf((byte) 0));",
|
||||
" Comparator<A> cCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Character.valueOf((char) 0));",
|
||||
" Comparator<A> sCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Short.valueOf((short) 0));",
|
||||
" Comparator<A> bCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparing(o -> Byte.valueOf((byte) 0));",
|
||||
" Comparator<A> cCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparing(o -> Character.valueOf((char) 0));",
|
||||
" Comparator<A> sCmp =",
|
||||
" Comparator.<A, A>comparing(o -> o).thenComparing(o -> Short.valueOf((short) 0));",
|
||||
" Comparator<A> iCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Integer.valueOf(0));",
|
||||
" Comparator<A> lCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Long.valueOf(0));",
|
||||
" Comparator<A> fCmp = Comparator.<A, A>comparing(o -> o).thenComparing(o -> Float.valueOf(0));",
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test;
|
||||
// XXX: The tests below show that `String.valueOf((String) null)` may be simplified, but
|
||||
// `String.valueOf(null)` may not. That is because the latter matches `String#valueOf(char[])`. We
|
||||
// could special-case `null` arguments, but that doesn't seem worth the trouble.
|
||||
public final class RedundantStringConversionCheckTest {
|
||||
final class RedundantStringConversionCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(RedundantStringConversionCheck.class, getClass());
|
||||
private final CompilationTestHelper customizedCompilationTestHelper =
|
||||
@@ -124,7 +124,7 @@ public final class RedundantStringConversionCheckTest {
|
||||
" s + String.valueOf((String) null),",
|
||||
" s + String.valueOf(null),",
|
||||
" s + String.valueOf(new char[0]),",
|
||||
"",
|
||||
" //",
|
||||
" 42 + this.toString(),",
|
||||
" 42 + super.toString(),",
|
||||
" 42 + i.toString(),",
|
||||
@@ -147,7 +147,7 @@ public final class RedundantStringConversionCheckTest {
|
||||
" String.valueOf((String) null) + s,",
|
||||
" String.valueOf(null) + s,",
|
||||
" String.valueOf(new char[0]) + s,",
|
||||
"",
|
||||
" //",
|
||||
" this.toString() + 42,",
|
||||
" super.toString() + 42,",
|
||||
" i.toString() + 42,",
|
||||
@@ -175,10 +175,7 @@ public final class RedundantStringConversionCheckTest {
|
||||
"",
|
||||
" int[] m2() {",
|
||||
" return new int[] {",
|
||||
" 1 + 1,",
|
||||
" 1 - 1,",
|
||||
" 1 * 1,",
|
||||
" 1 / 1,",
|
||||
" 1 + 1, 1 - 1, 1 * 1, 1 / 1,",
|
||||
" };",
|
||||
" }",
|
||||
"}")
|
||||
@@ -284,9 +281,9 @@ public final class RedundantStringConversionCheckTest {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.base.Preconditions.checkState;",
|
||||
"import static com.google.common.base.Preconditions.checkArgument;",
|
||||
"import static com.google.common.base.Preconditions.checkNotNull;",
|
||||
"import static com.google.common.base.Preconditions.checkState;",
|
||||
"import static com.google.common.base.Verify.verify;",
|
||||
"import static com.google.common.base.Verify.verifyNotNull;",
|
||||
"",
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class RefasterAnyOfUsageCheckTest {
|
||||
final class RefasterAnyOfUsageCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(RefasterAnyOfUsageCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
|
||||
@@ -13,12 +13,13 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.ComparisonFailure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public final class RefasterCheckTest {
|
||||
final class RefasterCheckTest {
|
||||
/** The names of all Refaster template groups defined in this module. */
|
||||
private static final ImmutableSet<String> TEMPLATE_GROUPS =
|
||||
ImmutableSet.of(
|
||||
@@ -139,8 +140,7 @@ public final class RefasterCheckTest {
|
||||
assertThatCode(() -> verifyRefactoring(group, namePattern(group, template)))
|
||||
.withFailMessage(
|
||||
"Template %s does not affect the tests for group %s; is it tested?", template, group)
|
||||
.isInstanceOf(AssertionError.class)
|
||||
.hasMessageFindingMatch("^(diff|expected):");
|
||||
.isInstanceOf(ComparisonFailure.class);
|
||||
}
|
||||
|
||||
private static ImmutableSetMultimap<String, String> indexTemplateNamesByGroup(
|
||||
|
||||
@@ -28,7 +28,6 @@ final class RequestMappingAnnotationCheckTest {
|
||||
"import org.springframework.web.bind.annotation.RequestBody;",
|
||||
"import org.springframework.web.bind.annotation.RequestHeader;",
|
||||
"import org.springframework.web.bind.annotation.RequestMapping;",
|
||||
"import org.springframework.web.bind.annotation.RequestMethod;",
|
||||
"import org.springframework.web.bind.annotation.RequestParam;",
|
||||
"import org.springframework.web.context.request.NativeWebRequest;",
|
||||
"import org.springframework.web.context.request.WebRequest;",
|
||||
@@ -38,48 +37,91 @@ final class RequestMappingAnnotationCheckTest {
|
||||
"",
|
||||
"interface A {",
|
||||
" A noMapping();",
|
||||
"",
|
||||
" A noMapping(String param);",
|
||||
" @DeleteMapping A properNoParameters();",
|
||||
" @GetMapping A properPathVariable(@PathVariable String param);",
|
||||
" @PatchMapping A properRequestBody(@RequestBody String body);",
|
||||
" @PostMapping A properRequestHeader(@RequestHeader String header);",
|
||||
" @PutMapping A properRequestParam(@RequestParam String param);",
|
||||
" @RequestMapping A properInputStream(InputStream input);",
|
||||
" @RequestMapping A properZoneId(ZoneId zoneId);",
|
||||
" @RequestMapping A properLocale(Locale locale);",
|
||||
" @RequestMapping A properTimeZone(TimeZone timeZone);",
|
||||
" @RequestMapping A properHttpServletRequest(HttpServletRequest request);",
|
||||
" @RequestMapping A properHttpServletResponse(HttpServletResponse response);",
|
||||
" @RequestMapping A properHttpMethod(HttpMethod method);",
|
||||
" @RequestMapping A properNativeWebRequest(NativeWebRequest request);",
|
||||
" @RequestMapping A properWebRequest(WebRequest request);",
|
||||
" @RequestMapping A properServerWebExchange(ServerWebExchange exchange);",
|
||||
" @RequestMapping A properServerUriBuilder(UriBuilder builder);",
|
||||
" @RequestMapping A properServerUriComponentsBuilder(UriComponentsBuilder builder);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @DeleteMapping A delete(String param);",
|
||||
" @DeleteMapping",
|
||||
" A properNoParameters();",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @GetMapping A get(String param);",
|
||||
" @GetMapping",
|
||||
" A properPathVariable(@PathVariable String param);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @PatchMapping A patch(String param);",
|
||||
" @PatchMapping",
|
||||
" A properRequestBody(@RequestBody String body);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @PostMapping A post(String param);",
|
||||
" @PostMapping",
|
||||
" A properRequestHeader(@RequestHeader String header);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @PutMapping A put(String param);",
|
||||
" @PutMapping",
|
||||
" A properRequestParam(@RequestParam String param);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping A requestMultiple(String param, String param2);",
|
||||
" @RequestMapping",
|
||||
" A properInputStream(InputStream input);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping A requestFirstParamViolation(String param, @PathVariable String param2);",
|
||||
" @RequestMapping",
|
||||
" A properZoneId(ZoneId zoneId);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properLocale(Locale locale);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properTimeZone(TimeZone timeZone);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properHttpServletRequest(HttpServletRequest request);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properHttpServletResponse(HttpServletResponse response);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properHttpMethod(HttpMethod method);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properNativeWebRequest(NativeWebRequest request);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properWebRequest(WebRequest request);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properServerWebExchange(ServerWebExchange exchange);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properServerUriBuilder(UriBuilder builder);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" A properServerUriComponentsBuilder(UriComponentsBuilder builder);",
|
||||
"",
|
||||
" @DeleteMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping A requestSecondParamViolation(@RequestBody String param, String param2);",
|
||||
" A delete(String param);",
|
||||
"",
|
||||
" @GetMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A get(String param);",
|
||||
"",
|
||||
" @PatchMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A patch(String param);",
|
||||
"",
|
||||
" @PostMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A post(String param);",
|
||||
"",
|
||||
" @PutMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A put(String param);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A requestMultiple(String param, String param2);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A requestFirstParamViolation(String param, @PathVariable String param2);",
|
||||
"",
|
||||
" @RequestMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A requestSecondParamViolation(@RequestBody String param, String param2);",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@@ -28,23 +28,36 @@ final class RequestParamTypeCheckTest {
|
||||
"import org.springframework.web.bind.annotation.RequestParam;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @PostMapping A properRequestParam(@RequestBody String body);",
|
||||
" @GetMapping A properRequestParam(@RequestParam int param);",
|
||||
" @GetMapping A properRequestParam(@RequestParam List<String> param);",
|
||||
" @PostMapping A properRequestParam(@RequestBody String body, @RequestParam Set<String> param);",
|
||||
" @PutMapping A properRequestParam(@RequestBody String body, @RequestParam Map<String, String> param);",
|
||||
" @PostMapping",
|
||||
" A properRequestParam(@RequestBody String body);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @GetMapping A get(@RequestParam ImmutableBiMap<String, String> param);",
|
||||
" @GetMapping",
|
||||
" A properRequestParam(@RequestParam int param);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @PostMapping A post(@Nullable @RequestParam ImmutableList<String> param);",
|
||||
" @GetMapping",
|
||||
" A properRequestParam(@RequestParam List<String> param);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @PutMapping A put(@RequestBody String body, @RequestParam ImmutableSet<String> param);",
|
||||
" @PostMapping",
|
||||
" A properRequestParam(@RequestBody String body, @RequestParam Set<String> param);",
|
||||
"",
|
||||
" @PutMapping",
|
||||
" A properRequestParam(@RequestBody String body, @RequestParam Map<String, String> param);",
|
||||
"",
|
||||
" @GetMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @DeleteMapping A delete(@RequestBody String body, @RequestParam ImmutableMap<String, String> param);",
|
||||
" A get(@RequestParam ImmutableBiMap<String, String> param);",
|
||||
"",
|
||||
" @PostMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A post(@Nullable @RequestParam ImmutableList<String> param);",
|
||||
"",
|
||||
" @PutMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A put(@RequestBody String body, @RequestParam ImmutableSet<String> param);",
|
||||
"",
|
||||
" @DeleteMapping",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" A delete(@RequestBody String body, @RequestParam ImmutableMap<String, String> param);",
|
||||
"",
|
||||
" void negative(ImmutableSet<Integer> set, ImmutableMap<String, String> map);",
|
||||
"}")
|
||||
|
||||
@@ -4,10 +4,8 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
||||
public final class ScheduledTransactionTraceCheckTest {
|
||||
final class ScheduledTransactionTraceCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(ScheduledTransactionTraceCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -45,10 +43,7 @@ public final class ScheduledTransactionTraceCheckTest {
|
||||
.doTest();
|
||||
}
|
||||
|
||||
// XXX: Enable this test for all JREs once https://github.com/google/error-prone/pull/2820 is
|
||||
// merged and released.
|
||||
@Test
|
||||
@DisabledForJreRange(min = JRE.JAVA_12)
|
||||
void replacement() {
|
||||
refactoringTestHelper
|
||||
.addInputLines(
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class Slf4jLogStatementCheckTest {
|
||||
final class Slf4jLogStatementCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(Slf4jLogStatementCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -44,7 +44,8 @@ public final class Slf4jLogStatementCheckTest {
|
||||
" LOG.info(marker, s, o, t);",
|
||||
"",
|
||||
" LOG.warn(FMT0);",
|
||||
" // BUG: Diagnostic contains: Log statement contains 0 placeholders, but specifies 1 matching argument(s)",
|
||||
" // BUG: Diagnostic contains: Log statement contains 0 placeholders, but specifies 1 matching",
|
||||
" // argument(s)",
|
||||
" LOG.error(FMT0, o);",
|
||||
" LOG.trace(FMT0, t);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
@@ -56,13 +57,15 @@ public final class Slf4jLogStatementCheckTest {
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.trace(marker, FMT0, o, t);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains: Log statement contains 1 placeholders, but specifies 0 matching argument(s)",
|
||||
" // BUG: Diagnostic contains: Log statement contains 1 placeholders, but specifies 0 matching",
|
||||
" // argument(s)",
|
||||
" LOG.debug(FMT1);",
|
||||
" LOG.info(FMT1, o);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.warn(FMT1, t);",
|
||||
" LOG.error(FMT1, o, t);",
|
||||
" // BUG: Diagnostic contains: Log statement contains 1 placeholders, but specifies 2 matching argument(s)",
|
||||
" // BUG: Diagnostic contains: Log statement contains 1 placeholders, but specifies 2 matching",
|
||||
" // argument(s)",
|
||||
" LOG.trace(FMT1, o, o);",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" LOG.debug(FMT1, o, o, t);",
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class SpringMvcAnnotationCheckTest {
|
||||
final class SpringMvcAnnotationCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(SpringMvcAnnotationCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -19,9 +19,9 @@ public final class SpringMvcAnnotationCheckTest {
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.DELETE;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.GET;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.HEAD;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.PATCH;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.POST;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.PUT;",
|
||||
"import static org.springframework.web.bind.annotation.RequestMethod.PATCH;",
|
||||
"",
|
||||
"import org.springframework.web.bind.annotation.DeleteMapping;",
|
||||
"import org.springframework.web.bind.annotation.GetMapping;",
|
||||
@@ -32,28 +32,53 @@ public final class SpringMvcAnnotationCheckTest {
|
||||
"import org.springframework.web.bind.annotation.RequestMethod;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @RequestMapping A simple();",
|
||||
" @RequestMapping(method = {}) A explicitDefault();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = RequestMethod.GET) A get();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {RequestMethod.POST}) A post();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {PUT}) A put();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {DELETE}) A delete();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {PATCH}) A patch();",
|
||||
" @RequestMapping(method = HEAD) A head();",
|
||||
" @RequestMapping(method = RequestMethod.OPTIONS) A options();",
|
||||
" @RequestMapping(method = {GET, POST}) A simpleMix();",
|
||||
" @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) A verboseMix();",
|
||||
" @RequestMapping",
|
||||
" A simple();",
|
||||
"",
|
||||
" @DeleteMapping A properDelete();",
|
||||
" @GetMapping A properGet();",
|
||||
" @PatchMapping A properPatch();",
|
||||
" @PostMapping A properPost();",
|
||||
" @PutMapping A properPut();",
|
||||
" @RequestMapping(method = {})",
|
||||
" A explicitDefault();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = RequestMethod.GET)",
|
||||
" A get();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {RequestMethod.POST})",
|
||||
" A post();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {PUT})",
|
||||
" A put();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {DELETE})",
|
||||
" A delete();",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" @RequestMapping(method = {PATCH})",
|
||||
" A patch();",
|
||||
"",
|
||||
" @RequestMapping(method = HEAD)",
|
||||
" A head();",
|
||||
"",
|
||||
" @RequestMapping(method = RequestMethod.OPTIONS)",
|
||||
" A options();",
|
||||
"",
|
||||
" @RequestMapping(method = {GET, POST})",
|
||||
" A simpleMix();",
|
||||
"",
|
||||
" @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})",
|
||||
" A verboseMix();",
|
||||
"",
|
||||
" @DeleteMapping",
|
||||
" A properDelete();",
|
||||
"",
|
||||
" @GetMapping",
|
||||
" A properGet();",
|
||||
"",
|
||||
" @PatchMapping",
|
||||
" A properPatch();",
|
||||
"",
|
||||
" @PostMapping",
|
||||
" A properPost();",
|
||||
"",
|
||||
" @PutMapping",
|
||||
" A properPut();",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
@@ -71,11 +96,25 @@ public final class SpringMvcAnnotationCheckTest {
|
||||
"import org.springframework.web.bind.annotation.RequestMethod;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @RequestMapping(method = RequestMethod.GET) A simple();",
|
||||
" @RequestMapping(path = \"/foo/bar\", method = POST) A prefixed();",
|
||||
" @RequestMapping(method = {RequestMethod.DELETE}, path = \"/foo/bar\") A suffixed();",
|
||||
" @RequestMapping(path = \"/foo/bar\", method = {PUT}, consumes = {\"a\", \"b\"}) A surrounded();",
|
||||
" @RequestMapping(method = {PATCH}) A curly();",
|
||||
" @RequestMapping(method = RequestMethod.GET)",
|
||||
" A simple();",
|
||||
"",
|
||||
" @RequestMapping(path = \"/foo/bar\", method = POST)",
|
||||
" A prefixed();",
|
||||
"",
|
||||
" @RequestMapping(",
|
||||
" method = {RequestMethod.DELETE},",
|
||||
" path = \"/foo/bar\")",
|
||||
" A suffixed();",
|
||||
"",
|
||||
" @RequestMapping(",
|
||||
" path = \"/foo/bar\",",
|
||||
" method = {PUT},",
|
||||
" consumes = {\"a\", \"b\"})",
|
||||
" A surrounded();",
|
||||
"",
|
||||
" @RequestMapping(method = {PATCH})",
|
||||
" A curly();",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
@@ -92,11 +131,22 @@ public final class SpringMvcAnnotationCheckTest {
|
||||
"import org.springframework.web.bind.annotation.RequestMethod;",
|
||||
"",
|
||||
"interface A {",
|
||||
" @GetMapping() A simple();",
|
||||
" @PostMapping(path = \"/foo/bar\") A prefixed();",
|
||||
" @DeleteMapping(path = \"/foo/bar\") A suffixed();",
|
||||
" @PutMapping(path = \"/foo/bar\", consumes = {\"a\", \"b\"}) A surrounded();",
|
||||
" @PatchMapping() A curly();",
|
||||
" @GetMapping()",
|
||||
" A simple();",
|
||||
"",
|
||||
" @PostMapping(path = \"/foo/bar\")",
|
||||
" A prefixed();",
|
||||
"",
|
||||
" @DeleteMapping(path = \"/foo/bar\")",
|
||||
" A suffixed();",
|
||||
"",
|
||||
" @PutMapping(",
|
||||
" path = \"/foo/bar\",",
|
||||
" consumes = {\"a\", \"b\"})",
|
||||
" A surrounded();",
|
||||
"",
|
||||
" @PatchMapping()",
|
||||
" A curly();",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class StaticImportCheckTest {
|
||||
final class StaticImportCheckTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(StaticImportCheck.class, getClass());
|
||||
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
|
||||
@@ -51,9 +51,8 @@ public final class StaticImportCheckTest {
|
||||
"import java.nio.charset.StandardCharsets;",
|
||||
"import java.time.ZoneOffset;",
|
||||
"import java.util.Optional;",
|
||||
"import java.util.function.Predicate;",
|
||||
"import java.util.UUID;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest;",
|
||||
"import java.util.function.Predicate;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;",
|
||||
"import org.springframework.http.MediaType;",
|
||||
"",
|
||||
@@ -135,10 +134,10 @@ public final class StaticImportCheckTest {
|
||||
"import java.util.Objects;",
|
||||
"import java.util.regex.Pattern;",
|
||||
"import org.junit.jupiter.params.provider.Arguments;",
|
||||
"import org.springframework.format.annotation.DateTimeFormat;",
|
||||
"import org.springframework.format.annotation.DateTimeFormat.ISO;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;",
|
||||
"import org.springframework.format.annotation.DateTimeFormat;",
|
||||
"import org.springframework.format.annotation.DateTimeFormat.ISO;",
|
||||
"import org.springframework.http.MediaType;",
|
||||
"",
|
||||
"class A {",
|
||||
@@ -181,15 +180,15 @@ public final class StaticImportCheckTest {
|
||||
" @DateTimeFormat(iso = ISO.TIME) String time) {}",
|
||||
"",
|
||||
" @BugPattern(",
|
||||
" name = \"TestBugPattern\",",
|
||||
" summary = \"\",",
|
||||
" linkType = BugPattern.LinkType.NONE,",
|
||||
" severity = SeverityLevel.SUGGESTION,",
|
||||
" tags = BugPattern.StandardTags.SIMPLIFICATION)",
|
||||
" name = \"TestBugPattern\",",
|
||||
" summary = \"\",",
|
||||
" linkType = BugPattern.LinkType.NONE,",
|
||||
" severity = SeverityLevel.SUGGESTION,",
|
||||
" tags = BugPattern.StandardTags.SIMPLIFICATION)",
|
||||
" static final class TestBugPattern {}",
|
||||
"",
|
||||
" @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)",
|
||||
" final class Test {}",
|
||||
" @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)",
|
||||
" final class Test {}",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"out/A.java",
|
||||
@@ -250,10 +249,7 @@ public final class StaticImportCheckTest {
|
||||
" Object o = UTF_8;",
|
||||
"",
|
||||
" ImmutableSet.of(",
|
||||
" MediaType.ALL,",
|
||||
" APPLICATION_XHTML_XML,",
|
||||
" TEXT_HTML,",
|
||||
" MediaType.valueOf(\"image/webp\"));",
|
||||
" MediaType.ALL, APPLICATION_XHTML_XML, TEXT_HTML, MediaType.valueOf(\"image/webp\"));",
|
||||
"",
|
||||
" Pattern.compile(\"\", CASE_INSENSITIVE);",
|
||||
" }",
|
||||
@@ -269,15 +265,15 @@ public final class StaticImportCheckTest {
|
||||
" @DateTimeFormat(iso = TIME) String time) {}",
|
||||
"",
|
||||
" @BugPattern(",
|
||||
" name = \"TestBugPattern\",",
|
||||
" summary = \"\",",
|
||||
" linkType = NONE,",
|
||||
" severity = SUGGESTION,",
|
||||
" tags = SIMPLIFICATION)",
|
||||
" name = \"TestBugPattern\",",
|
||||
" summary = \"\",",
|
||||
" linkType = NONE,",
|
||||
" severity = SUGGESTION,",
|
||||
" tags = SIMPLIFICATION)",
|
||||
" static final class TestBugPattern {}",
|
||||
"",
|
||||
" @SpringBootTest(webEnvironment = RANDOM_PORT)",
|
||||
" final class Test {}",
|
||||
" @SpringBootTest(webEnvironment = RANDOM_PORT)",
|
||||
" final class Test {}",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import static com.google.common.base.Predicates.containsPattern;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class TimeZoneUsageCheckTest {
|
||||
final class TimeZoneUsageCheckTest {
|
||||
private final CompilationTestHelper compilationHelper =
|
||||
CompilationTestHelper.newInstance(TimeZoneUsageCheck.class, getClass())
|
||||
.expectErrorMessage(
|
||||
|
||||
@@ -7,11 +7,11 @@ import org.assertj.core.api.AbstractBooleanAssert;
|
||||
|
||||
final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
AbstractBooleanAssert<?> testAbstractBooleanAssertIsEqualTo() {
|
||||
return assertThat(true).isNotEqualTo(!false);
|
||||
return assertThat(true).isNotEqualTo(!Boolean.FALSE);
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAbstractBooleanAssertIsNotEqualTo() {
|
||||
return assertThat(true).isEqualTo(!false);
|
||||
return assertThat(true).isEqualTo(!Boolean.FALSE);
|
||||
}
|
||||
|
||||
ImmutableSet<AbstractBooleanAssert<?>> testAbstractBooleanAssertIsTrue() {
|
||||
@@ -23,7 +23,7 @@ final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAssertThatBooleanIsTrue() {
|
||||
return assertThat(!true).isFalse();
|
||||
return assertThat(!Boolean.TRUE).isFalse();
|
||||
}
|
||||
|
||||
ImmutableSet<AbstractBooleanAssert<?>> testAbstractBooleanAssertIsFalse() {
|
||||
@@ -35,6 +35,6 @@ final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAssertThatBooleanIsFalse() {
|
||||
return assertThat(!true).isTrue();
|
||||
return assertThat(!Boolean.TRUE).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import org.assertj.core.api.AbstractBooleanAssert;
|
||||
|
||||
final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
AbstractBooleanAssert<?> testAbstractBooleanAssertIsEqualTo() {
|
||||
return assertThat(true).isEqualTo(false);
|
||||
return assertThat(true).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAbstractBooleanAssertIsNotEqualTo() {
|
||||
return assertThat(true).isNotEqualTo(false);
|
||||
return assertThat(true).isNotEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
ImmutableSet<AbstractBooleanAssert<?>> testAbstractBooleanAssertIsTrue() {
|
||||
@@ -23,7 +23,7 @@ final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAssertThatBooleanIsTrue() {
|
||||
return assertThat(true).isTrue();
|
||||
return assertThat(Boolean.TRUE).isTrue();
|
||||
}
|
||||
|
||||
ImmutableSet<AbstractBooleanAssert<?>> testAbstractBooleanAssertIsFalse() {
|
||||
@@ -35,6 +35,6 @@ final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
AbstractBooleanAssert<?> testAssertThatBooleanIsFalse() {
|
||||
return assertThat(true).isFalse();
|
||||
return assertThat(Boolean.TRUE).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,10 @@ final class AssortedTemplatesTest implements RefasterTemplateTestCase {
|
||||
// XXX: Only the first statement is rewritten. Make smarter.
|
||||
ImmutableSet<Boolean> testLogicalImplication() {
|
||||
return ImmutableSet.of(
|
||||
toString().isEmpty() || (!toString().isEmpty() && true),
|
||||
!toString().isEmpty() || (toString().isEmpty() && true),
|
||||
3 < 4 || (3 >= 4 && true),
|
||||
3 >= 4 || (3 < 4 && true));
|
||||
toString().isEmpty() || (!toString().isEmpty() && Boolean.TRUE),
|
||||
!toString().isEmpty() || (toString().isEmpty() && Boolean.TRUE),
|
||||
3 < 4 || (3 >= 4 && Boolean.TRUE),
|
||||
3 >= 4 || (3 < 4 && Boolean.TRUE));
|
||||
}
|
||||
|
||||
Stream<String> testUnboundedSingleElementStream() {
|
||||
|
||||
@@ -62,10 +62,10 @@ final class AssortedTemplatesTest implements RefasterTemplateTestCase {
|
||||
// XXX: Only the first statement is rewritten. Make smarter.
|
||||
ImmutableSet<Boolean> testLogicalImplication() {
|
||||
return ImmutableSet.of(
|
||||
toString().isEmpty() || true,
|
||||
!toString().isEmpty() || (toString().isEmpty() && true),
|
||||
3 < 4 || (3 >= 4 && true),
|
||||
3 >= 4 || (3 < 4 && true));
|
||||
toString().isEmpty() || Boolean.TRUE,
|
||||
!toString().isEmpty() || (toString().isEmpty() && Boolean.TRUE),
|
||||
3 < 4 || (3 >= 4 && Boolean.TRUE),
|
||||
3 >= 4 || (3 < 4 && Boolean.TRUE));
|
||||
}
|
||||
|
||||
Stream<String> testUnboundedSingleElementStream() {
|
||||
|
||||
@@ -27,13 +27,13 @@ final class EqualityTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
boolean testDoubleNegation() {
|
||||
return !!true;
|
||||
return !!Boolean.TRUE;
|
||||
}
|
||||
|
||||
ImmutableSet<Boolean> testNegation() {
|
||||
return ImmutableSet.of(
|
||||
true ? !false : false,
|
||||
!(true == false),
|
||||
Boolean.TRUE ? !Boolean.FALSE : Boolean.FALSE,
|
||||
!(Boolean.TRUE == Boolean.FALSE),
|
||||
!((byte) 3 == (byte) 4),
|
||||
!((short) 3 == (short) 4),
|
||||
!(3 == 4),
|
||||
@@ -45,8 +45,8 @@ final class EqualityTemplatesTest implements RefasterTemplateTestCase {
|
||||
|
||||
ImmutableSet<Boolean> testIndirectDoubleNegation() {
|
||||
return ImmutableSet.of(
|
||||
true ? false : !false,
|
||||
!(true != false),
|
||||
Boolean.TRUE ? Boolean.FALSE : !Boolean.FALSE,
|
||||
!(Boolean.TRUE != Boolean.FALSE),
|
||||
!((byte) 3 != (byte) 4),
|
||||
!((short) 3 != (short) 4),
|
||||
!(3 != 4),
|
||||
|
||||
@@ -27,13 +27,13 @@ final class EqualityTemplatesTest implements RefasterTemplateTestCase {
|
||||
}
|
||||
|
||||
boolean testDoubleNegation() {
|
||||
return true;
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
ImmutableSet<Boolean> testNegation() {
|
||||
return ImmutableSet.of(
|
||||
true != false,
|
||||
true != false,
|
||||
Boolean.TRUE != Boolean.FALSE,
|
||||
Boolean.TRUE != Boolean.FALSE,
|
||||
(byte) 3 != (byte) 4,
|
||||
(short) 3 != (short) 4,
|
||||
3 != 4,
|
||||
@@ -45,8 +45,8 @@ final class EqualityTemplatesTest implements RefasterTemplateTestCase {
|
||||
|
||||
ImmutableSet<Boolean> testIndirectDoubleNegation() {
|
||||
return ImmutableSet.of(
|
||||
true == false,
|
||||
true == false,
|
||||
Boolean.TRUE == Boolean.FALSE,
|
||||
Boolean.TRUE == Boolean.FALSE,
|
||||
(byte) 3 == (byte) 4,
|
||||
(short) 3 == (short) 4,
|
||||
3 == 4,
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -18,13 +16,7 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(
|
||||
Arrays.class,
|
||||
Collections.class,
|
||||
Comparator.class,
|
||||
Streams.class,
|
||||
collectingAndThen(null, null),
|
||||
naturalOrder(),
|
||||
toList());
|
||||
Arrays.class, Collections.class, Comparator.class, Streams.class, naturalOrder());
|
||||
}
|
||||
|
||||
ImmutableList.Builder<String> testImmutableListBuilder() {
|
||||
@@ -43,10 +35,8 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
Arrays.stream(new Integer[] {8}).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testStreamToImmutableList() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableList.copyOf(Stream.of(1).iterator()),
|
||||
Stream.of(2).collect(collectingAndThen(toList(), ImmutableList::copyOf)));
|
||||
ImmutableList<Integer> testStreamToImmutableList() {
|
||||
return ImmutableList.copyOf(Stream.of(1).iterator());
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
|
||||
|
||||
@@ -3,8 +3,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -19,13 +17,7 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(
|
||||
Arrays.class,
|
||||
Collections.class,
|
||||
Comparator.class,
|
||||
Streams.class,
|
||||
collectingAndThen(null, null),
|
||||
naturalOrder(),
|
||||
toList());
|
||||
Arrays.class, Collections.class, Comparator.class, Streams.class, naturalOrder());
|
||||
}
|
||||
|
||||
ImmutableList.Builder<String> testImmutableListBuilder() {
|
||||
@@ -44,9 +36,8 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
ImmutableList.copyOf(new Integer[] {8}));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testStreamToImmutableList() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of(1).collect(toImmutableList()), Stream.of(2).collect(toImmutableList()));
|
||||
ImmutableList<Integer> testStreamToImmutableList() {
|
||||
return Stream.of(1).collect(toImmutableList());
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
@@ -14,7 +12,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableMultiset.Builder<String> testImmutableMultisetBuilder() {
|
||||
@@ -39,9 +37,7 @@ final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
Arrays.stream(new Integer[] {8}).collect(toImmutableMultiset()));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMultiset<Integer>> testStreamToImmutableMultiset() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableMultiset.copyOf(Stream.of(1).iterator()),
|
||||
Stream.of(2).collect(collectingAndThen(toList(), ImmutableMultiset::copyOf)));
|
||||
ImmutableMultiset<Integer> testStreamToImmutableMultiset() {
|
||||
return ImmutableMultiset.copyOf(Stream.of(1).iterator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
@@ -14,7 +12,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableMultiset.Builder<String> testImmutableMultisetBuilder() {
|
||||
@@ -37,8 +35,7 @@ final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
ImmutableMultiset.copyOf(new Integer[] {8}));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableMultiset<Integer>> testStreamToImmutableMultiset() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of(1).collect(toImmutableMultiset()), Stream.of(2).collect(toImmutableMultiset()));
|
||||
ImmutableMultiset<Integer> testStreamToImmutableMultiset() {
|
||||
return Stream.of(1).collect(toImmutableMultiset());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -17,13 +14,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(
|
||||
Arrays.class,
|
||||
Collections.class,
|
||||
Streams.class,
|
||||
collectingAndThen(null, null),
|
||||
toList(),
|
||||
toSet());
|
||||
return ImmutableSet.of(Arrays.class, Collections.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<String> testImmutableSetBuilder() {
|
||||
@@ -45,9 +36,7 @@ final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
ImmutableSet<ImmutableSet<Integer>> testStreamToImmutableSet() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.copyOf(Stream.of(1).iterator()),
|
||||
Stream.of(2).distinct().collect(toImmutableSet()),
|
||||
Stream.of(3).collect(collectingAndThen(toList(), ImmutableSet::copyOf)),
|
||||
Stream.of(4).collect(collectingAndThen(toSet(), ImmutableSet::copyOf)));
|
||||
Stream.of(2).distinct().collect(toImmutableSet()));
|
||||
}
|
||||
|
||||
ImmutableSet<Integer> testImmutableSetCopyOfSetView() {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -17,13 +14,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(
|
||||
Arrays.class,
|
||||
Collections.class,
|
||||
Streams.class,
|
||||
collectingAndThen(null, null),
|
||||
toList(),
|
||||
toSet());
|
||||
return ImmutableSet.of(Arrays.class, Collections.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<String> testImmutableSetBuilder() {
|
||||
@@ -44,10 +35,7 @@ final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
|
||||
ImmutableSet<ImmutableSet<Integer>> testStreamToImmutableSet() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of(1).collect(toImmutableSet()),
|
||||
Stream.of(2).collect(toImmutableSet()),
|
||||
Stream.of(3).collect(toImmutableSet()),
|
||||
Stream.of(4).collect(toImmutableSet()));
|
||||
Stream.of(1).collect(toImmutableSet()), Stream.of(2).collect(toImmutableSet()));
|
||||
}
|
||||
|
||||
ImmutableSet<Integer> testImmutableSetCopyOfSetView() {
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
@@ -17,7 +15,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSortedMultiset.Builder<String> testImmutableSortedMultisetBuilder() {
|
||||
@@ -58,9 +56,7 @@ final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTest
|
||||
Arrays.stream(new Integer[] {10}).collect(toImmutableSortedMultiset(naturalOrder())));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableSortedMultiset<Integer>> testStreamToImmutableSortedMultiset() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSortedMultiset.copyOf(Stream.of(1).iterator()),
|
||||
Stream.of(2).collect(collectingAndThen(toList(), ImmutableSortedMultiset::copyOf)));
|
||||
ImmutableSortedMultiset<Integer> testStreamToImmutableSortedMultiset() {
|
||||
return ImmutableSortedMultiset.copyOf(Stream.of(1).iterator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
@@ -17,7 +15,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSortedMultiset.Builder<String> testImmutableSortedMultisetBuilder() {
|
||||
@@ -50,9 +48,7 @@ final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTest
|
||||
ImmutableSortedMultiset.copyOf(new Integer[] {10}));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableSortedMultiset<Integer>> testStreamToImmutableSortedMultiset() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of(1).collect(toImmutableSortedMultiset(naturalOrder())),
|
||||
Stream.of(2).collect(toImmutableSortedMultiset(naturalOrder())));
|
||||
ImmutableSortedMultiset<Integer> testStreamToImmutableSortedMultiset() {
|
||||
return Stream.of(1).collect(toImmutableSortedMultiset(naturalOrder()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -16,7 +14,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSortedSet.Builder<String> testImmutableSortedSetBuilder() {
|
||||
@@ -53,9 +51,7 @@ final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase
|
||||
Arrays.stream(new Integer[] {10}).collect(toImmutableSortedSet(naturalOrder())));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableSortedSet<Integer>> testStreamToImmutableSortedSet() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSortedSet.copyOf(Stream.of(1).iterator()),
|
||||
Stream.of(2).collect(collectingAndThen(toList(), ImmutableSortedSet::copyOf)));
|
||||
ImmutableSortedSet<Integer> testStreamToImmutableSortedSet() {
|
||||
return ImmutableSortedSet.copyOf(Stream.of(1).iterator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
||||
import static java.util.Comparator.naturalOrder;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -16,7 +14,7 @@ import java.util.stream.Stream;
|
||||
final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(Arrays.class, Streams.class, collectingAndThen(null, null), toList());
|
||||
return ImmutableSet.of(Arrays.class, Streams.class);
|
||||
}
|
||||
|
||||
ImmutableSortedSet.Builder<String> testImmutableSortedSetBuilder() {
|
||||
@@ -50,9 +48,7 @@ final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase
|
||||
ImmutableSortedSet.copyOf(new Integer[] {10}));
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableSortedSet<Integer>> testStreamToImmutableSortedSet() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of(1).collect(toImmutableSortedSet(naturalOrder())),
|
||||
Stream.of(2).collect(toImmutableSortedSet(naturalOrder())));
|
||||
ImmutableSortedSet<Integer> testStreamToImmutableSortedSet() {
|
||||
return Stream.of(1).collect(toImmutableSortedSet(naturalOrder()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,14 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
|
||||
Mono.just("bar").map(Optional::of).switchIfEmpty(Mono.just(Optional.empty())));
|
||||
}
|
||||
|
||||
Mono<Number> testMonoCast() {
|
||||
return Mono.just(1).map(Number.class::cast);
|
||||
}
|
||||
|
||||
Flux<Number> testFluxCast() {
|
||||
return Flux.just(1).map(Number.class::cast);
|
||||
}
|
||||
|
||||
ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
|
||||
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
|
||||
}
|
||||
|
||||
@@ -75,6 +75,14 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
|
||||
Mono.just("bar").flux().collect(toOptional()));
|
||||
}
|
||||
|
||||
Mono<Number> testMonoCast() {
|
||||
return Mono.just(1).cast(Number.class);
|
||||
}
|
||||
|
||||
Flux<Number> testFluxCast() {
|
||||
return Flux.just(1).cast(Number.class);
|
||||
}
|
||||
|
||||
ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
|
||||
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.HEAD;
|
||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||
import static org.springframework.http.HttpMethod.PATCH;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -9,12 +15,58 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(fromValue(""));
|
||||
return ImmutableSet.of(fromValue(""), GET, HEAD, OPTIONS, PATCH, POST, PUT);
|
||||
}
|
||||
|
||||
ImmutableSet<?> testBodyValue() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create("foo").post().body(fromValue("bar")),
|
||||
WebClient.create().post().body(fromValue("bar")),
|
||||
WebTestClient.bindToServer().build().post().body(fromValue("bar")));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientGet() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(GET), WebTestClient.bindToServer().build().method(GET));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientHead() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(HEAD), WebTestClient.bindToServer().build().method(HEAD));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientOptions() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(OPTIONS), WebTestClient.bindToServer().build().method(OPTIONS));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPatch() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(PATCH), WebTestClient.bindToServer().build().method(PATCH));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPost() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(POST), WebTestClient.bindToServer().build().method(POST));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPut() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().method(PUT), WebTestClient.bindToServer().build().method(PUT));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testRequestHeadersUriSpecUri() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create("foo").get().uri(uriBuilder -> uriBuilder.path("/bar").build()),
|
||||
WebClient.create("bar")
|
||||
.post()
|
||||
.uri(uriBuilder -> uriBuilder.path("/bar/{baz}").build("quux")),
|
||||
WebTestClient.bindToServer()
|
||||
.build()
|
||||
.get()
|
||||
.uri(uriBuilder -> uriBuilder.path("/baz").build()),
|
||||
WebTestClient.bindToServer()
|
||||
.build()
|
||||
.post()
|
||||
.uri(uriBuilder -> uriBuilder.path("/qux/{quux}/{quuz}").build("corge", "grault")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.HEAD;
|
||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||
import static org.springframework.http.HttpMethod.PATCH;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -9,12 +15,46 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(fromValue(""));
|
||||
return ImmutableSet.of(fromValue(""), GET, HEAD, OPTIONS, PATCH, POST, PUT);
|
||||
}
|
||||
|
||||
ImmutableSet<?> testBodyValue() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create("foo").post().bodyValue("bar"),
|
||||
WebClient.create().post().bodyValue("bar"),
|
||||
WebTestClient.bindToServer().build().post().bodyValue("bar"));
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientGet() {
|
||||
return ImmutableSet.of(WebClient.create().get(), WebTestClient.bindToServer().build().get());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientHead() {
|
||||
return ImmutableSet.of(WebClient.create().head(), WebTestClient.bindToServer().build().head());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientOptions() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().options(), WebTestClient.bindToServer().build().options());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPatch() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create().patch(), WebTestClient.bindToServer().build().patch());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPost() {
|
||||
return ImmutableSet.of(WebClient.create().post(), WebTestClient.bindToServer().build().post());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testWebClientPut() {
|
||||
return ImmutableSet.of(WebClient.create().put(), WebTestClient.bindToServer().build().put());
|
||||
}
|
||||
|
||||
ImmutableSet<?> testRequestHeadersUriSpecUri() {
|
||||
return ImmutableSet.of(
|
||||
WebClient.create("foo").get().uri("/bar"),
|
||||
WebClient.create("bar").post().uri("/bar/{baz}", "quux"),
|
||||
WebTestClient.bindToServer().build().get().uri("/baz"),
|
||||
WebTestClient.bindToServer().build().post().uri("/qux/{quux}/{quuz}", "corge", "grault"));
|
||||
}
|
||||
}
|
||||
|
||||
258
pom.xml
258
pom.xml
@@ -75,11 +75,11 @@
|
||||
arguments. In particular, JaCoCo relies on this for the configuration
|
||||
of its Java agent. -->
|
||||
<argLine>
|
||||
<!-- Error Prone makes extensive use of unsupported
|
||||
<!-- The JVM arguments specified in `.mvn/jvm.config` also apply to
|
||||
test JVMs, as those are also non-interactive processess running
|
||||
Error Prone, and thus similarly make extensive use of unsupported
|
||||
`javac`-internal APIs, in some cases even reflectively inspecting
|
||||
them. These APIs are accessed at compile time and when running
|
||||
tests. The former case is covered by flags in `.mvn/jvm.config`;
|
||||
the latter is covered here. -->
|
||||
them. -->
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
|
||||
@@ -93,9 +93,6 @@
|
||||
<!-- The test JVMs are short-running. By disabling certain
|
||||
expensive JIT optimizations we actually speed up most tests. -->
|
||||
-XX:TieredStopAtLevel=1
|
||||
<!-- We cap memory usage. This is primarily relevant for build agents,
|
||||
but locally this should also be more than enough. -->
|
||||
-Xmx512m
|
||||
<!-- This argument cannot be set through Surefire's
|
||||
'systemPropertyVariables' configuration setting. Setting the file
|
||||
encoding is necessary because forked unit test invocations
|
||||
@@ -134,16 +131,17 @@
|
||||
<version.auto-service>1.0.1</version.auto-service>
|
||||
<version.auto-value>1.9</version.auto-value>
|
||||
<version.error-prone>${version.error-prone-orig}</version.error-prone>
|
||||
<version.error-prone-fork>v${version.error-prone-orig}-picnic-1</version.error-prone-fork>
|
||||
<version.error-prone-orig>2.10.0</version.error-prone-orig>
|
||||
<version.error-prone-slf4j>0.1.4</version.error-prone-slf4j>
|
||||
<version.error-prone-fork>v${version.error-prone-orig}-picnic-2</version.error-prone-fork>
|
||||
<version.error-prone-orig>2.14.0</version.error-prone-orig>
|
||||
<version.error-prone-slf4j>0.1.12</version.error-prone-slf4j>
|
||||
<version.findbugs-format-string>3.0.0</version.findbugs-format-string>
|
||||
<version.guava-beta-checker>1.0</version.guava-beta-checker>
|
||||
<version.jdk>11</version.jdk>
|
||||
<!-- XXX: Configure Renovate to open upgrade PRs for this property. -->
|
||||
<version.maven>3.6.3</version.maven>
|
||||
<version.mockito>4.6.1</version.mockito>
|
||||
<version.nopen-checker>1.0.1</version.nopen-checker>
|
||||
<version.nullaway>0.9.7</version.nullaway>
|
||||
<version.nullaway>0.9.9</version.nullaway>
|
||||
<!-- XXX: Two other dependencies are potentially of interest:
|
||||
`com.palantir.assertj-automation:assertj-refaster-rules` and
|
||||
`com.palantir.baseline:baseline-refaster-rules` contain Refaster rules
|
||||
@@ -152,7 +150,7 @@
|
||||
that we can pick them up. (But in case of `baseline-refaster-rules`
|
||||
perhaps we can simply incorporate all of them.) -->
|
||||
<version.palantir-assertj-automation>0.6.0</version.palantir-assertj-automation>
|
||||
<version.palantir-baseline>4.42.0</version.palantir-baseline>
|
||||
<version.palantir-baseline>4.145.0</version.palantir-baseline>
|
||||
<version.surefire>2.22.2</version.surefire>
|
||||
</properties>
|
||||
|
||||
@@ -237,6 +235,11 @@
|
||||
<artifactId>javac</artifactId>
|
||||
<version>9+181-r4173-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.googlejavaformat</groupId>
|
||||
<artifactId>google-java-format</artifactId>
|
||||
<version>1.15.0</version>
|
||||
</dependency>
|
||||
<!-- Specified as a workaround for
|
||||
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
|
||||
<dependency>
|
||||
@@ -247,14 +250,14 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava-bom</artifactId>
|
||||
<version>31.0.1-jre</version>
|
||||
<version>31.1-jre</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.truth</groupId>
|
||||
<artifactId>truth</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<!-- Specified as a workaround for
|
||||
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
|
||||
@@ -266,7 +269,7 @@
|
||||
<dependency>
|
||||
<groupId>com.newrelic.agent.java</groupId>
|
||||
<artifactId>newrelic-api</artifactId>
|
||||
<version>7.7.0</version>
|
||||
<version>7.9.0</version>
|
||||
</dependency>
|
||||
<!-- Specified as a workaround for
|
||||
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
|
||||
@@ -292,7 +295,7 @@
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-bom</artifactId>
|
||||
<version>2020.0.19</version>
|
||||
<version>2020.0.21</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -309,7 +312,7 @@
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
@@ -346,12 +349,17 @@
|
||||
<dependency>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
<artifactId>checker-qual</artifactId>
|
||||
<version>3.22.1</version>
|
||||
<version>3.24.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<version>5.9.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -362,6 +370,11 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reactivestreams</groupId>
|
||||
<artifactId>reactive-streams</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
@@ -370,14 +383,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>5.3.20</version>
|
||||
<version>5.3.22</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
@@ -393,7 +406,7 @@
|
||||
<plugin>
|
||||
<groupId>com.github.ekryd.sortpom</groupId>
|
||||
<artifactId>sortpom-maven-plugin</artifactId>
|
||||
<version>3.1.3</version>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<createBackupFile>false</createBackupFile>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
@@ -420,9 +433,10 @@
|
||||
<plugin>
|
||||
<groupId>com.spotify.fmt</groupId>
|
||||
<artifactId>fmt-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<configuration>
|
||||
<forkMode>never</forkMode>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
@@ -472,14 +486,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.takari</groupId>
|
||||
<artifactId>maven</artifactId>
|
||||
<version>0.7.7</version>
|
||||
<configuration>
|
||||
<maven>${version.maven}</maven>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
@@ -488,8 +494,20 @@
|
||||
<checkstyleRules>
|
||||
<!-- We only enable rules that are not enforced by
|
||||
Error Prone or automatically corrected through
|
||||
application of google-java-format. -->
|
||||
application of google-java-format (GJF). -->
|
||||
<module name="Checker">
|
||||
<module name="RegexpMultiline">
|
||||
<!-- GJF drops trailing horizontal
|
||||
whitespace and blank lines preceding a
|
||||
closing curly brace, but it does not remove
|
||||
a blank line following an opening curly
|
||||
brace. Here we disallow that specific case.
|
||||
(The regular expression assumes that the
|
||||
code has already been formatted using GJF.) -->
|
||||
<property name="fileExtensions" value="java" />
|
||||
<property name="format" value="\{\r?\n\r?\n" />
|
||||
<property name="message" value="Avoid blank lines at the start of a block." />
|
||||
</module>
|
||||
<module name="SuppressWarningsFilter" />
|
||||
<module name="TreeWalker">
|
||||
<module name="AbbreviationAsWordInName" />
|
||||
@@ -703,13 +721,17 @@
|
||||
</sourceDirectories>
|
||||
<testSourceDirectories>
|
||||
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
|
||||
<!-- Refaster input and output test files represent
|
||||
valid Java code, exposed as resources on the test
|
||||
classpath. -->
|
||||
<testSourceDirectory>${basedir}/src/test/resources</testSourceDirectory>
|
||||
</testSourceDirectories>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>10.3</version>
|
||||
<version>10.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
@@ -731,12 +753,64 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<!-- XXX: MCOMPILER-503: The plugin contructs a highly
|
||||
unintuitive annotation processor classpath, in which
|
||||
some indirect dependencies take precedence over
|
||||
explicitly defined dependencies. This can largely be
|
||||
mitigated through careful ordering of the dependencies,
|
||||
but this prevents (where relevant) declaring these
|
||||
dependencies as part of their corresponding Maven
|
||||
profile. -->
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>${groupId.error-prone}</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
<version>${version.error-prone}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
<version>${version.auto-service}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava-beta-checker</artifactId>
|
||||
<version>${version.guava-beta-checker}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.jakewharton.nopen</groupId>
|
||||
<artifactId>nopen-checker</artifactId>
|
||||
<version>${version.nopen-checker}</version>
|
||||
</path>
|
||||
<!-- XXX: Before enabling these plugins we'll
|
||||
need to resolve some violations. Some of the
|
||||
checks will need to be disabled.
|
||||
<path>
|
||||
<groupId>com.palantir.assertj-automation</groupId>
|
||||
<artifactId>assertj-error-prone</artifactId>
|
||||
<version>${version.palantir-assertj-automation}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.palantir.baseline</groupId>
|
||||
<artifactId>baseline-error-prone</artifactId>
|
||||
<version>${version.palantir-baseline}</version>
|
||||
</path>
|
||||
-->
|
||||
<path>
|
||||
<groupId>com.uber.nullaway</groupId>
|
||||
<artifactId>nullaway</artifactId>
|
||||
<version>${version.nullaway}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>jp.skypencil.errorprone.slf4j</groupId>
|
||||
<artifactId>errorprone-slf4j</artifactId>
|
||||
<version>${version.error-prone-slf4j}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-errorprone</artifactId>
|
||||
<version>${version.mockito}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs>
|
||||
<arg>-Xmaxerrs</arg>
|
||||
@@ -769,7 +843,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<retryFailedDeploymentCount>3</retryFailedDeploymentCount>
|
||||
</configuration>
|
||||
@@ -777,7 +851,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<fail>false</fail>
|
||||
<rules>
|
||||
@@ -814,7 +888,7 @@
|
||||
<dependency>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>extra-enforcer-rules</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
@@ -842,7 +916,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<version>3.0.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -907,7 +981,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<delimiters>
|
||||
<delimiter>@</delimiter>
|
||||
@@ -999,6 +1073,7 @@
|
||||
<includedLicense>GPL-2.0-with-classpath-exception</includedLicense>
|
||||
<includedLicense>LGPL-3.0+</includedLicense>
|
||||
<includedLicense>MIT</includedLicense>
|
||||
<includedLicense>MIT-0</includedLicense>
|
||||
<includedLicense>Public Domain</includedLicense>
|
||||
</includedLicenses>
|
||||
<licenseMerges>
|
||||
@@ -1127,7 +1202,7 @@
|
||||
<plugin>
|
||||
<groupId>org.pitest</groupId>
|
||||
<artifactId>pitest-maven</artifactId>
|
||||
<version>1.8.0</version>
|
||||
<version>1.9.3</version>
|
||||
<configuration>
|
||||
<!-- Use multiple threads to speed things up. Extend
|
||||
timeouts to prevent false positives as a result of
|
||||
@@ -1140,7 +1215,7 @@
|
||||
<dependency>
|
||||
<groupId>org.pitest</groupId>
|
||||
<artifactId>pitest-junit5-plugin</artifactId>
|
||||
<version>0.15</version>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
@@ -1241,7 +1316,7 @@
|
||||
`BugChecker` test code and the Refaster test files) does not
|
||||
exhibit anti-patterns other than those associated with the
|
||||
check/template under test. Ideally all test cases are realistic. -->
|
||||
<error-prone.self-check-args>-Xep:MethodReferenceUsage:OFF</error-prone.self-check-args>
|
||||
<error-prone.self-check-args>-XepAllSuggestionsAsWarnings -Xep:MethodReferenceUsage:OFF</error-prone.self-check-args>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -1391,65 +1466,6 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths combine.children="append">
|
||||
<path>
|
||||
<groupId>${groupId.error-prone}</groupId>
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
<version>${version.error-prone}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>${groupId.error-prone}</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
<version>${version.error-prone}</version>
|
||||
</path>
|
||||
<!-- This is a dependency of some Error Prone
|
||||
plugins, but for licensing reasons it is not
|
||||
packaged with the artifact. -->
|
||||
<path>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jFormatString</artifactId>
|
||||
<version>${version.findbugs-format-string}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava-beta-checker</artifactId>
|
||||
<version>${version.guava-beta-checker}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.jakewharton.nopen</groupId>
|
||||
<artifactId>nopen-checker</artifactId>
|
||||
<version>${version.nopen-checker}</version>
|
||||
</path>
|
||||
<!-- XXX: Before enabling these plugins we'll
|
||||
need to resolve some violations. Some of the
|
||||
checks will need to be disabled.
|
||||
<path>
|
||||
<groupId>com.palantir.assertj-automation</groupId>
|
||||
<artifactId>assertj-error-prone</artifactId>
|
||||
<version>${version.palantir-assertj-automation}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>com.palantir.baseline</groupId>
|
||||
<artifactId>baseline-error-prone</artifactId>
|
||||
<version>${version.palantir-baseline}</version>
|
||||
</path>
|
||||
-->
|
||||
<path>
|
||||
<groupId>com.uber.nullaway</groupId>
|
||||
<artifactId>nullaway</artifactId>
|
||||
<version>${version.nullaway}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>jp.skypencil.errorprone.slf4j</groupId>
|
||||
<artifactId>errorprone-slf4j</artifactId>
|
||||
<version>${version.error-prone-slf4j}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-errorprone</artifactId>
|
||||
<version>${version.mockito}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs combine.children="append">
|
||||
<!-- Enable and configure Error Prone. -->
|
||||
<arg>
|
||||
@@ -1469,18 +1485,28 @@
|
||||
<!-- XXX: Enable this once we open-source
|
||||
this library. -->
|
||||
-Xep:BetaApi:OFF
|
||||
<!-- XXX: Enable this check. -->
|
||||
-Xep:BugPatternNaming:OFF
|
||||
<!-- We don't target JDK 7. -->
|
||||
-Xep:Java7ApiChecker:OFF
|
||||
<!-- We don't target JDK 8. -->
|
||||
-Xep:Java8ApiChecker:OFF
|
||||
<!-- We don't target Android. -->
|
||||
-Xep:StaticOrDefaultInterfaceMethod:OFF
|
||||
<!-- We generally discourage `var` use. -->
|
||||
-Xep:Varifier:OFF
|
||||
<!-- XXX: This check flags false positives.
|
||||
See https://github.com/google/error-prone/issues/2679. -->
|
||||
-Xep:VoidMissingNullable:OFF
|
||||
-XepOpt:CheckReturnValue:CheckAllConstructors=true
|
||||
<!-- XXX: Enable once there are fewer
|
||||
false-positives.
|
||||
-XepOpt:CheckReturnValue:CheckAllMethods=true -->
|
||||
-XepOpt:InlineMe:SkipInliningsWithComments=false
|
||||
-XepOpt:NullAway:AnnotatedPackages=tech.picnic
|
||||
-XepOpt:NullAway:AssertsEnabled=true
|
||||
-XepOpt:NullAway:CheckOptionalEmptiness=true
|
||||
-XepOpt:Nullness:Conservative=false
|
||||
<!-- Append additional custom arguments. -->
|
||||
${error-prone.patch-args}
|
||||
${error-prone.self-check-args}
|
||||
@@ -1533,6 +1559,13 @@
|
||||
<verifyFail>stop</verifyFail>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify.fmt</groupId>
|
||||
<artifactId>fmt-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<failOnError>true</failOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>de.thetaphi</groupId>
|
||||
<artifactId>forbiddenapis</artifactId>
|
||||
@@ -1595,31 +1628,6 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<!-- A counterpart to the `disallow-warnings` profile which
|
||||
explicitly "tones down" plugins enabled by the `build-checks`
|
||||
profile. Necessary for dealing with plugins that default to failing
|
||||
the build upon encountering a violation. -->
|
||||
<id>avoid-errors</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>verification.warn</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.spotify.fmt</groupId>
|
||||
<artifactId>fmt-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>sonar</id>
|
||||
<properties>
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.StandardLocation;
|
||||
@@ -91,6 +92,7 @@ final class RefasterRuleCompilerTaskListener implements TaskListener {
|
||||
ClassTree tree) {
|
||||
ListMultimap<ClassTree, CodeTransformer> rules = ArrayListMultimap.create();
|
||||
new TreeScanner<Void, Void>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Void visitClass(ClassTree node, Void v) {
|
||||
rules.putAll(node, RefasterRuleBuilderScanner.extractRules(node, context));
|
||||
|
||||
@@ -17,7 +17,6 @@ final class IsArrayTest {
|
||||
CompilationTestHelper.newInstance(TestChecker.class, getClass())
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"package test.foo;",
|
||||
"class A {",
|
||||
" Object negative1() {",
|
||||
" return alwaysNull();",
|
||||
|
||||
Reference in New Issue
Block a user