├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── release.yml └── workflows │ ├── build.yml │ ├── codeql.yml │ ├── deploy-website.yml │ ├── error-prone-compat.yml │ ├── integration-tests.yml │ ├── openssf-scorecard.yml │ ├── pitest-analyze-pr.yml │ ├── pitest-update-pr.yml │ ├── reviewdog.yml │ └── sonarcloud.yml ├── .gitignore ├── .idea └── icon.svg ├── .mvn ├── jvm.config └── maven.config ├── .renovaterc.json ├── .reviewdog.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── apply-error-prone-suggestions.sh ├── arcmutate-licence.txt ├── documentation-support ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── documentation │ │ ├── BugPatternExtractor.java │ │ ├── BugPatternTestExtractor.java │ │ ├── DocumentationGenerator.java │ │ ├── DocumentationGeneratorTaskListener.java │ │ ├── Extractor.java │ │ ├── Json.java │ │ ├── RefasterRuleCollectionTestExtractor.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── documentation │ ├── BugPatternExtractorTest.java │ ├── BugPatternTestExtractorTest.java │ ├── Compilation.java │ ├── DocumentationGeneratorTaskListenerTest.java │ ├── DocumentationGeneratorTest.java │ ├── JsonTest.java │ └── RefasterRuleCollectionTestExtractorTest.java ├── error-prone-contrib ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ ├── bugpatterns │ │ ├── AmbiguousJsonCreator.java │ │ ├── AssertJIsNull.java │ │ ├── AutowiredConstructor.java │ │ ├── CanonicalAnnotationSyntax.java │ │ ├── CanonicalClassNameUsage.java │ │ ├── ClassCastLambdaUsage.java │ │ ├── CollectorMutability.java │ │ ├── ConstantNaming.java │ │ ├── DirectReturn.java │ │ ├── EagerStringFormatting.java │ │ ├── EmptyMethod.java │ │ ├── EmptyMonoZip.java │ │ ├── ExplicitArgumentEnumeration.java │ │ ├── ExplicitEnumOrdering.java │ │ ├── FluxFlatMapUsage.java │ │ ├── FluxImplicitBlock.java │ │ ├── FormatStringConcatenation.java │ │ ├── IdentityConversion.java │ │ ├── ImmutablesSortedSetComparator.java │ │ ├── IsInstanceLambdaUsage.java │ │ ├── JUnitClassModifiers.java │ │ ├── JUnitMethodDeclaration.java │ │ ├── JUnitNullaryParameterizedTestDeclaration.java │ │ ├── JUnitValueSource.java │ │ ├── LexicographicalAnnotationAttributeListing.java │ │ ├── LexicographicalAnnotationListing.java │ │ ├── MockitoMockClassReference.java │ │ ├── MockitoStubbing.java │ │ ├── MongoDBTextFilterUsage.java │ │ ├── NestedOptionals.java │ │ ├── NestedPublishers.java │ │ ├── NonEmptyMono.java │ │ ├── NonStaticImport.java │ │ ├── OptionalOrElseGet.java │ │ ├── PrimitiveComparison.java │ │ ├── RedundantStringConversion.java │ │ ├── RedundantStringEscape.java │ │ ├── RequestMappingAnnotation.java │ │ ├── RequestParamType.java │ │ ├── Slf4jLogStatement.java │ │ ├── Slf4jLoggerDeclaration.java │ │ ├── SpringMvcAnnotation.java │ │ ├── StaticImport.java │ │ ├── StringJoin.java │ │ ├── TimeZoneUsage.java │ │ └── package-info.java │ │ └── refasterrules │ │ ├── AssertJBigDecimalRules.java │ │ ├── AssertJBigIntegerRules.java │ │ ├── AssertJBooleanRules.java │ │ ├── AssertJByteRules.java │ │ ├── AssertJCharSequenceRules.java │ │ ├── AssertJComparableRules.java │ │ ├── AssertJDoubleRules.java │ │ ├── AssertJEnumerableRules.java │ │ ├── AssertJFloatRules.java │ │ ├── AssertJIntegerRules.java │ │ ├── AssertJIterableRules.java │ │ ├── AssertJIteratorRules.java │ │ ├── AssertJLongRules.java │ │ ├── AssertJMapRules.java │ │ ├── AssertJNumberRules.java │ │ ├── AssertJObjectRules.java │ │ ├── AssertJOptionalRules.java │ │ ├── AssertJPrimitiveRules.java │ │ ├── AssertJRules.java │ │ ├── AssertJShortRules.java │ │ ├── AssertJStringRules.java │ │ ├── AssertJThrowingCallableRules.java │ │ ├── AssortedRules.java │ │ ├── BigDecimalRules.java │ │ ├── BugCheckerRules.java │ │ ├── CharSequenceRules.java │ │ ├── ClassRules.java │ │ ├── CollectionRules.java │ │ ├── ComparatorRules.java │ │ ├── DoubleStreamRules.java │ │ ├── EqualityRules.java │ │ ├── FileRules.java │ │ ├── ImmutableEnumSetRules.java │ │ ├── ImmutableListMultimapRules.java │ │ ├── ImmutableListRules.java │ │ ├── ImmutableMapRules.java │ │ ├── ImmutableMultisetRules.java │ │ ├── ImmutableSetMultimapRules.java │ │ ├── ImmutableSetRules.java │ │ ├── ImmutableSortedMapRules.java │ │ ├── ImmutableSortedMultisetRules.java │ │ ├── ImmutableSortedSetRules.java │ │ ├── ImmutableTableRules.java │ │ ├── InputStreamRules.java │ │ ├── IntStreamRules.java │ │ ├── JUnitRules.java │ │ ├── JUnitToAssertJRules.java │ │ ├── JacksonRules.java │ │ ├── LongStreamRules.java │ │ ├── MapEntryRules.java │ │ ├── MapRules.java │ │ ├── MicrometerRules.java │ │ ├── MockitoRules.java │ │ ├── MultimapRules.java │ │ ├── NullRules.java │ │ ├── OptionalRules.java │ │ ├── PatternRules.java │ │ ├── PreconditionsRules.java │ │ ├── PrimitiveRules.java │ │ ├── ReactorRules.java │ │ ├── RxJava2AdapterRules.java │ │ ├── StreamRules.java │ │ ├── StringRules.java │ │ ├── SuggestedFixRules.java │ │ ├── TestNGToAssertJRules.java │ │ ├── TimeRules.java │ │ ├── WebClientRules.java │ │ └── package-info.java │ └── test │ ├── java │ └── tech │ │ └── picnic │ │ └── errorprone │ │ ├── bugpatterns │ │ ├── AmbiguousJsonCreatorTest.java │ │ ├── AssertJIsNullTest.java │ │ ├── AutowiredConstructorTest.java │ │ ├── CanonicalAnnotationSyntaxTest.java │ │ ├── CanonicalClassNameUsageTest.java │ │ ├── ClassCastLambdaUsageTest.java │ │ ├── CollectorMutabilityTest.java │ │ ├── ConstantNamingTest.java │ │ ├── DirectReturnTest.java │ │ ├── EagerStringFormattingTest.java │ │ ├── EmptyMethodTest.java │ │ ├── EmptyMonoZipTest.java │ │ ├── ExplicitArgumentEnumerationTest.java │ │ ├── ExplicitEnumOrderingTest.java │ │ ├── FluxFlatMapUsageTest.java │ │ ├── FluxImplicitBlockTest.java │ │ ├── FormatStringConcatenationTest.java │ │ ├── IdentityConversionTest.java │ │ ├── ImmutablesSortedSetComparatorTest.java │ │ ├── IsInstanceLambdaUsageTest.java │ │ ├── JUnitClassModifiersTest.java │ │ ├── JUnitMethodDeclarationTest.java │ │ ├── JUnitNullaryParameterizedTestDeclarationTest.java │ │ ├── JUnitValueSourceTest.java │ │ ├── LexicographicalAnnotationAttributeListingTest.java │ │ ├── LexicographicalAnnotationListingTest.java │ │ ├── MockitoMockClassReferenceTest.java │ │ ├── MockitoStubbingTest.java │ │ ├── MongoDBTextFilterUsageTest.java │ │ ├── NestedOptionalsTest.java │ │ ├── NestedPublishersTest.java │ │ ├── NonEmptyMonoTest.java │ │ ├── NonStaticImportTest.java │ │ ├── OptionalOrElseGetTest.java │ │ ├── PrimitiveComparisonTest.java │ │ ├── RedundantStringConversionTest.java │ │ ├── RedundantStringEscapeTest.java │ │ ├── RequestMappingAnnotationTest.java │ │ ├── RequestParamTypeTest.java │ │ ├── Slf4jLogStatementTest.java │ │ ├── Slf4jLoggerDeclarationTest.java │ │ ├── SpringMvcAnnotationTest.java │ │ ├── StaticImportTest.java │ │ ├── StringJoinTest.java │ │ └── TimeZoneUsageTest.java │ │ └── refasterrules │ │ ├── RefasterRulesTest.java │ │ └── StringRulesRecipesTest.java │ └── resources │ └── tech │ └── picnic │ └── errorprone │ └── refasterrules │ ├── AssertJBigDecimalRulesTestInput.java │ ├── AssertJBigDecimalRulesTestOutput.java │ ├── AssertJBigIntegerRulesTestInput.java │ ├── AssertJBigIntegerRulesTestOutput.java │ ├── AssertJBooleanRulesTestInput.java │ ├── AssertJBooleanRulesTestOutput.java │ ├── AssertJByteRulesTestInput.java │ ├── AssertJByteRulesTestOutput.java │ ├── AssertJCharSequenceRulesTestInput.java │ ├── AssertJCharSequenceRulesTestOutput.java │ ├── AssertJComparableRulesTestInput.java │ ├── AssertJComparableRulesTestOutput.java │ ├── AssertJDoubleRulesTestInput.java │ ├── AssertJDoubleRulesTestOutput.java │ ├── AssertJEnumerableRulesTestInput.java │ ├── AssertJEnumerableRulesTestOutput.java │ ├── AssertJFloatRulesTestInput.java │ ├── AssertJFloatRulesTestOutput.java │ ├── AssertJIntegerRulesTestInput.java │ ├── AssertJIntegerRulesTestOutput.java │ ├── AssertJIterableRulesTestInput.java │ ├── AssertJIterableRulesTestOutput.java │ ├── AssertJIteratorRulesTestInput.java │ ├── AssertJIteratorRulesTestOutput.java │ ├── AssertJLongRulesTestInput.java │ ├── AssertJLongRulesTestOutput.java │ ├── AssertJMapRulesTestInput.java │ ├── AssertJMapRulesTestOutput.java │ ├── AssertJNumberRulesTestInput.java │ ├── AssertJNumberRulesTestOutput.java │ ├── AssertJObjectRulesTestInput.java │ ├── AssertJObjectRulesTestOutput.java │ ├── AssertJOptionalRulesTestInput.java │ ├── AssertJOptionalRulesTestOutput.java │ ├── AssertJPrimitiveRulesTestInput.java │ ├── AssertJPrimitiveRulesTestOutput.java │ ├── AssertJShortRulesTestInput.java │ ├── AssertJShortRulesTestOutput.java │ ├── AssertJStringRulesTestInput.java │ ├── AssertJStringRulesTestOutput.java │ ├── AssertJThrowingCallableRulesTestInput.java │ ├── AssertJThrowingCallableRulesTestOutput.java │ ├── AssortedRulesTestInput.java │ ├── AssortedRulesTestOutput.java │ ├── BigDecimalRulesTestInput.java │ ├── BigDecimalRulesTestOutput.java │ ├── BugCheckerRulesTestInput.java │ ├── BugCheckerRulesTestOutput.java │ ├── CharSequenceRulesTestInput.java │ ├── CharSequenceRulesTestOutput.java │ ├── ClassRulesTestInput.java │ ├── ClassRulesTestOutput.java │ ├── CollectionRulesTestInput.java │ ├── CollectionRulesTestOutput.java │ ├── ComparatorRulesTestInput.java │ ├── ComparatorRulesTestOutput.java │ ├── DoubleStreamRulesTestInput.java │ ├── DoubleStreamRulesTestOutput.java │ ├── EqualityRulesTestInput.java │ ├── EqualityRulesTestOutput.java │ ├── FileRulesTestInput.java │ ├── FileRulesTestOutput.java │ ├── ImmutableEnumSetRulesTestInput.java │ ├── ImmutableEnumSetRulesTestOutput.java │ ├── ImmutableListMultimapRulesTestInput.java │ ├── ImmutableListMultimapRulesTestOutput.java │ ├── ImmutableListRulesTestInput.java │ ├── ImmutableListRulesTestOutput.java │ ├── ImmutableMapRulesTestInput.java │ ├── ImmutableMapRulesTestOutput.java │ ├── ImmutableMultisetRulesTestInput.java │ ├── ImmutableMultisetRulesTestOutput.java │ ├── ImmutableSetMultimapRulesTestInput.java │ ├── ImmutableSetMultimapRulesTestOutput.java │ ├── ImmutableSetRulesTestInput.java │ ├── ImmutableSetRulesTestOutput.java │ ├── ImmutableSortedMapRulesTestInput.java │ ├── ImmutableSortedMapRulesTestOutput.java │ ├── ImmutableSortedMultisetRulesTestInput.java │ ├── ImmutableSortedMultisetRulesTestOutput.java │ ├── ImmutableSortedSetRulesTestInput.java │ ├── ImmutableSortedSetRulesTestOutput.java │ ├── ImmutableTableRulesTestInput.java │ ├── ImmutableTableRulesTestOutput.java │ ├── InputStreamRulesTestInput.java │ ├── InputStreamRulesTestOutput.java │ ├── IntStreamRulesTestInput.java │ ├── IntStreamRulesTestOutput.java │ ├── JUnitRulesTestInput.java │ ├── JUnitRulesTestOutput.java │ ├── JUnitToAssertJRulesTestInput.java │ ├── JUnitToAssertJRulesTestOutput.java │ ├── JacksonRulesTestInput.java │ ├── JacksonRulesTestOutput.java │ ├── LongStreamRulesTestInput.java │ ├── LongStreamRulesTestOutput.java │ ├── MapEntryRulesTestInput.java │ ├── MapEntryRulesTestOutput.java │ ├── MapRulesTestInput.java │ ├── MapRulesTestOutput.java │ ├── MicrometerRulesTestInput.java │ ├── MicrometerRulesTestOutput.java │ ├── MockitoRulesTestInput.java │ ├── MockitoRulesTestOutput.java │ ├── MultimapRulesTestInput.java │ ├── MultimapRulesTestOutput.java │ ├── NullRulesTestInput.java │ ├── NullRulesTestOutput.java │ ├── OptionalRulesTestInput.java │ ├── OptionalRulesTestOutput.java │ ├── PatternRulesTestInput.java │ ├── PatternRulesTestOutput.java │ ├── PreconditionsRulesTestInput.java │ ├── PreconditionsRulesTestOutput.java │ ├── PrimitiveRulesTestInput.java │ ├── PrimitiveRulesTestOutput.java │ ├── ReactorRulesTestInput.java │ ├── ReactorRulesTestOutput.java │ ├── RxJava2AdapterRulesTestInput.java │ ├── RxJava2AdapterRulesTestOutput.java │ ├── StreamRulesTestInput.java │ ├── StreamRulesTestOutput.java │ ├── StringRulesTestInput.java │ ├── StringRulesTestOutput.java │ ├── SuggestedFixRulesTestInput.java │ ├── SuggestedFixRulesTestOutput.java │ ├── TestNGToAssertJRulesTestInput.java │ ├── TestNGToAssertJRulesTestOutput.java │ ├── TimeRulesTestInput.java │ ├── TimeRulesTestOutput.java │ ├── WebClientRulesTestInput.java │ └── WebClientRulesTestOutput.java ├── error-prone-experimental ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── experimental │ │ └── bugpatterns │ │ ├── MethodReferenceUsage.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── experimental │ └── bugpatterns │ └── MethodReferenceUsageTest.java ├── error-prone-guidelines ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── guidelines │ │ └── bugpatterns │ │ ├── AssociativeMethodInvocation.java │ │ ├── BugPatternLink.java │ │ ├── ErrorProneRuntimeClasspath.java │ │ ├── ErrorProneTestHelperSourceFormat.java │ │ ├── ExhaustiveRefasterTypeMigration.java │ │ ├── RefasterAnyOfUsage.java │ │ ├── RefasterMethodParameterOrder.java │ │ ├── RefasterRuleModifiers.java │ │ ├── UnqualifiedSuggestedFixImport.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── guidelines │ └── bugpatterns │ ├── AssociativeMethodInvocationTest.java │ ├── BugPatternLinkTest.java │ ├── ErrorProneRuntimeClasspathTest.java │ ├── ErrorProneTestHelperSourceFormatTest.java │ ├── ExhaustiveRefasterTypeMigrationTest.java │ ├── RefasterAnyOfUsageTest.java │ ├── RefasterMethodParameterOrderTest.java │ ├── RefasterRuleModifiersTest.java │ └── UnqualifiedSuggestedFixImportTest.java ├── error-prone-utils ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── utils │ │ ├── AnnotationAttributeMatcher.java │ │ ├── ConflictDetection.java │ │ ├── Documentation.java │ │ ├── Flags.java │ │ ├── MethodMatcherFactory.java │ │ ├── MoreASTHelpers.java │ │ ├── MoreJUnitMatchers.java │ │ ├── MoreMatchers.java │ │ ├── MoreTypePredicates.java │ │ ├── MoreTypes.java │ │ ├── SourceCode.java │ │ ├── ThirdPartyLibrary.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── utils │ ├── AnnotationAttributeMatcherTest.java │ ├── ConflictDetectionTest.java │ ├── FlagsTest.java │ ├── MethodMatcherFactoryTest.java │ ├── MoreASTHelpersTest.java │ ├── MoreJUnitMatchersTest.java │ ├── MoreMatchersTest.java │ ├── MoreTypesTest.java │ ├── SourceCodeTest.java │ └── ThirdPartyLibraryTest.java ├── generate-docs.sh ├── integration-tests ├── checkstyle-expected-changes.patch ├── checkstyle-expected-warnings.txt ├── checkstyle-init.patch ├── checkstyle.sh ├── metrics-expected-changes.patch ├── metrics-expected-warnings.txt ├── metrics-init.patch ├── metrics.sh ├── prometheus-java-client-expected-changes.patch ├── prometheus-java-client-expected-warnings.txt ├── prometheus-java-client-init.patch ├── prometheus-java-client.sh └── run-integration-test.sh ├── list-sonarcloud-profile-modifications.sh ├── pom.xml ├── refaster-compiler ├── pom.xml └── src │ └── main │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── refaster │ └── plugin │ ├── RefasterRuleCompiler.java │ ├── RefasterRuleCompilerTaskListener.java │ └── package-info.java ├── refaster-runner ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── refaster │ │ └── runner │ │ ├── CodeTransformers.java │ │ ├── Refaster.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── refaster │ └── runner │ ├── CodeTransformersTest.java │ ├── FooRules.java │ └── RefasterTest.java ├── refaster-support ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── refaster │ │ ├── AnnotatedCompositeCodeTransformer.java │ │ ├── annotation │ │ ├── Description.java │ │ ├── OnlineDocumentation.java │ │ ├── Severity.java │ │ ├── TypeMigration.java │ │ └── package-info.java │ │ ├── matchers │ │ ├── IsArray.java │ │ ├── IsCharacter.java │ │ ├── IsEmpty.java │ │ ├── IsIdentityOperation.java │ │ ├── IsLambdaExpressionOrMethodReference.java │ │ ├── IsRefasterAsVarargs.java │ │ ├── RequiresComputation.java │ │ ├── ThrowsCheckedException.java │ │ └── package-info.java │ │ └── package-info.java │ └── test │ └── java │ └── tech │ └── picnic │ └── errorprone │ └── refaster │ ├── AnnotatedCompositeCodeTransformerTest.java │ └── matchers │ ├── AbstractMatcherTestChecker.java │ ├── IsArrayTest.java │ ├── IsCharacterTest.java │ ├── IsEmptyTest.java │ ├── IsIdentityOperationTest.java │ ├── IsLambdaExpressionOrMethodReferenceTest.java │ ├── IsRefasterAsVarargsTest.java │ ├── RequiresComputationTest.java │ └── ThrowsCheckedExceptionTest.java ├── refaster-test-support ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── refaster │ │ └── test │ │ ├── RefasterRuleCollection.java │ │ ├── RefasterRuleCollectionTestCase.java │ │ └── package-info.java │ └── test │ ├── java │ └── tech │ │ └── picnic │ │ └── errorprone │ │ └── refaster │ │ └── test │ │ ├── MatchInWrongMethodRules.java │ │ ├── MethodWithoutPrefixRules.java │ │ ├── MisnamedTestClassRules.java │ │ ├── MissingTestAndWrongTestRules.java │ │ ├── PartialTestMatchRules.java │ │ ├── RefasterRuleCollectionTest.java │ │ ├── RuleWithoutTestRules.java │ │ └── ValidRules.java │ └── resources │ └── tech │ └── picnic │ └── errorprone │ └── refaster │ └── test │ ├── MatchInWrongMethodRulesTestInput.java │ ├── MatchInWrongMethodRulesTestOutput.java │ ├── MethodWithoutPrefixRulesTestInput.java │ ├── MethodWithoutPrefixRulesTestOutput.java │ ├── MisnamedTestClassRulesTestInput.java │ ├── MisnamedTestClassRulesTestOutput.java │ ├── MissingTestAndWrongTestRulesTestInput.java │ ├── MissingTestAndWrongTestRulesTestOutput.java │ ├── PartialTestMatchRulesTestInput.java │ ├── PartialTestMatchRulesTestOutput.java │ ├── RuleWithoutTestRulesTestInput.java │ ├── RuleWithoutTestRulesTestOutput.java │ ├── ValidRulesTestInput.java │ └── ValidRulesTestOutput.java ├── run-branch-mutation-tests.sh ├── run-full-build.sh ├── run-mutation-tests.sh ├── settings.xml └── website ├── .gitignore ├── .ruby-version ├── 404.md ├── Gemfile ├── README.md ├── _config.yml ├── _data └── compatibility.yml ├── _includes ├── footer_custom.html └── head_custom.html ├── _sass └── color_schemes │ ├── _common.scss │ ├── _variables.scss │ ├── eps-dark.scss │ └── eps-light.scss ├── assets ├── css │ ├── just-the-docs-eps-dark.scss │ └── just-the-docs-eps-light.scss └── images │ ├── android-chrome-192x192.png │ ├── android-chrome-512x512.png │ ├── apple-touch-icon.png │ ├── browserconfig.xml │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon.svg │ ├── logo-dark.svg │ ├── logo.svg │ ├── mstile-150x150.png │ ├── picnic-logo@2x.png │ ├── safari-pinned-tab.svg │ └── site.webmanifest ├── bugpatterns.md ├── compatibility.md ├── favicon.ico ├── generate-version-compatibility-overview.sh └── refasterrules.md /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug report 3 | about: Create a report to help us improve. 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | ### Describe the bug 10 | 11 | 12 | 13 | - [ ] I have verified that the issue is reproducible against the latest version 14 | of the project. 15 | - [ ] I have searched through existing issues to verify that this issue is not 16 | already known. 17 | 18 | ### Minimal Reproducible Example 19 | 20 | 22 | 23 | ```java 24 | If applicable and possible, please replace this section with the code that 25 | triggered the isue. 26 | ``` 27 | 28 |
29 | Logs 30 | 31 | ```sh 32 | Please replace this sentence with log output, if applicable. 33 | ``` 34 |
35 | 36 | ### Expected behavior 37 | 38 | 39 | 40 | ### Setup 41 | 42 | 43 | 44 | - Operating system (e.g. MacOS Monterey). 45 | - Java version (i.e. `java --version`, e.g. `17.0.13`). 46 | - Error Prone version (e.g. `2.35.1`). 47 | - Error Prone Support version (e.g. `0.19.0`). 48 | 49 | ### Additional context 50 | 51 | 52 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Request a new feature 3 | about: Suggest a new feature. 4 | title: "" 5 | labels: new feature 6 | assignees: "" 7 | --- 8 | 9 | ### Problem 10 | 11 | 13 | 14 | ### Description of the proposed new feature 15 | 16 | 17 | 18 | - [ ] Support a stylistic preference. 19 | - [ ] Avoid a common gotcha, or potential problem. 20 | - [ ] Improve performance. 21 | 22 | 27 | 28 | I would like to rewrite the following code: 29 | ```java 30 | // XXX: Write the code to match here. 31 | ``` 32 | 33 | to: 34 | ```java 35 | // XXX: Write the desired code here. 36 | ``` 37 | 38 | ### Considerations 39 | 40 | 48 | 49 | ### Participation 50 | 51 | 53 | 54 | - [ ] I am willing to submit a pull request to implement this improvement. 55 | 56 | ### Additional context 57 | 58 | 59 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - "ignore-changelog" 5 | categories: 6 | - title: ":warning: Update considerations and deprecations" 7 | labels: 8 | - "breaking change" 9 | - "deprecation" 10 | - title: ":rocket: New Error Prone checks and Refaster rules" 11 | labels: 12 | - "new feature" 13 | - title: ":sparkles: Improvements" 14 | labels: 15 | - "improvement" 16 | - title: ":bug: Bug fixes" 17 | labels: 18 | - "bug" 19 | - "bug fix" 20 | - title: ":books: Documentation, test and build improvements" 21 | labels: 22 | - "documentation" 23 | - "chore" 24 | - title: ":chart_with_upwards_trend: Dependency upgrades" 25 | labels: 26 | - "dependencies" 27 | - title: "Other changes" 28 | labels: 29 | - "*" 30 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # Analyzes the code using GitHub's default CodeQL query database. 2 | # Identified issues are registered with GitHub's code scanning dashboard. When 3 | # a pull request is analyzed, any offending lines are annotated. See 4 | # https://codeql.github.com for details. 5 | name: CodeQL analysis 6 | on: 7 | pull_request: 8 | push: 9 | branches: [ master ] 10 | schedule: 11 | - cron: '0 4 * * 1' 12 | permissions: 13 | contents: read 14 | jobs: 15 | analyze: 16 | strategy: 17 | matrix: 18 | language: [ java, ruby ] 19 | permissions: 20 | contents: read 21 | security-events: write 22 | runs-on: ubuntu-24.04 23 | steps: 24 | - name: Install Harden-Runner 25 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 26 | with: 27 | disable-sudo-and-containers: true 28 | egress-policy: block 29 | allowed-endpoints: > 30 | api.adoptium.net:443 31 | api.github.com:443 32 | github.com:443 33 | hosted-compute-watchdog-prod-*.githubapp.com:443 34 | objects.githubusercontent.com:443 35 | repo.maven.apache.org:443 36 | uploads.github.com:443 37 | - name: Check out code and set up JDK and Maven 38 | uses: s4u/setup-maven-action@4f7fb9d9675e899ca81c6161dadbba0189a4ebb1 # v1.18.0 39 | with: 40 | java-version: 17.0.13 41 | java-distribution: temurin 42 | maven-version: 3.9.9 43 | - name: Initialize CodeQL 44 | uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 45 | with: 46 | languages: ${{ matrix.language }} 47 | - name: Perform minimal build 48 | if: matrix.language == 'java' 49 | run: mvn -T1C clean package -DskipTests -Dverification.skip 50 | - name: Perform CodeQL analysis 51 | uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 52 | with: 53 | category: /language:${{ matrix.language }} 54 | -------------------------------------------------------------------------------- /.github/workflows/error-prone-compat.yml: -------------------------------------------------------------------------------- 1 | # Validates compatibility with the latest Error Prone release. 2 | # 3 | # XXX: This workflow compiles the code against the `LATEST` Error Prone release 4 | # as determined by Maven, and subsequently runs the unit tests. No other checks 5 | # are performed. This guards against false positives, but is not quite as 6 | # thorough as the validation performed by 7 | # `website/generate-version-compatibility-overview.sh`. Consider unifying these 8 | # approaches. 9 | # XXX: Instead of the `LATEST` release, this workflow could also attempt to 10 | # build against the `1.0-HEAD-SNAPSHOT` version published to the Sonatype 11 | # snapshot repository. This would enable advance notification of upcoming 12 | # incompatibilities. 13 | name: Error Prone compatibility check 14 | on: 15 | push: 16 | branches: [ master ] 17 | schedule: 18 | - cron: '0 4 * * *' 19 | permissions: 20 | contents: read 21 | jobs: 22 | validate: 23 | runs-on: ubuntu-24.04 24 | steps: 25 | - name: Install Harden-Runner 26 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 27 | with: 28 | disable-sudo-and-containers: true 29 | egress-policy: block 30 | allowed-endpoints: > 31 | api.adoptium.net:443 32 | github.com:443 33 | objects.githubusercontent.com:443 34 | repo.maven.apache.org:443 35 | - name: Check out code and set up JDK and Maven 36 | uses: s4u/setup-maven-action@4f7fb9d9675e899ca81c6161dadbba0189a4ebb1 # v1.18.0 37 | with: 38 | java-version: 17.0.13 39 | java-distribution: temurin 40 | maven-version: 3.9.9 41 | - name: Build project against the latest Error Prone release 42 | run: mvn -T1C clean install -Dverification.skip -Dversion.error-prone=LATEST 43 | -------------------------------------------------------------------------------- /.github/workflows/pitest-update-pr.yml: -------------------------------------------------------------------------------- 1 | # Updates a pull request based on the corresponding mutation testing analysis 2 | # performed by the `pitest-analyze-pr.yml` workflow. See 3 | # https://blog.pitest.org/oss-pitest-pr/ for details. 4 | name: "Mutation testing: post results" 5 | on: 6 | workflow_run: 7 | workflows: ["Mutation testing"] 8 | types: 9 | - completed 10 | permissions: 11 | actions: read 12 | jobs: 13 | update-pr: 14 | if: ${{ github.event.workflow_run.conclusion == 'success' }} 15 | permissions: 16 | actions: read 17 | checks: write 18 | contents: read 19 | pull-requests: write 20 | runs-on: ubuntu-24.04 21 | steps: 22 | - name: Install Harden-Runner 23 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 24 | with: 25 | disable-sudo-and-containers: true 26 | egress-policy: block 27 | allowed-endpoints: > 28 | api.adoptium.net:443 29 | api.github.com:443 30 | github.com:443 31 | objects.githubusercontent.com:443 32 | repo.maven.apache.org:443 33 | - name: Check out code and set up JDK and Maven 34 | uses: s4u/setup-maven-action@4f7fb9d9675e899ca81c6161dadbba0189a4ebb1 # v1.18.0 35 | with: 36 | java-version: 17.0.13 37 | java-distribution: temurin 38 | maven-version: 3.9.9 39 | - name: Download Pitest analysis artifact 40 | uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4 41 | with: 42 | workflow: ${{ github.event.workflow_run.workflow_id }} 43 | name: pitest-reports 44 | path: ./target/pit-reports-ci 45 | - name: Update PR 46 | run: mvn -DrepoToken="${{ secrets.GITHUB_TOKEN }}" pitest-github:updatePR 47 | -------------------------------------------------------------------------------- /.github/workflows/sonarcloud.yml: -------------------------------------------------------------------------------- 1 | # Analyzes the code base using SonarCloud. See 2 | # https://sonarcloud.io/project/overview?id=PicnicSupermarket_error-prone-support. 3 | name: SonarCloud analysis 4 | on: 5 | pull_request: 6 | push: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '0 4 * * 1' 10 | permissions: 11 | contents: read 12 | jobs: 13 | analyze: 14 | # Analysis of code in forked repositories is skipped, as such workflow runs 15 | # do not have access to the requisite secrets. 16 | if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository 17 | runs-on: ubuntu-24.04 18 | steps: 19 | - name: Install Harden-Runner 20 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 21 | with: 22 | disable-sudo-and-containers: true 23 | egress-policy: block 24 | allowed-endpoints: > 25 | analysis-sensorcache-eu-central-1-prod.s3.amazonaws.com:443 26 | api.adoptium.net:443 27 | api.nuget.org:443 28 | ea6ne4j2sb.execute-api.eu-central-1.amazonaws.com:443 29 | github.com:443 30 | objects.githubusercontent.com:443 31 | repo.maven.apache.org:443 32 | sc-cleancode-sensorcache-eu-central-1-prod.s3.amazonaws.com:443 33 | *.sonarcloud.io:443 34 | sonarcloud.io:443 35 | - name: Check out code and set up JDK and Maven 36 | uses: s4u/setup-maven-action@4f7fb9d9675e899ca81c6161dadbba0189a4ebb1 # v1.18.0 37 | with: 38 | checkout-fetch-depth: 0 39 | java-version: 17.0.13 40 | java-distribution: temurin 41 | maven-version: 3.9.9 42 | - name: Create missing `test` directory 43 | # XXX: Drop this step in favour of actually having a test. 44 | run: mkdir refaster-compiler/src/test 45 | - name: Perform SonarCloud analysis 46 | env: 47 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 48 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 49 | run: mvn -T1C jacoco:prepare-agent verify jacoco:report sonar:sonar -Dverification.skip -Dsonar.projectKey=PicnicSupermarket_error-prone-support 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # General Java development. 2 | .attach_pid* 3 | .classpath 4 | .DS_Store 5 | .factorypath 6 | .idea 7 | !.idea/icon.svg 8 | .project 9 | .settings 10 | target 11 | *.iml 12 | *.swp 13 | 14 | # The Git repositories checked out by the integration test framework. 15 | integration-tests/.repos 16 | -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -XX:ReservedCodeCacheSize=512m 2 | -XX:SoftRefLRUPolicyMSPerMB=10 3 | -XX:+UseParallelGC 4 | --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED 5 | --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED 6 | --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED 7 | --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED 8 | --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED 9 | --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED 10 | --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED 11 | --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED 12 | --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 13 | --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED 14 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | --batch-mode 2 | --errors 3 | --strict-checksums 4 | -------------------------------------------------------------------------------- /.renovaterc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "helpers:pinGitHubActionDigests" 5 | ], 6 | "customManagers": [ 7 | { 8 | "customType": "regex", 9 | "fileMatch": [ 10 | "^integration-tests/.*(-init\\.patch|\\.sh)$" 11 | ], 12 | "matchStrings": [ 13 | "\\b(?[a-z0-9_.-]+?:[a-z0-9_.-]+?):(?[^:]+?):[a-zA-Z0-9_-]+\\b", 14 | "(?.*?)" 15 | ], 16 | "datasourceTemplate": "maven" 17 | } 18 | ], 19 | "packageRules": [ 20 | { 21 | "matchPackageNames": [ 22 | "/^org\\.springframework:spring-framework-bom$/", 23 | "/^org\\.springframework\\.boot:spring-boot[a-z-]*$/" 24 | ], 25 | "separateMinorPatch": true 26 | }, 27 | { 28 | "matchPackageNames": [ 29 | "dawidd6/action-download-artifact", 30 | "github/codeql-action", 31 | "ruby/setup-ruby" 32 | ], 33 | "schedule": "every 4 weeks on Monday" 34 | } 35 | ], 36 | "reviewers": [ 37 | "rickie", 38 | "Stephan202" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /.reviewdog.yml: -------------------------------------------------------------------------------- 1 | # Reviewdog requires that this file is present. See 2 | # `.github/workflows/reviewdog.yml` for configuration. 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2024 Picnic Technologies BV 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security policy 2 | 3 | We take security seriously. We are mindful of Error Prone Support's place in 4 | the software supply chain, and the risks and responsibilities that come with 5 | this. 6 | 7 | ## Supported versions 8 | 9 | This project uses [semantic versioning][semantic-versioning]. In general, only 10 | the latest version of this software is supported. That said, if users have a 11 | compelling reason to ask for patch release of an older major release, then we 12 | will seriously consider such a request. We do urge users to stay up-to-date and 13 | use the latest release where feasible. 14 | 15 | ## Reporting a vulnerability 16 | 17 | To report a vulnerability, please visit the [security 18 | advisories][security-advisories] page and click _Report a vulnerability_. We 19 | will take such reports seriously and work with you to resolve the issue in a 20 | timely manner. 21 | 22 | [security-advisories]: https://github.com/PicnicSupermarket/error-prone-support/security/advisories 23 | [semantic-versioning]: https://semver.org 24 | -------------------------------------------------------------------------------- /apply-error-prone-suggestions.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Compiles the code using Error Prone and applies its suggestions. The set of 4 | # checks applied can optionally be restricted by name. 5 | # 6 | # As this script may modify the project's code, it is important to execute it 7 | # in a clean Git working directory. 8 | 9 | set -e -u -o pipefail 10 | 11 | if [ "${#}" -gt 1 ]; then 12 | echo "Usage: ${0} [PatchChecks]" 13 | exit 1 14 | fi 15 | 16 | patchChecks=${1:-} 17 | 18 | mvn clean test-compile fmt:format \ 19 | -s "$(dirname "${0}")/settings.xml" \ 20 | -T 1.0C \ 21 | -Perror-prone \ 22 | -Perror-prone-fork \ 23 | -Ppatch \ 24 | -Pself-check \ 25 | -Derror-prone.patch-checks="${patchChecks}" \ 26 | -Dverification.skip 27 | -------------------------------------------------------------------------------- /arcmutate-licence.txt: -------------------------------------------------------------------------------- 1 | # Arcmutate license for Error Prone Support, requested by sending an email to 2 | # support@arcmutate.com. 3 | expires=27/10/2025 4 | keyVersion=1 5 | signature=aQLVt0J//7nXDAlJuBe9ru7Dq6oApcLh17rxsgHoJqBkUCd2zvrtRxkcPm5PmF1I8gBDT9PHb+kTf6Kcfz+D1fT0wRrZv38ip56521AQPD6zjRSqak9O2Gisjo+QTPMD7oS009aSWKzQ1SMdtuZ+KIRvw4Gl+frtYzexqnGWEUQ\= 6 | packages=tech.picnic.errorprone.* 7 | type=OSSS 8 | -------------------------------------------------------------------------------- /documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.documentation; 2 | 3 | import com.google.errorprone.VisitorState; 4 | import com.google.errorprone.annotations.Immutable; 5 | import com.sun.source.tree.ClassTree; 6 | import java.util.Optional; 7 | 8 | /** 9 | * Interface implemented by classes that define how to extract data of some type {@link T} from a 10 | * given {@link ClassTree}. 11 | * 12 | * @param The type of data that is extracted. 13 | */ 14 | @Immutable 15 | interface Extractor { 16 | /** 17 | * Returns the unique identifier of this extractor. 18 | * 19 | * @return A non-{@code null} string. 20 | */ 21 | String identifier(); 22 | 23 | /** 24 | * Attempts to extract an instance of type {@link T} using the provided arguments. 25 | * 26 | * @param tree The {@link ClassTree} to analyze and from which to extract an instance of type 27 | * {@link T}. 28 | * @param state A {@link VisitorState} describing the context in which the given {@link ClassTree} 29 | * is found. 30 | * @return An instance of type {@link T}, if possible. 31 | */ 32 | Optional tryExtract(ClassTree tree, VisitorState state); 33 | } 34 | -------------------------------------------------------------------------------- /documentation-support/src/main/java/tech/picnic/errorprone/documentation/Json.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.documentation; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; 4 | import com.fasterxml.jackson.annotation.PropertyAccessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.datatype.guava.GuavaModule; 7 | import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; 8 | import com.google.errorprone.annotations.FormatMethod; 9 | import java.io.IOException; 10 | import java.io.UncheckedIOException; 11 | import java.nio.file.Path; 12 | 13 | /** 14 | * Utility class that offers mutually consistent JSON serialization and deserialization operations, 15 | * without further specifying the exact schema used. 16 | */ 17 | final class Json { 18 | private static final ObjectMapper OBJECT_MAPPER = 19 | new ObjectMapper() 20 | .setVisibility(PropertyAccessor.FIELD, Visibility.ANY) 21 | .registerModules(new GuavaModule(), new ParameterNamesModule()); 22 | 23 | private Json() {} 24 | 25 | static T read(Path path, Class clazz) { 26 | try { 27 | return OBJECT_MAPPER.readValue(path.toFile(), clazz); 28 | } catch (IOException e) { 29 | throw failure(e, "Failure reading from '%s'", path); 30 | } 31 | } 32 | 33 | static void write(Path path, T object) { 34 | try { 35 | OBJECT_MAPPER.writeValue(path.toFile(), object); 36 | } catch (IOException e) { 37 | throw failure(e, "Failure writing to '%s'", path); 38 | } 39 | } 40 | 41 | @FormatMethod 42 | private static UncheckedIOException failure(IOException cause, String format, Object... args) { 43 | return new UncheckedIOException(String.format(format, args), cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /documentation-support/src/main/java/tech/picnic/errorprone/documentation/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A Java compiler plugin that extracts data from compiled classes, in support of the Error Prone 3 | * Support documentation. 4 | */ 5 | @com.google.errorprone.annotations.CheckReturnValue 6 | @org.jspecify.annotations.NullMarked 7 | package tech.picnic.errorprone.documentation; 8 | -------------------------------------------------------------------------------- /documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.documentation; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 5 | import static tech.picnic.errorprone.documentation.DocumentationGenerator.OUTPUT_DIRECTORY_FLAG; 6 | 7 | import java.nio.file.InvalidPathException; 8 | import java.nio.file.Path; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.params.ParameterizedTest; 11 | import org.junit.jupiter.params.provider.ValueSource; 12 | 13 | final class DocumentationGeneratorTest { 14 | @ParameterizedTest 15 | @ValueSource(strings = {"bar", "foo"}) 16 | void getOutputPath(String path) { 17 | assertThat(DocumentationGenerator.getOutputPath(OUTPUT_DIRECTORY_FLAG + '=' + path)) 18 | .isEqualTo(Path.of(path)); 19 | } 20 | 21 | @ParameterizedTest 22 | @ValueSource(strings = {"", "-XoutputDirectory", "invalidOption=Test", "nothing"}) 23 | void getOutputPathWithInvalidArgument(String pathArg) { 24 | assertThatThrownBy(() -> DocumentationGenerator.getOutputPath(pathArg)) 25 | .isInstanceOf(IllegalArgumentException.class) 26 | .hasMessage("'%s' must be of the form '%s='", pathArg, OUTPUT_DIRECTORY_FLAG); 27 | } 28 | 29 | @Test 30 | void getOutputPathWithInvalidPath() { 31 | String basePath = "path-with-null-char-\0"; 32 | assertThatThrownBy( 33 | () -> DocumentationGenerator.getOutputPath(OUTPUT_DIRECTORY_FLAG + '=' + basePath)) 34 | .isInstanceOf(IllegalArgumentException.class) 35 | .hasCauseInstanceOf(InvalidPathException.class) 36 | .hasMessageEndingWith("Invalid path '%s'", basePath); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/package-info.java: -------------------------------------------------------------------------------- 1 | /** Picnic Error Prone Contrib checks. */ 2 | @com.google.errorprone.annotations.CheckReturnValue 3 | @org.jspecify.annotations.NullMarked 4 | package tech.picnic.errorprone.bugpatterns; 5 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJIteratorRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | 6 | import com.google.errorprone.refaster.annotation.AfterTemplate; 7 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 8 | import com.google.errorprone.refaster.annotation.UseImportPolicy; 9 | import java.util.Iterator; 10 | import org.assertj.core.api.AbstractBooleanAssert; 11 | import org.assertj.core.api.IteratorAssert; 12 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 13 | 14 | @OnlineDocumentation 15 | final class AssertJIteratorRules { 16 | private AssertJIteratorRules() {} 17 | 18 | static final class AssertThatHasNext { 19 | @BeforeTemplate 20 | AbstractBooleanAssert before(Iterator iterator) { 21 | return assertThat(iterator.hasNext()).isTrue(); 22 | } 23 | 24 | @AfterTemplate 25 | @UseImportPolicy(STATIC_IMPORT_ALWAYS) 26 | IteratorAssert after(Iterator iterator) { 27 | return assertThat(iterator).hasNext(); 28 | } 29 | } 30 | 31 | static final class AssertThatIsExhausted { 32 | @BeforeTemplate 33 | AbstractBooleanAssert before(Iterator iterator) { 34 | return assertThat(iterator.hasNext()).isFalse(); 35 | } 36 | 37 | @AfterTemplate 38 | @UseImportPolicy(STATIC_IMPORT_ALWAYS) 39 | IteratorAssert after(Iterator iterator) { 40 | return assertThat(iterator).isExhausted(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CharSequenceRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.errorprone.refaster.Refaster; 4 | import com.google.errorprone.refaster.annotation.AfterTemplate; 5 | import com.google.errorprone.refaster.annotation.AlsoNegation; 6 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 7 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 8 | 9 | /** Refaster rules related to expressions dealing with {@link CharSequence}s. */ 10 | @OnlineDocumentation 11 | final class CharSequenceRules { 12 | private CharSequenceRules() {} 13 | 14 | /** 15 | * Prefer {@link CharSequence#isEmpty()} over alternatives that consult the char sequence's 16 | * length. 17 | */ 18 | // XXX: Drop this rule once we (and OpenRewrite) no longer support projects targeting Java 14 or 19 | // below. 20 | static final class CharSequenceIsEmpty { 21 | @BeforeTemplate 22 | boolean before(CharSequence charSequence) { 23 | return Refaster.anyOf( 24 | charSequence.length() == 0, charSequence.length() <= 0, charSequence.length() < 1); 25 | } 26 | 27 | @AfterTemplate 28 | @AlsoNegation 29 | boolean after(CharSequence charSequence) { 30 | return charSequence.isEmpty(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/InputStreamRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.io.ByteStreams; 4 | import com.google.errorprone.refaster.annotation.AfterTemplate; 5 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 10 | 11 | /** Refaster rules related to expressions dealing with {@link InputStream}s. */ 12 | @OnlineDocumentation 13 | final class InputStreamRules { 14 | private InputStreamRules() {} 15 | 16 | static final class InputStreamTransferTo { 17 | @BeforeTemplate 18 | long before(InputStream in, OutputStream out) throws IOException { 19 | return ByteStreams.copy(in, out); 20 | } 21 | 22 | @AfterTemplate 23 | long after(InputStream in, OutputStream out) throws IOException { 24 | return in.transferTo(out); 25 | } 26 | } 27 | 28 | static final class InputStreamReadAllBytes { 29 | @BeforeTemplate 30 | byte[] before(InputStream in) throws IOException { 31 | return ByteStreams.toByteArray(in); 32 | } 33 | 34 | @AfterTemplate 35 | byte[] after(InputStream in) throws IOException { 36 | return in.readAllBytes(); 37 | } 38 | } 39 | 40 | static final class InputStreamReadNBytes { 41 | @BeforeTemplate 42 | byte[] before(InputStream in, int n) throws IOException { 43 | return ByteStreams.limit(in, n).readAllBytes(); 44 | } 45 | 46 | @AfterTemplate 47 | byte[] after(InputStream in, int n) throws IOException { 48 | return in.readNBytes(n); 49 | } 50 | } 51 | 52 | static final class InputStreamSkipNBytes { 53 | @BeforeTemplate 54 | void before(InputStream in, long n) throws IOException { 55 | ByteStreams.skipFully(in, n); 56 | } 57 | 58 | @AfterTemplate 59 | void after(InputStream in, long n) throws IOException { 60 | in.skipNBytes(n); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; 4 | import static org.junit.jupiter.params.provider.Arguments.arguments; 5 | 6 | import com.google.errorprone.refaster.annotation.AfterTemplate; 7 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 8 | import com.google.errorprone.refaster.annotation.Repeated; 9 | import com.google.errorprone.refaster.annotation.UseImportPolicy; 10 | import org.junit.jupiter.params.provider.Arguments; 11 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 12 | 13 | /** Refaster rules related to JUnit expressions and statements. */ 14 | @OnlineDocumentation 15 | final class JUnitRules { 16 | private JUnitRules() {} 17 | 18 | /** Prefer statically imported {@link Arguments#arguments} over {@link Arguments#of} calls. */ 19 | static final class ArgumentsEnumeration { 20 | @BeforeTemplate 21 | Arguments before(@Repeated T objects) { 22 | return Arguments.of(objects); 23 | } 24 | 25 | @AfterTemplate 26 | @UseImportPolicy(STATIC_IMPORT_ALWAYS) 27 | Arguments after(@Repeated T objects) { 28 | return arguments(objects); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JacksonRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.google.errorprone.refaster.Refaster; 5 | import com.google.errorprone.refaster.annotation.AfterTemplate; 6 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 7 | import java.util.Optional; 8 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 9 | 10 | /** Refaster rules related to Jackson expressions and statements. */ 11 | @OnlineDocumentation 12 | final class JacksonRules { 13 | private JacksonRules() {} 14 | 15 | /** Prefer {@link JsonNode#optional(int)} over more contrived alternatives. */ 16 | static final class JsonNodeOptionalInt { 17 | @BeforeTemplate 18 | Optional before(JsonNode node, int index) { 19 | return Refaster.anyOf( 20 | node.get(index).asOptional(), 21 | node.path(index).asOptional(), 22 | Optional.of(node.get(index)), 23 | Optional.ofNullable(node.get(index))); 24 | } 25 | 26 | @AfterTemplate 27 | Optional after(JsonNode node, int index) { 28 | return node.optional(index); 29 | } 30 | } 31 | 32 | /** Prefer {@link JsonNode#optional(String)} over more contrived alternatives. */ 33 | static final class JsonNodeOptionalString { 34 | @BeforeTemplate 35 | Optional before(JsonNode node, String fieldName) { 36 | return Refaster.anyOf( 37 | node.get(fieldName).asOptional(), 38 | node.path(fieldName).asOptional(), 39 | Optional.of(node.get(fieldName)), 40 | Optional.ofNullable(node.get(fieldName))); 41 | } 42 | 43 | @AfterTemplate 44 | Optional after(JsonNode node, String fieldName) { 45 | return node.optional(fieldName); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PatternRules.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.base.Predicates.containsPattern; 4 | 5 | import com.google.common.base.Predicates; 6 | import com.google.errorprone.refaster.annotation.AfterTemplate; 7 | import com.google.errorprone.refaster.annotation.BeforeTemplate; 8 | import java.util.function.Predicate; 9 | import java.util.regex.Pattern; 10 | import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; 11 | 12 | /** Refaster rules related to code dealing with regular expressions. */ 13 | @OnlineDocumentation 14 | final class PatternRules { 15 | private PatternRules() {} 16 | 17 | /** Prefer {@link Pattern#asPredicate()} over non-JDK alternatives. */ 18 | // XXX: This rule could also replace `s -> pattern.matcher(s).find()`, though the lambda 19 | // expression may match functional interfaces other than `Predicate`. If we do add such a rule, we 20 | // should also add a rule that replaces `s -> pattern.matcher(s).matches()` with 21 | // `pattern.asMatchPredicate()`. 22 | static final class PatternAsPredicate { 23 | @BeforeTemplate 24 | Predicate before(Pattern pattern) { 25 | return Predicates.contains(pattern); 26 | } 27 | 28 | @AfterTemplate 29 | Predicate after(Pattern pattern) { 30 | return pattern.asPredicate(); 31 | } 32 | } 33 | 34 | /** Prefer {@link Pattern#asPredicate()} over non-JDK alternatives. */ 35 | static final class PatternCompileAsPredicate { 36 | @BeforeTemplate 37 | Predicate before(String pattern) { 38 | return containsPattern(pattern); 39 | } 40 | 41 | @AfterTemplate 42 | Predicate after(String pattern) { 43 | return Pattern.compile(pattern).asPredicate(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java: -------------------------------------------------------------------------------- 1 | /** Picnic Refaster rules. */ 2 | @com.google.errorprone.annotations.CheckReturnValue 3 | @org.jspecify.annotations.NullMarked 4 | package tech.picnic.errorprone.refasterrules; 5 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssertJIsNullTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.bugpatterns; 2 | 3 | import com.google.errorprone.BugCheckerRefactoringTestHelper; 4 | import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; 5 | import com.google.errorprone.CompilationTestHelper; 6 | import org.junit.jupiter.api.Test; 7 | 8 | final class AssertJIsNullTest { 9 | @Test 10 | void identification() { 11 | CompilationTestHelper.newInstance(AssertJIsNull.class, getClass()) 12 | .addSourceLines( 13 | "A.java", 14 | "import static org.assertj.core.api.Assertions.assertThat;", 15 | "", 16 | "class A {", 17 | " void m() {", 18 | " assertThat(1).isEqualTo(1);", 19 | " // BUG: Diagnostic contains:", 20 | " assertThat(1).isEqualTo(null);", 21 | " // BUG: Diagnostic contains:", 22 | " assertThat(\"foo\").isEqualTo(null);", 23 | " isEqualTo(null);", 24 | " }", 25 | "", 26 | " private boolean isEqualTo(Object value) {", 27 | " return value.equals(\"bar\");", 28 | " }", 29 | "}") 30 | .doTest(); 31 | } 32 | 33 | @Test 34 | void replacement() { 35 | BugCheckerRefactoringTestHelper.newInstance(AssertJIsNull.class, getClass()) 36 | .addInputLines( 37 | "A.java", 38 | "import static org.assertj.core.api.Assertions.assertThat;", 39 | "", 40 | "class A {", 41 | " void m() {", 42 | " assertThat(1).isEqualTo(null);", 43 | " assertThat(\"foo\").isEqualTo(null);", 44 | " }", 45 | "}") 46 | .addOutputLines( 47 | "A.java", 48 | "import static org.assertj.core.api.Assertions.assertThat;", 49 | "", 50 | "class A {", 51 | " void m() {", 52 | " assertThat(1).isNull();", 53 | " assertThat(\"foo\").isNull();", 54 | " }", 55 | "}") 56 | .doTest(TestMode.TEXT_MATCH); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsageTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.bugpatterns; 2 | 3 | import com.google.errorprone.CompilationTestHelper; 4 | import org.junit.jupiter.api.Test; 5 | 6 | final class MongoDBTextFilterUsageTest { 7 | @Test 8 | void identification() { 9 | CompilationTestHelper.newInstance(MongoDBTextFilterUsage.class, getClass()) 10 | .addSourceLines( 11 | "A.java", 12 | "import com.mongodb.client.model.Filters;", 13 | "import com.mongodb.client.model.TextSearchOptions;", 14 | "", 15 | "class A {", 16 | " void m() {", 17 | " Filters.eq(\"foo\", \"bar\");", 18 | " // BUG: Diagnostic contains:", 19 | " Filters.text(\"foo\");", 20 | " // BUG: Diagnostic contains:", 21 | " Filters.text(\"foo\", new TextSearchOptions());", 22 | " }", 23 | "}") 24 | .doTest(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.bugpatterns; 2 | 3 | import com.google.errorprone.CompilationTestHelper; 4 | import org.junit.jupiter.api.Test; 5 | 6 | final class NestedOptionalsTest { 7 | @Test 8 | void identification() { 9 | CompilationTestHelper.newInstance(NestedOptionals.class, getClass()) 10 | .addSourceLines( 11 | "A.java", 12 | "import java.util.Optional;", 13 | "import java.util.stream.Stream;", 14 | "", 15 | "class A {", 16 | " void m() {", 17 | " Optional.empty();", 18 | " Optional.of(1);", 19 | " // BUG: Diagnostic contains:", 20 | " Optional.of(Optional.empty());", 21 | " // BUG: Diagnostic contains:", 22 | " Optional.of(Optional.of(1));", 23 | "", 24 | " Optional.ofNullable(null);", 25 | " // BUG: Diagnostic contains:", 26 | " Optional.ofNullable((Optional) null);", 27 | "", 28 | " Optional.of(\"foo\").map(String::length);", 29 | " // BUG: Diagnostic contains:", 30 | " Optional.of(\"foo\").map(Optional::of);", 31 | "", 32 | " Stream.of(\"foo\").findFirst();", 33 | " // BUG: Diagnostic contains:", 34 | " Stream.of(\"foo\").map(Optional::of).findFirst();", 35 | " }", 36 | "}") 37 | .doTest(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.bugpatterns; 2 | 3 | import com.google.errorprone.CompilationTestHelper; 4 | import org.junit.jupiter.api.Test; 5 | 6 | final class NestedPublishersTest { 7 | @Test 8 | void identification() { 9 | CompilationTestHelper.newInstance(NestedPublishers.class, getClass()) 10 | .addSourceLines( 11 | "A.java", 12 | "import org.reactivestreams.Publisher;", 13 | "import reactor.core.publisher.Flux;", 14 | "import reactor.core.publisher.GroupedFlux;", 15 | "import reactor.core.publisher.Mono;", 16 | "", 17 | "class A {", 18 | " void m() {", 19 | " Mono.empty();", 20 | " Flux.just(1);", 21 | " Flux.just(1, 2).groupBy(i -> i).map(groupedFlux -> (GroupedFlux) groupedFlux);", 22 | "", 23 | " // BUG: Diagnostic contains:", 24 | " Mono.just(Mono.empty());", 25 | " // BUG: Diagnostic contains:", 26 | " Flux.just(Flux.empty());", 27 | " // BUG: Diagnostic contains:", 28 | " Mono.just((Flux) Flux.just(1));", 29 | " // BUG: Diagnostic contains:", 30 | " Flux.just((Publisher) Mono.just(1));", 31 | " // BUG: Diagnostic contains:", 32 | " Mono.just(1).map(Mono::just);", 33 | " }", 34 | "}") 35 | .doTest(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import java.math.BigDecimal; 9 | import org.assertj.core.api.AbstractBigDecimalAssert; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class AssertJBigDecimalRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(offset(0), withPercentage(0)); 16 | } 17 | 18 | ImmutableSet> testAbstractBigDecimalAssertIsEqualByComparingTo() { 19 | return ImmutableSet.of( 20 | assertThat(BigDecimal.ZERO).isCloseTo(BigDecimal.ONE, offset(BigDecimal.ZERO)), 21 | assertThat(BigDecimal.ZERO).isCloseTo(BigDecimal.ONE, withPercentage(0))); 22 | } 23 | 24 | ImmutableSet> testAbstractBigDecimalAssertIsNotEqualByComparingTo() { 25 | return ImmutableSet.of( 26 | assertThat(BigDecimal.ZERO).isNotCloseTo(BigDecimal.ONE, offset(BigDecimal.ZERO)), 27 | assertThat(BigDecimal.ZERO).isNotCloseTo(BigDecimal.ONE, withPercentage(0))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import java.math.BigDecimal; 9 | import org.assertj.core.api.AbstractBigDecimalAssert; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class AssertJBigDecimalRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(offset(0), withPercentage(0)); 16 | } 17 | 18 | ImmutableSet> testAbstractBigDecimalAssertIsEqualByComparingTo() { 19 | return ImmutableSet.of( 20 | assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE), 21 | assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE)); 22 | } 23 | 24 | ImmutableSet> testAbstractBigDecimalAssertIsNotEqualByComparingTo() { 25 | return ImmutableSet.of( 26 | assertThat(BigDecimal.ZERO).isNotEqualByComparingTo(BigDecimal.ONE), 27 | assertThat(BigDecimal.ZERO).isNotEqualByComparingTo(BigDecimal.ONE)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import java.math.BigInteger; 9 | import org.assertj.core.api.AbstractBigIntegerAssert; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class AssertJBigIntegerRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(offset(0), withPercentage(0)); 16 | } 17 | 18 | ImmutableSet> testAbstractBigIntegerAssertIsEqualTo() { 19 | return ImmutableSet.of( 20 | assertThat(BigInteger.ZERO).isEqualTo(BigInteger.ONE), 21 | assertThat(BigInteger.ZERO).isEqualTo(BigInteger.ONE)); 22 | } 23 | 24 | ImmutableSet> testAbstractBigIntegerAssertIsNotEqualTo() { 25 | return ImmutableSet.of( 26 | assertThat(BigInteger.ZERO).isNotEqualTo(BigInteger.ONE), 27 | assertThat(BigInteger.ZERO).isNotEqualTo(BigInteger.ONE)); 28 | } 29 | 30 | ImmutableSet> testAbstractBigIntegerAssertIsZero() { 31 | return ImmutableSet.of( 32 | assertThat(BigInteger.ZERO).isEqualTo(0), 33 | assertThat(BigInteger.ZERO).isEqualTo(0), 34 | assertThat(BigInteger.ZERO).isEqualTo(0)); 35 | } 36 | 37 | ImmutableSet> testAbstractBigIntegerAssertIsNotZero() { 38 | return ImmutableSet.of( 39 | assertThat(BigInteger.ZERO).isNotEqualTo(0), 40 | assertThat(BigInteger.ZERO).isNotEqualTo(0), 41 | assertThat(BigInteger.ZERO).isNotEqualTo(0)); 42 | } 43 | 44 | ImmutableSet> testAbstractBigIntegerAssertIsOne() { 45 | return ImmutableSet.of( 46 | assertThat(BigInteger.ZERO).isEqualTo(1), 47 | assertThat(BigInteger.ZERO).isEqualTo(1), 48 | assertThat(BigInteger.ZERO).isEqualTo(1)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractBooleanAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJBooleanRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { 11 | return assertThat(true).isNotEqualTo(!Boolean.FALSE); 12 | } 13 | 14 | AbstractBooleanAssert testAbstractBooleanAssertIsNotEqualTo() { 15 | return assertThat(true).isEqualTo(!Boolean.FALSE); 16 | } 17 | 18 | ImmutableSet> testAbstractBooleanAssertIsTrue() { 19 | return ImmutableSet.of( 20 | assertThat(true).isEqualTo(true), 21 | assertThat(true).isEqualTo(Boolean.TRUE), 22 | assertThat(true).isNotEqualTo(false), 23 | assertThat(true).isNotEqualTo(Boolean.FALSE)); 24 | } 25 | 26 | AbstractBooleanAssert testAssertThatBooleanIsTrue() { 27 | return assertThat(!Boolean.TRUE).isFalse(); 28 | } 29 | 30 | ImmutableSet> testAbstractBooleanAssertIsFalse() { 31 | return ImmutableSet.of( 32 | assertThat(true).isEqualTo(false), 33 | assertThat(true).isEqualTo(Boolean.FALSE), 34 | assertThat(true).isNotEqualTo(true), 35 | assertThat(true).isNotEqualTo(Boolean.TRUE)); 36 | } 37 | 38 | AbstractBooleanAssert testAssertThatBooleanIsFalse() { 39 | return assertThat(!Boolean.TRUE).isTrue(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractBooleanAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJBooleanRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { 11 | return assertThat(true).isEqualTo(Boolean.FALSE); 12 | } 13 | 14 | AbstractBooleanAssert testAbstractBooleanAssertIsNotEqualTo() { 15 | return assertThat(true).isNotEqualTo(Boolean.FALSE); 16 | } 17 | 18 | ImmutableSet> testAbstractBooleanAssertIsTrue() { 19 | return ImmutableSet.of( 20 | assertThat(true).isTrue(), 21 | assertThat(true).isTrue(), 22 | assertThat(true).isTrue(), 23 | assertThat(true).isTrue()); 24 | } 25 | 26 | AbstractBooleanAssert testAssertThatBooleanIsTrue() { 27 | return assertThat(Boolean.TRUE).isTrue(); 28 | } 29 | 30 | ImmutableSet> testAbstractBooleanAssertIsFalse() { 31 | return ImmutableSet.of( 32 | assertThat(true).isFalse(), 33 | assertThat(true).isFalse(), 34 | assertThat(true).isFalse(), 35 | assertThat(true).isFalse()); 36 | } 37 | 38 | AbstractBooleanAssert testAssertThatBooleanIsFalse() { 39 | return assertThat(Boolean.TRUE).isFalse(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractByteAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJByteRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractByteAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat((byte) 0).isCloseTo((byte) 1, offset((byte) 0)), 20 | assertThat((byte) 0).isCloseTo((byte) 1, withPercentage(0))); 21 | } 22 | 23 | ImmutableSet> testAbstractByteAssertIsNotEqualTo() { 24 | return ImmutableSet.of( 25 | assertThat((byte) 0).isNotCloseTo((byte) 1, offset((byte) 0)), 26 | assertThat((byte) 0).isNotCloseTo((byte) 1, withPercentage(0))); 27 | } 28 | 29 | AbstractByteAssert testAbstractByteAssertIsZero() { 30 | return assertThat((byte) 0).isZero(); 31 | } 32 | 33 | AbstractByteAssert testAbstractByteAssertIsNotZero() { 34 | return assertThat((byte) 0).isNotZero(); 35 | } 36 | 37 | AbstractByteAssert testAbstractByteAssertIsOne() { 38 | return assertThat((byte) 0).isOne(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractByteAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJByteRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractByteAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat((byte) 0).isEqualTo((byte) 1), assertThat((byte) 0).isEqualTo((byte) 1)); 20 | } 21 | 22 | ImmutableSet> testAbstractByteAssertIsNotEqualTo() { 23 | return ImmutableSet.of( 24 | assertThat((byte) 0).isNotEqualTo((byte) 1), assertThat((byte) 0).isNotEqualTo((byte) 1)); 25 | } 26 | 27 | AbstractByteAssert testAbstractByteAssertIsZero() { 28 | return assertThat((byte) 0).isEqualTo((byte) 0); 29 | } 30 | 31 | AbstractByteAssert testAbstractByteAssertIsNotZero() { 32 | return assertThat((byte) 0).isNotEqualTo((byte) 0); 33 | } 34 | 35 | AbstractByteAssert testAbstractByteAssertIsOne() { 36 | return assertThat((byte) 0).isEqualTo((byte) 1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJCharSequenceRulesTest implements RefasterRuleCollectionTestCase { 10 | void testAssertThatCharSequenceIsEmpty() { 11 | assertThat("foo".isEmpty()).isTrue(); 12 | assertThat("bar".length()).isEqualTo(0L); 13 | assertThat("baz".length()).isNotPositive(); 14 | } 15 | 16 | ImmutableSet> testAssertThatCharSequenceIsNotEmpty() { 17 | return ImmutableSet.of( 18 | assertThat("foo".isEmpty()).isFalse(), 19 | assertThat("bar".length()).isNotEqualTo(0), 20 | assertThat("baz".length()).isPositive()); 21 | } 22 | 23 | AbstractAssert testAssertThatCharSequenceHasSize() { 24 | return assertThat("foo".length()).isEqualTo(3); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJCharSequenceRulesTest implements RefasterRuleCollectionTestCase { 10 | void testAssertThatCharSequenceIsEmpty() { 11 | assertThat("foo").isEmpty(); 12 | assertThat("bar").isEmpty(); 13 | assertThat("baz").isEmpty(); 14 | } 15 | 16 | ImmutableSet> testAssertThatCharSequenceIsNotEmpty() { 17 | return ImmutableSet.of( 18 | assertThat("foo").isNotEmpty(), 19 | assertThat("bar").isNotEmpty(), 20 | assertThat("baz").isNotEmpty()); 21 | } 22 | 23 | AbstractAssert testAssertThatCharSequenceHasSize() { 24 | return assertThat("foo").hasSize(3); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigDecimal; 6 | import org.assertj.core.api.AbstractComparableAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJComparableRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractComparableAssert testAssertThatIsEqualByComparingTo() { 11 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isEqualTo(0); 12 | } 13 | 14 | AbstractComparableAssert testAssertThatIsNotEqualByComparingTo() { 15 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotEqualTo(0); 16 | } 17 | 18 | AbstractComparableAssert testAssertThatIsLessThan() { 19 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNegative(); 20 | } 21 | 22 | AbstractComparableAssert testAssertThatIsLessThanOrEqualTo() { 23 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotPositive(); 24 | } 25 | 26 | AbstractComparableAssert testAssertThatIsGreaterThan() { 27 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isPositive(); 28 | } 29 | 30 | AbstractComparableAssert testAssertThatIsGreaterThanOrEqualTo() { 31 | return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotNegative(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.math.BigDecimal; 6 | import org.assertj.core.api.AbstractComparableAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJComparableRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractComparableAssert testAssertThatIsEqualByComparingTo() { 11 | return assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE); 12 | } 13 | 14 | AbstractComparableAssert testAssertThatIsNotEqualByComparingTo() { 15 | return assertThat(BigDecimal.ZERO).isNotEqualByComparingTo(BigDecimal.ONE); 16 | } 17 | 18 | AbstractComparableAssert testAssertThatIsLessThan() { 19 | return assertThat(BigDecimal.ZERO).isLessThan(BigDecimal.ONE); 20 | } 21 | 22 | AbstractComparableAssert testAssertThatIsLessThanOrEqualTo() { 23 | return assertThat(BigDecimal.ZERO).isLessThanOrEqualTo(BigDecimal.ONE); 24 | } 25 | 26 | AbstractComparableAssert testAssertThatIsGreaterThan() { 27 | return assertThat(BigDecimal.ZERO).isGreaterThan(BigDecimal.ONE); 28 | } 29 | 30 | AbstractComparableAssert testAssertThatIsGreaterThanOrEqualTo() { 31 | return assertThat(BigDecimal.ZERO).isGreaterThanOrEqualTo(BigDecimal.ONE); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractDoubleAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJDoubleRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractDoubleAssertIsCloseToWithOffset() { 18 | return ImmutableSet.of( 19 | assertThat(0.0).isEqualTo(1, offset(0.0)), 20 | assertThat(0.0).isEqualTo(Double.valueOf(1), offset(0.0))); 21 | } 22 | 23 | ImmutableSet> testAbstractDoubleAssertIsEqualTo() { 24 | return ImmutableSet.of( 25 | assertThat(0.0).isCloseTo(1, offset(0.0)), assertThat(0.0).isCloseTo(1, withPercentage(0))); 26 | } 27 | 28 | ImmutableSet> testAbstractDoubleAssertIsNotEqualTo() { 29 | return ImmutableSet.of( 30 | assertThat(0.0).isNotCloseTo(1, offset(0.0)), 31 | assertThat(0.0).isNotCloseTo(1, withPercentage(0))); 32 | } 33 | 34 | AbstractDoubleAssert testAbstractDoubleAssertIsZero() { 35 | return assertThat(0.0).isZero(); 36 | } 37 | 38 | AbstractDoubleAssert testAbstractDoubleAssertIsNotZero() { 39 | return assertThat(0.0).isNotZero(); 40 | } 41 | 42 | AbstractDoubleAssert testAbstractDoubleAssertIsOne() { 43 | return assertThat(0.0).isOne(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractDoubleAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJDoubleRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractDoubleAssertIsCloseToWithOffset() { 18 | return ImmutableSet.of( 19 | assertThat(0.0).isCloseTo(1, offset(0.0)), 20 | assertThat(0.0).isCloseTo(Double.valueOf(1), offset(0.0))); 21 | } 22 | 23 | ImmutableSet> testAbstractDoubleAssertIsEqualTo() { 24 | return ImmutableSet.of(assertThat(0.0).isEqualTo(1), assertThat(0.0).isEqualTo(1)); 25 | } 26 | 27 | ImmutableSet> testAbstractDoubleAssertIsNotEqualTo() { 28 | return ImmutableSet.of(assertThat(0.0).isNotEqualTo(1), assertThat(0.0).isNotEqualTo(1)); 29 | } 30 | 31 | AbstractDoubleAssert testAbstractDoubleAssertIsZero() { 32 | return assertThat(0.0).isEqualTo(0); 33 | } 34 | 35 | AbstractDoubleAssert testAbstractDoubleAssertIsNotZero() { 36 | return assertThat(0.0).isNotEqualTo(0); 37 | } 38 | 39 | AbstractDoubleAssert testAbstractDoubleAssertIsOne() { 40 | return assertThat(0.0).isEqualTo(1); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractFloatAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJFloatRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractFloatAssertIsCloseToWithOffset() { 18 | return ImmutableSet.of( 19 | assertThat(0F).isEqualTo(1, offset(0F)), 20 | assertThat(0F).isEqualTo(Float.valueOf(1), offset(0F))); 21 | } 22 | 23 | ImmutableSet> testAbstractFloatAssertIsEqualTo() { 24 | return ImmutableSet.of( 25 | assertThat(0F).isCloseTo(1, offset(0F)), assertThat(0F).isCloseTo(1, withPercentage(0))); 26 | } 27 | 28 | ImmutableSet> testAbstractFloatAssertIsNotEqualTo() { 29 | return ImmutableSet.of( 30 | assertThat(0F).isNotCloseTo(1, offset(0F)), 31 | assertThat(0F).isNotCloseTo(1, withPercentage(0))); 32 | } 33 | 34 | AbstractFloatAssert testAbstractFloatAssertIsZero() { 35 | return assertThat(0F).isZero(); 36 | } 37 | 38 | AbstractFloatAssert testAbstractFloatAssertIsNotZero() { 39 | return assertThat(0F).isNotZero(); 40 | } 41 | 42 | AbstractFloatAssert testAbstractFloatAssertIsOne() { 43 | return assertThat(0F).isOne(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractFloatAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJFloatRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractFloatAssertIsCloseToWithOffset() { 18 | return ImmutableSet.of( 19 | assertThat(0F).isCloseTo(1, offset(0F)), 20 | assertThat(0F).isCloseTo(Float.valueOf(1), offset(0F))); 21 | } 22 | 23 | ImmutableSet> testAbstractFloatAssertIsEqualTo() { 24 | return ImmutableSet.of(assertThat(0F).isEqualTo(1), assertThat(0F).isEqualTo(1)); 25 | } 26 | 27 | ImmutableSet> testAbstractFloatAssertIsNotEqualTo() { 28 | return ImmutableSet.of(assertThat(0F).isNotEqualTo(1), assertThat(0F).isNotEqualTo(1)); 29 | } 30 | 31 | AbstractFloatAssert testAbstractFloatAssertIsZero() { 32 | return assertThat(0F).isEqualTo(0); 33 | } 34 | 35 | AbstractFloatAssert testAbstractFloatAssertIsNotZero() { 36 | return assertThat(0F).isNotEqualTo(0); 37 | } 38 | 39 | AbstractFloatAssert testAbstractFloatAssertIsOne() { 40 | return assertThat(0F).isEqualTo(1); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractIntegerAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJIntegerRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractIntegerAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat(0).isCloseTo(1, offset(0)), assertThat(0).isCloseTo(1, withPercentage(0))); 20 | } 21 | 22 | ImmutableSet> testAbstractIntegerAssertIsNotEqualTo() { 23 | return ImmutableSet.of( 24 | assertThat(0).isNotCloseTo(1, offset(0)), assertThat(0).isNotCloseTo(1, withPercentage(0))); 25 | } 26 | 27 | AbstractIntegerAssert testAbstractIntegerAssertIsZero() { 28 | return assertThat(0).isZero(); 29 | } 30 | 31 | AbstractIntegerAssert testAbstractIntegerAssertIsNotZero() { 32 | return assertThat(0).isNotZero(); 33 | } 34 | 35 | AbstractIntegerAssert testAbstractIntegerAssertIsOne() { 36 | return assertThat(0).isOne(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractIntegerAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJIntegerRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractIntegerAssertIsEqualTo() { 18 | return ImmutableSet.of(assertThat(0).isEqualTo(1), assertThat(0).isEqualTo(1)); 19 | } 20 | 21 | ImmutableSet> testAbstractIntegerAssertIsNotEqualTo() { 22 | return ImmutableSet.of(assertThat(0).isNotEqualTo(1), assertThat(0).isNotEqualTo(1)); 23 | } 24 | 25 | AbstractIntegerAssert testAbstractIntegerAssertIsZero() { 26 | return assertThat(0).isEqualTo(0); 27 | } 28 | 29 | AbstractIntegerAssert testAbstractIntegerAssertIsNotZero() { 30 | return assertThat(0).isNotEqualTo(0); 31 | } 32 | 33 | AbstractIntegerAssert testAbstractIntegerAssertIsOne() { 34 | return assertThat(0).isEqualTo(1); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIterableRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import com.google.common.collect.Iterables; 7 | import org.assertj.core.api.AbstractAssert; 8 | import org.assertj.core.api.AbstractIntegerAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJIterableRulesTest implements RefasterRuleCollectionTestCase { 12 | public ImmutableSet elidedTypesAndStaticImports() { 13 | return ImmutableSet.of(Iterables.class); 14 | } 15 | 16 | void testAssertThatIterableIsEmpty() { 17 | assertThat(ImmutableSet.of(1).iterator()).isExhausted(); 18 | assertThat(ImmutableSet.of(2).isEmpty()).isTrue(); 19 | } 20 | 21 | ImmutableSet> testAssertThatIterableIsNotEmpty() { 22 | return ImmutableSet.of( 23 | assertThat(ImmutableSet.of(1).iterator()).hasNext(), 24 | assertThat(ImmutableSet.of(2).isEmpty()).isFalse()); 25 | } 26 | 27 | ImmutableSet> testAssertThatIterableSize() { 28 | return ImmutableSet.of( 29 | assertThat(Iterables.size(ImmutableSet.of(1))), assertThat(ImmutableSet.of(2).size())); 30 | } 31 | 32 | AbstractAssert testAssertThatIterableHasOneElementEqualTo() { 33 | return assertThat(Iterables.getOnlyElement(ImmutableSet.of(new Object()))).isEqualTo("foo"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIterableRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import com.google.common.collect.Iterables; 7 | import org.assertj.core.api.AbstractAssert; 8 | import org.assertj.core.api.AbstractIntegerAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJIterableRulesTest implements RefasterRuleCollectionTestCase { 12 | public ImmutableSet elidedTypesAndStaticImports() { 13 | return ImmutableSet.of(Iterables.class); 14 | } 15 | 16 | void testAssertThatIterableIsEmpty() { 17 | assertThat(ImmutableSet.of(1)).isEmpty(); 18 | assertThat(ImmutableSet.of(2)).isEmpty(); 19 | } 20 | 21 | ImmutableSet> testAssertThatIterableIsNotEmpty() { 22 | return ImmutableSet.of( 23 | assertThat(ImmutableSet.of(1)).isNotEmpty(), assertThat(ImmutableSet.of(2)).isNotEmpty()); 24 | } 25 | 26 | ImmutableSet> testAssertThatIterableSize() { 27 | return ImmutableSet.of( 28 | assertThat(ImmutableSet.of(1)).size(), assertThat(ImmutableSet.of(2)).size()); 29 | } 30 | 31 | AbstractAssert testAssertThatIterableHasOneElementEqualTo() { 32 | return assertThat(ImmutableSet.of(new Object())).containsExactly("foo"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIteratorRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJIteratorRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractAssert testAssertThatHasNext() { 11 | return assertThat(ImmutableSet.of().iterator().hasNext()).isTrue(); 12 | } 13 | 14 | AbstractAssert testAssertThatIsExhausted() { 15 | return assertThat(ImmutableSet.of().iterator().hasNext()).isFalse(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIteratorRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.assertj.core.api.AbstractAssert; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class AssertJIteratorRulesTest implements RefasterRuleCollectionTestCase { 10 | AbstractAssert testAssertThatHasNext() { 11 | return assertThat(ImmutableSet.of().iterator()).hasNext(); 12 | } 13 | 14 | AbstractAssert testAssertThatIsExhausted() { 15 | return assertThat(ImmutableSet.of().iterator()).isExhausted(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractLongAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJLongRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractLongAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat(0L).isCloseTo(1, offset(0L)), assertThat(0L).isCloseTo(1, withPercentage(0))); 20 | } 21 | 22 | ImmutableSet> testAbstractLongAssertIsNotEqualTo() { 23 | return ImmutableSet.of( 24 | assertThat(0L).isNotCloseTo(1, offset(0L)), 25 | assertThat(0L).isNotCloseTo(1, withPercentage(0))); 26 | } 27 | 28 | AbstractLongAssert testAbstractLongAssertIsZero() { 29 | return assertThat(0L).isZero(); 30 | } 31 | 32 | AbstractLongAssert testAbstractLongAssertIsNotZero() { 33 | return assertThat(0L).isNotZero(); 34 | } 35 | 36 | AbstractLongAssert testAbstractLongAssertIsOne() { 37 | return assertThat(0L).isOne(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractLongAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJLongRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractLongAssertIsEqualTo() { 18 | return ImmutableSet.of(assertThat(0L).isEqualTo(1), assertThat(0L).isEqualTo(1)); 19 | } 20 | 21 | ImmutableSet> testAbstractLongAssertIsNotEqualTo() { 22 | return ImmutableSet.of(assertThat(0L).isNotEqualTo(1), assertThat(0L).isNotEqualTo(1)); 23 | } 24 | 25 | AbstractLongAssert testAbstractLongAssertIsZero() { 26 | return assertThat(0L).isEqualTo(0); 27 | } 28 | 29 | AbstractLongAssert testAbstractLongAssertIsNotZero() { 30 | return assertThat(0L).isNotEqualTo(0); 31 | } 32 | 33 | AbstractLongAssert testAbstractLongAssertIsOne() { 34 | return assertThat(0L).isEqualTo(1); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.assertj.core.api.AbstractAssert; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class AssertJObjectRulesTest implements RefasterRuleCollectionTestCase { 9 | AbstractAssert testAssertThatIsInstanceOf() { 10 | return assertThat("foo" instanceof String).isTrue(); 11 | } 12 | 13 | AbstractAssert testAssertThatIsNotInstanceOf() { 14 | return assertThat("foo" instanceof String).isFalse(); 15 | } 16 | 17 | AbstractAssert testAssertThatIsIsEqualTo() { 18 | return assertThat("foo".equals("bar")).isTrue(); 19 | } 20 | 21 | AbstractAssert testAssertThatIsIsNotEqualTo() { 22 | return assertThat("foo".equals("bar")).isFalse(); 23 | } 24 | 25 | AbstractAssert testAssertThatHasToString() { 26 | return assertThat(new Object().toString()).isEqualTo("foo"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.assertj.core.api.AbstractAssert; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class AssertJObjectRulesTest implements RefasterRuleCollectionTestCase { 9 | AbstractAssert testAssertThatIsInstanceOf() { 10 | return assertThat("foo").isInstanceOf(String.class); 11 | } 12 | 13 | AbstractAssert testAssertThatIsNotInstanceOf() { 14 | return assertThat("foo").isNotInstanceOf(String.class); 15 | } 16 | 17 | AbstractAssert testAssertThatIsIsEqualTo() { 18 | return assertThat("foo").isEqualTo("bar"); 19 | } 20 | 21 | AbstractAssert testAssertThatIsIsNotEqualTo() { 22 | return assertThat("foo").isNotEqualTo("bar"); 23 | } 24 | 25 | AbstractAssert testAssertThatHasToString() { 26 | return assertThat(new Object()).hasToString("foo"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import java.util.Optional; 7 | import org.assertj.core.api.AbstractAssert; 8 | import org.assertj.core.api.OptionalAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJOptionalRulesTest implements RefasterRuleCollectionTestCase { 12 | AbstractAssert testAssertThatOptional() { 13 | return assertThat(Optional.of(new Object())).get(); 14 | } 15 | 16 | ImmutableSet> testAbstractOptionalAssertIsPresent() { 17 | return ImmutableSet.of( 18 | assertThat(Optional.of(1)).isPresent(), assertThat(Optional.of(2)).isPresent()); 19 | } 20 | 21 | ImmutableSet> testAssertThatOptionalIsPresent() { 22 | return ImmutableSet.of( 23 | assertThat(Optional.of(1)).isPresent(), assertThat(Optional.of(2)).isPresent()); 24 | } 25 | 26 | ImmutableSet> testAbstractOptionalAssertIsEmpty() { 27 | return ImmutableSet.of( 28 | assertThat(Optional.of(1)).isEmpty(), assertThat(Optional.of(2)).isEmpty()); 29 | } 30 | 31 | ImmutableSet> testAssertThatOptionalIsEmpty() { 32 | return ImmutableSet.of( 33 | assertThat(Optional.of(1)).isEmpty(), assertThat(Optional.of(2)).isEmpty()); 34 | } 35 | 36 | ImmutableSet> testAbstractOptionalAssertHasValue() { 37 | return ImmutableSet.of( 38 | assertThat(Optional.of(1)).hasValue(1), 39 | assertThat(Optional.of(2)).hasValue(2), 40 | assertThat(Optional.of(3)).hasValue(3), 41 | assertThat(Optional.of(4)).hasValue(4)); 42 | } 43 | 44 | ImmutableSet> testAbstractOptionalAssertContainsSame() { 45 | return ImmutableSet.of( 46 | assertThat(Optional.of(1)).containsSame(1), assertThat(Optional.of(2)).containsSame(2)); 47 | } 48 | 49 | AbstractAssert testAssertThatOptionalHasValueMatching() { 50 | return assertThat(Optional.of("foo")).get().matches(String::isEmpty); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractShortAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJShortRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractShortAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat((short) 0).isCloseTo((short) 1, offset((short) 0)), 20 | assertThat((short) 0).isCloseTo((short) 1, withPercentage(0))); 21 | } 22 | 23 | ImmutableSet> testAbstractShortAssertIsNotEqualTo() { 24 | return ImmutableSet.of( 25 | assertThat((short) 0).isNotCloseTo((short) 1, offset((short) 0)), 26 | assertThat((short) 0).isNotCloseTo((short) 1, withPercentage(0))); 27 | } 28 | 29 | AbstractShortAssert testAbstractShortAssertIsZero() { 30 | return assertThat((short) 0).isZero(); 31 | } 32 | 33 | AbstractShortAssert testAbstractShortAssertIsNotZero() { 34 | return assertThat((short) 0).isNotZero(); 35 | } 36 | 37 | AbstractShortAssert testAbstractShortAssertIsOne() { 38 | return assertThat((short) 0).isOne(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.assertj.core.data.Offset.offset; 5 | import static org.assertj.core.data.Percentage.withPercentage; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.assertj.core.api.AbstractShortAssert; 9 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 10 | 11 | final class AssertJShortRulesTest implements RefasterRuleCollectionTestCase { 12 | @Override 13 | public ImmutableSet elidedTypesAndStaticImports() { 14 | return ImmutableSet.of(offset(0), withPercentage(0)); 15 | } 16 | 17 | ImmutableSet> testAbstractShortAssertIsEqualTo() { 18 | return ImmutableSet.of( 19 | assertThat((short) 0).isEqualTo((short) 1), assertThat((short) 0).isEqualTo((short) 1)); 20 | } 21 | 22 | ImmutableSet> testAbstractShortAssertIsNotEqualTo() { 23 | return ImmutableSet.of( 24 | assertThat((short) 0).isNotEqualTo((short) 1), 25 | assertThat((short) 0).isNotEqualTo((short) 1)); 26 | } 27 | 28 | AbstractShortAssert testAbstractShortAssertIsZero() { 29 | return assertThat((short) 0).isEqualTo((short) 0); 30 | } 31 | 32 | AbstractShortAssert testAbstractShortAssertIsNotZero() { 33 | return assertThat((short) 0).isNotEqualTo((short) 0); 34 | } 35 | 36 | AbstractShortAssert testAbstractShortAssertIsOne() { 37 | return assertThat((short) 0).isEqualTo((short) 1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import java.io.IOException; 7 | import java.nio.charset.Charset; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import org.assertj.core.api.AbstractAssert; 11 | import org.assertj.core.api.AbstractStringAssert; 12 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 13 | 14 | final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { 15 | @Override 16 | public ImmutableSet elidedTypesAndStaticImports() { 17 | return ImmutableSet.of(Files.class); 18 | } 19 | 20 | void testAbstractStringAssertStringIsEmpty() { 21 | assertThat("foo").isEqualTo(""); 22 | } 23 | 24 | AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { 25 | return assertThat("foo").isNotEqualTo(""); 26 | } 27 | 28 | AbstractAssert testAssertThatStringContains() { 29 | return assertThat("foo".contains("bar")).isTrue(); 30 | } 31 | 32 | AbstractAssert testAssertThatStringDoesNotContain() { 33 | return assertThat("foo".contains("bar")).isFalse(); 34 | } 35 | 36 | AbstractAssert testAssertThatMatches() { 37 | return assertThat("foo".matches(".*")).isTrue(); 38 | } 39 | 40 | AbstractAssert testAssertThatDoesNotMatch() { 41 | return assertThat("foo".matches(".*")).isFalse(); 42 | } 43 | 44 | AbstractStringAssert testAssertThatPathContent() throws IOException { 45 | return assertThat(Files.readString(Paths.get(""), Charset.defaultCharset())); 46 | } 47 | 48 | AbstractStringAssert testAssertThatPathContentUtf8() throws IOException { 49 | return assertThat(Files.readString(Paths.get(""))); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.nio.charset.StandardCharsets.UTF_8; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | 6 | import com.google.common.collect.ImmutableSet; 7 | import java.io.IOException; 8 | import java.nio.charset.Charset; 9 | import java.nio.file.Files; 10 | import java.nio.file.Paths; 11 | import org.assertj.core.api.AbstractAssert; 12 | import org.assertj.core.api.AbstractStringAssert; 13 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 14 | 15 | final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { 16 | @Override 17 | public ImmutableSet elidedTypesAndStaticImports() { 18 | return ImmutableSet.of(Files.class); 19 | } 20 | 21 | void testAbstractStringAssertStringIsEmpty() { 22 | assertThat("foo").isEmpty(); 23 | } 24 | 25 | AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { 26 | return assertThat("foo").isNotEmpty(); 27 | } 28 | 29 | AbstractAssert testAssertThatStringContains() { 30 | return assertThat("foo").contains("bar"); 31 | } 32 | 33 | AbstractAssert testAssertThatStringDoesNotContain() { 34 | return assertThat("foo").doesNotContain("bar"); 35 | } 36 | 37 | AbstractAssert testAssertThatMatches() { 38 | return assertThat("foo").matches(".*"); 39 | } 40 | 41 | AbstractAssert testAssertThatDoesNotMatch() { 42 | return assertThat("foo").doesNotMatch(".*"); 43 | } 44 | 45 | AbstractStringAssert testAssertThatPathContent() throws IOException { 46 | return assertThat(Paths.get("")).content(Charset.defaultCharset()); 47 | } 48 | 49 | AbstractStringAssert testAssertThatPathContentUtf8() throws IOException { 50 | return assertThat(Paths.get("")).content(UTF_8); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.errorprone.BugCheckerRefactoringTestHelper; 5 | import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; 6 | import com.google.errorprone.bugpatterns.BugChecker; 7 | import com.sun.tools.javac.util.Constants; 8 | import com.sun.tools.javac.util.Convert; 9 | import javax.lang.model.element.Name; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(Constants.class, Convert.class, FixChoosers.class); 16 | } 17 | 18 | ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { 19 | return ImmutableSet.of( 20 | BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) 21 | .setFixChooser(FixChoosers.FIRST), 22 | BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) 23 | .setImportOrder("static-first")); 24 | } 25 | 26 | BugCheckerRefactoringTestHelper 27 | testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() { 28 | return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) 29 | .addInputLines("A.java", "class A {}") 30 | .addOutputLines("A.java", "class A {}"); 31 | } 32 | 33 | ImmutableSet testConstantsFormat() { 34 | return ImmutableSet.of(Constants.format("foo"), String.format("\"%s\"", Convert.quote("bar"))); 35 | } 36 | 37 | ImmutableSet testNameContentEquals() { 38 | return ImmutableSet.of( 39 | ((Name) null).toString().equals("foo".subSequence(0, 1).toString()), 40 | ((com.sun.tools.javac.util.Name) null).toString().equals("bar")); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.errorprone.BugCheckerRefactoringTestHelper; 5 | import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; 6 | import com.google.errorprone.bugpatterns.BugChecker; 7 | import com.sun.tools.javac.util.Constants; 8 | import com.sun.tools.javac.util.Convert; 9 | import javax.lang.model.element.Name; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | import tech.picnic.errorprone.utils.SourceCode; 12 | 13 | final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(Constants.class, Convert.class, FixChoosers.class); 17 | } 18 | 19 | ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { 20 | return ImmutableSet.of( 21 | BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()), 22 | BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())); 23 | } 24 | 25 | BugCheckerRefactoringTestHelper 26 | testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() { 27 | return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) 28 | .addInputLines("A.java", "class A {}") 29 | .expectUnchanged(); 30 | } 31 | 32 | ImmutableSet testConstantsFormat() { 33 | return ImmutableSet.of( 34 | SourceCode.toStringConstantExpression("foo", /* REPLACEME */ null), 35 | SourceCode.toStringConstantExpression("bar", /* REPLACEME */ null)); 36 | } 37 | 38 | ImmutableSet testNameContentEquals() { 39 | return ImmutableSet.of( 40 | ((Name) null).contentEquals("foo".subSequence(0, 1)), 41 | ((com.sun.tools.javac.util.Name) null).contentEquals("bar")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CharSequenceRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 5 | 6 | final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase { 7 | ImmutableSet testCharSequenceIsEmpty() { 8 | return ImmutableSet.of( 9 | new StringBuilder("foo").length() == 0, 10 | new StringBuilder("bar").length() <= 0, 11 | new StringBuilder("baz").length() < 1, 12 | new StringBuilder("qux").length() != 0, 13 | new StringBuilder("quux").length() > 0, 14 | new StringBuilder("corge").length() >= 1); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CharSequenceRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 5 | 6 | final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase { 7 | ImmutableSet testCharSequenceIsEmpty() { 8 | return ImmutableSet.of( 9 | new StringBuilder("foo").isEmpty(), 10 | new StringBuilder("bar").isEmpty(), 11 | new StringBuilder("baz").isEmpty(), 12 | !new StringBuilder("qux").isEmpty(), 13 | !new StringBuilder("quux").isEmpty(), 14 | !new StringBuilder("corge").isEmpty()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.util.function.Function; 5 | import java.util.function.Predicate; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class ClassRulesTest implements RefasterRuleCollectionTestCase { 9 | boolean testClassIsInstance() { 10 | return CharSequence.class.isAssignableFrom("foo".getClass()); 11 | } 12 | 13 | ImmutableSet testInstanceof() { 14 | Class clazz = CharSequence.class; 15 | return ImmutableSet.of(CharSequence.class.isInstance("foo"), clazz.isInstance("bar")); 16 | } 17 | 18 | Predicate testClassLiteralIsInstancePredicate() { 19 | return s -> s instanceof CharSequence; 20 | } 21 | 22 | Predicate testClassReferenceIsInstancePredicate() { 23 | Class clazz = CharSequence.class; 24 | return s -> clazz.isInstance(s); 25 | } 26 | 27 | Function testClassReferenceCast() { 28 | return i -> Integer.class.cast(i); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.util.function.Function; 5 | import java.util.function.Predicate; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class ClassRulesTest implements RefasterRuleCollectionTestCase { 9 | boolean testClassIsInstance() { 10 | return CharSequence.class.isInstance("foo"); 11 | } 12 | 13 | ImmutableSet testInstanceof() { 14 | Class clazz = CharSequence.class; 15 | return ImmutableSet.of("foo" instanceof CharSequence, clazz.isInstance("bar")); 16 | } 17 | 18 | Predicate testClassLiteralIsInstancePredicate() { 19 | return CharSequence.class::isInstance; 20 | } 21 | 22 | Predicate testClassReferenceIsInstancePredicate() { 23 | Class clazz = CharSequence.class; 24 | return clazz::isInstance; 25 | } 26 | 27 | Function testClassReferenceCast() { 28 | return Integer.class::cast; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/FileRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.net.URI; 7 | import java.nio.charset.StandardCharsets; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class FileRulesTest implements RefasterRuleCollectionTestCase { 14 | Path testPathOfUri() { 15 | return Paths.get(URI.create("foo")); 16 | } 17 | 18 | ImmutableSet testPathOfString() { 19 | return ImmutableSet.of(Paths.get("foo"), Paths.get("bar", "baz", "qux")); 20 | } 21 | 22 | Path testPathInstance() { 23 | return Path.of("foo").toFile().toPath(); 24 | } 25 | 26 | String testFilesReadStringWithCharset() throws IOException { 27 | return new String(Files.readAllBytes(Paths.get("foo")), StandardCharsets.ISO_8859_1); 28 | } 29 | 30 | String testFilesReadString() throws IOException { 31 | return Files.readString(Paths.get("foo"), StandardCharsets.UTF_8); 32 | } 33 | 34 | ImmutableSet testFilesCreateTempFileToFile() throws IOException { 35 | return ImmutableSet.of( 36 | File.createTempFile("foo", "bar"), File.createTempFile("baz", "qux", null)); 37 | } 38 | 39 | File testFilesCreateTempFileInCustomDirectoryToFile() throws IOException { 40 | return File.createTempFile("foo", "bar", new File("baz")); 41 | } 42 | 43 | ImmutableSet testPathToFileMkDirsFilesExists() { 44 | return ImmutableSet.of( 45 | Files.exists(Path.of("foo")) || Path.of("foo").toFile().mkdirs(), 46 | !Files.exists(Path.of("bar")) && !Path.of("bar").toFile().mkdirs()); 47 | } 48 | 49 | ImmutableSet testFileMkDirsFileExists() { 50 | return ImmutableSet.of( 51 | new File("foo").exists() || new File("foo").mkdirs(), 52 | !new File("bar").exists() && !new File("bar").mkdirs()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/FileRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.net.URI; 7 | import java.nio.charset.StandardCharsets; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class FileRulesTest implements RefasterRuleCollectionTestCase { 14 | Path testPathOfUri() { 15 | return Path.of(URI.create("foo")); 16 | } 17 | 18 | ImmutableSet testPathOfString() { 19 | return ImmutableSet.of(Path.of("foo"), Path.of("bar", "baz", "qux")); 20 | } 21 | 22 | Path testPathInstance() { 23 | return Path.of("foo"); 24 | } 25 | 26 | String testFilesReadStringWithCharset() throws IOException { 27 | return Files.readString(Paths.get("foo"), StandardCharsets.ISO_8859_1); 28 | } 29 | 30 | String testFilesReadString() throws IOException { 31 | return Files.readString(Paths.get("foo")); 32 | } 33 | 34 | ImmutableSet testFilesCreateTempFileToFile() throws IOException { 35 | return ImmutableSet.of( 36 | Files.createTempFile("foo", "bar").toFile(), Files.createTempFile("baz", "qux").toFile()); 37 | } 38 | 39 | File testFilesCreateTempFileInCustomDirectoryToFile() throws IOException { 40 | return Files.createTempFile(new File("baz").toPath(), "foo", "bar").toFile(); 41 | } 42 | 43 | ImmutableSet testPathToFileMkDirsFilesExists() { 44 | return ImmutableSet.of( 45 | Path.of("foo").toFile().mkdirs() || Files.exists(Path.of("foo")), 46 | !Path.of("bar").toFile().mkdirs() && !Files.exists(Path.of("bar"))); 47 | } 48 | 49 | ImmutableSet testFileMkDirsFileExists() { 50 | return ImmutableSet.of( 51 | new File("foo").mkdirs() || new File("foo").exists(), 52 | !new File("bar").mkdirs() && !new File("bar").exists()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | import com.google.common.collect.ImmutableMultiset; 7 | import com.google.common.collect.ImmutableSet; 8 | import com.google.common.collect.Streams; 9 | import java.util.Arrays; 10 | import java.util.stream.Stream; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class ImmutableMultisetRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(Arrays.class, Streams.class); 17 | } 18 | 19 | ImmutableMultiset.Builder testImmutableMultisetBuilder() { 20 | return new ImmutableMultiset.Builder<>(); 21 | } 22 | 23 | ImmutableMultiset> testEmptyImmutableMultiset() { 24 | return ImmutableMultiset.of( 25 | ImmutableMultiset.builder().build(), 26 | Stream.empty().collect(toImmutableMultiset())); 27 | } 28 | 29 | @SuppressWarnings("unchecked") 30 | ImmutableMultiset> testIterableToImmutableMultiset() { 31 | return ImmutableMultiset.of( 32 | ImmutableList.of(1).stream().collect(toImmutableMultiset()), 33 | Streams.stream(ImmutableList.of(2)::iterator).collect(toImmutableMultiset()), 34 | Streams.stream(ImmutableList.of(3).iterator()).collect(toImmutableMultiset()), 35 | ImmutableMultiset.builder().addAll(ImmutableMultiset.of(4)).build(), 36 | ImmutableMultiset.builder().addAll(ImmutableMultiset.of(5)::iterator).build(), 37 | ImmutableMultiset.builder().addAll(ImmutableMultiset.of(6).iterator()).build(), 38 | ImmutableMultiset.builder().add(new Integer[] {7}).build(), 39 | Arrays.stream(new Integer[] {8}).collect(toImmutableMultiset())); 40 | } 41 | 42 | ImmutableMultiset testStreamToImmutableMultiset() { 43 | return ImmutableMultiset.copyOf(Stream.of(1).iterator()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | import com.google.common.collect.ImmutableMultiset; 7 | import com.google.common.collect.ImmutableSet; 8 | import com.google.common.collect.Streams; 9 | import java.util.Arrays; 10 | import java.util.stream.Stream; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class ImmutableMultisetRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(Arrays.class, Streams.class); 17 | } 18 | 19 | ImmutableMultiset.Builder testImmutableMultisetBuilder() { 20 | return ImmutableMultiset.builder(); 21 | } 22 | 23 | ImmutableMultiset> testEmptyImmutableMultiset() { 24 | return ImmutableMultiset.of(ImmutableMultiset.of(), ImmutableMultiset.of()); 25 | } 26 | 27 | @SuppressWarnings("unchecked") 28 | ImmutableMultiset> testIterableToImmutableMultiset() { 29 | return ImmutableMultiset.of( 30 | ImmutableMultiset.copyOf(ImmutableList.of(1)), 31 | ImmutableMultiset.copyOf(ImmutableList.of(2)::iterator), 32 | ImmutableMultiset.copyOf(ImmutableList.of(3).iterator()), 33 | ImmutableMultiset.copyOf(ImmutableMultiset.of(4)), 34 | ImmutableMultiset.copyOf(ImmutableMultiset.of(5)::iterator), 35 | ImmutableMultiset.copyOf(ImmutableMultiset.of(6).iterator()), 36 | ImmutableMultiset.copyOf(new Integer[] {7}), 37 | ImmutableMultiset.copyOf(new Integer[] {8})); 38 | } 39 | 40 | ImmutableMultiset testStreamToImmutableMultiset() { 41 | return Stream.of(1).collect(toImmutableMultiset()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableTableRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.collect.ImmutableTable.toImmutableTable; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import com.google.common.collect.ImmutableTable; 7 | import com.google.common.collect.Table; 8 | import com.google.common.collect.Tables; 9 | import java.util.stream.Stream; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class ImmutableTableRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(Table.class); 16 | } 17 | 18 | ImmutableTable.Builder testImmutableTableBuilder() { 19 | return new ImmutableTable.Builder<>(); 20 | } 21 | 22 | ImmutableTable testImmutableTableBuilderBuildOrThrow() { 23 | return ImmutableTable.builder().build(); 24 | } 25 | 26 | ImmutableSet> testCellToImmutableTable() { 27 | return ImmutableSet.of( 28 | ImmutableTable.builder() 29 | .put(Tables.immutableCell("foo", 1, "bar")) 30 | .buildOrThrow(), 31 | Stream.of(Tables.immutableCell("baz", 2, "qux")) 32 | .collect( 33 | toImmutableTable( 34 | Table.Cell::getRowKey, Table.Cell::getColumnKey, Table.Cell::getValue))); 35 | } 36 | 37 | ImmutableTable testStreamOfCellsToImmutableTable() { 38 | return Stream.of(1, 2, 3) 39 | .map(n -> Tables.immutableCell(n, n.toString(), n * 2)) 40 | .collect( 41 | toImmutableTable( 42 | Table.Cell::getRowKey, Table.Cell::getColumnKey, Table.Cell::getValue)); 43 | } 44 | 45 | ImmutableTable testImmutableTableOf() { 46 | return ImmutableTable.builder().buildOrThrow(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableTableRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.collect.ImmutableTable.toImmutableTable; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import com.google.common.collect.ImmutableTable; 7 | import com.google.common.collect.Table; 8 | import com.google.common.collect.Tables; 9 | import java.util.stream.Stream; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class ImmutableTableRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(Table.class); 16 | } 17 | 18 | ImmutableTable.Builder testImmutableTableBuilder() { 19 | return ImmutableTable.builder(); 20 | } 21 | 22 | ImmutableTable testImmutableTableBuilderBuildOrThrow() { 23 | return ImmutableTable.builder().buildOrThrow(); 24 | } 25 | 26 | ImmutableSet> testCellToImmutableTable() { 27 | return ImmutableSet.of( 28 | ImmutableTable.of( 29 | Tables.immutableCell("foo", 1, "bar").getRowKey(), 30 | Tables.immutableCell("foo", 1, "bar").getColumnKey(), 31 | Tables.immutableCell("foo", 1, "bar").getValue()), 32 | ImmutableTable.of( 33 | Tables.immutableCell("baz", 2, "qux").getRowKey(), 34 | Tables.immutableCell("baz", 2, "qux").getColumnKey(), 35 | Tables.immutableCell("baz", 2, "qux").getValue())); 36 | } 37 | 38 | ImmutableTable testStreamOfCellsToImmutableTable() { 39 | return Stream.of(1, 2, 3).collect(toImmutableTable(n -> n, n -> n.toString(), n -> n * 2)); 40 | } 41 | 42 | ImmutableTable testImmutableTableOf() { 43 | return ImmutableTable.of(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/InputStreamRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.io.ByteStreams; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.IOException; 8 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 9 | 10 | final class InputStreamRulesTest implements RefasterRuleCollectionTestCase { 11 | @Override 12 | public ImmutableSet elidedTypesAndStaticImports() { 13 | return ImmutableSet.of(ByteStreams.class); 14 | } 15 | 16 | long testInputStreamTransferTo() throws IOException { 17 | return ByteStreams.copy(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream()); 18 | } 19 | 20 | byte[] testInputStreamReadAllBytes() throws IOException { 21 | return ByteStreams.toByteArray(new ByteArrayInputStream(new byte[0])); 22 | } 23 | 24 | byte[] testInputStreamReadNBytes() throws IOException { 25 | return ByteStreams.limit(new ByteArrayInputStream(new byte[0]), 0).readAllBytes(); 26 | } 27 | 28 | void testInputStreamSkipNBytes() throws IOException { 29 | ByteStreams.skipFully(new ByteArrayInputStream(new byte[0]), 0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/InputStreamRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.io.ByteStreams; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.IOException; 8 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 9 | 10 | final class InputStreamRulesTest implements RefasterRuleCollectionTestCase { 11 | @Override 12 | public ImmutableSet elidedTypesAndStaticImports() { 13 | return ImmutableSet.of(ByteStreams.class); 14 | } 15 | 16 | long testInputStreamTransferTo() throws IOException { 17 | return new ByteArrayInputStream(new byte[0]).transferTo(new ByteArrayOutputStream()); 18 | } 19 | 20 | byte[] testInputStreamReadAllBytes() throws IOException { 21 | return new ByteArrayInputStream(new byte[0]).readAllBytes(); 22 | } 23 | 24 | byte[] testInputStreamReadNBytes() throws IOException { 25 | return new ByteArrayInputStream(new byte[0]).readNBytes(0); 26 | } 27 | 28 | void testInputStreamSkipNBytes() throws IOException { 29 | new ByteArrayInputStream(new byte[0]).skipNBytes(0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import org.junit.jupiter.params.provider.Arguments; 5 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 6 | 7 | final class JUnitRulesTest implements RefasterRuleCollectionTestCase { 8 | ImmutableSet testArgumentsEnumeration() { 9 | return ImmutableSet.of( 10 | Arguments.of("foo"), Arguments.of(1, "foo", 2, "bar"), Arguments.of(new Object())); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.junit.jupiter.params.provider.Arguments.arguments; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import org.junit.jupiter.params.provider.Arguments; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class JUnitRulesTest implements RefasterRuleCollectionTestCase { 10 | ImmutableSet testArgumentsEnumeration() { 11 | return ImmutableSet.of( 12 | arguments("foo"), arguments(1, "foo", 2, "bar"), arguments(new Object())); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JacksonRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.node.NullNode; 5 | import com.google.common.collect.ImmutableSet; 6 | import java.util.Optional; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class JacksonRulesTest implements RefasterRuleCollectionTestCase { 10 | ImmutableSet> testJsonNodeOptionalInt() { 11 | return ImmutableSet.of( 12 | NullNode.getInstance().get(1).asOptional(), 13 | NullNode.getInstance().path(2).asOptional(), 14 | Optional.of(NullNode.getInstance().get(3)), 15 | Optional.ofNullable(NullNode.getInstance().get(4))); 16 | } 17 | 18 | ImmutableSet> testJsonNodeOptionalString() { 19 | return ImmutableSet.of( 20 | NullNode.getInstance().get("foo").asOptional(), 21 | NullNode.getInstance().path("bar").asOptional(), 22 | Optional.of(NullNode.getInstance().get("baz")), 23 | Optional.ofNullable(NullNode.getInstance().get("qux"))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JacksonRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.node.NullNode; 5 | import com.google.common.collect.ImmutableSet; 6 | import java.util.Optional; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class JacksonRulesTest implements RefasterRuleCollectionTestCase { 10 | ImmutableSet> testJsonNodeOptionalInt() { 11 | return ImmutableSet.of( 12 | NullNode.getInstance().optional(1), 13 | NullNode.getInstance().optional(2), 14 | NullNode.getInstance().optional(3), 15 | NullNode.getInstance().optional(4)); 16 | } 17 | 18 | ImmutableSet> testJsonNodeOptionalString() { 19 | return ImmutableSet.of( 20 | NullNode.getInstance().optional("foo"), 21 | NullNode.getInstance().optional("bar"), 22 | NullNode.getInstance().optional("baz"), 23 | NullNode.getInstance().optional("qux")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.collect.Maps; 5 | import java.util.AbstractMap; 6 | import java.util.Comparator; 7 | import java.util.Map; 8 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 9 | 10 | final class MapEntryRulesTest implements RefasterRuleCollectionTestCase { 11 | @Override 12 | public ImmutableSet elidedTypesAndStaticImports() { 13 | return ImmutableSet.of(AbstractMap.class, Maps.class); 14 | } 15 | 16 | ImmutableSet> testMapEntry() { 17 | return ImmutableSet.of( 18 | Maps.immutableEntry("foo", 1), new AbstractMap.SimpleImmutableEntry<>("bar", 2)); 19 | } 20 | 21 | ImmutableSet>> testMapEntryComparingByKey() { 22 | return ImmutableSet.of( 23 | Comparator.comparing(Map.Entry::getKey), 24 | Map.Entry.comparingByKey(Comparator.naturalOrder())); 25 | } 26 | 27 | Comparator> testMapEntryComparingByKeyWithCustomComparator() { 28 | return Comparator.comparing(Map.Entry::getKey, Comparator.comparingInt(i -> i * 2)); 29 | } 30 | 31 | ImmutableSet>> testMapEntryComparingByValue() { 32 | return ImmutableSet.of( 33 | Comparator.comparing(Map.Entry::getValue), 34 | Map.Entry.comparingByValue(Comparator.naturalOrder())); 35 | } 36 | 37 | Comparator> testMapEntryComparingByValueWithCustomComparator() { 38 | return Comparator.comparing(Map.Entry::getValue, Comparator.comparingInt(String::length)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.util.Map.Entry.comparingByKey; 4 | import static java.util.Map.Entry.comparingByValue; 5 | 6 | import com.google.common.collect.ImmutableSet; 7 | import com.google.common.collect.Maps; 8 | import java.util.AbstractMap; 9 | import java.util.Comparator; 10 | import java.util.Map; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class MapEntryRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(AbstractMap.class, Maps.class); 17 | } 18 | 19 | ImmutableSet> testMapEntry() { 20 | return ImmutableSet.of(Map.entry("foo", 1), Map.entry("bar", 2)); 21 | } 22 | 23 | ImmutableSet>> testMapEntryComparingByKey() { 24 | return ImmutableSet.of(comparingByKey(), comparingByKey()); 25 | } 26 | 27 | Comparator> testMapEntryComparingByKeyWithCustomComparator() { 28 | return comparingByKey(Comparator.comparingInt(i -> i * 2)); 29 | } 30 | 31 | ImmutableSet>> testMapEntryComparingByValue() { 32 | return ImmutableSet.of(comparingByValue(), comparingByValue()); 33 | } 34 | 35 | Comparator> testMapEntryComparingByValueWithCustomComparator() { 36 | return comparingByValue(Comparator.comparingInt(String::length)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.util.Objects.requireNonNullElse; 4 | 5 | import com.google.common.collect.ImmutableMap; 6 | import com.google.common.collect.ImmutableSet; 7 | import java.math.RoundingMode; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import java.util.stream.Stream; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class MapRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); 17 | } 18 | 19 | Map testCreateEnumMap() { 20 | return new HashMap<>(); 21 | } 22 | 23 | String testMapGetOrNull() { 24 | return ImmutableMap.of(1, "foo").getOrDefault("bar", null); 25 | } 26 | 27 | String testMapGetOrDefault() { 28 | return requireNonNullElse(ImmutableMap.of(1, "foo").get("bar"), "baz"); 29 | } 30 | 31 | ImmutableSet testMapIsEmpty() { 32 | return ImmutableSet.of( 33 | ImmutableMap.of("foo", 1).keySet().isEmpty(), 34 | ImmutableMap.of("bar", 2).values().isEmpty(), 35 | ImmutableMap.of("baz", 3).entrySet().isEmpty()); 36 | } 37 | 38 | ImmutableSet testMapSize() { 39 | return ImmutableSet.of( 40 | ImmutableMap.of("foo", 1).keySet().size(), 41 | ImmutableMap.of("bar", 2).values().size(), 42 | ImmutableMap.of("baz", 3).entrySet().size()); 43 | } 44 | 45 | boolean testMapContainsKey() { 46 | return ImmutableMap.of("foo", 1).keySet().contains("bar"); 47 | } 48 | 49 | boolean testMapContainsValue() { 50 | return ImmutableMap.of("foo", 1).values().contains(2); 51 | } 52 | 53 | Stream testMapKeyStream() { 54 | return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getKey); 55 | } 56 | 57 | Stream testMapValueStream() { 58 | return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.util.Objects.requireNonNullElse; 4 | 5 | import com.google.common.collect.ImmutableMap; 6 | import com.google.common.collect.ImmutableSet; 7 | import java.math.RoundingMode; 8 | import java.util.EnumMap; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | import java.util.stream.Stream; 12 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 13 | 14 | final class MapRulesTest implements RefasterRuleCollectionTestCase { 15 | @Override 16 | public ImmutableSet elidedTypesAndStaticImports() { 17 | return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); 18 | } 19 | 20 | Map testCreateEnumMap() { 21 | return new EnumMap<>(RoundingMode.class); 22 | } 23 | 24 | String testMapGetOrNull() { 25 | return ImmutableMap.of(1, "foo").get("bar"); 26 | } 27 | 28 | String testMapGetOrDefault() { 29 | return ImmutableMap.of(1, "foo").getOrDefault("bar", "baz"); 30 | } 31 | 32 | ImmutableSet testMapIsEmpty() { 33 | return ImmutableSet.of( 34 | ImmutableMap.of("foo", 1).isEmpty(), 35 | ImmutableMap.of("bar", 2).isEmpty(), 36 | ImmutableMap.of("baz", 3).isEmpty()); 37 | } 38 | 39 | ImmutableSet testMapSize() { 40 | return ImmutableSet.of( 41 | ImmutableMap.of("foo", 1).size(), 42 | ImmutableMap.of("bar", 2).size(), 43 | ImmutableMap.of("baz", 3).size()); 44 | } 45 | 46 | boolean testMapContainsKey() { 47 | return ImmutableMap.of("foo", 1).containsKey("bar"); 48 | } 49 | 50 | boolean testMapContainsValue() { 51 | return ImmutableMap.of("foo", 1).containsValue(2); 52 | } 53 | 54 | Stream testMapKeyStream() { 55 | return ImmutableMap.of("foo", 1).keySet().stream(); 56 | } 57 | 58 | Stream testMapValueStream() { 59 | return ImmutableMap.of("foo", 1).values().stream(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MicrometerRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.common.collect.ImmutableSet; 5 | import io.micrometer.core.instrument.Tag; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class MicrometerRulesTest implements RefasterRuleCollectionTestCase { 9 | @Override 10 | public ImmutableSet elidedTypesAndStaticImports() { 11 | return ImmutableSet.of(ImmutableList.class); 12 | } 13 | 14 | ImmutableSet> testTagsOf1() { 15 | return ImmutableSet.of( 16 | ImmutableSet.of(Tag.of("foo", "v1")), ImmutableList.of(Tag.of("bar", "v2"))); 17 | } 18 | 19 | ImmutableSet> testTagsOf2() { 20 | return ImmutableSet.of( 21 | ImmutableSet.of(Tag.of("foo", "v1"), Tag.of("bar", "v2")), 22 | ImmutableList.of(Tag.of("baz", "v3"), Tag.of("qux", "v4"))); 23 | } 24 | 25 | ImmutableSet> testTagsOf3() { 26 | return ImmutableSet.of( 27 | ImmutableSet.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3")), 28 | ImmutableList.of(Tag.of("qux", "v4"), Tag.of("quux", "v5"), Tag.of("corge", "v6"))); 29 | } 30 | 31 | ImmutableSet> testTagsOf4() { 32 | return ImmutableSet.of( 33 | ImmutableSet.of( 34 | Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3"), Tag.of("qux", "v4")), 35 | ImmutableList.of( 36 | Tag.of("quux", "v5"), 37 | Tag.of("corge", "v6"), 38 | Tag.of("grault", "v7"), 39 | Tag.of("garply", "v8"))); 40 | } 41 | 42 | ImmutableSet> testTagsOf5() { 43 | return ImmutableSet.of( 44 | ImmutableSet.of( 45 | Tag.of("foo", "v1"), 46 | Tag.of("bar", "v2"), 47 | Tag.of("baz", "v3"), 48 | Tag.of("qux", "v4"), 49 | Tag.of("quux", "v5")), 50 | ImmutableList.of( 51 | Tag.of("corge", "v6"), 52 | Tag.of("grault", "v7"), 53 | Tag.of("garply", "v8"), 54 | Tag.of("waldo", "v9"), 55 | Tag.of("fred", "v10"))); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MicrometerRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.common.collect.ImmutableSet; 5 | import io.micrometer.core.instrument.Tag; 6 | import io.micrometer.core.instrument.Tags; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class MicrometerRulesTest implements RefasterRuleCollectionTestCase { 10 | @Override 11 | public ImmutableSet elidedTypesAndStaticImports() { 12 | return ImmutableSet.of(ImmutableList.class); 13 | } 14 | 15 | ImmutableSet> testTagsOf1() { 16 | return ImmutableSet.of(Tags.of(Tag.of("foo", "v1")), Tags.of(Tag.of("bar", "v2"))); 17 | } 18 | 19 | ImmutableSet> testTagsOf2() { 20 | return ImmutableSet.of( 21 | Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2")), 22 | Tags.of(Tag.of("baz", "v3"), Tag.of("qux", "v4"))); 23 | } 24 | 25 | ImmutableSet> testTagsOf3() { 26 | return ImmutableSet.of( 27 | Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3")), 28 | Tags.of(Tag.of("qux", "v4"), Tag.of("quux", "v5"), Tag.of("corge", "v6"))); 29 | } 30 | 31 | ImmutableSet> testTagsOf4() { 32 | return ImmutableSet.of( 33 | Tags.of(Tag.of("foo", "v1"), Tag.of("bar", "v2"), Tag.of("baz", "v3"), Tag.of("qux", "v4")), 34 | Tags.of( 35 | Tag.of("quux", "v5"), 36 | Tag.of("corge", "v6"), 37 | Tag.of("grault", "v7"), 38 | Tag.of("garply", "v8"))); 39 | } 40 | 41 | ImmutableSet> testTagsOf5() { 42 | return ImmutableSet.of( 43 | Tags.of( 44 | Tag.of("foo", "v1"), 45 | Tag.of("bar", "v2"), 46 | Tag.of("baz", "v3"), 47 | Tag.of("qux", "v4"), 48 | Tag.of("quux", "v5")), 49 | Tags.of( 50 | Tag.of("corge", "v6"), 51 | Tag.of("grault", "v7"), 52 | Tag.of("garply", "v8"), 53 | Tag.of("waldo", "v9"), 54 | Tag.of("fred", "v10"))); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.mockito.Mockito.mock; 4 | import static org.mockito.Mockito.times; 5 | import static org.mockito.Mockito.verify; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import org.mockito.invocation.InvocationOnMock; 9 | import org.mockito.verification.VerificationMode; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class MockitoRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(times(1)); 16 | } 17 | 18 | VerificationMode testNever() { 19 | return times(0); 20 | } 21 | 22 | Object testVerifyOnce() { 23 | return verify(mock(Object.class), times(1)); 24 | } 25 | 26 | Object testInvocationOnMockGetArguments() { 27 | return ((InvocationOnMock) null).getArguments()[0]; 28 | } 29 | 30 | ImmutableSet testInvocationOnMockGetArgumentsWithTypeParameter() { 31 | return ImmutableSet.of( 32 | ((InvocationOnMock) null).getArgument(0, Integer.class), 33 | (Double) ((InvocationOnMock) null).getArgument(1)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static org.mockito.Mockito.mock; 4 | import static org.mockito.Mockito.never; 5 | import static org.mockito.Mockito.times; 6 | import static org.mockito.Mockito.verify; 7 | 8 | import com.google.common.collect.ImmutableSet; 9 | import org.mockito.invocation.InvocationOnMock; 10 | import org.mockito.verification.VerificationMode; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class MockitoRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(times(1)); 17 | } 18 | 19 | VerificationMode testNever() { 20 | return never(); 21 | } 22 | 23 | Object testVerifyOnce() { 24 | return verify(mock(Object.class)); 25 | } 26 | 27 | Object testInvocationOnMockGetArguments() { 28 | return ((InvocationOnMock) null).getArgument(0); 29 | } 30 | 31 | ImmutableSet testInvocationOnMockGetArgumentsWithTypeParameter() { 32 | return ImmutableSet.of( 33 | ((InvocationOnMock) null).getArgument(0), 34 | ((InvocationOnMock) null).getArgument(1)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import com.google.common.collect.ImmutableSetMultimap; 5 | import com.google.common.collect.Multimap; 6 | import com.google.common.collect.Multimaps; 7 | import java.util.Collection; 8 | import java.util.Map; 9 | import java.util.Set; 10 | import java.util.stream.Stream; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class MultimapRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | public ImmutableSet elidedTypesAndStaticImports() { 16 | return ImmutableSet.of(Map.class, Multimaps.class); 17 | } 18 | 19 | Set testMultimapKeySet() { 20 | return ImmutableSetMultimap.of("foo", "bar").keySet(); 21 | } 22 | 23 | ImmutableSet testMultimapIsEmpty() { 24 | return ImmutableSet.of( 25 | ImmutableSetMultimap.of("foo", 1).isEmpty(), 26 | ImmutableSetMultimap.of("bar", 2).isEmpty(), 27 | ImmutableSetMultimap.of("baz", 3).isEmpty(), 28 | ImmutableSetMultimap.of("qux", 54).isEmpty()); 29 | } 30 | 31 | int testMultimapSize() { 32 | return ImmutableSetMultimap.of().size(); 33 | } 34 | 35 | ImmutableSet testMultimapContainsKey() { 36 | return ImmutableSet.of( 37 | ImmutableSetMultimap.of("foo", 1).containsKey("bar"), 38 | ImmutableSetMultimap.of("baz", 1).containsKey("qux")); 39 | } 40 | 41 | boolean testMultimapContainsValue() { 42 | return ImmutableSetMultimap.of("foo", 1).containsValue(2); 43 | } 44 | 45 | ImmutableSet> testMultimapGet() { 46 | return ImmutableSet.of( 47 | ImmutableSetMultimap.of(1, 2).get(1), 48 | ((Multimap) ImmutableSetMultimap.of(1, 2)).get(1)); 49 | } 50 | 51 | Stream testMultimapKeysStream() { 52 | return ImmutableSetMultimap.of("foo", 1).keys().stream(); 53 | } 54 | 55 | Stream testMultimapValuesStream() { 56 | return ImmutableSetMultimap.of("foo", 1).values().stream(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.util.function.Predicate.not; 4 | 5 | import com.google.common.base.MoreObjects; 6 | import com.google.common.collect.ImmutableSet; 7 | import java.util.Objects; 8 | import java.util.Optional; 9 | import java.util.function.Predicate; 10 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 11 | 12 | final class NullRulesTest implements RefasterRuleCollectionTestCase { 13 | @Override 14 | public ImmutableSet elidedTypesAndStaticImports() { 15 | return ImmutableSet.of(MoreObjects.class, Optional.class, not(null)); 16 | } 17 | 18 | ImmutableSet testIsNull() { 19 | return ImmutableSet.of(null == "foo", Objects.isNull("bar")); 20 | } 21 | 22 | ImmutableSet testIsNotNull() { 23 | return ImmutableSet.of(null != "foo", Objects.nonNull("bar")); 24 | } 25 | 26 | ImmutableSet testRequireNonNullElse() { 27 | return ImmutableSet.of( 28 | MoreObjects.firstNonNull("foo", "bar"), Optional.ofNullable("baz").orElse("qux")); 29 | } 30 | 31 | String testRequireNonNullElseGet() { 32 | return Optional.ofNullable("foo").orElseGet(() -> "bar"); 33 | } 34 | 35 | ImmutableSet> testIsNullFunction() { 36 | return ImmutableSet.of(s -> s == null, not(Objects::nonNull)); 37 | } 38 | 39 | ImmutableSet> testNonNullFunction() { 40 | return ImmutableSet.of(s -> s != null, not(Objects::isNull)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static java.util.Objects.requireNonNullElse; 4 | import static java.util.Objects.requireNonNullElseGet; 5 | import static java.util.function.Predicate.not; 6 | 7 | import com.google.common.base.MoreObjects; 8 | import com.google.common.collect.ImmutableSet; 9 | import java.util.Objects; 10 | import java.util.Optional; 11 | import java.util.function.Predicate; 12 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 13 | 14 | final class NullRulesTest implements RefasterRuleCollectionTestCase { 15 | @Override 16 | public ImmutableSet elidedTypesAndStaticImports() { 17 | return ImmutableSet.of(MoreObjects.class, Optional.class, not(null)); 18 | } 19 | 20 | ImmutableSet testIsNull() { 21 | return ImmutableSet.of("foo" == null, "bar" == null); 22 | } 23 | 24 | ImmutableSet testIsNotNull() { 25 | return ImmutableSet.of("foo" != null, "bar" != null); 26 | } 27 | 28 | ImmutableSet testRequireNonNullElse() { 29 | return ImmutableSet.of(requireNonNullElse("foo", "bar"), requireNonNullElse("baz", "qux")); 30 | } 31 | 32 | String testRequireNonNullElseGet() { 33 | return requireNonNullElseGet("foo", () -> "bar"); 34 | } 35 | 36 | ImmutableSet> testIsNullFunction() { 37 | return ImmutableSet.of(Objects::isNull, Objects::isNull); 38 | } 39 | 40 | ImmutableSet> testNonNullFunction() { 41 | return ImmutableSet.of(Objects::nonNull, Objects::nonNull); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.base.Predicates; 4 | import com.google.common.collect.ImmutableSet; 5 | import java.util.function.Predicate; 6 | import java.util.regex.Pattern; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class PatternRulesTest implements RefasterRuleCollectionTestCase { 10 | @Override 11 | public ImmutableSet elidedTypesAndStaticImports() { 12 | return ImmutableSet.of(Predicates.class); 13 | } 14 | 15 | Predicate testPatternAsPredicate() { 16 | return Predicates.contains(Pattern.compile("foo")); 17 | } 18 | 19 | Predicate testPatternCompileAsPredicate() { 20 | return Predicates.containsPattern("foo"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.common.base.Predicates; 4 | import com.google.common.collect.ImmutableSet; 5 | import java.util.function.Predicate; 6 | import java.util.regex.Pattern; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class PatternRulesTest implements RefasterRuleCollectionTestCase { 10 | @Override 11 | public ImmutableSet elidedTypesAndStaticImports() { 12 | return ImmutableSet.of(Predicates.class); 13 | } 14 | 15 | Predicate testPatternAsPredicate() { 16 | return Pattern.compile("foo").asPredicate(); 17 | } 18 | 19 | Predicate testPatternCompileAsPredicate() { 20 | return Pattern.compile("foo").asPredicate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PreconditionsRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.base.Preconditions.checkNotNull; 4 | 5 | import com.google.common.collect.ImmutableSet; 6 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 7 | 8 | final class PreconditionsRulesTest implements RefasterRuleCollectionTestCase { 9 | @Override 10 | @SuppressWarnings("RequireNonNull") 11 | public ImmutableSet elidedTypesAndStaticImports() { 12 | return ImmutableSet.of(checkNotNull(null)); 13 | } 14 | 15 | void testCheckArgument() { 16 | if ("foo".isEmpty()) { 17 | throw new IllegalArgumentException(); 18 | } 19 | } 20 | 21 | void testCheckArgumentWithMessage() { 22 | if ("foo".isEmpty()) { 23 | throw new IllegalArgumentException("The string is empty"); 24 | } 25 | } 26 | 27 | void testCheckElementIndexWithMessage() { 28 | if (1 < 0 || 1 >= 2) { 29 | throw new IndexOutOfBoundsException("My index"); 30 | } 31 | } 32 | 33 | String testRequireNonNull() { 34 | return checkNotNull("foo"); 35 | } 36 | 37 | void testRequireNonNullStatement() { 38 | if ("foo" == null) { 39 | throw new NullPointerException(); 40 | } 41 | } 42 | 43 | String testRequireNonNullWithMessage() { 44 | return checkNotNull("foo", "The string is null"); 45 | } 46 | 47 | void testRequireNonNullWithMessageStatement() { 48 | if ("foo" == null) { 49 | throw new NullPointerException("The string is null"); 50 | } 51 | } 52 | 53 | void testCheckPositionIndex() { 54 | if (1 < 0 || 1 > 2) { 55 | throw new IndexOutOfBoundsException(); 56 | } 57 | } 58 | 59 | void testCheckPositionIndexWithMessage() { 60 | if (1 < 0 || 1 > 2) { 61 | throw new IndexOutOfBoundsException("My position"); 62 | } 63 | } 64 | 65 | void testCheckState() { 66 | if ("foo".isEmpty()) { 67 | throw new IllegalStateException(); 68 | } 69 | } 70 | 71 | void testCheckStateWithMessage() { 72 | if ("foo".isEmpty()) { 73 | throw new IllegalStateException("The string is empty"); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PreconditionsRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import static com.google.common.base.Preconditions.checkArgument; 4 | import static com.google.common.base.Preconditions.checkElementIndex; 5 | import static com.google.common.base.Preconditions.checkNotNull; 6 | import static com.google.common.base.Preconditions.checkPositionIndex; 7 | import static com.google.common.base.Preconditions.checkState; 8 | import static java.util.Objects.requireNonNull; 9 | 10 | import com.google.common.collect.ImmutableSet; 11 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 12 | 13 | final class PreconditionsRulesTest implements RefasterRuleCollectionTestCase { 14 | @Override 15 | @SuppressWarnings("RequireNonNull") 16 | public ImmutableSet elidedTypesAndStaticImports() { 17 | return ImmutableSet.of(checkNotNull(null)); 18 | } 19 | 20 | void testCheckArgument() { 21 | checkArgument(!"foo".isEmpty()); 22 | } 23 | 24 | void testCheckArgumentWithMessage() { 25 | checkArgument(!"foo".isEmpty(), "The string is empty"); 26 | } 27 | 28 | void testCheckElementIndexWithMessage() { 29 | checkElementIndex(1, 2, "My index"); 30 | } 31 | 32 | String testRequireNonNull() { 33 | return requireNonNull("foo"); 34 | } 35 | 36 | void testRequireNonNullStatement() { 37 | requireNonNull("foo"); 38 | } 39 | 40 | String testRequireNonNullWithMessage() { 41 | return requireNonNull("foo", "The string is null"); 42 | } 43 | 44 | void testRequireNonNullWithMessageStatement() { 45 | requireNonNull("foo", "The string is null"); 46 | } 47 | 48 | void testCheckPositionIndex() { 49 | checkPositionIndex(1, 2); 50 | } 51 | 52 | void testCheckPositionIndexWithMessage() { 53 | checkPositionIndex(1, 2, "My position"); 54 | } 55 | 56 | void testCheckState() { 57 | checkState(!"foo".isEmpty()); 58 | } 59 | 60 | void testCheckStateWithMessage() { 61 | checkState(!"foo".isEmpty(), "The string is empty"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.errorprone.VisitorState; 4 | import com.google.errorprone.fixes.SuggestedFix; 5 | import com.sun.source.tree.ExpressionTree; 6 | import com.sun.source.tree.Tree; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class SuggestedFixRulesTest implements RefasterRuleCollectionTestCase { 10 | SuggestedFix testSuggestedFixDelete() { 11 | return SuggestedFix.builder().delete(null).build(); 12 | } 13 | 14 | SuggestedFix testSuggestedFixReplaceTree() { 15 | return SuggestedFix.builder().replace(null, "foo").build(); 16 | } 17 | 18 | SuggestedFix testSuggestedFixReplaceStartEnd() { 19 | return SuggestedFix.builder().replace(1, 2, "foo").build(); 20 | } 21 | 22 | SuggestedFix testSuggestedFixReplaceTreeStartEnd() { 23 | return SuggestedFix.builder().replace(null, "foo", 1, 2).build(); 24 | } 25 | 26 | SuggestedFix testSuggestedFixSwap() { 27 | return SuggestedFix.builder() 28 | .swap((Tree) null, (ExpressionTree) null, (VisitorState) null) 29 | .build(); 30 | } 31 | 32 | SuggestedFix testSuggestedFixPrefixWith() { 33 | return SuggestedFix.builder().prefixWith(null, "foo").build(); 34 | } 35 | 36 | SuggestedFix testSuggestedFixPostfixWith() { 37 | return SuggestedFix.builder().postfixWith(null, "foo").build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.refasterrules; 2 | 3 | import com.google.errorprone.VisitorState; 4 | import com.google.errorprone.fixes.SuggestedFix; 5 | import com.sun.source.tree.ExpressionTree; 6 | import com.sun.source.tree.Tree; 7 | import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; 8 | 9 | final class SuggestedFixRulesTest implements RefasterRuleCollectionTestCase { 10 | SuggestedFix testSuggestedFixDelete() { 11 | return SuggestedFix.delete(null); 12 | } 13 | 14 | SuggestedFix testSuggestedFixReplaceTree() { 15 | return SuggestedFix.replace(null, "foo"); 16 | } 17 | 18 | SuggestedFix testSuggestedFixReplaceStartEnd() { 19 | return SuggestedFix.replace(1, 2, "foo"); 20 | } 21 | 22 | SuggestedFix testSuggestedFixReplaceTreeStartEnd() { 23 | return SuggestedFix.replace(null, "foo", 1, 2); 24 | } 25 | 26 | SuggestedFix testSuggestedFixSwap() { 27 | return SuggestedFix.swap((Tree) null, (ExpressionTree) null, (VisitorState) null); 28 | } 29 | 30 | SuggestedFix testSuggestedFixPrefixWith() { 31 | return SuggestedFix.prefixWith(null, "foo"); 32 | } 33 | 34 | SuggestedFix testSuggestedFixPostfixWith() { 35 | return SuggestedFix.postfixWith(null, "foo"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /error-prone-experimental/README.md: -------------------------------------------------------------------------------- 1 | # Experimental Error Prone checks 2 | 3 | This module contains Error Prone checks that are currently under development or 4 | evaluation. These checks may be works-in-progress or have uncertain impact on 5 | code. Having this module allows for controlled experimentation and refinement 6 | before integration into production environments. 7 | -------------------------------------------------------------------------------- /error-prone-experimental/src/main/java/tech/picnic/errorprone/experimental/bugpatterns/package-info.java: -------------------------------------------------------------------------------- 1 | /** Experimental Error Prone checks. */ 2 | @com.google.errorprone.annotations.CheckReturnValue 3 | @org.jspecify.annotations.NullMarked 4 | package tech.picnic.errorprone.experimental.bugpatterns; 5 | -------------------------------------------------------------------------------- /error-prone-guidelines/README.md: -------------------------------------------------------------------------------- 1 | # Error Prone Support coding guidelines 2 | 3 | This module provides Error Prone checks that describe and suggest coding 4 | guidelines for both Error Prone checks and Refaster rules. These rules are only 5 | meant to be applied to Error Prone Support itself. 6 | -------------------------------------------------------------------------------- /error-prone-guidelines/src/main/java/tech/picnic/errorprone/guidelines/bugpatterns/package-info.java: -------------------------------------------------------------------------------- 1 | /** Error Prone Support coding guidelines. */ 2 | @com.google.errorprone.annotations.CheckReturnValue 3 | @org.jspecify.annotations.NullMarked 4 | package tech.picnic.errorprone.guidelines.bugpatterns; 5 | -------------------------------------------------------------------------------- /error-prone-guidelines/src/test/java/tech/picnic/errorprone/guidelines/bugpatterns/UnqualifiedSuggestedFixImportTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.guidelines.bugpatterns; 2 | 3 | import com.google.errorprone.CompilationTestHelper; 4 | import org.junit.jupiter.api.Test; 5 | 6 | final class UnqualifiedSuggestedFixImportTest { 7 | @Test 8 | void identification() { 9 | CompilationTestHelper.newInstance(UnqualifiedSuggestedFixImport.class, getClass()) 10 | .expectErrorMessage( 11 | "IMPORT", 12 | m -> 13 | m.contains( 14 | "Prefer `SuggestedFixes#qualifyType` over direct invocation of `SuggestedFix.Builder#addImport`")) 15 | .expectErrorMessage( 16 | "STATIC_IMPORT", 17 | m -> 18 | m.contains( 19 | "Prefer `SuggestedFixes#qualifyStaticImport` over direct invocation of `SuggestedFix.Builder#addStaticImport`")) 20 | .addSourceLines( 21 | "A.java", 22 | "import com.google.errorprone.fixes.SuggestedFix;", 23 | "", 24 | "class A {", 25 | " void m() {", 26 | " System.out.println(\"foo\");", 27 | " addImport(\"bar\");", 28 | " addStaticImport(\"baz\");", 29 | "", 30 | " SuggestedFix.Builder builder = SuggestedFix.builder();", 31 | " // BUG: Diagnostic matches: IMPORT", 32 | " builder.addImport(\"java.lang.String\");", 33 | " // BUG: Diagnostic matches: STATIC_IMPORT", 34 | " builder.addStaticImport(\"java.lang.String.toString\");", 35 | " builder.build();", 36 | " }", 37 | "", 38 | " private void addImport(String s) {}", 39 | "", 40 | " private void addStaticImport(String s) {}", 41 | "}") 42 | .doTest(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /error-prone-utils/src/main/java/tech/picnic/errorprone/utils/Documentation.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.utils; 2 | 3 | /** Utility class providing documentation-related code. */ 4 | public final class Documentation { 5 | /** The base URL at which Error Prone Support bug patterns are hosted. */ 6 | public static final String BUG_PATTERNS_BASE_URL = "https://error-prone.picnic.tech/bugpatterns/"; 7 | 8 | private Documentation() {} 9 | } 10 | -------------------------------------------------------------------------------- /error-prone-utils/src/main/java/tech/picnic/errorprone/utils/Flags.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.utils; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.common.collect.ImmutableSet; 5 | import com.google.errorprone.ErrorProneFlags; 6 | 7 | /** Helper methods for working with {@link ErrorProneFlags}. */ 8 | public final class Flags { 9 | private Flags() {} 10 | 11 | /** 12 | * Returns the list of (comma-separated) arguments passed using the given Error Prone flag. 13 | * 14 | * @param errorProneFlags The full set of flags provided. 15 | * @param name The name of the flag of interest. 16 | * @return A non-{@code null} list of provided arguments; this list is empty if the flag was not 17 | * provided, or if the flag's value is the empty string. 18 | */ 19 | public static ImmutableList getList(ErrorProneFlags errorProneFlags, String name) { 20 | ImmutableList list = errorProneFlags.getListOrEmpty(name); 21 | return list.equals(ImmutableList.of("")) ? ImmutableList.of() : list; 22 | } 23 | 24 | /** 25 | * Returns the set of (comma-separated) arguments passed using the given Error Prone flag. 26 | * 27 | * @param errorProneFlags The full set of flags provided. 28 | * @param name The name of the flag of interest. 29 | * @return A non-{@code null} set of provided arguments; this set is empty if the flag was not 30 | * provided, or if the flag's value is the empty string. 31 | * @implNote This method does not delegate to {@link ErrorProneFlags#getSetOrEmpty(String)}, as 32 | * that method wouldn't allow us to identify a non-singleton set of empty strings; such a set 33 | * should not be treated as empty. 34 | */ 35 | public static ImmutableSet getSet(ErrorProneFlags errorProneFlags, String name) { 36 | return ImmutableSet.copyOf(getList(errorProneFlags, name)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /error-prone-utils/src/main/java/tech/picnic/errorprone/utils/MoreMatchers.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.utils; 2 | 3 | import static com.google.errorprone.matchers.Matchers.typePredicateMatcher; 4 | import static tech.picnic.errorprone.utils.MoreTypePredicates.hasAnnotation; 5 | 6 | import com.google.errorprone.matchers.Matcher; 7 | import com.google.errorprone.matchers.Matchers; 8 | import com.google.errorprone.suppliers.Supplier; 9 | import com.sun.source.tree.AnnotationTree; 10 | import com.sun.source.tree.Tree; 11 | import com.sun.tools.javac.code.Type; 12 | 13 | /** 14 | * A collection of general-purpose {@link Matcher}s. 15 | * 16 | *

