Repository navigation
Hoist visitor matchers and regexes into private static final constants (K4 of #1330) - #1357
Merged
Merged
Conversation
Matchers, type patterns and FQN strings that were instance fields of anonymous visitors or locals in `getVisitor()` are now constants on the recipe class, so they are built once rather than per visitor. Matchers built from recipe options stay per instance.
`LombokUtils`, `UpgradeDockerImageVersion`, `UpdateSdkMan`, `RemoveTemporalAnnotation` and `AddTransientAnnotationToCollections` compiled constant regexes per call or per visitor. `NoGuavaCreateTempDir` used `String.matches` to compare fully qualified names, which compiles a regex on every call; it now uses `equals`.
`static final` matchers in `URLConstructorsToNewURI`, `URLConstructorToURICreate`, `OptionalStreamRecipe` and `NoGuavaCreateTempDir` now follow constant naming; the latter's matcher moves to the recipe class so the precondition reuses it. `JREThrowableFinalMethods` builds its matchers from recipe options, so those stay locals and lose their constant-style names instead.
22 of 72 tasks
…s-v1 # Conflicts: # src/main/java/org/openrewrite/java/migrate/UpgradeDockerImageVersion.java # src/main/java/org/openrewrite/java/migrate/javax/RemoveTemporalAnnotation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses K4 of #1330.
Several recipes rebuilt matchers, FQN strings and regexes for every visitor or every call, and a few constants used camelCase names that read like fields. This moves the option-independent ones into
private static final UPPER_SNAKEconstants on the recipe class; no recipe behavior changes.Hoisted matchers and FQNs:
JacksonProviderOverrides,AddTableGenerator,AddScopeToInjectedClass,JREThrowableFinalMethods(java.lang.Throwable),AddMockitoJavaAgentToMavenSurefirePlugin(configuration tag template),OptionalNotEmptyToIsPresent(whoseisEmpty()matcher was misnamedoptionalIsPresentMatcher),OptionalNotPresentToIsEmpty,FindInternalJavaxApis,RemoveTemporalAnnotation(FQNs, type set and do-not-remove map),ArrayStoreExceptionToTypeNotPresentException,IllegalArgumentExceptionToAlreadyConnectedException, and the@lombok.NonNullmatcher inLombokUtils.UseJoinColumnForMapping's FQN fields are nowstatic.Precompiled patterns:
LombokUtils,UpgradeDockerImageVersion,UpdateSdkMan, plusRemoveTemporalAnnotationandAddTransientAnnotationToCollections, which had the same per-visitorPattern.compile.NoGuavaCreateTempDircompared FQNs withString.matches, compiling a regex per call; it now usesequals.UpdateSdkMan's major-version pattern depends on the matched input, so it stays per call.Renamed constants:
URLConstructorsToNewURI,URLConstructorToURICreate,OptionalStreamRecipeandNoGuavaCreateTempDir; the latter's matcher moved to the recipe class so its precondition reuses it.Option-dependent matchers stay per instance:
JREThrowableFinalMethodsbuilds its matchers from constructor options, so they remain locals and drop their constant-style names instead.ReplaceLocalizedStreamMethodsalready uses camelCase locals built from options, so nothing changed there.Already fixed on main and skipped:
RemovedSecurityManagerMethods,JerseyLoggingFilterToFeature,UpdateAddAnnotatedTypes,UpdateBeanManagerMethods,UpdateGetRealPath,JettyConnectorGetPortandHttpSessionInvalidatealready usestatic finalmatchers.Verified with
./gradlew testfiltered to the tests of every touched recipe plusorg.openrewrite.java.migrate.lombok.*(forLombokUtils): 41 test classes, 492 tests, 0 failures (5 skipped, pre-existing).