mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Compare commits
46 Commits
rossendrij
...
sschroever
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3b5ead02b | ||
|
|
7daa39a0b5 | ||
|
|
5fc7bc29ee | ||
|
|
83f3f8bedc | ||
|
|
12585a8969 | ||
|
|
72b701cae3 | ||
|
|
24e3251eb0 | ||
|
|
f124749a4f | ||
|
|
2a3d9c8dd5 | ||
|
|
0fa59a5cec | ||
|
|
d316e8ac70 | ||
|
|
53fe15c356 | ||
|
|
acb8b651b7 | ||
|
|
ace6bc2813 | ||
|
|
f69fef2f52 | ||
|
|
d033b84b5b | ||
|
|
3e702733bc | ||
|
|
f212e9476d | ||
|
|
da00863e34 | ||
|
|
476916f381 | ||
|
|
67bf5b98a8 | ||
|
|
db7757c556 | ||
|
|
bfd309800b | ||
|
|
0121f7b33c | ||
|
|
8dbff50a8b | ||
|
|
aec56ce025 | ||
|
|
1b8ffd86b9 | ||
|
|
ee7be7e3b2 | ||
|
|
57825decf0 | ||
|
|
2b3e11bd24 | ||
|
|
23cb29b6fc | ||
|
|
ba1dd2cd08 | ||
|
|
75a9786f8f | ||
|
|
0b4fd8ddd1 | ||
|
|
2eda393c03 | ||
|
|
512a3bebad | ||
|
|
db18d6a1fc | ||
|
|
75ca3030f7 | ||
|
|
f484c3f10b | ||
|
|
0753de05d1 | ||
|
|
ab0847e49f | ||
|
|
f9383e4e94 | ||
|
|
50b6c31675 | ||
|
|
63e78933ac | ||
|
|
cd0e962ef7 | ||
|
|
107d135894 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -42,7 +42,7 @@ jobs:
|
||||
# additionally enabling all checks defined in this project and any Error
|
||||
# Prone checks available only from other artifact repositories.
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
java-version: ${{ matrix.jdk }}
|
||||
java-distribution: ${{ matrix.distribution }}
|
||||
|
||||
2
.github/workflows/codeql.yml
vendored
2
.github/workflows/codeql.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
||||
repo.maven.apache.org:443
|
||||
uploads.github.com:443
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
java-version: 17.0.13
|
||||
java-distribution: temurin
|
||||
|
||||
4
.github/workflows/pitest-analyze-pr.yml
vendored
4
.github/workflows/pitest-analyze-pr.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
objects.githubusercontent.com:443
|
||||
repo.maven.apache.org:443
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
checkout-fetch-depth: 2
|
||||
java-version: 17.0.13
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Aggregate Pitest reports
|
||||
run: mvn pitest-git:aggregate -DkilledEmoji=":tada:" -DmutantEmoji=":zombie:" -DtrailingText="Mutation testing report by [Pitest](https://pitest.org/). Review any surviving mutants by inspecting the line comments under [_Files changed_](${{ github.event.number }}/files)."
|
||||
- name: Upload Pitest reports as artifact
|
||||
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
|
||||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
|
||||
with:
|
||||
name: pitest-reports
|
||||
path: ./target/pit-reports-ci
|
||||
|
||||
2
.github/workflows/pitest-update-pr.yml
vendored
2
.github/workflows/pitest-update-pr.yml
vendored
@@ -31,7 +31,7 @@ jobs:
|
||||
objects.githubusercontent.com:443
|
||||
repo.maven.apache.org:443
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
java-version: 17.0.13
|
||||
java-distribution: temurin
|
||||
|
||||
12
.github/workflows/run-integration-tests.yml
vendored
12
.github/workflows/run-integration-tests.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
integration-test: [ "checkstyle", "metrics" ]
|
||||
integration-test: [ "checkstyle", "metrics", "prometheus-java-client" ]
|
||||
steps:
|
||||
- name: Install Harden-Runner
|
||||
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
|
||||
@@ -27,17 +27,23 @@ jobs:
|
||||
disable-sudo: true
|
||||
egress-policy: block
|
||||
allowed-endpoints: >
|
||||
# XXX: After updating the validation build flags in
|
||||
# `integration-tests/prometheus-java-client.sh`, review whether the
|
||||
# Docker domains specified here can be dropped.
|
||||
api.adoptium.net:443
|
||||
auth.docker.io:443
|
||||
checkstyle.org:443
|
||||
example.com:80
|
||||
github.com:443
|
||||
objects.githubusercontent.com:443
|
||||
oss.sonatype.org:443
|
||||
production.cloudflare.docker.com:443
|
||||
raw.githubusercontent.com:443
|
||||
registry-1.docker.io:443
|
||||
repo.maven.apache.org:443
|
||||
repository.sonatype.org:443
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
checkout-ref: "refs/pull/${{ github.event.issue.number }}/head"
|
||||
java-version: 17.0.13
|
||||
@@ -49,7 +55,7 @@ jobs:
|
||||
run: xvfb-run "./integration-tests/${{ matrix.integration-test }}.sh" "${{ runner.temp }}/artifacts"
|
||||
- name: Upload artifacts on failure
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
|
||||
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
|
||||
with:
|
||||
name: "integration-test-${{ matrix.integration-test }}"
|
||||
path: "${{ runner.temp }}/artifacts"
|
||||
|
||||
2
.github/workflows/sonarcloud.yml
vendored
2
.github/workflows/sonarcloud.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
||||
*.sonarcloud.io:443
|
||||
sonarcloud.io:443
|
||||
- name: Check out code and set up JDK and Maven
|
||||
uses: s4u/setup-maven-action@382542f77617f34e56bf83868920a4d45b7451e7 # v1.16.0
|
||||
uses: s4u/setup-maven-action@9a27433d289dd99d73851f653607c39d3444e8ba # v1.17.0
|
||||
with:
|
||||
checkout-fetch-depth: 0
|
||||
java-version: 17.0.13
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
|
||||
|
||||
@@ -217,7 +217,7 @@ Other highly relevant commands:
|
||||
- `mvn fmt:format` formats the code using
|
||||
[`google-java-format`][google-java-format].
|
||||
- [`./run-full-build.sh`][script-run-full-build] builds the project twice,
|
||||
where the second pass validates compatbility with Picnic's [Error Prone
|
||||
where the second pass validates compatibility with Picnic's [Error Prone
|
||||
fork][error-prone-fork-repo] and compliance of the code with any rules
|
||||
defined within this project. (Consider running this before [opening a pull
|
||||
request][contributing-pull-request], as the PR checks also perform this
|
||||
|
||||
@@ -72,6 +72,10 @@
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
@@ -162,11 +166,22 @@
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gaul</groupId>
|
||||
<artifactId>modernizer-maven-plugin</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<!-- XXX: Consider making optional? Ship only the definitions? -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.immutables</groupId>
|
||||
<artifactId>value-annotations</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jspecify</groupId>
|
||||
<artifactId>jspecify</artifactId>
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.sun.source.tree.LambdaExpressionTree;
|
||||
import com.sun.source.tree.TypeCastTree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import tech.picnic.errorprone.utils.SourceCode;
|
||||
|
||||
/**
|
||||
@@ -48,11 +49,14 @@ public final class ClassCastLambdaUsage extends BugChecker implements LambdaExpr
|
||||
}
|
||||
|
||||
Type type = ASTHelpers.getType(typeCast);
|
||||
if (type == null || type.isParameterized() || type.isPrimitive()) {
|
||||
if (type == null
|
||||
|| type.isParameterized()
|
||||
|| type.isPrimitive()
|
||||
|| type.getKind() == TypeKind.TYPEVAR) {
|
||||
/*
|
||||
* The method reference syntax does not support casting to parameterized types. Additionally,
|
||||
* `Class#cast` does not support the same range of type conversions between (boxed) primitive
|
||||
* types as the cast operator.
|
||||
* The method reference syntax does not support casting to parameterized types, and type
|
||||
* variables aren't supported either. Additionally, `Class#cast` does not support the same
|
||||
* range of type conversions between (boxed) primitive types as the cast operator.
|
||||
*/
|
||||
// XXX: Depending on the declared type of the value being cast, in some cases we _can_ rewrite
|
||||
// primitive casts. Add support for this.
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.errorprone.BugPattern.LinkType.CUSTOM;
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.PERFORMANCE;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION;
|
||||
import static com.google.errorprone.matchers.Matchers.allOf;
|
||||
import static com.google.errorprone.matchers.Matchers.anyOf;
|
||||
import static com.google.errorprone.matchers.Matchers.instanceMethod;
|
||||
import static com.google.errorprone.matchers.Matchers.staticMethod;
|
||||
import static com.google.errorprone.matchers.Matchers.symbolMatcher;
|
||||
import static tech.picnic.errorprone.utils.Documentation.BUG_PATTERNS_BASE_URL;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
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.google.errorprone.util.ASTHelpers;
|
||||
import com.google.errorprone.util.Visibility;
|
||||
import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
import com.sun.source.tree.MethodTree;
|
||||
import com.sun.tools.javac.code.Symbol.MethodSymbol;
|
||||
import com.sun.tools.javac.code.Symbol.VarSymbol;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.lang.model.element.Element;
|
||||
import tech.picnic.errorprone.utils.SourceCode;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} that flags single-argument method invocations with an iterable of explicitly
|
||||
* enumerated values, for which a semantically equivalent varargs variant (appears to) exists as
|
||||
* well.
|
||||
*
|
||||
* <p>This check drops selected {@link ImmutableSet#of} and {@link Set#of} invocations, with the
|
||||
* assumption that these operations do not deduplicate the collection of explicitly enumerated
|
||||
* values. It also drops {@link ImmutableMultiset#of} and {@link Set#of} invocations, with the
|
||||
* assumption that these do not materially impact iteration order.
|
||||
*
|
||||
* <p>This checker attempts to identify {@link Iterable}-accepting methods for which a varargs
|
||||
* overload exists, and suggests calling the varargs overload instead. This is an imperfect
|
||||
* heuristic, but it e.g. allows invocations of <a
|
||||
* href="https://immutables.github.io/immutable.html#copy-methods">Immutables-generated {@code
|
||||
* with*}</a> methods to be simplified.
|
||||
*/
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
summary = "Iterable creation can be avoided by using a varargs alternative method",
|
||||
link = BUG_PATTERNS_BASE_URL + "ExplicitArgumentEnumeration",
|
||||
linkType = CUSTOM,
|
||||
severity = SUGGESTION,
|
||||
tags = {PERFORMANCE, SIMPLIFICATION})
|
||||
public final class ExplicitArgumentEnumeration extends BugChecker
|
||||
implements MethodInvocationTreeMatcher {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Matcher<ExpressionTree> EXPLICIT_ITERABLE_CREATOR =
|
||||
anyOf(
|
||||
staticMethod()
|
||||
.onClassAny(
|
||||
ImmutableList.class.getCanonicalName(),
|
||||
ImmutableMultiset.class.getCanonicalName(),
|
||||
ImmutableSet.class.getCanonicalName(),
|
||||
List.class.getCanonicalName(),
|
||||
Set.class.getCanonicalName())
|
||||
.named("of"),
|
||||
allOf(
|
||||
staticMethod()
|
||||
.onClassAny(
|
||||
ImmutableList.class.getCanonicalName(),
|
||||
ImmutableMultiset.class.getCanonicalName(),
|
||||
ImmutableSet.class.getCanonicalName())
|
||||
.named("copyOf"),
|
||||
symbolMatcher(
|
||||
(symbol, state) ->
|
||||
state
|
||||
.getSymtab()
|
||||
.arrayClass
|
||||
.equals(((MethodSymbol) symbol).params().get(0).type.tsym))),
|
||||
staticMethod().onClass(Arrays.class.getCanonicalName()).named("asList"));
|
||||
private static final Matcher<ExpressionTree> IMMUTABLE_COLLECTION_BUILDER =
|
||||
instanceMethod().onDescendantOf(ImmutableCollection.Builder.class.getCanonicalName());
|
||||
private static final Matcher<ExpressionTree> OBJECT_ENUMERABLE_ASSERT =
|
||||
instanceMethod().onDescendantOf("org.assertj.core.api.ObjectEnumerableAssert");
|
||||
private static final Matcher<ExpressionTree> STEP_VERIFIER_STEP =
|
||||
instanceMethod().onDescendantOf("reactor.test.StepVerifier.Step");
|
||||
private static final ImmutableTable<Matcher<ExpressionTree>, String, String> ALTERNATIVE_METHODS =
|
||||
ImmutableTable.<Matcher<ExpressionTree>, String, String>builder()
|
||||
.put(IMMUTABLE_COLLECTION_BUILDER, "addAll", "add")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "containsAnyElementsOf", "containsAnyOf")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "containsAll", "contains")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "containsExactlyElementsOf", "containsExactly")
|
||||
.put(
|
||||
OBJECT_ENUMERABLE_ASSERT,
|
||||
"containsExactlyInAnyOrderElementsOf",
|
||||
"containsExactlyInAnyOrder")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "containsOnlyElementsOf", "containsOnly")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "containsOnlyOnceElementsOf", "containsOnlyOnce")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "doesNotContainAnyElementsOf", "doesNotContain")
|
||||
.put(OBJECT_ENUMERABLE_ASSERT, "hasSameElementsAs", "containsOnly")
|
||||
.put(STEP_VERIFIER_STEP, "expectNextSequence", "expectNext")
|
||||
.build();
|
||||
|
||||
/** Instantiates a new {@link ExplicitArgumentEnumeration} instance. */
|
||||
public ExplicitArgumentEnumeration() {}
|
||||
|
||||
@Override
|
||||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
|
||||
if (tree.getArguments().size() != 1) {
|
||||
/* Performance optimization: non-unary method invocations cannot be simplified. */
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
MethodSymbol method = ASTHelpers.getSymbol(tree);
|
||||
if (!isUnaryIterableAcceptingMethod(method, state) || isLocalOverload(method, state)) {
|
||||
/*
|
||||
* This isn't a method invocation we can simplify, or it's an invocation of a local overload.
|
||||
* The latter type of invocation we do not suggest replacing, as this is fairly likely to
|
||||
* introduce an unbounded recursive call chain.
|
||||
*/
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
ExpressionTree argument = tree.getArguments().get(0);
|
||||
if (!EXPLICIT_ITERABLE_CREATOR.matches(argument, state)) {
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
return trySuggestCallingVarargsOverload(method, (MethodInvocationTree) argument, state)
|
||||
.or(() -> trySuggestCallingCustomAlternative(tree, (MethodInvocationTree) argument, state))
|
||||
.map(fix -> describeMatch(tree, fix))
|
||||
.orElse(Description.NO_MATCH);
|
||||
}
|
||||
|
||||
private static boolean isUnaryIterableAcceptingMethod(MethodSymbol method, VisitorState state) {
|
||||
List<VarSymbol> params = method.params();
|
||||
return !method.isVarArgs()
|
||||
&& params.size() == 1
|
||||
&& ASTHelpers.isSubtype(params.get(0).type, state.getSymtab().iterableType, state);
|
||||
}
|
||||
|
||||
private static boolean isLocalOverload(MethodSymbol calledMethod, VisitorState state) {
|
||||
MethodTree enclosingMethod = state.findEnclosing(MethodTree.class);
|
||||
if (enclosingMethod == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MethodSymbol callingMethod = ASTHelpers.getSymbol(enclosingMethod);
|
||||
return Objects.equals(callingMethod.getEnclosingElement(), calledMethod.getEnclosingElement())
|
||||
&& callingMethod.getSimpleName().equals(calledMethod.getSimpleName());
|
||||
}
|
||||
|
||||
private static Optional<SuggestedFix> trySuggestCallingVarargsOverload(
|
||||
MethodSymbol method, MethodInvocationTree argument, VisitorState state) {
|
||||
/*
|
||||
* Collect all overloads of the given method that we are sure to be able to call. Note that the
|
||||
* `isAtLeastAsVisible` check is conservative heuristic.
|
||||
*/
|
||||
ImmutableList<MethodSymbol> overloads =
|
||||
ASTHelpers.matchingMethods(
|
||||
method.getSimpleName(),
|
||||
m -> isAtLeastAsVisible(m, method),
|
||||
method.enclClass().type,
|
||||
state.getTypes())
|
||||
.collect(toImmutableList());
|
||||
|
||||
/*
|
||||
* If all overloads have a single parameter, and at least one of them is a varargs method, then
|
||||
* we assume that unwrapping the iterable argument will cause a suitable overload to be invoked.
|
||||
* (Note that there may be multiple varargs overloads, either with different parameter types, or
|
||||
* due to method overriding; this check does not attempt to determine which exact method or
|
||||
* overload will be invoked as a result of the suggested simplification.)
|
||||
*
|
||||
* Note that this is a (highly!) imperfect heuristic, but it is sufficient to prevent e.g.
|
||||
* unwrapping of arguments to `org.jooq.impl.DSL#row`, which can cause the expression's return
|
||||
* type to change from `RowN` to (e.g.) `Row2`.
|
||||
*/
|
||||
// XXX: There are certainly cases where it _would_ be nice to unwrap the arguments to
|
||||
// `org.jooq.impl.DSL#row(Collection<?>)`. Look into this.
|
||||
// XXX: Ideally we do check that one of the overloads accepts the unwrapped arguments.
|
||||
// XXX: Ideally we validate that eligible overloads have compatible return types.
|
||||
boolean hasLikelySuitableVarargsOverload =
|
||||
overloads.stream().allMatch(m -> m.params().size() == 1)
|
||||
&& overloads.stream().anyMatch(MethodSymbol::isVarArgs);
|
||||
|
||||
return hasLikelySuitableVarargsOverload
|
||||
? Optional.of(SourceCode.unwrapMethodInvocation(argument, state))
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<SuggestedFix> trySuggestCallingCustomAlternative(
|
||||
MethodInvocationTree tree, MethodInvocationTree argument, VisitorState state) {
|
||||
return ALTERNATIVE_METHODS.rowMap().entrySet().stream()
|
||||
.filter(e -> e.getKey().matches(tree, state))
|
||||
.findFirst()
|
||||
.flatMap(e -> trySuggestCallingCustomAlternative(tree, argument, state, e.getValue()));
|
||||
}
|
||||
|
||||
private static Optional<SuggestedFix> trySuggestCallingCustomAlternative(
|
||||
MethodInvocationTree tree,
|
||||
MethodInvocationTree argument,
|
||||
VisitorState state,
|
||||
Map<String, String> alternatives) {
|
||||
return Optional.ofNullable(
|
||||
alternatives.get(ASTHelpers.getSymbol(tree).getSimpleName().toString()))
|
||||
.map(
|
||||
replacement ->
|
||||
SuggestedFix.builder()
|
||||
.merge(SuggestedFixes.renameMethodInvocation(tree, replacement, state))
|
||||
.merge(SourceCode.unwrapMethodInvocation(argument, state))
|
||||
.build());
|
||||
}
|
||||
|
||||
private static boolean isAtLeastAsVisible(Element symbol, Element reference) {
|
||||
return Visibility.fromModifiers(symbol.getModifiers())
|
||||
.compareTo(Visibility.fromModifiers(reference.getModifiers()))
|
||||
>= 0;
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,8 @@ public final class JUnitMethodDeclaration extends BugChecker implements MethodTr
|
||||
.build());
|
||||
}
|
||||
|
||||
// XXX: Consider dropping leading underscores that otherwise result when canonicalizing
|
||||
// `test_some_method_name`.
|
||||
private static Optional<String> tryCanonicalizeMethodName(MethodSymbol symbol) {
|
||||
return Optional.of(symbol.getQualifiedName().toString())
|
||||
.filter(name -> name.startsWith(TEST_PREFIX))
|
||||
|
||||
@@ -0,0 +1,371 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.ImmutableTable.toImmutableTable;
|
||||
import static com.google.errorprone.BugPattern.LinkType.CUSTOM;
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
|
||||
import static com.google.errorprone.BugPattern.StandardTags.REFACTORING;
|
||||
import static com.google.errorprone.matchers.Matchers.allOf;
|
||||
import static com.google.errorprone.predicates.TypePredicates.isDescendantOf;
|
||||
import static com.google.errorprone.predicates.TypePredicates.isExactType;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static tech.picnic.errorprone.utils.Documentation.BUG_PATTERNS_BASE_URL;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.auto.value.AutoValue.CopyAnnotations;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
import com.google.errorprone.BugPattern;
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.annotations.Immutable;
|
||||
import com.google.errorprone.annotations.Var;
|
||||
import com.google.errorprone.bugpatterns.BugChecker;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.AnnotationTreeMatcher;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.IdentifierTreeMatcher;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.MemberReferenceTreeMatcher;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.MemberSelectTreeMatcher;
|
||||
import com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher;
|
||||
import com.google.errorprone.matchers.Description;
|
||||
import com.google.errorprone.matchers.Matcher;
|
||||
import com.google.errorprone.predicates.TypePredicate;
|
||||
import com.google.errorprone.suppliers.Supplier;
|
||||
import com.google.errorprone.util.ASTHelpers;
|
||||
import com.sun.source.tree.AnnotationTree;
|
||||
import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.IdentifierTree;
|
||||
import com.sun.source.tree.MemberReferenceTree;
|
||||
import com.sun.source.tree.MemberSelectTree;
|
||||
import com.sun.source.tree.NewClassTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.tools.javac.api.BasicJavacTask;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.jvm.Target;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.Name;
|
||||
|
||||
/**
|
||||
* A {@link BugChecker} that flags the same legacy APIs as the <a
|
||||
* href="https://github.com/gaul/modernizer-maven-plugin">Modernizer Maven Plugin</a>.
|
||||
*
|
||||
* <p>This checker is primarily useful for people who run Error Prone anyway; it obviates the need
|
||||
* for an additional source code analysis pass using another Maven plugin.
|
||||
*/
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
summary = "Avoid constants and methods superseded by more recent equivalents",
|
||||
link = BUG_PATTERNS_BASE_URL + "Modernizer",
|
||||
linkType = CUSTOM,
|
||||
severity = SUGGESTION,
|
||||
tags = REFACTORING)
|
||||
public final class Modernizer extends BugChecker
|
||||
implements AnnotationTreeMatcher,
|
||||
IdentifierTreeMatcher,
|
||||
MemberReferenceTreeMatcher,
|
||||
MemberSelectTreeMatcher,
|
||||
NewClassTreeMatcher {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// XXX: Load lazily?
|
||||
private final ImmutableTable<String, Matcher<ExpressionTree>, String> violations =
|
||||
loadViolations();
|
||||
|
||||
/** Instantiates a new {@link MockitoStubbing} instance. */
|
||||
public Modernizer() {}
|
||||
|
||||
@Override
|
||||
public Description matchAnnotation(AnnotationTree tree, VisitorState state) {
|
||||
// XXX: Use or drop
|
||||
// XXX: See
|
||||
// https://github.com/google/guava-beta-checker/commit/9b26aa980be7f70631921fd6695013547728eb1e;
|
||||
// we may be on the right track without this.
|
||||
return Description.NO_MATCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description matchIdentifier(IdentifierTree tree, VisitorState state) {
|
||||
return match(tree.getName(), tree, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
|
||||
return match(tree.getName(), tree, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
|
||||
return match(tree.getIdentifier(), tree, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description matchNewClass(NewClassTree tree, VisitorState state) {
|
||||
Symbol createdType =
|
||||
requireNonNull(ASTHelpers.getSymbol(tree).getEnclosingElement(), "No enclosing class");
|
||||
return match(createdType.getQualifiedName(), tree, state);
|
||||
}
|
||||
|
||||
private Description match(Name identifier, ExpressionTree tree, VisitorState state) {
|
||||
return violations.row(identifier.toString()).entrySet().stream()
|
||||
.filter(e -> e.getKey().matches(tree, state))
|
||||
.findFirst()
|
||||
.map(e -> buildDescription(tree).setMessage(e.getValue()).build())
|
||||
.orElse(Description.NO_MATCH);
|
||||
}
|
||||
|
||||
private ImmutableTable<String, Matcher<ExpressionTree>, String> loadViolations() {
|
||||
InputStream resource = getClass().getResourceAsStream("/modernizer.xml");
|
||||
// XXX: Or silently skip?
|
||||
checkState(resource != null, "Modernizer configuration not found on classpath");
|
||||
|
||||
XmlMapper mapper = new XmlMapper();
|
||||
try (resource) {
|
||||
return mapper.readValue(resource, Violations.class).getViolation().stream()
|
||||
.filter(v -> v.getChecker().isPresent())
|
||||
.collect(
|
||||
toImmutableTable(
|
||||
Violation::getIdentifier,
|
||||
v -> v.getChecker().orElseThrow(),
|
||||
Violation::getComment));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to parse Modernizer configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Further simplify with Auto Value?
|
||||
@Immutable
|
||||
static final class Violations {
|
||||
@JacksonXmlElementWrapper(useWrapping = false)
|
||||
private final ImmutableList<Violation> violation;
|
||||
|
||||
@JsonCreator
|
||||
private Violations(@JsonProperty("violation") List<Violation> violation) {
|
||||
this.violation = ImmutableList.copyOf(violation);
|
||||
}
|
||||
|
||||
// XXX: Jackson relies on this naming and visibility. Ugh.
|
||||
public ImmutableList<Violation> getViolation() {
|
||||
return violation;
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@AutoValue
|
||||
abstract static class Violation {
|
||||
private static final Pattern NAME_PATTERN =
|
||||
Pattern.compile(
|
||||
"(?<type>[^.]+)(?:\\.(?<member>[^:]+):(?:\\((?<params>[^)]*)\\))?(?<return>[^()]+))?");
|
||||
|
||||
abstract Optional<Target> getTarget();
|
||||
|
||||
abstract String getIdentifier();
|
||||
|
||||
@CopyAnnotations
|
||||
@SuppressWarnings("Immutable")
|
||||
abstract Matcher<ExpressionTree> getMatcher();
|
||||
|
||||
abstract String getComment();
|
||||
|
||||
Optional<Matcher<ExpressionTree>> getChecker() {
|
||||
return getTarget().map(t -> allOf(getMatcher(), targetMatcher(t)));
|
||||
}
|
||||
|
||||
// XXX: Overkill? Not if we use auto value.
|
||||
// XXX: Modernizer also flags annotation declarations, presumably by type.
|
||||
// XXX: `ExpressionTree` is wrong here. Depends on type.
|
||||
@JsonCreator
|
||||
static Violation create(
|
||||
@JsonProperty("version") String version,
|
||||
@JsonProperty("name") String signature,
|
||||
@JsonProperty("comment") String comment) {
|
||||
Optional<Target> target = Optional.ofNullable(Target.lookup(version));
|
||||
|
||||
java.util.regex.Matcher matcher = NAME_PATTERN.matcher(signature);
|
||||
checkState(matcher.matches(), "Failed to parse signature '%s'", signature);
|
||||
|
||||
String type =
|
||||
replaceSlashes(requireNonNull(matcher.group("type"), "Signature must contain type"));
|
||||
|
||||
String member = matcher.group("member");
|
||||
if (member == null) {
|
||||
// XXX: Should not implement this interface. Something like:
|
||||
// violations.put(type, allOf(isSubtypeOf(type), versionRequirement), this.comment)
|
||||
return new AutoValue_Modernizer_Violation(target, type, (t, s) -> false, comment);
|
||||
}
|
||||
|
||||
String params = matcher.group("params");
|
||||
if (params == null) {
|
||||
return new AutoValue_Modernizer_Violation(target, member, isField(type), comment);
|
||||
}
|
||||
|
||||
ImmutableList<Supplier<Type>> parameters = parseParams(params);
|
||||
|
||||
if ("\"<init>\"".equals(member)) {
|
||||
return new AutoValue_Modernizer_Violation(
|
||||
target, type, isConstructor(type, parameters), comment);
|
||||
}
|
||||
|
||||
// XXX: Should we disallow _extension_ of this method?
|
||||
return new AutoValue_Modernizer_Violation(
|
||||
target, member, isMethod(type, parameters), comment);
|
||||
}
|
||||
|
||||
private static Matcher<ExpressionTree> targetMatcher(Target target) {
|
||||
return (tree, state) -> target.compareTo(getTargetVersion(state)) <= 0;
|
||||
}
|
||||
|
||||
private static Target getTargetVersion(VisitorState state) {
|
||||
return Target.instance(
|
||||
Optional.ofNullable(state.context.get(JavacTask.class))
|
||||
.filter(BasicJavacTask.class::isInstance)
|
||||
.map(BasicJavacTask.class::cast)
|
||||
.map(BasicJavacTask::getContext)
|
||||
.orElse(state.context));
|
||||
}
|
||||
|
||||
private static Matcher<ExpressionTree> isField(String onDescendantOf) {
|
||||
return isMember(ElementKind::isField, isDescendantOf(onDescendantOf), ImmutableList.of());
|
||||
}
|
||||
|
||||
private static Matcher<ExpressionTree> isConstructor(
|
||||
String ofClass, ImmutableList<Supplier<Type>> withParameters) {
|
||||
return isMember(k -> k == ElementKind.CONSTRUCTOR, isExactType(ofClass), withParameters);
|
||||
}
|
||||
|
||||
private static Matcher<ExpressionTree> isMethod(
|
||||
String onDescendantOf, ImmutableList<Supplier<Type>> withParameters) {
|
||||
return isMember(k -> k == ElementKind.METHOD, isDescendantOf(onDescendantOf), withParameters);
|
||||
}
|
||||
|
||||
private static Matcher<ExpressionTree> isMember(
|
||||
Predicate<ElementKind> ofKind,
|
||||
TypePredicate ownedBy,
|
||||
ImmutableList<Supplier<Type>> withParameters) {
|
||||
return (tree, state) ->
|
||||
Optional.ofNullable(ASTHelpers.getSymbol(tree))
|
||||
.filter(s -> ofKind.test(s.getKind()))
|
||||
.filter(s -> isOwnedBy(s, ownedBy, state))
|
||||
.filter(s -> hasSameParameters(s, withParameters, state))
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
private static boolean isOwnedBy(Symbol symbol, TypePredicate expected, VisitorState state) {
|
||||
Symbol owner = symbol.getEnclosingElement();
|
||||
return owner != null && expected.apply(owner.asType(), state);
|
||||
}
|
||||
|
||||
private static boolean hasSameParameters(
|
||||
Symbol method, ImmutableList<Supplier<Type>> expected, VisitorState state) {
|
||||
List<Type> actual = method.asType().getParameterTypes();
|
||||
if (actual.size() != expected.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < actual.size(); ++i) {
|
||||
if (!ASTHelpers.isSameType(actual.get(i), expected.get(i).get(state), state)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ImmutableList<Supplier<Type>> parseParams(String params) {
|
||||
ImmutableList.Builder<Supplier<Type>> types = ImmutableList.builder();
|
||||
|
||||
@Var int index = 0;
|
||||
while (index < params.length()) {
|
||||
index = parseType(params, index, types::add);
|
||||
}
|
||||
|
||||
return types.build();
|
||||
}
|
||||
|
||||
private static int parseType(String params, int index, Consumer<Supplier<Type>> sink) {
|
||||
return switch (params.charAt(index)) {
|
||||
case '[' -> parseArrayType(params, index, sink);
|
||||
case 'L' -> parseTypeReference(params, index, sink);
|
||||
default -> parsePrimitiveType(params, index, sink);
|
||||
};
|
||||
}
|
||||
|
||||
private static int parseArrayType(String params, int index, Consumer<Supplier<Type>> sink) {
|
||||
int typeIndex = index + 1;
|
||||
checkArgument(
|
||||
params.length() > typeIndex && params.charAt(index) == '[',
|
||||
"Cannot parse array type in parameter string '%s' at index %s",
|
||||
params,
|
||||
index);
|
||||
|
||||
return parseType(
|
||||
params,
|
||||
typeIndex,
|
||||
type ->
|
||||
sink.accept(s -> s.getType(type.get(s), /* isArray= */ true, ImmutableList.of())));
|
||||
}
|
||||
|
||||
private static int parsePrimitiveType(String params, int index, Consumer<Supplier<Type>> sink) {
|
||||
String primitive =
|
||||
Optional.of(params)
|
||||
.filter(p -> p.length() > index)
|
||||
.flatMap(p -> fromPrimitiveAlias(p.charAt(index)))
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException(
|
||||
String.format(
|
||||
"Cannot parse primitive type in parameter string '%s' at index %s",
|
||||
params, index)));
|
||||
sink.accept(s -> s.getTypeFromString(primitive));
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
private static Optional<String> fromPrimitiveAlias(char alias) {
|
||||
return switch (alias) {
|
||||
case 'Z' -> Optional.of("boolean");
|
||||
case 'B' -> Optional.of("byte");
|
||||
case 'C' -> Optional.of("char");
|
||||
case 'S' -> Optional.of("short");
|
||||
case 'I' -> Optional.of("int");
|
||||
case 'J' -> Optional.of("long");
|
||||
case 'F' -> Optional.of("float");
|
||||
case 'D' -> Optional.of("double");
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
private static int parseTypeReference(String params, int index, Consumer<Supplier<Type>> sink) {
|
||||
int identifierIndex = index + 1;
|
||||
if (params.length() > identifierIndex && params.charAt(index) == 'L') {
|
||||
int delimiter = params.indexOf(';', identifierIndex);
|
||||
if (delimiter > index) {
|
||||
sink.accept(
|
||||
s ->
|
||||
s.getTypeFromString(
|
||||
replaceSlashes(params.substring(identifierIndex, delimiter))));
|
||||
return delimiter + 1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Cannot parse reference type in parameter string '%s' at index %s", params, index));
|
||||
}
|
||||
|
||||
private static String replaceSlashes(String typeName) {
|
||||
return typeName.replace('/', '.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,9 @@ import tech.picnic.errorprone.utils.SourceCode;
|
||||
*/
|
||||
// XXX: What about `v1 + "sep" + v2` and similar expressions? Do we want to rewrite those to
|
||||
// `String.join`, or should some `String.join` invocations be rewritten to use the `+` operator?
|
||||
// (The latter suggestion would conflict with the `FormatStringConcatenation` check.)
|
||||
// (The latter suggestion would conflict with the `FormatStringConcatenation` check, but does make
|
||||
// more sense when `"sep"` is a long string. Similarly for `String.format("%s some long text %s",
|
||||
// arg1, arg2)`.)
|
||||
@AutoService(BugChecker.class)
|
||||
@BugPattern(
|
||||
summary = "Prefer `String#join` over `String#format`",
|
||||
|
||||
@@ -3,9 +3,6 @@ package tech.picnic.errorprone.refasterrules;
|
||||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultiset;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
@@ -15,7 +12,6 @@ import com.google.errorprone.refaster.annotation.Matches;
|
||||
import com.google.errorprone.refaster.annotation.NotMatches;
|
||||
import com.google.errorprone.refaster.annotation.Repeated;
|
||||
import com.google.errorprone.refaster.annotation.UseImportPolicy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -204,32 +200,8 @@ final class AssertJRules {
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return Refaster.anyOf(
|
||||
iterAssert.containsAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.containsAnyOf(element),
|
||||
iterAssert.containsAll(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.containsSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.containsSequence(element),
|
||||
iterAssert.containsSubsequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.containsSubsequence(element));
|
||||
}
|
||||
|
||||
@@ -244,20 +216,7 @@ final class AssertJRules {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return Refaster.anyOf(
|
||||
iterAssert.doesNotContainAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.doesNotContainSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.doesNotContainSequence(element));
|
||||
return iterAssert.doesNotContainSequence(element);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@@ -270,25 +229,7 @@ final class AssertJRules {
|
||||
static final class ObjectEnumerableContainsExactlyOneElement<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return Refaster.anyOf(
|
||||
iterAssert.containsExactlyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))),
|
||||
iterAssert.containsExactlyInAnyOrderElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element))));
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> before2(
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, @NotMatches(IsArray.class) T element) {
|
||||
return iterAssert.containsExactlyInAnyOrder(element);
|
||||
}
|
||||
@@ -313,42 +254,6 @@ final class AssertJRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsOneDistinctElement<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return iterAssert.hasSameElementsAs(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return iterAssert.containsOnly(element);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableIsSubsetOfOneElement<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return iterAssert.isSubsetOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(element),
|
||||
Arrays.asList(element),
|
||||
ImmutableSet.of(element),
|
||||
ImmutableMultiset.of(element)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T element) {
|
||||
return iterAssert.isSubsetOf(element);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Iterable
|
||||
//
|
||||
@@ -359,6 +264,7 @@ final class AssertJRules {
|
||||
Refaster.anyOf(
|
||||
assertThat(iterable).hasSize(0),
|
||||
assertThat(iterable.iterator().hasNext()).isFalse(),
|
||||
assertThat(iterable.iterator()).isExhausted(),
|
||||
assertThat(Iterables.size(iterable)).isEqualTo(0L),
|
||||
assertThat(Iterables.size(iterable)).isNotPositive());
|
||||
}
|
||||
@@ -1155,824 +1061,6 @@ final class AssertJRules {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// BELOW: Generated code.
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsAnyOf
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsAnyOfTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsAnyOf(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsAnyOfThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsAnyOf(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsAnyOfFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsAnyOf(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsAnyOfFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsAnyOf(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: contains
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsAll(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.contains(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsAll(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.contains(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsAll(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.contains(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsAll(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.contains(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsExactly
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsExactlyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsExactly(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsExactlyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsExactly(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsExactlyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsExactly(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsExactlyFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsExactlyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsExactly(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsExactlyInAnyOrder
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyInAnyOrderTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsExactlyInAnyOrderElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsExactlyInAnyOrder(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyInAnyOrderThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsExactlyInAnyOrderElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsExactlyInAnyOrder(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsExactlyInAnyOrderFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsExactlyInAnyOrderElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsExactlyInAnyOrder(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsExactlyInAnyOrderFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsExactlyInAnyOrderElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsExactlyInAnyOrder(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsSequence
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsSequenceTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsSequence(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsSequenceThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsSequence(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsSequenceFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsSequence(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsSequenceFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsSequence(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsSubsequence
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsSubsequenceTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsSubsequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsSubsequence(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsSubsequenceThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsSubsequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsSubsequence(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsSubsequenceFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsSubsequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsSubsequence(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsSubsequenceFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsSubsequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsSubsequence(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: doesNotContain
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.doesNotContainAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.doesNotContain(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.doesNotContainAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.doesNotContain(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.doesNotContainAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.doesNotContain(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableDoesNotContainFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.doesNotContainAnyElementsOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.doesNotContain(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: doesNotContainSequence
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainSequenceTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.doesNotContainSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.doesNotContainSequence(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainSequenceThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.doesNotContainSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.doesNotContainSequence(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableDoesNotContainSequenceFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.doesNotContainSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.doesNotContainSequence(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableDoesNotContainSequenceFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.doesNotContainSequence(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.doesNotContainSequence(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: containsOnly
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableContainsOnlyTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.hasSameElementsAs(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.containsOnly(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsOnlyThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.hasSameElementsAs(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.containsOnly(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableContainsOnlyFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.hasSameElementsAs(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.containsOnly(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableContainsOnlyFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.hasSameElementsAs(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.containsOnly(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectEnumerableAssert: isSubsetOf
|
||||
//
|
||||
|
||||
static final class ObjectEnumerableIsSubsetOfTwoElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.isSubsetOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2),
|
||||
Arrays.asList(e1, e2),
|
||||
ImmutableSet.of(e1, e2),
|
||||
ImmutableMultiset.of(e1, e2)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2) {
|
||||
return iterAssert.isSubsetOf(e1, e2);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableIsSubsetOfThreeElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.isSubsetOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3),
|
||||
Arrays.asList(e1, e2, e3),
|
||||
ImmutableSet.of(e1, e2, e3),
|
||||
ImmutableMultiset.of(e1, e2, e3)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3) {
|
||||
return iterAssert.isSubsetOf(e1, e2, e3);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ObjectEnumerableIsSubsetOfFourElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.isSubsetOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4),
|
||||
Arrays.asList(e1, e2, e3, e4),
|
||||
ImmutableSet.of(e1, e2, e3, e4),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4) {
|
||||
return iterAssert.isSubsetOf(e1, e2, e3, e4);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add variants for 6+ elements?
|
||||
static final class ObjectEnumerableIsSubsetOfFiveElements<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
ObjectEnumerableAssert<?, S> before(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.isSubsetOf(
|
||||
Refaster.anyOf(
|
||||
ImmutableList.of(e1, e2, e3, e4, e5),
|
||||
Arrays.asList(e1, e2, e3, e4, e5),
|
||||
ImmutableSet.of(e1, e2, e3, e4, e5),
|
||||
ImmutableMultiset.of(e1, e2, e3, e4, e5)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@SuppressWarnings("unchecked")
|
||||
ObjectEnumerableAssert<?, S> after(
|
||||
ObjectEnumerableAssert<?, S> iterAssert, T e1, T e2, T e3, T e4, T e5) {
|
||||
return iterAssert.isSubsetOf(e1, e2, e3, e4, e5);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Above: Generated code.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Organize the code below.
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.assertj.core.api.AbstractBooleanAssert;
|
||||
import org.assertj.core.api.AbstractStringAssert;
|
||||
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
|
||||
|
||||
@@ -69,6 +70,32 @@ final class AssertJStringRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatStringContains {
|
||||
@BeforeTemplate
|
||||
AbstractBooleanAssert<?> before(String string, String substring) {
|
||||
return assertThat(string.contains(substring)).isTrue();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractStringAssert<?> after(String string, String substring) {
|
||||
return assertThat(string).contains(substring);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatStringDoesNotContain {
|
||||
@BeforeTemplate
|
||||
AbstractBooleanAssert<?> before(String string, String substring) {
|
||||
return assertThat(string.contains(substring)).isFalse();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractStringAssert<?> after(String string, String substring) {
|
||||
return assertThat(string).doesNotContain(substring);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatMatches {
|
||||
@BeforeTemplate
|
||||
AbstractAssert<?, ?> before(String string, String regex) {
|
||||
|
||||
@@ -7,7 +7,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.throwable;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.type;
|
||||
|
||||
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;
|
||||
@@ -16,6 +19,7 @@ import java.io.IOException;
|
||||
import org.assertj.core.api.AbstractObjectAssert;
|
||||
import org.assertj.core.api.AbstractThrowableAssert;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.assertj.core.api.ThrowableAssertAlternative;
|
||||
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
|
||||
|
||||
/**
|
||||
@@ -31,6 +35,21 @@ import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
|
||||
final class AssertJThrowingCallableRules {
|
||||
private AssertJThrowingCallableRules() {}
|
||||
|
||||
static final class AssertThatThrownByIsInstanceOf<T extends Throwable> {
|
||||
@BeforeTemplate
|
||||
void before(ThrowingCallable throwingCallable, Class<T> exceptionType) {
|
||||
Refaster.anyOf(
|
||||
assertThatThrownBy(throwingCallable).asInstanceOf(throwable(exceptionType)),
|
||||
assertThatThrownBy(throwingCallable).asInstanceOf(type(exceptionType)));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
void after(ThrowingCallable throwingCallable, Class<T> exceptionType) {
|
||||
assertThatThrownBy(throwingCallable).isInstanceOf(exceptionType);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIllegalArgumentException {
|
||||
@BeforeTemplate
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable) {
|
||||
@@ -61,6 +80,27 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIllegalArgumentExceptionRootCauseHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByIllegalArgumentException" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatIllegalArgumentException()
|
||||
.isThrownBy(throwingCallable)
|
||||
.havingRootCause()
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatThrownBy(throwingCallable)
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.rootCause()
|
||||
.hasMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIllegalArgumentExceptionHasMessageParameters {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
@@ -171,6 +211,27 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIllegalStateExceptionRootCauseHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByIllegalStateException" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatIllegalStateException()
|
||||
.isThrownBy(throwingCallable)
|
||||
.havingRootCause()
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatThrownBy(throwingCallable)
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.rootCause()
|
||||
.hasMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIllegalStateExceptionHasMessageParameters {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
@@ -279,6 +340,27 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByNullPointerExceptionRootCauseHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByNullPointerException" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatNullPointerException()
|
||||
.isThrownBy(throwingCallable)
|
||||
.havingRootCause()
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatThrownBy(throwingCallable)
|
||||
.isInstanceOf(NullPointerException.class)
|
||||
.rootCause()
|
||||
.hasMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByNullPointerExceptionHasMessageParameters {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
@@ -386,6 +468,26 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIOExceptionRootCauseHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatIOException()
|
||||
.isThrownBy(throwingCallable)
|
||||
.havingRootCause()
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(ThrowingCallable throwingCallable, String message) {
|
||||
return assertThatThrownBy(throwingCallable)
|
||||
.isInstanceOf(IOException.class)
|
||||
.rootCause()
|
||||
.hasMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByIOExceptionHasMessageParameters {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */)
|
||||
@@ -452,24 +554,24 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownBy {
|
||||
static final class AssertThatThrownByAsInstanceOfThrowable<T extends Throwable> {
|
||||
@BeforeTemplate
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable, Class<? extends Throwable> exceptionType) {
|
||||
ThrowableAssertAlternative<T> before(
|
||||
ThrowingCallable throwingCallable, Class<T> exceptionType) {
|
||||
return assertThatExceptionOfType(exceptionType).isThrownBy(throwingCallable);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(
|
||||
ThrowingCallable throwingCallable, Class<? extends Throwable> exceptionType) {
|
||||
return assertThatThrownBy(throwingCallable).isInstanceOf(exceptionType);
|
||||
AbstractThrowableAssert<?, T> after(ThrowingCallable throwingCallable, Class<T> exceptionType) {
|
||||
return assertThatThrownBy(throwingCallable).asInstanceOf(throwable(exceptionType));
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
@@ -489,9 +591,37 @@ final class AssertJThrowingCallableRules {
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByRootCauseHasMessage {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
String message) {
|
||||
return assertThatExceptionOfType(exceptionType)
|
||||
.isThrownBy(throwingCallable)
|
||||
.havingRootCause()
|
||||
.withMessage(message);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
|
||||
AbstractObjectAssert<?, ?> after(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
String message) {
|
||||
return assertThatThrownBy(throwingCallable)
|
||||
.isInstanceOf(exceptionType)
|
||||
.rootCause()
|
||||
.hasMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
static final class AssertThatThrownByHasMessageParameters {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
@@ -517,7 +647,8 @@ final class AssertJThrowingCallableRules {
|
||||
|
||||
static final class AssertThatThrownByHasMessageStartingWith {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
@@ -541,7 +672,8 @@ final class AssertJThrowingCallableRules {
|
||||
|
||||
static final class AssertThatThrownByHasMessageContaining {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
@@ -565,7 +697,8 @@ final class AssertJThrowingCallableRules {
|
||||
|
||||
static final class AssertThatThrownByHasMessageNotContaining {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
|
||||
@SuppressWarnings(
|
||||
"AssertThatThrownByAsInstanceOfThrowable" /* This is a more specific template. */)
|
||||
AbstractObjectAssert<?, ?> before(
|
||||
ThrowingCallable throwingCallable,
|
||||
Class<? extends Throwable> exceptionType,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
import com.google.errorprone.refaster.annotation.AfterTemplate;
|
||||
import com.google.errorprone.refaster.annotation.AlsoNegation;
|
||||
import com.google.errorprone.refaster.annotation.BeforeTemplate;
|
||||
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
|
||||
|
||||
/** Refaster rules related to expressions dealing with {@link CharSequence}s. */
|
||||
@OnlineDocumentation
|
||||
final class CharSequenceRules {
|
||||
private CharSequenceRules() {}
|
||||
|
||||
/**
|
||||
* Prefer {@link CharSequence#isEmpty()} over alternatives that consult the char sequence's
|
||||
* length.
|
||||
*/
|
||||
// XXX: Drop this rule once we (and OpenRewrite) no longer support projects targeting Java 14 or
|
||||
// below.
|
||||
static final class CharSequenceIsEmpty {
|
||||
@BeforeTemplate
|
||||
boolean before(CharSequence charSequence) {
|
||||
return Refaster.anyOf(
|
||||
charSequence.length() == 0, charSequence.length() <= 0, charSequence.length() < 1);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@AlsoNegation
|
||||
boolean after(CharSequence charSequence) {
|
||||
return charSequence.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,7 @@ final class ImmutableListMultimapRules {
|
||||
* Prefer {@link ImmutableListMultimap#builder()} over the associated constructor on constructions
|
||||
* that produce a less-specific type.
|
||||
*/
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableListMultimapBuilder<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMultimap.Builder<K, V> before() {
|
||||
|
||||
@@ -28,8 +28,7 @@ final class ImmutableListRules {
|
||||
private ImmutableListRules() {}
|
||||
|
||||
/** Prefer {@link ImmutableList#builder()} over the associated constructor. */
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableListBuilder<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableList.Builder<T> before() {
|
||||
|
||||
@@ -31,8 +31,7 @@ final class ImmutableMapRules {
|
||||
private ImmutableMapRules() {}
|
||||
|
||||
/** Prefer {@link ImmutableMap#builder()} over the associated constructor. */
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableMapBuilder<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableMap.Builder<K, V> before() {
|
||||
|
||||
@@ -21,8 +21,7 @@ final class ImmutableMultisetRules {
|
||||
private ImmutableMultisetRules() {}
|
||||
|
||||
/** Prefer {@link ImmutableMultiset#builder()} over the associated constructor. */
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableMultisetBuilder<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableMultiset.Builder<T> before() {
|
||||
|
||||
@@ -29,8 +29,7 @@ final class ImmutableSetMultimapRules {
|
||||
private ImmutableSetMultimapRules() {}
|
||||
|
||||
/** Prefer {@link ImmutableSetMultimap#builder()} over the associated constructor. */
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableSetMultimapBuilder<K, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableSetMultimap.Builder<K, V> before() {
|
||||
|
||||
@@ -29,8 +29,7 @@ final class ImmutableSetRules {
|
||||
private ImmutableSetRules() {}
|
||||
|
||||
/** Prefer {@link ImmutableSet#builder()} over the associated constructor. */
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableSetBuilder<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableSet.Builder<T> before() {
|
||||
|
||||
@@ -37,8 +37,7 @@ final class ImmutableSortedMapRules {
|
||||
* Prefer {@link ImmutableSortedMap#naturalOrder()} over the alternative that requires explicitly
|
||||
* providing the {@link Comparator}.
|
||||
*/
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableSortedMapNaturalOrderBuilder<K extends Comparable<? super K>, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMap.Builder<K, V> before() {
|
||||
@@ -55,8 +54,7 @@ final class ImmutableSortedMapRules {
|
||||
* Prefer {@link ImmutableSortedMap#reverseOrder()} over the alternative that requires explicitly
|
||||
* providing the {@link Comparator}.
|
||||
*/
|
||||
// XXX: This drops generic type information, sometimes leading to non-compilable code. See
|
||||
// https://github.com/google/error-prone/pull/2706.
|
||||
// XXX: This rule may drop generic type information, leading to non-compilable code.
|
||||
static final class ImmutableSortedMapReverseOrderBuilder<K extends Comparable<? super K>, V> {
|
||||
@BeforeTemplate
|
||||
ImmutableSortedMap.Builder<K, V> before() {
|
||||
|
||||
@@ -1742,6 +1742,91 @@ final class ReactorRules {
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasSubscribed()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasSubscribed<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
Refaster.anyOf(
|
||||
assertThat(probe.wasSubscribed()).isTrue(),
|
||||
assertThat(probe.subscribeCount()).isNotNegative(),
|
||||
assertThat(probe.subscribeCount()).isNotEqualTo(0),
|
||||
assertThat(probe.subscribeCount()).isPositive());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasSubscribed();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasNotSubscribed()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasNotSubscribed<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
Refaster.anyOf(
|
||||
assertThat(probe.wasSubscribed()).isFalse(),
|
||||
assertThat(probe.subscribeCount()).isEqualTo(0),
|
||||
assertThat(probe.subscribeCount()).isNotPositive());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasNotSubscribed();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasCancelled()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasCancelled<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
assertThat(probe.wasCancelled()).isTrue();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasNotCancelled()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasNotCancelled<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
assertThat(probe.wasCancelled()).isFalse();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasNotCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasRequested()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasRequested<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
assertThat(probe.wasRequested()).isTrue();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasRequested();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link PublisherProbe#assertWasNotRequested()} over more verbose alternatives. */
|
||||
static final class PublisherProbeAssertWasNotRequested<T> {
|
||||
@BeforeTemplate
|
||||
void before(PublisherProbe<T> probe) {
|
||||
assertThat(probe.wasRequested()).isFalse();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
void after(PublisherProbe<T> probe) {
|
||||
probe.assertWasNotRequested();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */
|
||||
static final class StepVerifierFromMono<T> {
|
||||
@BeforeTemplate
|
||||
|
||||
@@ -297,6 +297,22 @@ final class StreamRules {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer an unconditional {@link Map#get(Object)} call followed by a {@code null} check over a
|
||||
* call to {@link Map#containsKey(Object)}, as the former avoids a second lookup operation.
|
||||
*/
|
||||
static final class StreamMapFilter<T, K, V> {
|
||||
@BeforeTemplate
|
||||
Stream<V> before(Stream<T> stream, Map<K, V> map) {
|
||||
return stream.filter(map::containsKey).map(map::get);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Stream<V> after(Stream<T> stream, Map<K, V> map) {
|
||||
return stream.map(map::get).filter(Objects::nonNull);
|
||||
}
|
||||
}
|
||||
|
||||
static final class StreamMin<T> {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("java:S4266" /* This violation will be rewritten. */)
|
||||
|
||||
@@ -29,11 +29,14 @@ final class StringRules {
|
||||
private StringRules() {}
|
||||
|
||||
/** Prefer {@link String#isEmpty()} over alternatives that consult the string's length. */
|
||||
// XXX: Now that we build with JDK 15+, this rule can be generalized to cover all `CharSequence`
|
||||
// subtypes. This does require a mechanism (perhaps an annotation, or a separate Maven module) to
|
||||
// make sure that non-String expressions are rewritten only if client code also targets JDK 15+.
|
||||
// XXX: Drop this rule once we (and OpenRewrite) no longer support projects targeting Java 14 or
|
||||
// below. The `CharSequenceIsEmpty` rule then suffices. (This rule exists so that e.g. projects
|
||||
// that target JDK 11 can disable `CharSequenceIsEmpty` without losing a valuable rule.)
|
||||
// XXX: Look into a more general approach to supporting different Java language levels, such as
|
||||
// rule selection based on some annotation, or a separate Maven module.
|
||||
static final class StringIsEmpty {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("CharSequenceIsEmpty" /* This is a more specific template. */)
|
||||
boolean before(String str) {
|
||||
return Refaster.anyOf(str.length() == 0, str.length() <= 0, str.length() < 1);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ final class ClassCastLambdaUsageTest {
|
||||
"import java.util.stream.Stream;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" <T> void m() {",
|
||||
" Number localVariable = 0;",
|
||||
"",
|
||||
" Stream.of(0).map(i -> i);",
|
||||
@@ -32,13 +32,14 @@ final class ClassCastLambdaUsageTest {
|
||||
" i -> {",
|
||||
" return (Integer) i;",
|
||||
" });",
|
||||
" Stream.<ImmutableSet>of(ImmutableSet.of(5)).map(s -> (ImmutableSet<Number>) s);",
|
||||
" Stream.of(ImmutableSet.of(6)).map(s -> (ImmutableSet<?>) s);",
|
||||
" Stream.of(7).reduce((a, b) -> (Integer) a);",
|
||||
" IntStream.of(8).mapToObj(i -> (char) i);",
|
||||
" Stream.<ImmutableSet>of(ImmutableSet.of(6)).map(s -> (ImmutableSet<Number>) s);",
|
||||
" Stream.of(ImmutableSet.of(7)).map(s -> (ImmutableSet<?>) s);",
|
||||
" Stream.of(8).reduce((a, b) -> (Integer) a);",
|
||||
" IntStream.of(9).mapToObj(i -> (char) i);",
|
||||
" Stream.of(10).map(i -> (T) i);",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" Stream.of(8).map(i -> (Integer) i);",
|
||||
" Stream.of(11).map(i -> (Integer) i);",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
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 ExplicitArgumentEnumerationTest {
|
||||
@Test
|
||||
void identification() {
|
||||
CompilationTestHelper.newInstance(ExplicitArgumentEnumeration.class, getClass())
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import com.google.errorprone.bugpatterns.BugChecker;",
|
||||
"import org.jooq.impl.DSL;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.test.StepVerifier;",
|
||||
"",
|
||||
"class A {",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" private final int value = unaryMethod(ImmutableList.of(1, 2));",
|
||||
"",
|
||||
" void m() {",
|
||||
" ImmutableList<String> list = ImmutableList.of();",
|
||||
" assertThat(ImmutableList.of()).containsAnyElementsOf(list);",
|
||||
"",
|
||||
" ImmutableList.<ImmutableList<String>>builder().add(ImmutableList.of());",
|
||||
"",
|
||||
" DSL.row(ImmutableList.of(1, 2));",
|
||||
"",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" unaryMethod(ImmutableList.of(1, 2));",
|
||||
" unaryMethodWithLessVisibleOverload(ImmutableList.of(1, 2));",
|
||||
" binaryMethod(ImmutableList.of(1, 2), 3);",
|
||||
"",
|
||||
" ImmutableList.builder()",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .addAll(ImmutableList.of())",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .addAll(ImmutableList.copyOf(new String[0]))",
|
||||
" .addAll(ImmutableList.copyOf(ImmutableList.of()))",
|
||||
" .build();",
|
||||
"",
|
||||
" assertThat(ImmutableList.of(1))",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .containsAnyElementsOf(ImmutableList.of(1))",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .isSubsetOf(ImmutableList.of(1));",
|
||||
"",
|
||||
" Flux.just(1, 2)",
|
||||
" .as(StepVerifier::create)",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .expectNextSequence(ImmutableList.of(1, 2))",
|
||||
" .verifyComplete();",
|
||||
"",
|
||||
" CompilationTestHelper.newInstance(BugChecker.class, getClass())",
|
||||
" // BUG: Diagnostic contains:",
|
||||
" .setArgs(ImmutableList.of(\"foo\"))",
|
||||
" .withClasspath();",
|
||||
" }",
|
||||
"",
|
||||
" private int unaryMethod(ImmutableList<Integer> args) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" private int unaryMethod(Integer... args) {",
|
||||
" return unaryMethod(ImmutableList.copyOf(args));",
|
||||
" }",
|
||||
"",
|
||||
" void unaryMethodWithLessVisibleOverload(ImmutableList<Integer> args) {}",
|
||||
"",
|
||||
" private void unaryMethodWithLessVisibleOverload(Integer... args) {",
|
||||
" unaryMethodWithLessVisibleOverload(ImmutableList.copyOf(args));",
|
||||
" }",
|
||||
"",
|
||||
" private void binaryMethod(ImmutableList<Integer> args, int extraArg) {}",
|
||||
"",
|
||||
" private void binaryMethod(Integer... args) {",
|
||||
" binaryMethod(ImmutableList.copyOf(args), 0);",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacement() {
|
||||
BugCheckerRefactoringTestHelper.newInstance(ExplicitArgumentEnumeration.class, getClass())
|
||||
.addInputLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableMultiset;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import com.google.errorprone.bugpatterns.BugChecker;",
|
||||
"import java.util.Arrays;",
|
||||
"import java.util.List;",
|
||||
"import java.util.Set;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.test.StepVerifier;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" ImmutableList.builder().addAll(ImmutableList.of()).build();",
|
||||
"",
|
||||
" assertThat(ImmutableList.of()).containsAnyElementsOf(ImmutableMultiset.of());",
|
||||
" assertThat(ImmutableList.of()).containsAll(ImmutableSet.of());",
|
||||
" assertThat(ImmutableList.of()).containsExactlyElementsOf(List.of());",
|
||||
" assertThat(ImmutableList.of()).containsExactlyInAnyOrderElementsOf(Set.of());",
|
||||
" assertThat(ImmutableList.of()).containsSequence(Arrays.asList());",
|
||||
" assertThat(ImmutableList.of()).containsSubsequence(ImmutableList.of(1));",
|
||||
" assertThat(ImmutableList.of()).doesNotContainAnyElementsOf(ImmutableMultiset.of(2));",
|
||||
" assertThat(ImmutableList.of()).doesNotContainSequence(ImmutableSet.of(3));",
|
||||
" assertThat(ImmutableList.of()).doesNotContainSubsequence(List.of(4));",
|
||||
" assertThat(ImmutableList.of()).hasSameElementsAs(Set.of(5));",
|
||||
" assertThat(ImmutableList.of()).isSubsetOf(Arrays.asList(6));",
|
||||
"",
|
||||
" Flux.empty()",
|
||||
" .as(StepVerifier::create)",
|
||||
" .expectNextSequence(ImmutableList.of(1, 2))",
|
||||
" .verifyComplete();",
|
||||
"",
|
||||
" BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())",
|
||||
" .setArgs(ImmutableList.of(\"foo\", \"bar\"));",
|
||||
" CompilationTestHelper.newInstance(BugChecker.class, getClass())",
|
||||
" .setArgs(ImmutableList.of(\"foo\", \"bar\"));",
|
||||
" }",
|
||||
"}")
|
||||
.addOutputLines(
|
||||
"A.java",
|
||||
"import static org.assertj.core.api.Assertions.assertThat;",
|
||||
"",
|
||||
"import com.google.common.collect.ImmutableList;",
|
||||
"import com.google.common.collect.ImmutableMultiset;",
|
||||
"import com.google.common.collect.ImmutableSet;",
|
||||
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
|
||||
"import com.google.errorprone.CompilationTestHelper;",
|
||||
"import com.google.errorprone.bugpatterns.BugChecker;",
|
||||
"import java.util.Arrays;",
|
||||
"import java.util.List;",
|
||||
"import java.util.Set;",
|
||||
"import reactor.core.publisher.Flux;",
|
||||
"import reactor.test.StepVerifier;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() {",
|
||||
" ImmutableList.builder().add().build();",
|
||||
"",
|
||||
" assertThat(ImmutableList.of()).containsAnyOf();",
|
||||
" assertThat(ImmutableList.of()).contains();",
|
||||
" assertThat(ImmutableList.of()).containsExactly();",
|
||||
" assertThat(ImmutableList.of()).containsExactlyInAnyOrder();",
|
||||
" assertThat(ImmutableList.of()).containsSequence();",
|
||||
" assertThat(ImmutableList.of()).containsSubsequence(1);",
|
||||
" assertThat(ImmutableList.of()).doesNotContain(2);",
|
||||
" assertThat(ImmutableList.of()).doesNotContainSequence(3);",
|
||||
" assertThat(ImmutableList.of()).doesNotContainSubsequence(4);",
|
||||
" assertThat(ImmutableList.of()).containsOnly(5);",
|
||||
" assertThat(ImmutableList.of()).isSubsetOf(6);",
|
||||
"",
|
||||
" Flux.empty().as(StepVerifier::create).expectNext(1, 2).verifyComplete();",
|
||||
"",
|
||||
" BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()).setArgs(\"foo\", \"bar\");",
|
||||
" CompilationTestHelper.newInstance(BugChecker.class, getClass()).setArgs(\"foo\", \"bar\");",
|
||||
" }",
|
||||
"}")
|
||||
.doTest(TestMode.TEXT_MATCH);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ final class JUnitMethodDeclarationTest {
|
||||
CompilationTestHelper.newInstance(JUnitMethodDeclaration.class, getClass())
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static org.junit.jupiter.params.provider.Arguments.arguments;",
|
||||
"import static org.junit.jupiter.params.provider.Arguments.*;",
|
||||
"",
|
||||
"import org.junit.jupiter.api.AfterAll;",
|
||||
"import org.junit.jupiter.api.AfterEach;",
|
||||
@@ -154,8 +154,10 @@ final class JUnitMethodDeclarationTest {
|
||||
" void overload() {}",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains: (but note that `arguments` is already statically imported)",
|
||||
" void testArguments() {}",
|
||||
" // BUG: Diagnostic contains: (but note that another method named `arguments` is in scope)",
|
||||
" void testArguments() {",
|
||||
" arguments();",
|
||||
" }",
|
||||
"",
|
||||
" @Test",
|
||||
" // BUG: Diagnostic contains: (but note that `public` is not a valid identifier)",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
@@ -294,9 +293,8 @@ final class LexicographicalAnnotationAttributeListingTest {
|
||||
/* Some violations are not flagged because they are not in- or excluded. */
|
||||
CompilationTestHelper.newInstance(LexicographicalAnnotationAttributeListing.class, getClass())
|
||||
.setArgs(
|
||||
ImmutableList.of(
|
||||
"-XepOpt:LexicographicalAnnotationAttributeListing:Includes=pkg.A.Foo,pkg.A.Bar",
|
||||
"-XepOpt:LexicographicalAnnotationAttributeListing:Excludes=pkg.A.Bar#value"))
|
||||
"-XepOpt:LexicographicalAnnotationAttributeListing:Includes=pkg.A.Foo,pkg.A.Bar",
|
||||
"-XepOpt:LexicographicalAnnotationAttributeListing:Excludes=pkg.A.Bar#value")
|
||||
.addSourceLines(
|
||||
"pkg/A.java",
|
||||
"package pkg;",
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class ModernizerTest {
|
||||
private final CompilationTestHelper compilationTestHelper =
|
||||
CompilationTestHelper.newInstance(Modernizer.class, getClass());
|
||||
|
||||
// XXX: Also add calls that should not be flagged.
|
||||
// XXX: Test extension, field references, instance methods, static methods.
|
||||
// methods with primitives, primitive arrays, references, reference arrays
|
||||
// zero, one two args.
|
||||
// XXX: Also test constructors!
|
||||
// XXX: Test that the appropriate "prefer" message is emitted.
|
||||
// XXX: List the test cases in `ModernizerTest`?
|
||||
|
||||
@Test
|
||||
void fieldIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.base.Charsets.ISO_8859_1;",
|
||||
"",
|
||||
"import com.google.common.base.Charsets;",
|
||||
"import java.nio.charset.StandardCharsets;",
|
||||
"",
|
||||
"class A {",
|
||||
" {",
|
||||
" // BUG: Diagnostic contains: Prefer java.nio.charset.StandardCharsets",
|
||||
" Object o1 = ISO_8859_1;",
|
||||
" // BUG: Diagnostic contains: Prefer java.nio.charset.StandardCharsets",
|
||||
" Object o2 = Charsets.ISO_8859_1;",
|
||||
" // BUG: Diagnostic contains: Prefer java.nio.charset.StandardCharsets",
|
||||
" Object o3 = com.google.common.base.Charsets.ISO_8859_1;",
|
||||
"",
|
||||
" Object o4 = StandardCharsets.ISO_8859_1;",
|
||||
" Object o5 = java.nio.charset.StandardCharsets.ISO_8859_1;",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullaryMethodIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.base.Optional.absent;",
|
||||
"",
|
||||
"import com.google.common.base.Optional;",
|
||||
"import java.util.function.Supplier;",
|
||||
"",
|
||||
"class A {",
|
||||
" {",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Optional",
|
||||
" absent();",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Optional",
|
||||
" Optional.absent();",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Optional",
|
||||
" com.google.common.base.Optional.absent();",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Optional",
|
||||
" Supplier<?> s1 = Optional::absent;",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Optional",
|
||||
" Supplier<?> s2 = com.google.common.base.Optional::absent;",
|
||||
"",
|
||||
" java.util.Optional.empty();",
|
||||
" Supplier<?> s3 = java.util.Optional::empty;",
|
||||
"",
|
||||
" Dummy.absent();",
|
||||
" }",
|
||||
"",
|
||||
" static final class Dummy {",
|
||||
" static Optional<?> absent() {",
|
||||
" return null;",
|
||||
" }",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void unaryMethodWithIntegerArgumentIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.collect.Lists.newArrayListWithCapacity;",
|
||||
"",
|
||||
"import com.google.common.collect.Lists;",
|
||||
"import java.util.ArrayList;",
|
||||
"import java.util.function.IntFunction;",
|
||||
"",
|
||||
"class A {",
|
||||
" {",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.ArrayList<>(int)",
|
||||
" newArrayListWithCapacity(0);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.ArrayList<>(int)",
|
||||
" Lists.newArrayListWithCapacity(1);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.ArrayList<>(int)",
|
||||
" com.google.common.collect.Lists.newArrayListWithCapacity(2);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.ArrayList<>(int)",
|
||||
" IntFunction<?> f1 = Lists::newArrayListWithCapacity;",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.ArrayList<>(int)",
|
||||
" IntFunction<?> f2 = com.google.common.collect.Lists::newArrayListWithCapacity;",
|
||||
"",
|
||||
" new ArrayList<>(3);",
|
||||
" IntFunction<?> f3 = ArrayList::new;",
|
||||
" IntFunction<?> f4 = java.util.ArrayList::new;",
|
||||
"",
|
||||
" Dummy.newArrayListWithCapacity(4);",
|
||||
" }",
|
||||
"",
|
||||
" static final class Dummy {",
|
||||
" static ArrayList<?> newArrayListWithCapacity(int initialArraySize) {",
|
||||
" return null;",
|
||||
" }",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void binaryMethodWithObjectArgumentsIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import static com.google.common.base.Objects.equal;",
|
||||
"",
|
||||
"import com.google.common.base.Objects;",
|
||||
"import java.util.function.BiPredicate;",
|
||||
"",
|
||||
"class A {",
|
||||
" {",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.equals(Object, Object)",
|
||||
" equal(null, null);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.equals(Object, Object)",
|
||||
" Objects.equal(null, null);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.equals(Object, Object)",
|
||||
" com.google.common.base.Objects.equal(null, null);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.equals(Object, Object)",
|
||||
" BiPredicate<?, ?> p1 = Objects::equal;",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.equals(Object, Object)",
|
||||
" BiPredicate<?, ?> p2 = com.google.common.base.Objects::equal;",
|
||||
"",
|
||||
" java.util.Objects.equals(null, null);",
|
||||
" BiPredicate<?, ?> p3 = java.util.Objects::equals;",
|
||||
"",
|
||||
" Dummy.equal(null, null);",
|
||||
" }",
|
||||
"",
|
||||
" static final class Dummy {",
|
||||
" static boolean equal(Object a, Object b) {",
|
||||
" return false;",
|
||||
" }",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void varargsMethodWithObjectArgumentsIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import com.google.common.base.Objects;",
|
||||
"import java.util.function.ToIntFunction;",
|
||||
"",
|
||||
"class A {",
|
||||
" {",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.hash(Object...)",
|
||||
" Objects.hashCode((Object) null);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.hash(Object...)",
|
||||
" com.google.common.base.Objects.hashCode(null, null);",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.hash(Object...)",
|
||||
" ToIntFunction<?> f1 = Objects::hashCode;",
|
||||
" // BUG: Diagnostic contains: Prefer java.util.Objects.hash(Object...)",
|
||||
" ToIntFunction<?> f2 = com.google.common.base.Objects::hashCode;",
|
||||
"",
|
||||
" java.util.Objects.hash(null, null, null);",
|
||||
" ToIntFunction<?> f3 = java.util.Objects::hash;",
|
||||
"",
|
||||
" Dummy.hashCode(null, null, null, null);",
|
||||
" }",
|
||||
"",
|
||||
" static final class Dummy {",
|
||||
" static int hashCode(Object... objects) {",
|
||||
" return 0;",
|
||||
" }",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
void binaryConstructorWithByteArrayAndObjectArgumentsIdentification() {
|
||||
compilationTestHelper
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import java.io.UnsupportedEncodingException;",
|
||||
"import java.nio.charset.StandardCharsets;",
|
||||
"",
|
||||
"class A {",
|
||||
" void m() throws UnsupportedEncodingException {",
|
||||
" // BUG: Diagnostic contains: Prefer java.lang.String.<init>(byte[], java.nio.charset.Charset)",
|
||||
" new String(new byte[0], \"\");",
|
||||
" // BUG: Diagnostic contains: Prefer java.lang.String.<init>(byte[], java.nio.charset.Charset)",
|
||||
" new java.lang.String(new byte[] {}, toString());",
|
||||
"",
|
||||
" new String(new byte[0], StandardCharsets.UTF_8);",
|
||||
" new java.lang.String(new byte[0], StandardCharsets.UTF_8);",
|
||||
"",
|
||||
" new Dummy(new byte[0], \"\");",
|
||||
" }",
|
||||
"",
|
||||
" static final class Dummy {",
|
||||
" Dummy(byte bytes[], String charsetName) {}",
|
||||
" }",
|
||||
"}")
|
||||
.doTest();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
import com.google.errorprone.CompilationTestHelper;
|
||||
@@ -408,8 +407,7 @@ final class RedundantStringConversionTest {
|
||||
void identificationOfCustomConversionMethod() {
|
||||
CompilationTestHelper.newInstance(RedundantStringConversion.class, getClass())
|
||||
.setArgs(
|
||||
ImmutableList.of(
|
||||
"-XepOpt:RedundantStringConversion:ExtraConversionMethods=java.lang.Enum#name(),A#name(),A.B#toString(int)"))
|
||||
"-XepOpt:RedundantStringConversion:ExtraConversionMethods=java.lang.Enum#name(),A#name(),A.B#toString(int)")
|
||||
.addSourceLines(
|
||||
"A.java",
|
||||
"import java.math.RoundingMode;",
|
||||
|
||||
@@ -36,6 +36,7 @@ final class RefasterRulesTest {
|
||||
AssortedRules.class,
|
||||
BigDecimalRules.class,
|
||||
BugCheckerRules.class,
|
||||
CharSequenceRules.class,
|
||||
ClassRules.class,
|
||||
CollectionRules.class,
|
||||
ComparatorRules.class,
|
||||
|
||||
@@ -33,6 +33,14 @@ final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return assertThat("foo".isEmpty()).isFalse();
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatStringContains() {
|
||||
return assertThat("foo".contains("bar")).isTrue();
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatStringDoesNotContain() {
|
||||
return assertThat("foo".contains("bar")).isFalse();
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatMatches() {
|
||||
return assertThat("foo".matches(".*")).isTrue();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,14 @@ final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return assertThat("foo").isNotEmpty();
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatStringContains() {
|
||||
return assertThat("foo").contains("bar");
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatStringDoesNotContain() {
|
||||
return assertThat("foo").doesNotContain("bar");
|
||||
}
|
||||
|
||||
AbstractAssert<?, ?> testAssertThatMatches() {
|
||||
return assertThat("foo").matches(".*");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.throwable;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.type;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.assertj.core.api.AbstractObjectAssert;
|
||||
@@ -20,7 +22,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
assertThatIOException(),
|
||||
assertThatIllegalArgumentException(),
|
||||
assertThatIllegalStateException(),
|
||||
assertThatNullPointerException());
|
||||
assertThatNullPointerException(),
|
||||
type(Throwable.class));
|
||||
}
|
||||
|
||||
void testAssertThatThrownByIsInstanceOf() {
|
||||
assertThatThrownBy(() -> {}).asInstanceOf(throwable(IllegalArgumentException.class));
|
||||
assertThatThrownBy(() -> {}).asInstanceOf(type(IllegalArgumentException.class));
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentException() {
|
||||
@@ -31,6 +39,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatIllegalArgumentException().isThrownBy(() -> {}).withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionRootCauseHasMessage() {
|
||||
return assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> {})
|
||||
.havingRootCause()
|
||||
.withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionHasMessageParameters() {
|
||||
return assertThatIllegalArgumentException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
|
||||
}
|
||||
@@ -59,6 +74,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatIllegalStateException().isThrownBy(() -> {}).withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionRootCauseHasMessage() {
|
||||
return assertThatIllegalStateException()
|
||||
.isThrownBy(() -> {})
|
||||
.havingRootCause()
|
||||
.withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageParameters() {
|
||||
return assertThatIllegalStateException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
|
||||
}
|
||||
@@ -83,6 +105,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatNullPointerException().isThrownBy(() -> {}).withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionRootCauseHasMessage() {
|
||||
return assertThatNullPointerException()
|
||||
.isThrownBy(() -> {})
|
||||
.havingRootCause()
|
||||
.withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageParameters() {
|
||||
return assertThatNullPointerException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
|
||||
}
|
||||
@@ -107,6 +136,10 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatIOException().isThrownBy(() -> {}).withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionRootCauseHasMessage() {
|
||||
return assertThatIOException().isThrownBy(() -> {}).havingRootCause().withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageParameters() {
|
||||
return assertThatIOException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
|
||||
}
|
||||
@@ -123,7 +156,7 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatIOException().isThrownBy(() -> {}).withMessageNotContaining("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByAsInstanceOfThrowable() {
|
||||
return assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {});
|
||||
}
|
||||
|
||||
@@ -133,6 +166,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
.withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByRootCauseHasMessage() {
|
||||
return assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> {})
|
||||
.havingRootCause()
|
||||
.withMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageParameters() {
|
||||
return assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> {})
|
||||
|
||||
@@ -6,6 +6,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.throwable;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.type;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.IOException;
|
||||
@@ -21,7 +23,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
assertThatIOException(),
|
||||
assertThatIllegalArgumentException(),
|
||||
assertThatIllegalStateException(),
|
||||
assertThatNullPointerException());
|
||||
assertThatNullPointerException(),
|
||||
type(Throwable.class));
|
||||
}
|
||||
|
||||
void testAssertThatThrownByIsInstanceOf() {
|
||||
assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentException() {
|
||||
@@ -34,6 +42,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionRootCauseHasMessage() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.rootCause()
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionHasMessageParameters() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
@@ -68,6 +83,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatThrownBy(() -> {}).isInstanceOf(IllegalStateException.class).hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionRootCauseHasMessage() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.rootCause()
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageParameters() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
@@ -100,6 +122,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatThrownBy(() -> {}).isInstanceOf(NullPointerException.class).hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionRootCauseHasMessage() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(NullPointerException.class)
|
||||
.rootCause()
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageParameters() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(NullPointerException.class)
|
||||
@@ -132,6 +161,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionRootCauseHasMessage() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IOException.class)
|
||||
.rootCause()
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageParameters() {
|
||||
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo %s", "bar");
|
||||
}
|
||||
@@ -152,8 +188,8 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
.hasMessageNotContaining("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
|
||||
return assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class);
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByAsInstanceOfThrowable() {
|
||||
return assertThatThrownBy(() -> {}).asInstanceOf(throwable(IllegalArgumentException.class));
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessage() {
|
||||
@@ -162,6 +198,13 @@ final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTe
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByRootCauseHasMessage() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.rootCause()
|
||||
.hasMessage("foo");
|
||||
}
|
||||
|
||||
AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageParameters() {
|
||||
return assertThatThrownBy(() -> {})
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
|
||||
|
||||
final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase {
|
||||
ImmutableSet<Boolean> testCharSequenceIsEmpty() {
|
||||
return ImmutableSet.of(
|
||||
new StringBuilder("foo").length() == 0,
|
||||
new StringBuilder("bar").length() <= 0,
|
||||
new StringBuilder("baz").length() < 1,
|
||||
new StringBuilder("qux").length() != 0,
|
||||
new StringBuilder("quux").length() > 0,
|
||||
new StringBuilder("corge").length() >= 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;
|
||||
|
||||
final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase {
|
||||
ImmutableSet<Boolean> testCharSequenceIsEmpty() {
|
||||
return ImmutableSet.of(
|
||||
new StringBuilder("foo").isEmpty(),
|
||||
new StringBuilder("bar").isEmpty(),
|
||||
new StringBuilder("baz").isEmpty(),
|
||||
!new StringBuilder("qux").isEmpty(),
|
||||
!new StringBuilder("quux").isEmpty(),
|
||||
!new StringBuilder("corge").isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
||||
List.class,
|
||||
ImmutableCollection.class,
|
||||
ImmutableMap.class,
|
||||
assertThat(false),
|
||||
assertThat(0),
|
||||
maxBy(null),
|
||||
minBy(null),
|
||||
@@ -589,6 +590,35 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasSubscribed() {
|
||||
assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isTrue();
|
||||
assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isNotNegative();
|
||||
assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotEqualTo(0);
|
||||
assertThat(PublisherProbe.of(Mono.just(4)).subscribeCount()).isPositive();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotSubscribed() {
|
||||
assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isFalse();
|
||||
assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isEqualTo(0);
|
||||
assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotPositive();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasCancelled() {
|
||||
assertThat(PublisherProbe.empty().wasCancelled()).isTrue();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotCancelled() {
|
||||
assertThat(PublisherProbe.empty().wasCancelled()).isFalse();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasRequested() {
|
||||
assertThat(PublisherProbe.empty().wasRequested()).isTrue();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotRequested() {
|
||||
assertThat(PublisherProbe.empty().wasRequested()).isFalse();
|
||||
}
|
||||
|
||||
ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
|
||||
return ImmutableSet.of(
|
||||
StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create));
|
||||
|
||||
@@ -47,6 +47,7 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
||||
List.class,
|
||||
ImmutableCollection.class,
|
||||
ImmutableMap.class,
|
||||
assertThat(false),
|
||||
assertThat(0),
|
||||
maxBy(null),
|
||||
minBy(null),
|
||||
@@ -577,6 +578,35 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasSubscribed() {
|
||||
PublisherProbe.of(Mono.just(1)).assertWasSubscribed();
|
||||
PublisherProbe.of(Mono.just(2)).assertWasSubscribed();
|
||||
PublisherProbe.of(Mono.just(3)).assertWasSubscribed();
|
||||
PublisherProbe.of(Mono.just(4)).assertWasSubscribed();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotSubscribed() {
|
||||
PublisherProbe.of(Mono.just(1)).assertWasNotSubscribed();
|
||||
PublisherProbe.of(Mono.just(2)).assertWasNotSubscribed();
|
||||
PublisherProbe.of(Mono.just(3)).assertWasNotSubscribed();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasCancelled() {
|
||||
PublisherProbe.empty().assertWasCancelled();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotCancelled() {
|
||||
PublisherProbe.empty().assertWasNotCancelled();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasRequested() {
|
||||
PublisherProbe.empty().assertWasRequested();
|
||||
}
|
||||
|
||||
void testPublisherProbeAssertWasNotRequested() {
|
||||
PublisherProbe.empty().assertWasNotRequested();
|
||||
}
|
||||
|
||||
ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
|
||||
return ImmutableSet.of(
|
||||
Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create));
|
||||
|
||||
@@ -141,6 +141,12 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return Stream.of(1).findFirst().isPresent();
|
||||
}
|
||||
|
||||
Stream<Integer> testStreamMapFilter() {
|
||||
return Stream.of("foo")
|
||||
.filter(ImmutableMap.of(1, 2)::containsKey)
|
||||
.map(ImmutableMap.of(1, 2)::get);
|
||||
}
|
||||
|
||||
ImmutableSet<Optional<String>> testStreamMin() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of("foo").max(comparingInt(String::length).reversed()),
|
||||
|
||||
@@ -141,6 +141,10 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return Stream.of(1).findAny().isPresent();
|
||||
}
|
||||
|
||||
Stream<Integer> testStreamMapFilter() {
|
||||
return Stream.of("foo").map(ImmutableMap.of(1, 2)::get).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
ImmutableSet<Optional<String>> testStreamMin() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of("foo").min(comparingInt(String::length)),
|
||||
|
||||
@@ -28,9 +28,9 @@ final class StringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
"foo".length() == 0,
|
||||
"bar".length() <= 0,
|
||||
"baz".length() < 1,
|
||||
"foo".length() != 0,
|
||||
"bar".length() > 0,
|
||||
"baz".length() >= 1);
|
||||
"qux".length() != 0,
|
||||
"quux".length() > 0,
|
||||
"corge".length() >= 1);
|
||||
}
|
||||
|
||||
boolean testStringIsEmptyPredicate() {
|
||||
|
||||
@@ -31,9 +31,9 @@ final class StringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
"foo".isEmpty(),
|
||||
"bar".isEmpty(),
|
||||
"baz".isEmpty(),
|
||||
!"foo".isEmpty(),
|
||||
!"bar".isEmpty(),
|
||||
!"baz".isEmpty());
|
||||
!"qux".isEmpty(),
|
||||
!"quux".isEmpty(),
|
||||
!"corge".isEmpty());
|
||||
}
|
||||
|
||||
boolean testStringIsEmptyPredicate() {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package tech.picnic.errorprone.utils;
|
||||
|
||||
import static tech.picnic.errorprone.utils.JavaKeywords.isValidIdentifier;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.google.errorprone.VisitorState;
|
||||
import com.google.errorprone.util.ASTHelpers;
|
||||
import com.sun.source.tree.ImportTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.source.tree.ClassTree;
|
||||
import com.sun.source.tree.IdentifierTree;
|
||||
import com.sun.source.tree.MethodInvocationTree;
|
||||
import com.sun.source.util.TreeScanner;
|
||||
import com.sun.tools.javac.code.Symbol.MethodSymbol;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import java.util.Optional;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/** A set of helper methods for detecting conflicts that would be caused when applying fixes. */
|
||||
public final class ConflictDetection {
|
||||
@@ -24,9 +27,10 @@ public final class ConflictDetection {
|
||||
* <ul>
|
||||
* <li>Whether the rename would merely introduce a method overload, rather than clashing with an
|
||||
* existing method declaration in its class or a supertype.
|
||||
* <li>Whether the rename would in fact clash with a static import. (It could be that a static
|
||||
* import of the same name is only referenced from lexical scopes in which the method under
|
||||
* consideration cannot be referenced directly.)
|
||||
* <li>Whether the rename would in fact change the target of an existing method invocation in
|
||||
* the scope of its containing class. (It could e.g. be that said invocation targets an
|
||||
* identically-named method with different parameter types in some non-static nested type
|
||||
* declaration.)
|
||||
* </ul>
|
||||
*
|
||||
* @param method The method considered for renaming.
|
||||
@@ -43,11 +47,11 @@ public final class ConflictDetection {
|
||||
"a method named `%s` is already defined in this class or a supertype", newName));
|
||||
}
|
||||
|
||||
if (isSimpleNameStaticallyImported(newName, state)) {
|
||||
return Optional.of(String.format("`%s` is already statically imported", newName));
|
||||
if (isLocalMethodInvocation(newName, state)) {
|
||||
return Optional.of(String.format("another method named `%s` is in scope", newName));
|
||||
}
|
||||
|
||||
if (!isValidIdentifier(newName)) {
|
||||
if (!SourceCode.isValidIdentifier(newName)) {
|
||||
return Optional.of(String.format("`%s` is not a valid identifier", newName));
|
||||
}
|
||||
|
||||
@@ -60,16 +64,35 @@ public final class ConflictDetection {
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
private static boolean isSimpleNameStaticallyImported(String simpleName, VisitorState state) {
|
||||
return state.getPath().getCompilationUnit().getImports().stream()
|
||||
.filter(ImportTree::isStatic)
|
||||
.map(ImportTree::getQualifiedIdentifier)
|
||||
.map(tree -> getStaticImportSimpleName(tree, state))
|
||||
.anyMatch(simpleName::contentEquals);
|
||||
}
|
||||
private static boolean isLocalMethodInvocation(String name, VisitorState state) {
|
||||
return Boolean.TRUE.equals(
|
||||
new TreeScanner<Boolean, @Nullable Void>() {
|
||||
@Override
|
||||
public Boolean visitClass(ClassTree tree, @Nullable Void unused) {
|
||||
if (ASTHelpers.getSymbol(tree).isStatic()) {
|
||||
/*
|
||||
* Don't descend into static type definitions: in those context, any unqualified
|
||||
* method invocation cannot refer to a method in the outer scope.
|
||||
*/
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
private static CharSequence getStaticImportSimpleName(Tree tree, VisitorState state) {
|
||||
String source = SourceCode.treeToString(tree, state);
|
||||
return source.subSequence(source.lastIndexOf('.') + 1, source.length());
|
||||
return super.visitClass(tree, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitMethodInvocation(MethodInvocationTree tree, @Nullable Void unused) {
|
||||
return (tree.getMethodSelect() instanceof IdentifierTree identifier
|
||||
&& name.contentEquals(identifier.getName()))
|
||||
|| super.visitMethodInvocation(tree, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean reduce(Boolean r1, Boolean r2) {
|
||||
return Boolean.TRUE.equals(r1) || Boolean.TRUE.equals(r2);
|
||||
}
|
||||
}.scan(
|
||||
requireNonNull(state.findEnclosing(ClassTree.class), "No enclosing class").getMembers(),
|
||||
null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
package tech.picnic.errorprone.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/** Utility class that can be used to identify reserved keywords of the Java language. */
|
||||
// XXX: This class is no longer only about keywords. Consider changing its name and class-level
|
||||
// documentation.
|
||||
public final class JavaKeywords {
|
||||
/**
|
||||
* Enumeration of boolean and null literals.
|
||||
*
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.10.3">JDK 17
|
||||
* JLS section 3.10.3: Boolean Literals</a>
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.10.8">JDK 17
|
||||
* JLS section 3.10.8: The Null Literal</a>
|
||||
*/
|
||||
private static final ImmutableSet<String> BOOLEAN_AND_NULL_LITERALS =
|
||||
ImmutableSet.of("true", "false", "null");
|
||||
|
||||
/**
|
||||
* List of all reserved keywords in the Java language.
|
||||
*
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.9">JDK 17 JLS
|
||||
* section 3.9: Keywords</a>
|
||||
*/
|
||||
private static final ImmutableSet<String> RESERVED_KEYWORDS =
|
||||
ImmutableSet.of(
|
||||
"_",
|
||||
"abstract",
|
||||
"assert",
|
||||
"boolean",
|
||||
"break",
|
||||
"byte",
|
||||
"case",
|
||||
"catch",
|
||||
"char",
|
||||
"class",
|
||||
"const",
|
||||
"continue",
|
||||
"default",
|
||||
"do",
|
||||
"double",
|
||||
"else",
|
||||
"enum",
|
||||
"extends",
|
||||
"final",
|
||||
"finally",
|
||||
"float",
|
||||
"for",
|
||||
"goto",
|
||||
"if",
|
||||
"implements",
|
||||
"import",
|
||||
"instanceof",
|
||||
"int",
|
||||
"interface",
|
||||
"long",
|
||||
"native",
|
||||
"new",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"return",
|
||||
"short",
|
||||
"static",
|
||||
"strictfp",
|
||||
"super",
|
||||
"switch",
|
||||
"synchronized",
|
||||
"this",
|
||||
"throw",
|
||||
"throws",
|
||||
"transient",
|
||||
"try",
|
||||
"void",
|
||||
"volatile",
|
||||
"while");
|
||||
|
||||
/**
|
||||
* List of all contextual keywords in the Java language.
|
||||
*
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.9">JDK 17 JLS
|
||||
* section 3.9: Keywords</a>
|
||||
*/
|
||||
private static final ImmutableSet<String> CONTEXTUAL_KEYWORDS =
|
||||
ImmutableSet.of(
|
||||
"exports",
|
||||
"module",
|
||||
"non-sealed",
|
||||
"open",
|
||||
"opens",
|
||||
"permits",
|
||||
"provides",
|
||||
"record",
|
||||
"requires",
|
||||
"sealed",
|
||||
"to",
|
||||
"transitive",
|
||||
"uses",
|
||||
"var",
|
||||
"with",
|
||||
"yield");
|
||||
|
||||
/** List of all keywords in the Java language. */
|
||||
private static final ImmutableSet<String> ALL_KEYWORDS =
|
||||
Sets.union(RESERVED_KEYWORDS, CONTEXTUAL_KEYWORDS).immutableCopy();
|
||||
|
||||
private JavaKeywords() {}
|
||||
|
||||
/**
|
||||
* Tells whether the given string is a valid identifier in the Java language.
|
||||
*
|
||||
* @param str The string of interest.
|
||||
* @return {@code true} if the given string is a valid identifier in the Java language.
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.8">JDK 17 JLS
|
||||
* section 3.8: Identifiers</a>
|
||||
*/
|
||||
@SuppressWarnings("java:S1067" /* Chaining conjunctions like this does not impact readability. */)
|
||||
public static boolean isValidIdentifier(String str) {
|
||||
return !str.isEmpty()
|
||||
&& !isReservedKeyword(str)
|
||||
&& !BOOLEAN_AND_NULL_LITERALS.contains(str)
|
||||
&& Character.isJavaIdentifierStart(str.codePointAt(0))
|
||||
&& str.codePoints().skip(1).allMatch(Character::isUnicodeIdentifierPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the given string is a reserved keyword in the Java language.
|
||||
*
|
||||
* @param str The string of interest.
|
||||
* @return {@code true} if the given string is a reserved keyword in the Java language.
|
||||
*/
|
||||
public static boolean isReservedKeyword(String str) {
|
||||
return RESERVED_KEYWORDS.contains(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the given string is a contextual keyword in the Java language.
|
||||
*
|
||||
* @param str The string of interest.
|
||||
* @return {@code true} if the given string is a contextual keyword in the Java language.
|
||||
*/
|
||||
public static boolean isContextualKeyword(String str) {
|
||||
return CONTEXTUAL_KEYWORDS.contains(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the given string is a reserved or contextual keyword in the Java language.
|
||||
*
|
||||
* @param str The string of interest.
|
||||
* @return {@code true} if the given string is a reserved or contextual keyword in the Java
|
||||
* language.
|
||||
*/
|
||||
public static boolean isKeyword(String str) {
|
||||
return ALL_KEYWORDS.contains(str);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import com.sun.source.tree.Tree;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
import java.util.Optional;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
/**
|
||||
* A collection of Error Prone utility methods for dealing with the source code representation of
|
||||
@@ -28,6 +29,18 @@ public final class SourceCode {
|
||||
|
||||
private SourceCode() {}
|
||||
|
||||
/**
|
||||
* Tells whether the given string is a valid identifier in the Java language.
|
||||
*
|
||||
* @param str The string of interest.
|
||||
* @return {@code true} if the given string is a valid identifier in the Java language.
|
||||
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.8">JDK 17 JLS
|
||||
* section 3.8: Identifiers</a>
|
||||
*/
|
||||
public static boolean isValidIdentifier(String str) {
|
||||
return str.indexOf('.') < 0 && SourceVersion.isName(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the given {@link Tree}, preferring the original source code
|
||||
* (if available) over its prettified representation.
|
||||
|
||||
@@ -21,13 +21,13 @@ final class ConflictDetectionTest {
|
||||
"pkg/A.java",
|
||||
"package pkg;",
|
||||
"",
|
||||
"import static pkg.A.B.method3t;",
|
||||
"import static pkg.A.StaticType.method3t;",
|
||||
"import static pkg.A.StaticType.method4t;",
|
||||
"",
|
||||
"import pkg.A.method4t;",
|
||||
"",
|
||||
"class A {",
|
||||
" void method1() {",
|
||||
" method3t();",
|
||||
" method4(method4t.class);",
|
||||
" }",
|
||||
"",
|
||||
@@ -37,7 +37,7 @@ final class ConflictDetectionTest {
|
||||
"",
|
||||
" void method2t() {}",
|
||||
"",
|
||||
" // BUG: Diagnostic contains: `method3t` is already statically imported",
|
||||
" // BUG: Diagnostic contains: another method named `method3t` is in scope",
|
||||
" void method3() {}",
|
||||
"",
|
||||
" void method4(Object o) {}",
|
||||
@@ -45,8 +45,34 @@ final class ConflictDetectionTest {
|
||||
" // BUG: Diagnostic contains: `int` is not a valid identifier",
|
||||
" void in() {}",
|
||||
"",
|
||||
" static class B {",
|
||||
" static void method3t() {}",
|
||||
" class InstanceType {",
|
||||
" void m() {",
|
||||
" System.out.println(method3t());",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" static class StaticType {",
|
||||
" static int method3t() {",
|
||||
" return 0;",
|
||||
" }",
|
||||
"",
|
||||
" static void method4t() {",
|
||||
" method4t();",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" record RecordType() {",
|
||||
" void m() {",
|
||||
" method4t();",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" enum EnumType {",
|
||||
" ELEM;",
|
||||
"",
|
||||
" void m() {",
|
||||
" method4t();",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" class method4t {}",
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package tech.picnic.errorprone.utils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
final class JavaKeywordsTest {
|
||||
private static Stream<Arguments> isValidIdentifierTestCases() {
|
||||
/* { string, expected } */
|
||||
return Stream.of(
|
||||
arguments("", false),
|
||||
arguments("public", false),
|
||||
arguments("true", false),
|
||||
arguments("false", false),
|
||||
arguments("null", false),
|
||||
arguments("0", false),
|
||||
arguments("\0", false),
|
||||
arguments("a%\0", false),
|
||||
arguments("a", true),
|
||||
arguments("a0", true),
|
||||
arguments("_a0", true),
|
||||
arguments("test", true));
|
||||
}
|
||||
|
||||
@MethodSource("isValidIdentifierTestCases")
|
||||
@ParameterizedTest
|
||||
void isValidIdentifier(String string, boolean expected) {
|
||||
assertThat(JavaKeywords.isValidIdentifier(string)).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package tech.picnic.errorprone.utils;
|
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper;
|
||||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
|
||||
@@ -22,10 +24,41 @@ import com.sun.source.tree.MethodTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Name;
|
||||
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;
|
||||
|
||||
final class SourceCodeTest {
|
||||
private static Stream<Arguments> isValidIdentifierTestCases() {
|
||||
/* { string, expected } */
|
||||
return Stream.of(
|
||||
arguments("", false),
|
||||
arguments(".", false),
|
||||
arguments("a.", false),
|
||||
arguments(".a", false),
|
||||
arguments("a.b", false),
|
||||
arguments("public", false),
|
||||
arguments("true", false),
|
||||
arguments("false", false),
|
||||
arguments("null", false),
|
||||
arguments("0", false),
|
||||
arguments("\0", false),
|
||||
arguments("a%\0", false),
|
||||
arguments("a", true),
|
||||
arguments("a0", true),
|
||||
arguments("_a0", true),
|
||||
arguments("test", true));
|
||||
}
|
||||
|
||||
@MethodSource("isValidIdentifierTestCases")
|
||||
@ParameterizedTest
|
||||
void isValidIdentifier(String string, boolean expected) {
|
||||
assertThat(SourceCode.isValidIdentifier(string)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringConstantExpression() {
|
||||
BugCheckerRefactoringTestHelper.newInstance(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,10 @@ src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionParameterNumber
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionRecordComponentNameTest.java:[40,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionRecordComponentNumberTest.java:[39,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionReturnCountTest.java:[38,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `void` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionSeparatorWrapTest.java:[40,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `class` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionSeparatorWrapTest.java:[60,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `interface` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionSimplifyBooleanExpressionTest.java:[90,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `interface` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionSuperFinalizeTest.java:[40,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionThrowsCountTest.java:[39,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionTypeNameTest.java:[40,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionUncommentedMainTest.java:[39,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
@@ -57,7 +60,7 @@ src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionUnusedImportsTe
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/DetailAstImplTest.java:[595,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/PackageNamesLoaderTest.java:[58,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/api/FilterSetTest.java:[49,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java:[41,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java:[42,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheckTest.java:[77,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java:[39,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/OrderedPropertiesCheckTest.java:[49,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
@@ -110,8 +113,8 @@ src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocNodeImplTest
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagInfoTest.java:[230,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `throws` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagInfoTest.java:[294,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `return` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTagTest.java:[58,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTypeCheckTest.java:[83,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `protected` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTypeCheckTest.java:[89,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `public` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTypeCheckTest.java:[84,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `protected` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTypeCheckTest.java:[90,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `public` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocVariableCheckTest.java:[60,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `default` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/MissingJavadocTypeCheckTest.java:[118,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `protected` is not a valid identifier)
|
||||
src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/MissingJavadocTypeCheckTest.java:[126,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that `public` is not a valid identifier)
|
||||
|
||||
@@ -7,13 +7,18 @@
|
||||
+ <dependency>
|
||||
+ <groupId>org.assertj</groupId>
|
||||
+ <artifactId>assertj-core</artifactId>
|
||||
+ <version>3.26.3<!-- Renovate: org.assertj:assertj-bom --></version>
|
||||
+ <version>3.27.0<!-- Renovate: org.assertj:assertj-bom --></version>
|
||||
+ <scope>test</scope>
|
||||
+ </dependency>
|
||||
<dependency>
|
||||
<groupId>nl.jqno.equalsverifier</groupId>
|
||||
<artifactId>equalsverifier</artifactId>
|
||||
@@ -2420,6 +2426,8 @@
|
||||
@@ -2421,9 +2427,13 @@
|
||||
<compilerArgs>
|
||||
<arg>-Xpkginfo:always</arg>
|
||||
<arg>-XDcompilePolicy=simple</arg>
|
||||
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.36.0+ by default. -->
|
||||
+ <arg>--should-stop=ifError=FLOW</arg>
|
||||
<arg>
|
||||
-Xplugin:ErrorProne ${error-prone.configuration-args}
|
||||
</arg>
|
||||
@@ -22,7 +27,7 @@
|
||||
</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
@@ -2432,6 +2440,11 @@
|
||||
@@ -2436,6 +2446,11 @@
|
||||
<artifactId>error-prone-contrib</artifactId>
|
||||
<version>${error-prone-support.version}</version>
|
||||
</path>
|
||||
@@ -34,8 +39,12 @@
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -2474,9 +2487,10 @@
|
||||
@@ -2476,11 +2491,14 @@
|
||||
<compilerArgs>
|
||||
<arg>-Xpkginfo:always</arg>
|
||||
<arg>-XDcompilePolicy=simple</arg>
|
||||
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.36.0+ by default. -->
|
||||
+ <arg>--should-stop=ifError=FLOW</arg>
|
||||
<arg>
|
||||
-Xplugin:ErrorProne \
|
||||
- -XepExcludedPaths:.*[\\/]resources[\\/].* \
|
||||
@@ -46,7 +55,7 @@
|
||||
</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
@@ -2489,6 +2503,11 @@
|
||||
@@ -2493,6 +2511,11 @@
|
||||
<artifactId>error-prone-contrib</artifactId>
|
||||
<version>${error-prone-support.version}</version>
|
||||
</path>
|
||||
@@ -167,26 +176,6 @@
|
||||
public class TreeWalkerTest extends AbstractModuleTestSupport {
|
||||
|
||||
@TempDir
|
||||
--- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/utils/XdocGenerator.java
|
||||
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/utils/XdocGenerator.java
|
||||
@@ -55,7 +55,8 @@ public final class XdocGenerator {
|
||||
for (Path path : templatesFilePaths) {
|
||||
final String pathToFile = path.toString();
|
||||
final File inputFile = new File(pathToFile);
|
||||
- final File tempFile = File.createTempFile(pathToFile.replace(".template", ""), "");
|
||||
+ final File outputFile = new File(pathToFile.replace(".template", ""));
|
||||
+ final File tempFile = File.createTempFile(outputFile.getName(), "");
|
||||
tempFile.deleteOnExit();
|
||||
final XdocsTemplateSinkFactory sinkFactory = (XdocsTemplateSinkFactory)
|
||||
plexus.lookup(SinkFactory.ROLE, XDOCS_TEMPLATE_HINT);
|
||||
@@ -70,7 +71,6 @@ public final class XdocGenerator {
|
||||
finally {
|
||||
sink.close();
|
||||
}
|
||||
- final File outputFile = new File(pathToFile.replace(".template", ""));
|
||||
final StandardCopyOption copyOption = StandardCopyOption.REPLACE_EXISTING;
|
||||
Files.copy(tempFile.toPath(), outputFile.toPath(), copyOption);
|
||||
}
|
||||
--- a/src/test/java/com/puppycrawl/tools/checkstyle/utils/CheckUtilTest.java
|
||||
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/utils/CheckUtilTest.java
|
||||
@@ -47,6 +47,8 @@ import com.puppycrawl.tools.checkstyle.checks.coding.NestedIfDepthCheck;
|
||||
|
||||
@@ -5,7 +5,7 @@ set -e -u -o pipefail
|
||||
test_name="$(basename "${0}" .sh)"
|
||||
project='checkstyle'
|
||||
repository='https://github.com/checkstyle/checkstyle.git'
|
||||
revision='checkstyle-10.20.1'
|
||||
revision='checkstyle-10.21.0'
|
||||
additional_build_flags='-Perror-prone-compile,error-prone-test-compile -Dmaven.compiler.failOnError=true'
|
||||
additional_source_directories='${project.basedir}${file.separator}src${file.separator}it${file.separator}java,${project.basedir}${file.separator}src${file.separator}xdocs-examples${file.separator}java'
|
||||
shared_error_prone_flags='-XepExcludedPaths:(\Q${project.basedir}${file.separator}src${file.separator}\E(it|test|xdocs-examples)\Q${file.separator}resources\E|\Q${project.build.directory}${file.separator}\E).*'
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
+ <dependency>
|
||||
+ <groupId>com.google.guava</groupId>
|
||||
+ <artifactId>guava</artifactId>
|
||||
+ <version>33.3.1-jre<!-- Renovate: com.google.guava:guava-bom --></version>
|
||||
+ <version>33.4.0-jre<!-- Renovate: com.google.guava:guava-bom --></version>
|
||||
+ </dependency>
|
||||
+ </dependencies>
|
||||
+ </dependencyManagement>
|
||||
@@ -52,16 +52,18 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>jdk8</id>
|
||||
@@ -218,7 +239,7 @@
|
||||
@@ -218,7 +239,9 @@
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
<arg>-XDcompilePolicy=simple</arg>
|
||||
- <arg>-Xplugin:ErrorProne -XepExcludedPaths:.*/target/generated-sources/.*</arg>
|
||||
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.36.0+ by default. -->
|
||||
+ <arg>--should-stop=ifError=FLOW</arg>
|
||||
+ <arg>-Xplugin:ErrorProne ${error-prone.configuration-args}</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
|
||||
@@ -229,12 +250,24 @@
|
||||
@@ -229,12 +252,24 @@
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
|
||||
@@ -87,7 +89,7 @@
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
@@ -364,7 +397,7 @@
|
||||
@@ -364,7 +399,7 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
10363
integration-tests/prometheus-java-client-expected-changes.patch
Normal file
10363
integration-tests/prometheus-java-client-expected-changes.patch
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
integration-tests/it-exporter/it-exporter-httpserver-sample/src/main/java/io/prometheus/metrics/it/exporter/httpserver/HTTPServerSample.java:[15,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'SUCCESS', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-httpserver-sample/src/main/java/io/prometheus/metrics/it/exporter/httpserver/HTTPServerSample.java:[16,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'ERROR', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-no-protobuf/src/main/java/io/prometheus/metrics/it/exporter/httpserver/HTTPServerSample.java:[15,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'SUCCESS', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-no-protobuf/src/main/java/io/prometheus/metrics/it/exporter/httpserver/HTTPServerSample.java:[16,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'ERROR', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-servlet-jetty-sample/src/main/java/io/prometheus/metrics/it/exporter/servlet/jetty/ExporterServletJettySample.java:[18,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'SUCCESS', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-servlet-jetty-sample/src/main/java/io/prometheus/metrics/it/exporter/servlet/jetty/ExporterServletJettySample.java:[19,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'ERROR', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-servlet-tomcat-sample/src/main/java/io/prometheus/metrics/it/exporter/servlet/tomcat/ExporterServletTomcatSample.java:[21,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'SUCCESS', though note that this is not a private constant
|
||||
integration-tests/it-exporter/it-exporter-servlet-tomcat-sample/src/main/java/io/prometheus/metrics/it/exporter/servlet/tomcat/ExporterServletTomcatSample.java:[22,5] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'ERROR', though note that this is not a private constant
|
||||
prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java:[180,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `incWithExemplar` is already defined in this class or a supertype)
|
||||
prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/JvmNativeMemoryMetrics.java:[96,30] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'IS_ENABLED', though note that this is not a private constant
|
||||
prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/NativeImageChecker.java:[11,24] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'IS_GRAAL_VM_NATIVE_IMAGE', though note that this is not a private constant
|
||||
prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java:[16,42] [ConstantNaming] Constant variables should adhere to the `UPPER_SNAKE_CASE` naming convention; consider renaming to 'DEFAULT_REGISTRY', though note that this is not a private constant
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/LabelTest.java:[19,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `toString` is already defined in this class or a supertype)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/LabelTest.java:[24,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `equals` is already defined in this class or a supertype)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/LabelTest.java:[29,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that a method named `hashCode` is already defined in this class or a supertype)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/PrometheusNamingTest.java:[12,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that another method named `sanitizeMetricName` is in scope)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/PrometheusNamingTest.java:[44,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that another method named `sanitizeLabelName` is in scope)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/PrometheusNamingTest.java:[55,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that another method named `validateUnitName` is in scope)
|
||||
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/PrometheusNamingTest.java:[67,8] [JUnitMethodDeclaration] This method's name should not redundantly start with `test` (but note that another method named `sanitizeUnitName` is in scope)
|
||||
36
integration-tests/prometheus-java-client-init.patch
Normal file
36
integration-tests/prometheus-java-client-init.patch
Normal file
@@ -0,0 +1,36 @@
|
||||
--- a/pom.xml
|
||||
+++ b/pom.xml
|
||||
@@ -128,7 +128,6 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
- <scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -370,13 +369,24 @@
|
||||
-Xep:LongDoubleConversion:OFF
|
||||
-Xep:StringSplitter:OFF
|
||||
-XepExcludedPaths:.*/generated/.*
|
||||
+ ${error-prone.configuration-args}
|
||||
</arg>
|
||||
</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
- <version>2.36.0</version>
|
||||
+ <version>${error-prone.version}</version>
|
||||
+ </path>
|
||||
+ <path>
|
||||
+ <groupId>tech.picnic.error-prone-support</groupId>
|
||||
+ <artifactId>error-prone-contrib</artifactId>
|
||||
+ <version>${error-prone-support.version}</version>
|
||||
+ </path>
|
||||
+ <path>
|
||||
+ <groupId>tech.picnic.error-prone-support</groupId>
|
||||
+ <artifactId>refaster-runner</artifactId>
|
||||
+ <version>${error-prone-support.version}</version>
|
||||
</path>
|
||||
<!-- Other annotation processors go here.
|
||||
|
||||
40
integration-tests/prometheus-java-client.sh
Executable file
40
integration-tests/prometheus-java-client.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e -u -o pipefail
|
||||
|
||||
test_name="$(basename "${0}" .sh)"
|
||||
project='prometheus-java-client'
|
||||
repository='https://github.com/prometheus/client_java.git'
|
||||
revision='v1.3.5'
|
||||
additional_build_flags='-Djava.version=11 -Dwarnings='
|
||||
additional_source_directories=''
|
||||
shared_error_prone_flags=''
|
||||
patch_error_prone_flags=''
|
||||
validation_error_prone_flags=''
|
||||
# Validation skips some tests:
|
||||
# - Starting from a clean repository, the `PushGatewayIT` tests reference a JAR
|
||||
# file that is created only after test completion, causing the tests to fail.
|
||||
# - The `SlidingWindowTest#rotate` test is flaky.
|
||||
# XXX: Drop the `SlidingWindowTest` exclusion once prometheus/client_java#1242
|
||||
# is resolved. For unclear reasons, it appears that without this exclusion the
|
||||
# integration tests are no longer executed, meaning that perhaps all flags
|
||||
# specified here can then be dropped.
|
||||
validation_build_flags='-Dtest=!PushGatewayIT,!SlidingWindowTest#rotate -Dsurefire.failIfNoSpecifiedTests=false'
|
||||
|
||||
if [ "${#}" -gt 2 ] || ([ "${#}" = 2 ] && [ "${1:---sync}" != '--sync' ]); then
|
||||
>&2 echo "Usage: ${0} [--sync] [<report_directory>]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
"$(dirname "${0}")/run-integration-test.sh" \
|
||||
"${test_name}" \
|
||||
"${project}" \
|
||||
"${repository}" \
|
||||
"${revision}" \
|
||||
"${additional_build_flags}" \
|
||||
"${additional_source_directories}" \
|
||||
"${shared_error_prone_flags}" \
|
||||
"${patch_error_prone_flags}" \
|
||||
"${validation_error_prone_flags}" \
|
||||
"${validation_build_flags}" \
|
||||
$@
|
||||
81
pom.xml
81
pom.xml
@@ -93,6 +93,7 @@
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
|
||||
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
|
||||
@@ -113,7 +114,7 @@
|
||||
-Xmx${argLine.xmx}
|
||||
<!-- Configure the Byte Buddy Java agent used by Mockito to create
|
||||
mocks. -->
|
||||
-javaagent:${org.mockito:mockito-core:jar}
|
||||
<!-- -javaagent:${org.mockito:mockito-core:jar} -->
|
||||
<!-- This argument cannot be set through Surefire's
|
||||
'systemPropertyVariables' configuration setting. Setting the file
|
||||
encoding is necessary because forked unit test invocations
|
||||
@@ -211,16 +212,16 @@
|
||||
<version.auto-value>1.11.0</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.35.1</version.error-prone-orig>
|
||||
<version.error-prone-orig>2.36.0</version.error-prone-orig>
|
||||
<version.error-prone-slf4j>0.1.28</version.error-prone-slf4j>
|
||||
<version.guava-beta-checker>1.0</version.guava-beta-checker>
|
||||
<version.jdk>17</version.jdk>
|
||||
<version.maven>3.9.9</version.maven>
|
||||
<version.mockito>5.14.2</version.mockito>
|
||||
<version.nopen-checker>1.0.1</version.nopen-checker>
|
||||
<version.nullaway>0.12.1</version.nullaway>
|
||||
<version.nullaway>0.12.2</version.nullaway>
|
||||
<version.pitest-git>1.1.4</version.pitest-git>
|
||||
<version.rewrite-templating>1.17.1</version.rewrite-templating>
|
||||
<version.rewrite-templating>1.20.2</version.rewrite-templating>
|
||||
<version.surefire>3.2.3</version.surefire>
|
||||
</properties>
|
||||
|
||||
@@ -299,7 +300,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson</groupId>
|
||||
<artifactId>jackson-bom</artifactId>
|
||||
<version>2.18.1</version>
|
||||
<version>2.18.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -336,7 +337,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.googlejavaformat</groupId>
|
||||
<artifactId>google-java-format</artifactId>
|
||||
<version>1.25.0</version>
|
||||
<version>1.25.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
@@ -346,7 +347,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava-bom</artifactId>
|
||||
<version>33.3.1-jre</version>
|
||||
<version>33.4.0-jre</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -368,14 +369,14 @@
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-bom</artifactId>
|
||||
<version>1.14.0</version>
|
||||
<version>1.14.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-bom</artifactId>
|
||||
<version>2024.0.0</version>
|
||||
<version>2024.0.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -392,7 +393,7 @@
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>2.2.26</version>
|
||||
<version>2.2.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
@@ -427,7 +428,7 @@
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.15.10</version>
|
||||
<version>1.15.11</version>
|
||||
</dependency>
|
||||
<!-- Specified so that Renovate will file Maven upgrade PRs, which
|
||||
subsequently will cause `maven-enforcer-plugin` to require that
|
||||
@@ -445,14 +446,19 @@
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-bom</artifactId>
|
||||
<version>3.26.3</version>
|
||||
<version>3.27.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
<artifactId>checker-qual</artifactId>
|
||||
<version>3.48.2</version>
|
||||
<version>3.48.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gaul</groupId>
|
||||
<artifactId>modernizer-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
@@ -464,6 +470,11 @@
|
||||
<artifactId>value-annotations</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>3.19.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jspecify</groupId>
|
||||
<artifactId>jspecify</artifactId>
|
||||
@@ -472,7 +483,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.11.3</version>
|
||||
<version>5.11.4</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -496,7 +507,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openrewrite.recipe</groupId>
|
||||
<artifactId>rewrite-recipe-bom</artifactId>
|
||||
<version>2.22.0</version>
|
||||
<version>2.23.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -510,19 +521,19 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.2.0</version>
|
||||
<version>6.2.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-bom</artifactId>
|
||||
<version>6.4.1</version>
|
||||
<version>6.4.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -923,7 +934,7 @@
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>10.20.1</version>
|
||||
<version>10.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spring.nohttp</groupId>
|
||||
@@ -974,6 +985,7 @@
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
|
||||
@@ -1222,7 +1234,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.1</version>
|
||||
<version>3.11.2</version>
|
||||
<configuration>
|
||||
<additionalJOptions>
|
||||
<additionalJOption>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</additionalJOption>
|
||||
@@ -1308,7 +1320,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>license-maven-plugin</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.0</version>
|
||||
<configuration>
|
||||
<includedLicenses>
|
||||
<!-- The SPDX IDs of licenses of third-party
|
||||
@@ -1350,6 +1362,7 @@
|
||||
<!-- XXX: Get projects referencing just "BSD"
|
||||
to explicitly state the clause count. -->
|
||||
BSD-2-Clause
|
||||
| The BSD 2-Clause License
|
||||
| The BSD License
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
@@ -1363,6 +1376,8 @@
|
||||
| BSD licence
|
||||
| BSD License 3
|
||||
| Eclipse Distribution License (New BSD License)
|
||||
| Eclipse Distribution License - v 1.0
|
||||
| EDL 1.0
|
||||
| New BSD License
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
@@ -1516,7 +1531,7 @@
|
||||
<plugin>
|
||||
<groupId>org.pitest</groupId>
|
||||
<artifactId>pitest-maven</artifactId>
|
||||
<version>1.17.1</version>
|
||||
<version>1.17.3</version>
|
||||
<configuration>
|
||||
<excludedClasses>
|
||||
<!-- AutoValue generated classes. -->
|
||||
@@ -1962,12 +1977,6 @@
|
||||
<!-- XXX: Enable this once we open-source
|
||||
this library. -->
|
||||
-Xep:BetaApi:OFF
|
||||
<!-- This check flags bad member names, but
|
||||
also type names that we may want to accept.
|
||||
Consider contributing a flag to toggle this
|
||||
behavior. See
|
||||
https://github.com/google/error-prone/issues/4616 -->
|
||||
-Xep:IdentifierName:OFF
|
||||
<!-- We don't target JDK 7. -->
|
||||
-Xep:Java7ApiChecker:OFF
|
||||
<!-- We don't target JDK 8. -->
|
||||
@@ -1983,6 +1992,9 @@
|
||||
<!-- XXX: Enable once there are fewer
|
||||
false-positives.
|
||||
-XepOpt:CheckReturnValue:CheckAllMethods=true -->
|
||||
<!-- XXX: Consider renaming flagged types
|
||||
instead. -->
|
||||
-XepOpt:IdentifierName:AllowInitialismsInTypeName=true
|
||||
-XepOpt:InlineMe:SkipInliningsWithComments=false
|
||||
-XepOpt:NullAway:AnnotatedPackages=tech.picnic
|
||||
-XepOpt:NullAway:AssertsEnabled=true
|
||||
@@ -1997,11 +2009,18 @@
|
||||
</arg>
|
||||
<!-- The Error Prone plugin makes certain
|
||||
assumptions about the state of the AST at the
|
||||
moment it is invoked. Those assumptions are met
|
||||
when using the `simple` compile policy. This
|
||||
flag may be dropped after resolution of
|
||||
moment it is invoked. Those assumptions require
|
||||
the `simple` compile policy. This flag may be
|
||||
dropped after resolution of
|
||||
https://bugs.openjdk.java.net/browse/JDK-8155674. -->
|
||||
<arg>-XDcompilePolicy=simple</arg>
|
||||
<!-- Similarly, Error Prone requires that flow
|
||||
analysis has been performed, e.g. to determine
|
||||
whether variables are effectively final. This
|
||||
flag may be dropped if it ever becomes the
|
||||
default. See
|
||||
https://bugs.openjdk.org/browse/JDK-8134117. -->
|
||||
<arg>--should-stop=ifError=FLOW</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
releases:
|
||||
- version: 0.19.1
|
||||
compatible:
|
||||
- "2.36.0"
|
||||
- "2.35.1"
|
||||
- "2.35.0"
|
||||
- "2.34.0"
|
||||
@@ -12,6 +13,7 @@ releases:
|
||||
- "2.30.0"
|
||||
- version: 0.19.0
|
||||
compatible:
|
||||
- "2.36.0"
|
||||
- "2.35.1"
|
||||
- "2.35.0"
|
||||
- "2.34.0"
|
||||
@@ -21,6 +23,7 @@ releases:
|
||||
- "2.30.0"
|
||||
- version: 0.18.0
|
||||
compatible:
|
||||
- "2.36.0"
|
||||
- "2.35.1"
|
||||
- "2.35.0"
|
||||
- "2.34.0"
|
||||
|
||||
@@ -45,6 +45,13 @@ for eps_version in ${eps_versions}; do
|
||||
(set +u && echo n | sdk install maven "${mvn_version}")
|
||||
sdk use maven "${mvn_version}"
|
||||
|
||||
# As of version 2.36.0, Error Prone requires that the
|
||||
# `--should-stop=ifError=FLOW` flag is provided. Make sure that this flag is
|
||||
# always specified. (The `-XDcompilePolicy=simple` flag has been specified
|
||||
# since the first Error Prone Support release. It's okay if the added flag is
|
||||
# present more than once; the last variant listed wins.)
|
||||
sed -i 's,<arg>-XDcompilePolicy=simple</arg>,<arg>-XDcompilePolicy=simple</arg><arg>--should-stop=ifError=FLOW</arg>,' pom.xml
|
||||
|
||||
# Collect the list of checks supported by this version of Error Prone
|
||||
# Support.
|
||||
# XXX: Conditionally omit the `MethodReferenceUsage` exclusion once that
|
||||
|
||||
Reference in New Issue
Block a user