These methods are additions to the ones found in {@link Matchers}. 17 | */ 18 | public final class MoreMatchers { 19 | private MoreMatchers() {} 20 | 21 | /** 22 | * Returns a {@link Matcher} that determines whether a given {@link AnnotationTree} has a 23 | * meta-annotation of the specified type. 24 | * 25 | * @param The type of tree to match against. 26 | * @param annotationType The binary type name of the annotation (e.g. 27 | * "org.jspecify.annotations.Nullable", or "some.package.OuterClassName$InnerClassName") 28 | * @return A {@link Matcher} that matches trees with the specified meta-annotation. 29 | */ 30 | public static Matcher hasMetaAnnotation(String annotationType) { 31 | return typePredicateMatcher(hasAnnotation(annotationType)); 32 | } 33 | 34 | /** 35 | * Returns a {@link Matcher} that determines whether the type of a given {@link Tree} is a subtype 36 | * of the type returned by the specified {@link Supplier}. 37 | * 38 | *

This method differs from {@link Matchers#isSubtypeOf(Supplier)} in that it does not perform 39 | * type erasure. 40 | * 41 | * @param The type of tree to match against. 42 | * @param type The {@link Supplier} that returns the type to match against. 43 | * @return A {@link Matcher} that matches trees with the specified type. 44 | */ 45 | public static Matcher isSubTypeOf(Supplier type) { 46 | return typePredicateMatcher(MoreTypePredicates.isSubTypeOf(type)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /error-prone-utils/src/main/java/tech/picnic/errorprone/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** Auxiliary utilities for use by Error Prone checks. */ 2 | @com.google.errorprone.annotations.CheckReturnValue 3 | @org.jspecify.annotations.NullMarked 4 | package tech.picnic.errorprone.utils; 5 | -------------------------------------------------------------------------------- /error-prone-utils/src/test/java/tech/picnic/errorprone/utils/FlagsTest.java: -------------------------------------------------------------------------------- 1 | package tech.picnic.errorprone.utils; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.jupiter.params.provider.Arguments.arguments; 5 | 6 | import com.google.common.collect.ImmutableList; 7 | import com.google.common.collect.ImmutableSet; 8 | import com.google.errorprone.ErrorProneOptions; 9 | import java.util.stream.Stream; 10 | import org.junit.jupiter.params.ParameterizedTest; 11 | import org.junit.jupiter.params.provider.Arguments; 12 | import org.junit.jupiter.params.provider.MethodSource; 13 | 14 | final class FlagsTest { 15 | private static Stream getCollectionTestCases() { 16 | /* { args, flag, listed } */ 17 | return Stream.of( 18 | arguments(ImmutableList.of(), "Foo", ImmutableList.of()), 19 | arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Qux", ImmutableList.of()), 20 | arguments(ImmutableList.of("-XepOpt:Foo="), "Foo", ImmutableList.of()), 21 | arguments(ImmutableList.of("-XepOpt:Foo=bar"), "Foo", ImmutableList.of("bar")), 22 | arguments(ImmutableList.of("-XepOpt:Foo=bar,bar"), "Foo", ImmutableList.of("bar", "bar")), 23 | arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Foo", ImmutableList.of("bar", "baz")), 24 | arguments(ImmutableList.of("-XepOpt:Foo=,"), "Foo", ImmutableList.of("", ""))); 25 | } 26 | 27 | @MethodSource("getCollectionTestCases") 28 | @ParameterizedTest 29 | void getList(ImmutableList args, String flag, ImmutableList listed) { 30 | assertThat(Flags.getList(ErrorProneOptions.processArgs(args).getFlags(), flag)) 31 | .containsExactlyElementsOf(listed); 32 | } 33 | 34 | @MethodSource("getCollectionTestCases") 35 | @ParameterizedTest 36 | void getSet(ImmutableList args, String flag, ImmutableList listed) { 37 | assertThat(Flags.getSet(ErrorProneOptions.processArgs(args).getFlags(), flag)) 38 | .containsExactlyElementsOf(ImmutableSet.copyOf(listed)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /generate-docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -u -o pipefail 4 | 5 | REPOSITORY_ROOT="$(git rev-parse --show-toplevel)" 6 | WEBSITE_ROOT="${REPOSITORY_ROOT}/website" 7 | 8 | generate_homepage() { 9 | local homepage="${WEBSITE_ROOT}/index.md" 10 | 11 | echo "Generating ${homepage}..." 12 | cat - "${REPOSITORY_ROOT}/README.md" > "${homepage}" << EOF 13 | --- 14 | layout: default 15 | title: Home 16 | nav_order: 1 17 | --- 18 | EOF 19 | 20 | local macos_compat="" 21 | [[ "${OSTYPE}" == "darwin"* ]] && macos_compat="yes" 22 | sed -i ${macos_compat:+".bak"} 's/src="website\//src="/g' "${homepage}" 23 | sed -i ${macos_compat:+".bak"} 's/srcset="website\//srcset="/g' "${homepage}" 24 | } 25 | 26 | # Generate the website. 27 | generate_homepage 28 | -------------------------------------------------------------------------------- /integration-tests/checkstyle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -u -o pipefail 4 | 5 | test_name="$(basename "${0}" .sh)" 6 | project='checkstyle' 7 | repository='https://github.com/checkstyle/checkstyle.git' 8 | revision='checkstyle-10.21.0' 9 | additional_build_flags='-Perror-prone-compile,error-prone-test-compile -Dmaven.compiler.failOnError=true' 10 | 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' 11 | 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).*' 12 | patch_error_prone_flags='' 13 | validation_error_prone_flags='' 14 | # Validation skips some tests: 15 | # - The `metadataFilesGenerationAllFiles` test is skipped because it makes line 16 | # number assertions that will fail when the code is formatted or patched. 17 | # - The `allCheckSectionJavaDocs` test is skipped because it validates that 18 | # Javadoc has certain closing tags that are removed by Google Java Format. 19 | validation_build_flags='-Dtest=!MetadataGeneratorUtilTest#metadataFilesGenerationAllFiles,!XdocsJavaDocsTest#allCheckSectionJavaDocs' 20 | 21 | if [ "${#}" -gt 2 ] || ([ "${#}" = 2 ] && [ "${1:---sync}" != '--sync' ]); then 22 | >&2 echo "Usage: ${0} [--sync] []" 23 | exit 1 24 | fi 25 | 26 | "$(dirname "${0}")/run-integration-test.sh" \ 27 | "${test_name}" \ 28 | "${project}" \ 29 | "${repository}" \ 30 | "${revision}" \ 31 | "${additional_build_flags}" \ 32 | "${additional_source_directories}" \ 33 | "${shared_error_prone_flags}" \ 34 | "${patch_error_prone_flags}" \ 35 | "${validation_error_prone_flags}" \ 36 | "${validation_build_flags}" \ 37 | $@ 38 | -------------------------------------------------------------------------------- /integration-tests/metrics.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -u -o pipefail 4 | 5 | test_name="$(basename "${0}" .sh)" 6 | project='metrics' 7 | repository='https://github.com/dropwizard/metrics.git' 8 | revision='v5.0.0-rc22' 9 | additional_build_flags='' 10 | additional_source_directories='' 11 | shared_error_prone_flags='-XepExcludedPaths:.*/target/generated-sources/.* -XepOpt:Slf4jLoggerDeclaration:CanonicalStaticLoggerName=LOGGER' 12 | patch_error_prone_flags='' 13 | validation_error_prone_flags='' 14 | validation_build_flags='' 15 | 16 | if [ "${#}" -gt 2 ] || ([ "${#}" = 2 ] && [ "${1:---sync}" != '--sync' ]); then 17 | >&2 echo "Usage: ${0} [--sync] []" 18 | exit 1 19 | fi 20 | 21 | "$(dirname "${0}")/run-integration-test.sh" \ 22 | "${test_name}" \ 23 | "${project}" \ 24 | "${repository}" \ 25 | "${revision}" \ 26 | "${additional_build_flags}" \ 27 | "${additional_source_directories}" \ 28 | "${shared_error_prone_flags}" \ 29 | "${patch_error_prone_flags}" \ 30 | "${validation_error_prone_flags}" \ 31 | "${validation_build_flags}" \ 32 | $@ 33 | -------------------------------------------------------------------------------- /integration-tests/prometheus-java-client-init.patch: -------------------------------------------------------------------------------- 1 | --- a/pom.xml 2 | +++ b/pom.xml 3 | @@ -99,7 +99,6 @@ 4 | com.google.guava 5 | guava 6 | ${guava.version} 7 | - test 8 | 9 | 10 | org.slf4j 11 | @@ -320,13 +319,24 @@ 12 | -Xep:LongDoubleConversion:OFF 13 | -Xep:StringSplitter:OFF 14 | -XepExcludedPaths:.*/generated/.* 15 | + ${error-prone.configuration-args} 16 | 17 | 18 | 19 | 20 | com.google.errorprone 21 | error_prone_core 22 | - 2.38.0 23 | + ${error-prone.version} 24 | + 25 | + 26 | + tech.picnic.error-prone-support 27 | + error-prone-contrib 28 | + ${error-prone-support.version} 29 | + 30 | + 31 | + tech.picnic.error-prone-support 32 | + refaster-runner 33 | + ${error-prone-support.version} 34 | 35 | 10 | error-prone-fork 11 | 12 | 13 | error-prone-fork 14 | https://maven.pkg.github.com/PicnicSupermarket/error-prone 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | error-prone-fork 23 | ${env.GITHUB_ACTOR} 24 | ${env.GITHUB_TOKEN} 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Bundler and Jekyll. 2 | .bundle/ 3 | Gemfile.lock 4 | .jekyll-cache/ 5 | .jekyll-metadata 6 | .sass-cache/ 7 | _site/ 8 | vendor/ 9 | 10 | # Generated by `../generate-docs.sh`. 11 | *.bak 12 | index.md 13 | -------------------------------------------------------------------------------- /website/.ruby-version: -------------------------------------------------------------------------------- 1 | 3.1.2 2 | -------------------------------------------------------------------------------- /website/404.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Page not found 4 | permalink: /404 5 | nav_exclude: true 6 | search_exclude: true 7 | --- 8 | 9 | ## Page not found :( 10 | 11 | The requested page could not be found. 12 | -------------------------------------------------------------------------------- /website/Gemfile: -------------------------------------------------------------------------------- 1 | ruby File.read(".ruby-version").strip 2 | 3 | source "https://rubygems.org" 4 | gem "html-proofer", "4.4.1" 5 | gem "jekyll", "4.2.2" 6 | gem "jekyll-sitemap", "1.4" 7 | gem "just-the-docs", "0.4.0.rc2" 8 | gem "webrick", "1.7" 9 | -------------------------------------------------------------------------------- /website/_config.yml: -------------------------------------------------------------------------------- 1 | # General configuration. 2 | title: Error Prone Support 3 | logo: assets/images/favicon.svg 4 | url: https://error-prone.picnic.tech 5 | description: >- 6 | Error Prone extensions: extra bug checkers and a large battery of Refaster 7 | rules. 8 | 9 | theme: just-the-docs 10 | plugins: 11 | - jekyll-sitemap 12 | 13 | # Files and directories not to be deployed through GitHub pages. 14 | exclude: 15 | - Gemfile 16 | - Gemfile.lock 17 | - generate-version-compatibility-overview.sh 18 | - README.md 19 | - vendor 20 | 21 | # See https://jekyllrb.com/docs/permalinks/#built-in-formats. 22 | permalink: pretty 23 | 24 | # Theme (just-the-docs) configuration. 25 | # See 26 | # https://just-the-docs.github.io/just-the-docs/docs/navigation-structure/#external-navigation-links. 27 | nav_external_links: 28 | - title: Error Prone Support on GitHub 29 | url: https://github.com/PicnicSupermarket/error-prone-support 30 | hide_icon: false 31 | 32 | callouts: 33 | summary: 34 | color: blue 35 | note: 36 | color: grey-dk 37 | 38 | # SEO configuration. 39 | # See https://jekyll.github.io/jekyll-seo-tag/usage. 40 | social: 41 | name: Picnic 42 | links: 43 | - https://github.com/PicnicSupermarket 44 | - https://twitter.com/picnic 45 | - https://www.linkedin.com/company/picnictechnologies 46 | twitter: 47 | username: picnic 48 | card: summary 49 | -------------------------------------------------------------------------------- /website/_includes/footer_custom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | Copyright © 2017-2024 Picnic Technologies BV 5 |

6 | -------------------------------------------------------------------------------- /website/_includes/head_custom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 15 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /website/_sass/color_schemes/_common.scss: -------------------------------------------------------------------------------- 1 | // Add support for external anchor icons. 2 | .external > svg { 3 | width: 1rem; 4 | vertical-align: text-bottom; 5 | } 6 | 7 | .label { 8 | // Reduce spacing between labels and align with surrounding elements. 9 | margin-left: 0 !important; 10 | } 11 | 12 | footer { 13 | text-align: center; 14 | 15 | img#logo { 16 | width: 2rem; 17 | margin: 0 auto; 18 | display: block; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /website/_sass/color_schemes/_variables.scss: -------------------------------------------------------------------------------- 1 | // Overrides for Just the Docs. See 2 | // https://github.com/just-the-docs/just-the-docs/blob/main/_sass/support/_variables.scss. 3 | 4 | // Grid system. 5 | $nav-width: 400px; 6 | -------------------------------------------------------------------------------- /website/_sass/color_schemes/eps-dark.scss: -------------------------------------------------------------------------------- 1 | @import "./color_schemes/dark"; 2 | @import "_variables"; 3 | @import "_common"; 4 | 5 | // Swap `$blue-000` and `$blue-300`, mainly for callouts. This is done by 6 | // default for red, but not for other colors. 7 | $blue-000: #183385; 8 | $blue-300: #2c84fa; 9 | 10 | // Use light-theme greys in dark theme so that summary callouts stand out more. 11 | // (Note that the former has four shades, while the latter has five.) 12 | $grey-dk-000: $grey-lt-000; 13 | $grey-dk-100: $grey-lt-100; 14 | $grey-dk-200: $grey-lt-200; 15 | $grey-dk-250: $grey-lt-200; 16 | $grey-dk-300: $grey-lt-300; 17 | -------------------------------------------------------------------------------- /website/_sass/color_schemes/eps-light.scss: -------------------------------------------------------------------------------- 1 | @import "./color_schemes/light"; 2 | @import "_variables"; 3 | @import "_common"; 4 | -------------------------------------------------------------------------------- /website/assets/css/just-the-docs-eps-dark.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | {% include css/just-the-docs.scss.liquid color_scheme="eps-dark" %} 4 | -------------------------------------------------------------------------------- /website/assets/css/just-the-docs-eps-light.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | {% include css/just-the-docs.scss.liquid color_scheme="eps-light" %} 4 | -------------------------------------------------------------------------------- /website/assets/images/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/android-chrome-192x192.png -------------------------------------------------------------------------------- /website/assets/images/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/android-chrome-512x512.png -------------------------------------------------------------------------------- /website/assets/images/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/apple-touch-icon.png -------------------------------------------------------------------------------- /website/assets/images/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #da532c 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /website/assets/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/favicon-16x16.png -------------------------------------------------------------------------------- /website/assets/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/favicon-32x32.png -------------------------------------------------------------------------------- /website/assets/images/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/mstile-150x150.png -------------------------------------------------------------------------------- /website/assets/images/picnic-logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/assets/images/picnic-logo@2x.png -------------------------------------------------------------------------------- /website/assets/images/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Error Prone Support documentation", 3 | "short_name": "Error Prone Support", 4 | "icons": [ 5 | { 6 | "src": "/assets/images/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/assets/images/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /website/bugpatterns.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Bug Patterns 4 | nav_order: 2 5 | has_children: true 6 | --- 7 | 8 | # Bug Patterns 9 | -------------------------------------------------------------------------------- /website/compatibility.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Compatibility matrix 4 | nav_order: 2 5 | --- 6 | 7 | # Compatibility matrix 8 | 9 | {% comment %} 10 | XXX: Once available on the default branch, include a link to the 11 | `generate-version-compatibility-overview.sh` script. 12 | {% endcomment %} 13 | 14 | Error Prone Support releases are generally compatible with only a limited 15 | number of Error Prone releases. The table below shows, for each Error Prone 16 | Support release, the Error Prone versions it is expected to be compatible with. 17 | Compatibility is determined by: 18 | 1. Compiling and testing the Error Prone Support release source code against a 19 | given Error Prone version. This validates source and behavioral 20 | compatibility.[^1] [^2] 21 | 2. Applying the released Refaster rules using a given Error Prone version. This 22 | validates that the rules can be read by the targeted version of Error Prone, 23 | proving that the serialization format is compatible. 24 | 25 | | Error Prone Support version | Compatible Error Prone versions | 26 | | --------------------------- | ------------------------------- | 27 | {% for release in site.data.compatibility.releases -%} 28 | | [{{ release.version }}](https://github.com/PicnicSupermarket/error-prone-support/releases/tag/v{{ release.version }}) | {% 29 | for version in release.compatible -%} 30 | [{{ version }}](https://github.com/google/error-prone/releases/tag/v{{ version }}){% unless forloop.last %}, {% endunless %} 31 | {%- endfor %} | 32 | {% endfor %} 33 | 34 | [^1]: Note that this [does not prove][source-binary-compat] that the Error Prone Support and Error Prone versions are _binary_ compatible. This limitation does not appear to be an issue in practice. 35 | [^2]: The approach taken here may yield false negatives, because a reported incompatibility may merely be due to a test API incompatibility. 36 | [source-binary-compat]: https://stackoverflow.com/questions/57871898/ 37 | -------------------------------------------------------------------------------- /website/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PicnicSupermarket/error-prone-support/27637810db1cfe1cbce3dd0deb2a0d8268c85f22/website/favicon.ico -------------------------------------------------------------------------------- /website/refasterrules.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Refaster Rules 4 | nav_order: 2 5 | has_children: true 6 | --- 7 | 8 | # Refaster Rules 9 | --------------------------------------------------------------------------------