diff --git a/rewrite-core/src/main/java/org/openrewrite/Cursor.java b/rewrite-core/src/main/java/org/openrewrite/Cursor.java index 969872bc044..3be9d7c15a3 100644 --- a/rewrite-core/src/main/java/org/openrewrite/Cursor.java +++ b/rewrite-core/src/main/java/org/openrewrite/Cursor.java @@ -187,8 +187,8 @@ public String toString() { .map(t -> t instanceof Tree ? t.getClass().getSimpleName() : t.toString()) - .collect(Collectors.joining("->")) - + "}"; + .collect(Collectors.joining("->")) + + "}"; } public Cursor dropParentUntil(Predicate valuePredicate) { diff --git a/rewrite-core/src/main/java/org/openrewrite/PathUtils.java b/rewrite-core/src/main/java/org/openrewrite/PathUtils.java index 14e7c65e06b..96213005bf7 100755 --- a/rewrite-core/src/main/java/org/openrewrite/PathUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/PathUtils.java @@ -151,8 +151,8 @@ private static boolean matchesGlob(String pattern, String path) { if (!StringUtils.matchesGlob(pathTokens[pathIdxEnd], pattTokens[pattIdxEnd])) { return false; } - if (pattIdxEnd == (pattTokens.length - 1) - && (isFileSeparator(pattern.charAt(pattern.length() - 1)) ^ isFileSeparator(path.charAt(path.length() - 1)))) { + if (pattIdxEnd == (pattTokens.length - 1) && + (isFileSeparator(pattern.charAt(pattern.length() - 1)) ^ isFileSeparator(path.charAt(path.length() - 1)))) { return false; } pattIdxEnd--; @@ -293,8 +293,8 @@ private static boolean isFileSeparator(char ch) { @SuppressWarnings("SameParameterValue") private static boolean isFileSeparator(boolean strict, char ch) { - return strict - ? ch == File.separatorChar - : ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR; + return strict ? + ch == File.separatorChar : + ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR; } } diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java b/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java index bdeaaa07585..80e068c38f2 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java @@ -466,8 +466,8 @@ private static boolean matchesGlob(String pattern, String str, boolean caseSensi if (ch == '*') { break; } - if (ch != '?' - && different(caseSensitive, ch, str.charAt(strIdxStart))) { + if (ch != '?' && + different(caseSensitive, ch, str.charAt(strIdxStart))) { return false; // Character mismatch } patIdxStart++; @@ -554,9 +554,9 @@ private static boolean allStars(String chars, int start, int end) { } private static boolean different(boolean caseSensitive, char ch, char other) { - return caseSensitive - ? ch != other - : Character.toUpperCase(ch) != Character.toUpperCase(other); + return caseSensitive ? + ch != other : + Character.toUpperCase(ch) != Character.toUpperCase(other); } public static String indent(String text) { diff --git a/rewrite-core/src/main/java/org/openrewrite/ipc/http/OkHttpSender.java b/rewrite-core/src/main/java/org/openrewrite/ipc/http/OkHttpSender.java index acaba870a50..eb42f70c913 100644 --- a/rewrite-core/src/main/java/org/openrewrite/ipc/http/OkHttpSender.java +++ b/rewrite-core/src/main/java/org/openrewrite/ipc/http/OkHttpSender.java @@ -54,9 +54,9 @@ public Response send(Request request) { String methodValue = method.toString(); if (entity.length > 0) { String contentType = request.getRequestHeaders().get("Content-Type"); - MediaType mediaType = contentType != null - ? MediaType.get(contentType + "; charset=utf-8") - : MEDIA_TYPE_APPLICATION_JSON; + MediaType mediaType = contentType != null ? + MediaType.get(contentType + "; charset=utf-8") : + MEDIA_TYPE_APPLICATION_JSON; RequestBody body = RequestBody.create(entity, mediaType); requestBuilder.method(methodValue, body); } else { diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java index a6775ddab74..b2bb51c7077 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java @@ -195,9 +195,9 @@ public GitProvenance(UUID id, if (environment instanceof JenkinsBuildEnvironment) { JenkinsBuildEnvironment jenkinsBuildEnvironment = (JenkinsBuildEnvironment) environment; try (Repository repository = new RepositoryBuilder().findGitDir(projectDir.toFile()).build()) { - String branch = jenkinsBuildEnvironment.getLocalBranch() != null - ? jenkinsBuildEnvironment.getLocalBranch() - : localBranchName(repository, jenkinsBuildEnvironment.getBranch()); + String branch = jenkinsBuildEnvironment.getLocalBranch() != null ? + jenkinsBuildEnvironment.getLocalBranch() : + localBranchName(repository, jenkinsBuildEnvironment.getBranch()); return fromGitConfig(repository, branch, getChangeset(repository), gitRemoteParser); } catch (IllegalArgumentException | GitAPIException e) { // Silently ignore if the project directory is not a git repository diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BitbucketBuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BitbucketBuildEnvironment.java index ad2d33667f6..b0220e01f76 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BitbucketBuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BitbucketBuildEnvironment.java @@ -47,9 +47,9 @@ public static BitbucketBuildEnvironment build(UnaryOperator environment) @Override public GitProvenance buildGitProvenance() throws IncompleteGitConfigException { - if (StringUtils.isBlank(httpOrigin) - || StringUtils.isBlank(branch) - || StringUtils.isBlank(sha)) { + if (StringUtils.isBlank(httpOrigin) || + StringUtils.isBlank(branch) || + StringUtils.isBlank(sha)) { throw new IncompleteGitConfigException(); } else { return new GitProvenance(UUID.randomUUID(), httpOrigin, branch, sha, diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java index 0cb78df5f93..47cac47db41 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/BuildEnvironment.java @@ -36,8 +36,8 @@ public interface BuildEnvironment extends Marker { if (environment.apply("GITLAB_CI") != null) { return GitlabBuildEnvironment.build(environment); } - if (environment.apply("CI") != null && environment.apply("GITHUB_ACTION") != null - && environment.apply("GITHUB_RUN_ID") != null) { + if (environment.apply("CI") != null && environment.apply("GITHUB_ACTION") != null && + environment.apply("GITHUB_RUN_ID") != null) { return GithubActionsBuildEnvironment.build(environment); } if (environment.apply("DRONE") != null) { diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/CustomBuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/CustomBuildEnvironment.java index 75235b9c6fc..ee1f22c1ac9 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/CustomBuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/CustomBuildEnvironment.java @@ -47,9 +47,9 @@ public static CustomBuildEnvironment build(UnaryOperator environment) { @Override public GitProvenance buildGitProvenance() throws IncompleteGitConfigException { - if (StringUtils.isBlank(cloneURL) - || StringUtils.isBlank(ref) - || StringUtils.isBlank(sha)) { + if (StringUtils.isBlank(cloneURL) || + StringUtils.isBlank(ref) || + StringUtils.isBlank(sha)) { throw new IncompleteGitConfigException(); } else { return new GitProvenance(UUID.randomUUID(), cloneURL, ref, sha, diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/DroneBuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/DroneBuildEnvironment.java index f5abc81ac71..b1d61512e59 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/DroneBuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/DroneBuildEnvironment.java @@ -62,9 +62,9 @@ public static DroneBuildEnvironment build(UnaryOperator environment) { @Override public GitProvenance buildGitProvenance() throws IncompleteGitConfigException { - if (StringUtils.isBlank(remoteURL) - || (StringUtils.isBlank(branch) && StringUtils.isBlank(tag)) - || StringUtils.isBlank(commitSha)) { + if (StringUtils.isBlank(remoteURL) || + (StringUtils.isBlank(branch) && StringUtils.isBlank(tag)) || + StringUtils.isBlank(commitSha)) { throw new IncompleteGitConfigException(); } return new GitProvenance(UUID.randomUUID(), remoteURL, diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/GithubActionsBuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/GithubActionsBuildEnvironment.java index c1359b523b2..cb5ca645c6a 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/GithubActionsBuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/GithubActionsBuildEnvironment.java @@ -67,16 +67,16 @@ public GitProvenance buildGitProvenance() throws IncompleteGitConfigException { } else { gitRef = gitRef.replaceFirst("refs/heads/", ""); } - if (StringUtils.isBlank(ghRef) - || StringUtils.isBlank(host) - || StringUtils.isBlank(repository) - || StringUtils.isBlank(sha)) { + if (StringUtils.isBlank(ghRef) || + StringUtils.isBlank(host) || + StringUtils.isBlank(repository) || + StringUtils.isBlank(sha)) { throw new IncompleteGitConfigException( String.format("Invalid GitHub environment with host: %s, branch: %s, " + "repository: %s, sha: %s", host, ghRef, repository, sha)); } - return new GitProvenance(UUID.randomUUID(), host + "/" + getRepository() - + ".git", gitRef, getSha(), null, null, emptyList()); + return new GitProvenance(UUID.randomUUID(), host + "/" + getRepository() + + ".git", gitRef, getSha(), null, null, emptyList()); } } diff --git a/rewrite-core/src/main/java/org/openrewrite/marker/ci/GitlabBuildEnvironment.java b/rewrite-core/src/main/java/org/openrewrite/marker/ci/GitlabBuildEnvironment.java index 276c52c96ef..b1fecbbd412 100644 --- a/rewrite-core/src/main/java/org/openrewrite/marker/ci/GitlabBuildEnvironment.java +++ b/rewrite-core/src/main/java/org/openrewrite/marker/ci/GitlabBuildEnvironment.java @@ -56,9 +56,9 @@ public static GitlabBuildEnvironment build(UnaryOperator environment) { @Override public GitProvenance buildGitProvenance() throws IncompleteGitConfigException { - if (StringUtils.isBlank(ciRepositoryUrl) - || StringUtils.isBlank(ciCommitRefName) - || StringUtils.isBlank(ciCommitSha)) { + if (StringUtils.isBlank(ciRepositoryUrl) || + StringUtils.isBlank(ciCommitRefName) || + StringUtils.isBlank(ciCommitSha)) { throw new IncompleteGitConfigException(); } return new GitProvenance(UUID.randomUUID(), ciRepositoryUrl, ciCommitRefName, ciCommitSha, diff --git a/rewrite-core/src/main/java/org/openrewrite/semver/DependencyMatcher.java b/rewrite-core/src/main/java/org/openrewrite/semver/DependencyMatcher.java index fe6c7032705..0d75d0655db 100755 --- a/rewrite-core/src/main/java/org/openrewrite/semver/DependencyMatcher.java +++ b/rewrite-core/src/main/java/org/openrewrite/semver/DependencyMatcher.java @@ -75,9 +75,9 @@ public static Validated build(String pattern) { } public boolean matches(@Nullable String groupId, String artifactId, String version) { - return StringUtils.matchesGlob(groupId, groupPattern) - && StringUtils.matchesGlob(artifactId, artifactPattern) - && (versionComparator == null || versionComparator.isValid(null, version)); + return StringUtils.matchesGlob(groupId, groupPattern) && + StringUtils.matchesGlob(artifactId, artifactPattern) && + (versionComparator == null || versionComparator.isValid(null, version)); } public boolean matches(@Nullable String groupId, String artifactId) { diff --git a/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java b/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java index bb435c61c80..1f130cafa7e 100644 --- a/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java +++ b/rewrite-core/src/main/java/org/openrewrite/text/AppendToTextFile.java @@ -53,12 +53,12 @@ public class AppendToTextFile extends ScanningRecipe { @Nullable Boolean appendNewline; @Option(displayName = "Existing file strategy", - description = "Determines behavior if a file exists at this location prior to Rewrite execution.\n\n" - + "- `Continue`: append new content to existing file contents. If existing file is not plaintext, recipe does nothing.\n" - + "- `Replace`: remove existing content from file.\n" - + "- `Leave`: *(default)* do nothing. Existing file is fully preserved.\n\n" - + "Note: this only affects the first interaction with the specified file per Rewrite execution.\n" - + "Subsequent instances of this recipe in the same Rewrite execution will always append.", + description = "Determines behavior if a file exists at this location prior to Rewrite execution.\n\n" + + "- `Continue`: append new content to existing file contents. If existing file is not plaintext, recipe does nothing.\n" + + "- `Replace`: remove existing content from file.\n" + + "- `Leave`: *(default)* do nothing. Existing file is fully preserved.\n\n" + + "Note: this only affects the first interaction with the specified file per Rewrite execution.\n" + + "Subsequent instances of this recipe in the same Rewrite execution will always append.", valid = {"Continue", "Replace", "Leave"}, required = false) @Nullable Strategy existingFileStrategy; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyArtifactId.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyArtifactId.java index 8220bbae2a6..d54a40c6b77 100755 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyArtifactId.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyArtifactId.java @@ -151,8 +151,8 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m) { if (strings.size() >= 2 && strings.get(0) instanceof J.Literal) { Dependency dependency = DependencyStringNotationConverter.parse((String) requireNonNull(((J.Literal) strings.get(0)).getValue())); - if (dependency != null && !newArtifactId.equals(dependency.getArtifactId()) - && depMatcher.matches(dependency.getGroupId(), dependency.getArtifactId())) { + if (dependency != null && !newArtifactId.equals(dependency.getArtifactId()) && + depMatcher.matches(dependency.getGroupId(), dependency.getArtifactId())) { Dependency newDependency = dependency.withArtifactId(newArtifactId); updatedDependencies.put(dependency.getGav().asGroupArtifact(), newDependency.getGav().asGroupArtifact()); String replacement = newDependency.toStringNotation(); @@ -196,9 +196,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m) { version = valueValue; } } - if (groupId == null || artifactId == null - || (version == null && !depMatcher.matches(groupId, artifactId)) - || (version != null && !depMatcher.matches(groupId, artifactId, version))) { + if (groupId == null || artifactId == null || + (version == null && !depMatcher.matches(groupId, artifactId)) || + (version != null && !depMatcher.matches(groupId, artifactId, version))) { return m; } String delimiter = versionStringDelimiter; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyClassifier.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyClassifier.java index c2698f806b9..c11f7ccd68d 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyClassifier.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyClassifier.java @@ -157,10 +157,10 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) } index++; } - if (groupId == null || artifactId == null - || (version == null && !depMatcher.matches(groupId, artifactId)) - || (version != null && !depMatcher.matches(groupId, artifactId, version)) - || Objects.equals(newClassifier, classifier)) { + if (groupId == null || artifactId == null || + (version == null && !depMatcher.matches(groupId, artifactId)) || + (version != null && !depMatcher.matches(groupId, artifactId, version)) || + Objects.equals(newClassifier, classifier)) { return m; } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyExtension.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyExtension.java index 9847fd08be7..a6a617f627b 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyExtension.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyExtension.java @@ -146,10 +146,10 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) extension = valueValue; } } - if (groupId == null || artifactId == null - || (version == null && !depMatcher.matches(groupId, artifactId)) - || (version != null && !depMatcher.matches(groupId, artifactId, version)) - || extension == null) { + if (groupId == null || artifactId == null || + (version == null && !depMatcher.matches(groupId, artifactId)) || + (version != null && !depMatcher.matches(groupId, artifactId, version)) || + extension == null) { return m; } String delimiter = extensionStringDelimiter; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyGroupId.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyGroupId.java index 6f361ce6b94..550b71f1492 100755 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyGroupId.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependencyGroupId.java @@ -151,8 +151,8 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m) { if (strings.size() >= 2 && strings.get(0) instanceof J.Literal) { Dependency dependency = DependencyStringNotationConverter.parse((String) requireNonNull(((J.Literal) strings.get(0)).getValue())); - if (dependency != null && !newGroupId.equals(dependency.getGroupId()) - && depMatcher.matches(dependency.getGroupId(), dependency.getArtifactId())) { + if (dependency != null && !newGroupId.equals(dependency.getGroupId()) && + depMatcher.matches(dependency.getGroupId(), dependency.getArtifactId())) { Dependency newDependency = dependency.withGroupId(newGroupId); updatedDependencies.put(dependency.getGav().asGroupArtifact(), newDependency.getGav().asGroupArtifact()); String replacement = newDependency.toStringNotation(); @@ -196,9 +196,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation m) { version = valueValue; } } - if (groupId == null || artifactId == null - || (version == null && !depMatcher.matches(groupId, artifactId)) - || (version != null && !depMatcher.matches(groupId, artifactId, version))) { + if (groupId == null || artifactId == null || + (version == null && !depMatcher.matches(groupId, artifactId)) || + (version != null && !depMatcher.matches(groupId, artifactId, version))) { return m; } String delimiter = versionStringDelimiter; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeExtraProperty.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeExtraProperty.java index 060980259ee..ca1726e8b7b 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeExtraProperty.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeExtraProperty.java @@ -75,8 +75,8 @@ public J.Assignment visitAssignment(J.Assignment as, ExecutionContext ctx) { if(!Objects.equals(key, var.getSimpleName())) { return as; } - if((var.getTarget() instanceof J.Identifier && ((J.Identifier) var.getTarget()).getSimpleName().equals("ext")) - || (var.getTarget() instanceof J.FieldAccess && ((J.FieldAccess) var.getTarget()).getSimpleName().equals("ext")) ) { + if((var.getTarget() instanceof J.Identifier && ((J.Identifier) var.getTarget()).getSimpleName().equals("ext")) || + (var.getTarget() instanceof J.FieldAccess && ((J.FieldAccess) var.getTarget()).getSimpleName().equals("ext")) ) { as = updateAssignment(as); } } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyConstraintToRule.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyConstraintToRule.java index b0867c41771..474fea6c5d8 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyConstraintToRule.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyConstraintToRule.java @@ -340,15 +340,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Integ private static boolean isInDependenciesBlock(Cursor cursor) { Cursor c = cursor.dropParentUntil(value -> - value == Cursor.ROOT_VALUE - || (value instanceof J.MethodInvocation && DEPENDENCIES_DSL_MATCHER.matches((J.MethodInvocation) value))); + value == Cursor.ROOT_VALUE || + (value instanceof J.MethodInvocation && DEPENDENCIES_DSL_MATCHER.matches((J.MethodInvocation) value))); return c.getValue() instanceof J.MethodInvocation; } private static boolean isEachDependency(J.MethodInvocation m) { - return "eachDependency".equals(m.getSimpleName()) - && (m.getSelect() instanceof J.Identifier - && "resolutionStrategy".equals(((J.Identifier) m.getSelect()).getSimpleName())); + return "eachDependency".equals(m.getSimpleName()) && + (m.getSelect() instanceof J.Identifier && + "resolutionStrategy".equals(((J.Identifier) m.getSelect()).getSimpleName())); } private static boolean predicateRelatesToGav(J.If iff, GroupArtifactVersionBecause groupArtifactVersion) { diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyUseMapNotation.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyUseMapNotation.java index 88c5e68b977..0338bdc25d8 100755 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyUseMapNotation.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/DependencyUseMapNotation.java @@ -124,8 +124,8 @@ private J.MethodInvocation forGString(J.MethodInvocation m) { // Supporting all possible GString interpolations is impossible // Supporting all probable GString interpolations is difficult // This focuses on the most common case: When only the version number is interpolated - if (g.getStrings().size() != 2 || !(g.getStrings().get(0) instanceof J.Literal) - || !(g.getStrings().get(1) instanceof G.GString.Value)) { + if (g.getStrings().size() != 2 || !(g.getStrings().get(0) instanceof J.Literal) || + !(g.getStrings().get(1) instanceof G.GString.Value)) { return m; } J.Literal arg1 = (J.Literal)g.getStrings().get(0); diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveDependency.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveDependency.java index ae1c4bb520c..ca7f2ec837d 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveDependency.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveDependency.java @@ -145,8 +145,8 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) //noinspection DataFlowIssue return maybeRemoveDependency(m); } else if (firstArgument instanceof J.MethodInvocation && - (((J.MethodInvocation) firstArgument).getSimpleName().equals("platform") - || ((J.MethodInvocation) firstArgument).getSimpleName().equals("enforcedPlatform"))) { + (((J.MethodInvocation) firstArgument).getSimpleName().equals("platform") || + ((J.MethodInvocation) firstArgument).getSimpleName().equals("enforcedPlatform"))) { J after = maybeRemoveDependency((J.MethodInvocation) firstArgument); if (after == null) { //noinspection DataFlowIssue diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateJavaCompatibility.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateJavaCompatibility.java index 5ce95859218..6543204360c 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateJavaCompatibility.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateJavaCompatibility.java @@ -186,8 +186,8 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) } } - return SearchResult.found(m, "Attempted to update to Java version to " + version - + " but was unsuccessful, please update manually"); + return SearchResult.found(m, "Attempted to update to Java version to " + version + + " but was unsuccessful, please update manually"); } if (sourceCompatibilityDsl.matches(m) || targetCompatibilityDsl.matches(m)) { @@ -208,8 +208,8 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) } } - return SearchResult.found(m, "Attempted to update to Java version to " + version - + " but was unsuccessful, please update manually"); + return SearchResult.found(m, "Attempted to update to Java version to " + version + + " but was unsuccessful, please update manually"); } return m; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java index 671f45a89b8..9c71401d44d 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java @@ -434,9 +434,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation method, Execution return arg; } Dependency dep = DependencyStringNotationConverter.parse(gav); - if (dep != null && dependencyMatcher.matches(dep.getGroupId(), dep.getArtifactId()) - && dep.getVersion() != null - && !dep.getVersion().startsWith("$")) { + if (dep != null && dependencyMatcher.matches(dep.getGroupId(), dep.getArtifactId()) && + dep.getVersion() != null && + !dep.getVersion().startsWith("$")) { Object scanResult = acc.gaToNewVersion.get(new GroupArtifact(dep.getGroupId(), dep.getArtifactId())); if (scanResult instanceof Exception) { getCursor().putMessage(UPDATE_VERSION_ERROR_KEY, scanResult); @@ -472,9 +472,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation method, Execution m = Markup.warn(m, err); } List depArgs = m.getArguments(); - if (depArgs.size() >= 3 && depArgs.get(0) instanceof G.MapEntry - && depArgs.get(1) instanceof G.MapEntry - && depArgs.get(2) instanceof G.MapEntry) { + if (depArgs.size() >= 3 && depArgs.get(0) instanceof G.MapEntry && + depArgs.get(1) instanceof G.MapEntry && + depArgs.get(2) instanceof G.MapEntry) { Expression groupValue = ((G.MapEntry) depArgs.get(0)).getValue(); Expression artifactValue = ((G.MapEntry) depArgs.get(1)).getValue(); if (!(groupValue instanceof J.Literal) || !(artifactValue instanceof J.Literal)) { diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddPluginVisitor.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddPluginVisitor.java index 6dc13d46ea7..1a22bc3d5f9 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddPluginVisitor.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddPluginVisitor.java @@ -154,10 +154,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Integ .orElseThrow(() -> new IllegalArgumentException("Could not parse as Gradle")); if (FindMethods.find(cu, "RewriteGradleProject plugins(..)").isEmpty() && FindMethods.find(cu, "RewriteSettings plugins(..)").isEmpty()) { - if (cu.getSourcePath().endsWith(Paths.get("settings.gradle")) - && !cu.getStatements().isEmpty() - && cu.getStatements().get(0) instanceof J.MethodInvocation - && ((J.MethodInvocation) cu.getStatements().get(0)).getSimpleName().equals("pluginManagement")) { + if (cu.getSourcePath().endsWith(Paths.get("settings.gradle")) && + !cu.getStatements().isEmpty() && + cu.getStatements().get(0) instanceof J.MethodInvocation && + ((J.MethodInvocation) cu.getStatements().get(0)).getSimpleName().equals("pluginManagement")) { return cu.withStatements(ListUtils.insert(cu.getStatements(), autoFormat(statement.withPrefix(Space.format("\n\n")), ctx, getCursor()), 1)); } else { int insertAtIdx = 0; diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepository.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepository.java index 7176a720006..6337d228db0 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepository.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddSettingsPluginRepository.java @@ -78,16 +78,16 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon statements.add(pluginManagement); } else { Statement statement = statements.get(0); - if (statement instanceof J.MethodInvocation - && ((J.MethodInvocation) statement).getSimpleName().equals("pluginManagement")) { + if (statement instanceof J.MethodInvocation && + ((J.MethodInvocation) statement).getSimpleName().equals("pluginManagement")) { J.MethodInvocation m = (J.MethodInvocation) statement; m = m.withArguments(ListUtils.mapFirst(m.getArguments(), arg -> { if (arg instanceof J.Lambda && ((J.Lambda) arg).getBody() instanceof J.Block) { J.Lambda lambda = (J.Lambda) arg; J.Block block = (J.Block) lambda.getBody(); return lambda.withBody(block.withStatements(ListUtils.map(block.getStatements(), statement2 -> { - if ((statement2 instanceof J.MethodInvocation && ((J.MethodInvocation) statement2).getSimpleName().equals("repositories")) - || (statement2 instanceof J.Return && ((J.Return) statement2).getExpression() instanceof J.MethodInvocation && ((J.MethodInvocation) ((J.Return) statement2).getExpression()).getSimpleName().equals("repositories"))) { + if ((statement2 instanceof J.MethodInvocation && ((J.MethodInvocation) statement2).getSimpleName().equals("repositories")) || + (statement2 instanceof J.Return && ((J.Return) statement2).getExpression() instanceof J.MethodInvocation && ((J.MethodInvocation) ((J.Return) statement2).getExpression()).getSimpleName().equals("repositories"))) { J.MethodInvocation m2 = (J.MethodInvocation) (statement2 instanceof J.Return ? ((J.Return) statement2).getExpression() : statement2); return m2.withArguments(ListUtils.mapFirst(m2.getArguments(), arg2 -> { if (arg2 instanceof J.Lambda && ((J.Lambda) arg2).getBody() instanceof J.Block) { diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemovePluginVisitor.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemovePluginVisitor.java index 9e50bf1a058..6e1b50c167b 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemovePluginVisitor.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/RemovePluginVisitor.java @@ -48,8 +48,8 @@ public J.Block visitBlock(J.Block block, ExecutionContext executionContext) { J.MethodInvocation m = getCursor().firstEnclosing(J.MethodInvocation.class); if (m != null && buildPluginsContainerMatcher.matches(m) || settingsPluginsContainerMatcher.matches(m)) { b = b.withStatements(ListUtils.map(b.getStatements(), statement -> { - if (!(statement instanceof J.MethodInvocation - || (statement instanceof J.Return && ((J.Return) statement).getExpression() instanceof J.MethodInvocation))) { + if (!(statement instanceof J.MethodInvocation || + (statement instanceof J.Return && ((J.Return) statement).getExpression() instanceof J.MethodInvocation))) { return statement; } @@ -59,24 +59,24 @@ public J.Block visitBlock(J.Block block, ExecutionContext executionContext) { return null; } } else if (buildPluginWithVersionMatcher.matches(m2) || settingsPluginWithVersionMatcher.matches(m2)) { - if (m2.getSelect() instanceof J.MethodInvocation - && ((J.MethodInvocation) m2.getSelect()).getArguments().get(0) instanceof J.Literal - && pluginId.equals(((J.Literal) ((J.MethodInvocation) m2.getSelect()).getArguments().get(0)).getValue())) { + if (m2.getSelect() instanceof J.MethodInvocation && + ((J.MethodInvocation) m2.getSelect()).getArguments().get(0) instanceof J.Literal && + pluginId.equals(((J.Literal) ((J.MethodInvocation) m2.getSelect()).getArguments().get(0)).getValue())) { return null; } } else if (buildPluginWithApplyMatcher.matches(m2) || settingsPluginWithApplyMatcher.matches(m2)) { if (buildPluginMatcher.matches(m2.getSelect()) || settingsPluginMatcher.matches(m2.getSelect())) { - if (m2.getSelect() instanceof J.MethodInvocation - && ((J.MethodInvocation) m2.getSelect()).getArguments().get(0) instanceof J.Literal - && pluginId.equals(((J.Literal) ((J.MethodInvocation) m2.getSelect()).getArguments().get(0)).getValue())) { + if (m2.getSelect() instanceof J.MethodInvocation && + ((J.MethodInvocation) m2.getSelect()).getArguments().get(0) instanceof J.Literal && + pluginId.equals(((J.Literal) ((J.MethodInvocation) m2.getSelect()).getArguments().get(0)).getValue())) { return null; } } else if (buildPluginWithVersionMatcher.matches(m2.getSelect()) || settingsPluginWithVersionMatcher.matches(m2.getSelect())) { - if (m2.getSelect() instanceof J.MethodInvocation - && (buildPluginMatcher.matches(((J.MethodInvocation) m2.getSelect()).getSelect()) || settingsPluginMatcher.matches(((J.MethodInvocation) m2.getSelect()).getSelect()))) { - if (((J.MethodInvocation) m2.getSelect()).getSelect() instanceof J.MethodInvocation - && ((J.MethodInvocation) ((J.MethodInvocation) m2.getSelect()).getSelect()).getArguments().get(0) instanceof J.Literal - && pluginId.equals(((J.Literal) ((J.MethodInvocation) ((J.MethodInvocation) m2.getSelect()).getSelect()).getArguments().get(0)).getValue())) { + if (m2.getSelect() instanceof J.MethodInvocation && + (buildPluginMatcher.matches(((J.MethodInvocation) m2.getSelect()).getSelect()) || settingsPluginMatcher.matches(((J.MethodInvocation) m2.getSelect()).getSelect()))) { + if (((J.MethodInvocation) m2.getSelect()).getSelect() instanceof J.MethodInvocation && + ((J.MethodInvocation) ((J.MethodInvocation) m2.getSelect()).getSelect()).getArguments().get(0) instanceof J.Literal && + pluginId.equals(((J.Literal) ((J.MethodInvocation) ((J.MethodInvocation) m2.getSelect()).getSelect()).getArguments().get(0)).getValue())) { return null; } } @@ -95,9 +95,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu J.MethodInvocation m = super.visitMethodInvocation(method, executionContext); if (buildPluginsContainerMatcher.matches(m) || settingsPluginsContainerMatcher.matches(m)) { - if (m.getArguments().get(0) instanceof J.Lambda - && ((J.Lambda) m.getArguments().get(0)).getBody() instanceof J.Block - && ((J.Block) ((J.Lambda) m.getArguments().get(0)).getBody()).getStatements().isEmpty()) { + if (m.getArguments().get(0) instanceof J.Lambda && + ((J.Lambda) m.getArguments().get(0)).getBody() instanceof J.Block && + ((J.Block) ((J.Lambda) m.getArguments().get(0)).getBody()).getStatements().isEmpty()) { //noinspection DataFlowIssue return null; } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/FindRepository.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/FindRepository.java index c72774bd282..d8aa5750bc0 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/FindRepository.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/search/FindRepository.java @@ -75,8 +75,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu return new RepositoryVisitor().visitMethodInvocation(method, ctx); } else { boolean isPluginBlock = pluginManagementMatcher.matches(method) || buildscriptMatcher.matches(method); - if ((purpose == Purpose.Project && !isPluginBlock) - || (purpose == Purpose.Plugin && isPluginBlock)) { + if ((purpose == Purpose.Project && !isPluginBlock) || + (purpose == Purpose.Plugin && isPluginBlock)) { return new RepositoryVisitor().visitMethodInvocation(method, ctx); } } @@ -124,15 +124,15 @@ private boolean urlMatches(J.MethodInvocation m, String url) { for (Statement statement : block.getStatements()) { if (statement instanceof J.Assignment || (statement instanceof J.Return && ((J.Return) statement).getExpression() instanceof J.Assignment)) { J.Assignment assignment = (J.Assignment) (statement instanceof J.Return ? ((J.Return) statement).getExpression() : statement); - if (assignment.getVariable() instanceof J.Identifier - && "url".equals(((J.Identifier) assignment.getVariable()).getSimpleName())) { - if (assignment.getAssignment() instanceof J.Literal - && url.equals(((J.Literal) assignment.getAssignment()).getValue())) { + if (assignment.getVariable() instanceof J.Identifier && + "url".equals(((J.Identifier) assignment.getVariable()).getSimpleName())) { + if (assignment.getAssignment() instanceof J.Literal && + url.equals(((J.Literal) assignment.getAssignment()).getValue())) { return true; - } else if (assignment.getAssignment() instanceof J.MethodInvocation - && ((J.MethodInvocation) assignment.getAssignment()).getSimpleName().equals("uri") - && ((J.MethodInvocation) assignment.getAssignment()).getArguments().get(0) instanceof J.Literal - && url.equals(((J.Literal) ((J.MethodInvocation) assignment.getAssignment()).getArguments().get(0)).getValue())) { + } else if (assignment.getAssignment() instanceof J.MethodInvocation && + ((J.MethodInvocation) assignment.getAssignment()).getSimpleName().equals("uri") && + ((J.MethodInvocation) assignment.getAssignment()).getArguments().get(0) instanceof J.Literal && + url.equals(((J.Literal) ((J.MethodInvocation) assignment.getAssignment()).getArguments().get(0)).getValue())) { return true; } else if (assignment.getAssignment() instanceof G.GString) { String valueSource = assignment.getAssignment().withPrefix(Space.EMPTY).printTrimmed(new GroovyPrinter<>()); @@ -143,13 +143,13 @@ private boolean urlMatches(J.MethodInvocation m, String url) { } else if (statement instanceof J.MethodInvocation || (statement instanceof J.Return && ((J.Return) statement).getExpression() instanceof J.MethodInvocation)) { J.MethodInvocation m1 = (J.MethodInvocation) (statement instanceof J.Return ? ((J.Return) statement).getExpression() : statement); if (m1.getSimpleName().equals("setUrl") || m1.getSimpleName().equals("url")) { - if (m1.getArguments().get(0) instanceof J.Literal - && url.equals(((J.Literal) m1.getArguments().get(0)).getValue())) { + if (m1.getArguments().get(0) instanceof J.Literal && + url.equals(((J.Literal) m1.getArguments().get(0)).getValue())) { return true; - } else if (m1.getArguments().get(0) instanceof J.MethodInvocation - && ((J.MethodInvocation) m1.getArguments().get(0)).getSimpleName().equals("uri") - && ((J.MethodInvocation) m1.getArguments().get(0)).getArguments().get(0) instanceof J.Literal - && url.equals(((J.Literal) ((J.MethodInvocation) m1.getArguments().get(0)).getArguments().get(0)).getValue())) { + } else if (m1.getArguments().get(0) instanceof J.MethodInvocation && + ((J.MethodInvocation) m1.getArguments().get(0)).getSimpleName().equals("uri") && + ((J.MethodInvocation) m1.getArguments().get(0)).getArguments().get(0) instanceof J.Literal && + url.equals(((J.Literal) ((J.MethodInvocation) m1.getArguments().get(0)).getArguments().get(0)).getValue())) { return true; } else if (m1.getArguments().get(0) instanceof G.GString) { G.GString value = (G.GString) m1.getArguments().get(0); diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/util/ChangeStringLiteral.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/util/ChangeStringLiteral.java index e0f5e46c3ec..605224c0ec4 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/util/ChangeStringLiteral.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/util/ChangeStringLiteral.java @@ -29,8 +29,8 @@ public static J.Literal withStringValue(J.Literal l, String newValue) { return l; } String valueSource = l.getValueSource(); - String delimiter = (valueSource == null) ? "'" - : valueSource.substring(0, valueSource.indexOf(oldValue)); + String delimiter = (valueSource == null) ? "'" : + valueSource.substring(0, valueSource.indexOf(oldValue)); return l.withValue(newValue).withValueSource(delimiter + newValue + delimiter); } } diff --git a/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java b/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java index 8060e68c238..a1a0f5ed465 100644 --- a/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java +++ b/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java @@ -149,10 +149,10 @@ public G.CompilationUnit visit(SourceUnit unit, ModuleNode ast) throws GroovyPar } for (ClassNode aClass : ast.getClasses()) { - if (aClass.getSuperClass() == null - || !("groovy.lang.Script".equals(aClass.getSuperClass().getName()) - || "RewriteGradleProject".equals(aClass.getSuperClass().getName()) - || "RewriteSettings".equals(aClass.getSuperClass().getName()))) { + if (aClass.getSuperClass() == null || + !("groovy.lang.Script".equals(aClass.getSuperClass().getName()) || + "RewriteGradleProject".equals(aClass.getSuperClass().getName()) || + "RewriteSettings".equals(aClass.getSuperClass().getName()))) { sortedByPosition.computeIfAbsent(pos(aClass), i -> new ArrayList<>()).add(aClass); } } @@ -673,10 +673,10 @@ public void visitArgumentlistExpression(ArgumentListExpression expression) { // If the first parameter to a function is a Map, then groovy allows "named parameters" style invocations, see: // https://docs.groovy-lang.org/latest/html/documentation/#_named_parameters_2 // When named parameters are in use they may appear before, after, or intermixed with any positional arguments - if (unparsedArgs.size() > 1 && unparsedArgs.get(0) instanceof MapExpression - && (unparsedArgs.get(0).getLastLineNumber() > unparsedArgs.get(1).getLastLineNumber() - || (unparsedArgs.get(0).getLastLineNumber() == unparsedArgs.get(1).getLastLineNumber() - && unparsedArgs.get(0).getLastColumnNumber() > unparsedArgs.get(1).getLastColumnNumber()))) { + if (unparsedArgs.size() > 1 && unparsedArgs.get(0) instanceof MapExpression && + (unparsedArgs.get(0).getLastLineNumber() > unparsedArgs.get(1).getLastLineNumber() || + (unparsedArgs.get(0).getLastLineNumber() == unparsedArgs.get(1).getLastLineNumber() && + unparsedArgs.get(0).getLastColumnNumber() > unparsedArgs.get(1).getLastColumnNumber()))) { // Figure out the source-code ordering of the expressions MapExpression namedArgExpressions = (MapExpression) unparsedArgs.get(0); @@ -968,9 +968,9 @@ public void visitCatchStatement(CatchStatement node) { Space paramPrefix = whitespace(); // Groovy allows catch variables to omit their type, shorthand for being of type java.lang.Exception // Can't use isSynthetic() here because groovy doesn't record the line number on the Parameter - if ("java.lang.Exception".equals(param.getType().getName()) - && !source.startsWith("Exception", cursor) - && !source.startsWith("java.lang.Exception", cursor)) { + if ("java.lang.Exception".equals(param.getType().getName()) && + !source.startsWith("Exception", cursor) && + !source.startsWith("java.lang.Exception", cursor)) { paramType = new J.Identifier(randomId(), paramPrefix, Markers.EMPTY, emptyList(), "", JavaType.ShallowClass.build("java.lang.Exception"), null); } else { @@ -1016,9 +1016,9 @@ public void visitCaseStatement(CaseStatement statement) { J.Case.Type.Statement, null, JContainer.build(singletonList(JRightPadded.build(visit(statement.getExpression())))), - statement.getCode() instanceof EmptyStatement - ? JContainer.build(sourceBefore(":"), convertStatements(emptyList()), Markers.EMPTY) - : JContainer.build(sourceBefore(":"), convertStatements(((BlockStatement) statement.getCode()).getStatements()), Markers.EMPTY) + statement.getCode() instanceof EmptyStatement ? + JContainer.build(sourceBefore(":"), convertStatements(emptyList()), Markers.EMPTY) : + JContainer.build(sourceBefore(":"), convertStatements(((BlockStatement) statement.getCode()).getStatements()), Markers.EMPTY) , null) ); } @@ -1610,8 +1610,8 @@ public void visitMethodCallExpression(MethodCallExpression call) { MethodNode methodNode = (MethodNode) call.getNodeMetaData().get(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); JavaType.Method methodType = null; - if (methodNode == null && call.getObjectExpression() instanceof VariableExpression - && ((VariableExpression) call.getObjectExpression()).getAccessedVariable() != null) { + if (methodNode == null && call.getObjectExpression() instanceof VariableExpression && + ((VariableExpression) call.getObjectExpression()).getAccessedVariable() != null) { // Groovy doesn't know what kind of object this method is being invoked on // But if this invocation is inside a Closure we may have already enriched its parameters with types from the static type checker // Use any such type information to attempt to find a matching method diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/search/FindAndReplaceLiteral.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/search/FindAndReplaceLiteral.java index 98e7075adf4..08b9f594f4b 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/search/FindAndReplaceLiteral.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/search/FindAndReplaceLiteral.java @@ -43,8 +43,8 @@ public String getDisplayName() { @Override public String getDescription() { - return "Find and replace literal values in HCL files. This recipe parses the source files on which it runs as HCL, " - + "meaning you can execute HCL language-specific recipes before and after this recipe in a single recipe run."; + return "Find and replace literal values in HCL files. This recipe parses the source files on which it runs as HCL, " + + "meaning you can execute HCL language-specific recipes before and after this recipe in a single recipe run."; } @Option(displayName = "Find", description = "The literal to find (and replace)", example = "blacklist") diff --git a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java index 589ba611c16..7c121b539dd 100644 --- a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java +++ b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java @@ -111,8 +111,8 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) - && path.getFileName().toString().equals(baseName); + return kind.equals(getKind()) && + path.getFileName().toString().equals(baseName); } @Override diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java index 100e3763102..75d9a2509f6 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java @@ -331,8 +331,8 @@ public String inferBinaryName(Location location, JavaFileObject file) { public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException { if (StandardLocation.CLASS_PATH.equals(location)) { Iterable listed = super.list(location, packageName, kinds, recurse); - return classByteClasspath.isEmpty() ? listed - : Stream.concat(classByteClasspath.stream() + return classByteClasspath.isEmpty() ? listed : + Stream.concat(classByteClasspath.stream() .filter(jfo -> jfo.getPackage().equals(packageName)), StreamSupport.stream(listed.spliterator(), false) ).collect(toList()); diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java index 6708943d17b..c6bdfa9895e 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java @@ -111,8 +111,8 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) - && path.getFileName().toString().equals(baseName); + return kind.equals(getKind()) && + path.getFileName().toString().equals(baseName); } @Override diff --git a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21Parser.java b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21Parser.java index 2fda7bc1e06..823e2103f10 100644 --- a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21Parser.java +++ b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21Parser.java @@ -331,8 +331,8 @@ public String inferBinaryName(Location location, JavaFileObject file) { public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException { if (StandardLocation.CLASS_PATH.equals(location)) { Iterable listed = super.list(location, packageName, kinds, recurse); - return classByteClasspath.isEmpty() ? listed - : Stream.concat(classByteClasspath.stream() + return classByteClasspath.isEmpty() ? listed : + Stream.concat(classByteClasspath.stream() .filter(jfo -> jfo.getPackage().equals(packageName)), StreamSupport.stream(listed.spliterator(), false) ).collect(toList()); diff --git a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java index 2c7def892da..e2035dfcf71 100644 --- a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java +++ b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java @@ -111,8 +111,8 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) - && path.getFileName().toString().equals(baseName); + return kind.equals(getKind()) && + path.getFileName().toString().equals(baseName); } @Override diff --git a/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java b/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java index 6b8758f165e..a088d1811fc 100644 --- a/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java +++ b/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java @@ -110,8 +110,8 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) - && path.getFileName().toString().equals(baseName); + return kind.equals(getKind()) && + path.getFileName().toString().equals(baseName); } @Override diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java index e1f1186bde5..34c1fb4a23b 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java @@ -136,9 +136,9 @@ void matchNamedParameterMultipleReferences() { spec -> spec.recipe(toRecipe(() -> new JavaVisitor<>() { @Override public J visitBinary(J.Binary binary, ExecutionContext ctx) { - return JavaTemplate.matches("#{i:any(int)} == 1 && #{i} == #{j:any(int)}", getCursor()) - ? SearchResult.found(binary) - : super.visitBinary(binary, ctx); + return JavaTemplate.matches("#{i:any(int)} == 1 && #{i} == #{j:any(int)}", getCursor()) ? + SearchResult.found(binary) : + super.visitBinary(binary, ctx); } })), java( diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest4Test.java b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest4Test.java index 73affde6a62..eda98fda77e 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest4Test.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest4Test.java @@ -62,10 +62,10 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex .as("Changing the method's parameters should have resulted in the first parameter's type being 'int'") .isEqualTo(JavaType.Primitive.Int); assertThat(type.getParameterTypes().get(1)) - .matches(jt -> jt instanceof JavaType.Parameterized - && ((JavaType.Parameterized) jt).getType().getFullyQualifiedName().equals("java.util.List") - && ((JavaType.Parameterized) jt).getTypeParameters().size() == 1 - && TypeUtils.asFullyQualified(((JavaType.Parameterized) jt).getTypeParameters().get(0)).getFullyQualifiedName().equals("java.lang.String"), + .matches(jt -> jt instanceof JavaType.Parameterized && + ((JavaType.Parameterized) jt).getType().getFullyQualifiedName().equals("java.util.List") && + ((JavaType.Parameterized) jt).getTypeParameters().size() == 1 && + TypeUtils.asFullyQualified(((JavaType.Parameterized) jt).getTypeParameters().get(0)).getFullyQualifiedName().equals("java.lang.String"), "Changing the method's parameters should have resulted in the second parameter's type being 'List'" ); assertThat(m.getName().getType()).isEqualTo(type); diff --git a/rewrite-java-test/src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java b/rewrite-java-test/src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java index fd2b66b97ae..6722c2063b9 100644 --- a/rewrite-java-test/src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java +++ b/rewrite-java-test/src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java @@ -210,8 +210,8 @@ public void closeAnalyzer() throws Exception { if (!success && tempFileLocation.exists()) { final String[] l = tempFileLocation.list(); if (l != null && l.length > 0) { - LOGGER.warn("Failed to delete the Archive Analyzer's temporary files from `{}`, " - + "see the log for more details", tempFileLocation.toString()); + LOGGER.warn("Failed to delete the Archive Analyzer's temporary files from `{}`, " + + "see the log for more details", tempFileLocation.toString()); } } } @@ -511,14 +511,14 @@ private void ensureReadableJar(final String archiveExt, BufferedInputStream in) in.mark(7); final byte[] b = new byte[7]; final int read = in.read(b); - if (read == 7 - && b[0] == '#' - && b[1] == '!' - && b[2] == '/' - && b[3] == 'b' - && b[4] == 'i' - && b[5] == 'n' - && b[6] == '/') { + if (read == 7 && + b[0] == '#' && + b[1] == '!' && + b[2] == '/' && + b[3] == 'b' && + b[4] == 'i' && + b[5] == 'n' && + b[6] == '/') { boolean stillLooking = true; int chr; int nxtChr; @@ -646,8 +646,8 @@ private boolean isZipFileActuallyJarFile(Dependency dependency) { ZipFile zip = null; try { zip = new ZipFile(dependency.getActualFilePath()); - if (zip.getEntry("META-INF/MANIFEST.MF") != null - || zip.getEntry("META-INF/maven") != null) { + if (zip.getEntry("META-INF/MANIFEST.MF") != null || + zip.getEntry("META-INF/maven") != null) { final Enumeration entries = zip.getEntries(); while (entries.hasMoreElements()) { final ZipArchiveEntry entry = entries.nextElement(); diff --git a/rewrite-java-test/src/test/resources/dataflow-functional-tests/FileUtils.java b/rewrite-java-test/src/test/resources/dataflow-functional-tests/FileUtils.java index 2976e2f06e4..aae7cb22995 100644 --- a/rewrite-java-test/src/test/resources/dataflow-functional-tests/FileUtils.java +++ b/rewrite-java-test/src/test/resources/dataflow-functional-tests/FileUtils.java @@ -1719,10 +1719,10 @@ public static void forceMkdir(File directory) throws IOException { if (directory.exists()) { if (!directory.isDirectory()) { String message = - "File " - + directory - + " exists and is " - + "not a directory. Unable to create directory."; + "File " + + directory + + " exists and is " + + "not a directory. Unable to create directory."; throw new IOException(message); } } else { @@ -1823,8 +1823,8 @@ public static boolean isFileNewer(File file, File reference) { throw new IllegalArgumentException("No specified reference file"); } if (!reference.exists()) { - throw new IllegalArgumentException("The reference file '" - + reference + "' doesn't exist"); + throw new IllegalArgumentException("The reference file '" + + reference + "' doesn't exist"); } return isFileNewer(file, reference.lastModified()); } @@ -1890,8 +1890,8 @@ public static boolean isFileOlder(File file, File reference) { throw new IllegalArgumentException("No specified reference file"); } if (!reference.exists()) { - throw new IllegalArgumentException("The reference file '" - + reference + "' doesn't exist"); + throw new IllegalArgumentException("The reference file '" + + reference + "' doesn't exist"); } return isFileOlder(file, reference.lastModified()); } diff --git a/rewrite-java-test/src/test/resources/dataflow-functional-tests/GitCommandLineUtils.java b/rewrite-java-test/src/test/resources/dataflow-functional-tests/GitCommandLineUtils.java index 723adc93ffd..858517a7366 100644 --- a/rewrite-java-test/src/test/resources/dataflow-functional-tests/GitCommandLineUtils.java +++ b/rewrite-java-test/src/test/resources/dataflow-functional-tests/GitCommandLineUtils.java @@ -96,8 +96,8 @@ public static void addTarget( Commandline cl, List files ) } catch ( IOException ex ) { - throw new IllegalArgumentException( "Could not get canonical paths for workingDirectory = " - + workingDirectory + " or files=" + files, ex ); + throw new IllegalArgumentException( "Could not get canonical paths for workingDirectory = " + + workingDirectory + " or files=" + files, ex ); } } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java b/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java index d32a50a1ed9..a3996085614 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java @@ -60,8 +60,8 @@ public static SourceFile validateTypes(SourceFile source, TypeValidation typeVal } private static void assertValidTypes(TypeValidation typeValidation, J sf) { - if (typeValidation.identifiers() || typeValidation.methodInvocations() || typeValidation.methodDeclarations() || typeValidation.classDeclarations() - || typeValidation.constructorInvocations()) { + if (typeValidation.identifiers() || typeValidation.methodInvocations() || typeValidation.methodDeclarations() || typeValidation.classDeclarations() || + typeValidation.constructorInvocations()) { List missingTypeResults = FindMissingTypes.findMissingTypes(sf); missingTypeResults = missingTypeResults.stream() .filter(missingType -> { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java b/rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java index 3977032dafa..3a91450d242 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ChangePackage.java @@ -337,9 +337,9 @@ private boolean isTargetFullyQualifiedType(JavaType.@Nullable FullyQualified fq) } private boolean isTargetRecursivePackageName(String packageName) { - return (recursive == null || recursive) - && packageName.startsWith(oldPackageName + ".") - && !packageName.startsWith(newPackageName); + return (recursive == null || recursive) && + packageName.startsWith(oldPackageName + ".") && + !packageName.startsWith(newPackageName); } } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ChangeStaticFieldToMethod.java b/rewrite-java/src/main/java/org/openrewrite/java/ChangeStaticFieldToMethod.java index 7f83e218494..d4c278783cc 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ChangeStaticFieldToMethod.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ChangeStaticFieldToMethod.java @@ -127,8 +127,8 @@ private J useNewMethod(TypeTree tree) { method = (J.MethodInvocation) newArray.getInitializer().get(0); } if (method == null || method.getMethodType() == null) { - throw new IllegalArgumentException("Error while changing a static field to a method. The generated template using a the new class [" - + newClass + "] and the method [" + newMethodName + "] resulted in a null method type."); + throw new IllegalArgumentException("Error while changing a static field to a method. The generated template using a the new class [" + + newClass + "] and the method [" + newMethodName + "] resulted in a null method type."); } if (tree.getType() != null) { JavaType.Method mt = method.getMethodType().withReturnType(tree.getType()); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ImplementInterface.java b/rewrite-java/src/main/java/org/openrewrite/java/ImplementInterface.java index 4423eea4bb9..7400a7814da 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ImplementInterface.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ImplementInterface.java @@ -40,8 +40,8 @@ public ImplementInterface(J.ClassDeclaration scope, JavaType.FullyQualified inte public ImplementInterface(J.ClassDeclaration scope, String interface_, @Nullable List typeParameters) { this(scope, ListUtils.nullIfEmpty(typeParameters) != null ? - new JavaType.Parameterized(null, JavaType.ShallowClass.build(interface_), typeParameters.stream().map(Expression::getType).collect(Collectors.toList())) - : JavaType.ShallowClass.build(interface_), + new JavaType.Parameterized(null, JavaType.ShallowClass.build(interface_), typeParameters.stream().map(Expression::getType).collect(Collectors.toList())) : + JavaType.ShallowClass.build(interface_), typeParameters ); } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java index d65f98c917a..41a1b56b905 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java @@ -252,8 +252,8 @@ public boolean matches(J.MethodDeclaration method, J.ClassDeclaration enclosing) // aspectJUtils does not support matching classes separated by packages. // [^.]* is the product of a fully wild card match for a method. `* foo()` - boolean matchesTargetType = (targetTypePattern != null && "[^.]*".equals(targetTypePattern.pattern())) - || matchesTargetType(enclosing.getType()); + boolean matchesTargetType = (targetTypePattern != null && "[^.]*".equals(targetTypePattern.pattern())) || + matchesTargetType(enclosing.getType()); if (!matchesTargetType) { return false; } @@ -279,8 +279,8 @@ public boolean matches(J.MethodDeclaration method, J.NewClass enclosing) { // aspectJUtils does not support matching classes separated by packages. // [^.]* is the product of a fully wild card match for a method. `* foo()` - boolean matchesTargetType = (targetTypePattern != null && "[^.]*".equals(targetTypePattern.pattern())) - || TypeUtils.isAssignableTo(targetType, enclosing.getType()); + boolean matchesTargetType = (targetTypePattern != null && "[^.]*".equals(targetTypePattern.pattern())) || + TypeUtils.isAssignableTo(targetType, enclosing.getType()); if (!matchesTargetType) { return false; } @@ -337,9 +337,9 @@ private boolean matchesAllowingUnknownTypes(J.MethodInvocation method) { return false; } - if (method.getSelect() != null - && method.getSelect() instanceof J.Identifier - && !matchesSelectBySimpleNameAlone(((J.Identifier) method.getSelect()))) { + if (method.getSelect() != null && + method.getSelect() instanceof J.Identifier && + !matchesSelectBySimpleNameAlone(((J.Identifier) method.getSelect()))) { return false; } @@ -366,9 +366,9 @@ private String argumentsFromExpressionTypes(J.MethodInvocation method) { StringJoiner joiner = new StringJoiner(","); for (Expression expr : method.getArguments()) { final JavaType exprType = expr.getType(); - String s = exprType == null - ? JavaType.Unknown.getInstance().getFullyQualifiedName() - : typePattern(exprType); + String s = exprType == null ? + JavaType.Unknown.getInstance().getFullyQualifiedName() : + typePattern(exprType); joiner.add(s); } return joiner.toString(); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/QualifyThisVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/QualifyThisVisitor.java index 4adcda701af..3ccb7c0eeba 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/QualifyThisVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/QualifyThisVisitor.java @@ -29,9 +29,9 @@ public class QualifyThisVisitor extends JavaVisitor { @Override public J visitIdentifier(J.Identifier ident, ExecutionContext executionContext) { - if (ident.getSimpleName().equals("this") - && !isAlreadyQualified(ident) - && ident.getType() instanceof JavaType.Class) { + if (ident.getSimpleName().equals("this") && + !isAlreadyQualified(ident) && + ident.getType() instanceof JavaType.Class) { JavaType.Class type = (JavaType.Class) ident.getType(); return new J.FieldAccess( Tree.randomId(), diff --git a/rewrite-java/src/main/java/org/openrewrite/java/RemoveImport.java b/rewrite-java/src/main/java/org/openrewrite/java/RemoveImport.java index b0a33af0dfc..22787f86897 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/RemoveImport.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/RemoveImport.java @@ -75,8 +75,8 @@ public RemoveImport(String type, boolean force) { for (JavaType.Variable variable : cu.getTypesInUse().getVariables()) { JavaType.FullyQualified fq = TypeUtils.asFullyQualified(variable.getOwner()); - if (fq != null && (TypeUtils.fullyQualifiedNamesAreEqual(fq.getFullyQualifiedName(), type) - || TypeUtils.fullyQualifiedNamesAreEqual(fq.getFullyQualifiedName(), owner))) { + if (fq != null && (TypeUtils.fullyQualifiedNamesAreEqual(fq.getFullyQualifiedName(), type) || + TypeUtils.fullyQualifiedNamesAreEqual(fq.getFullyQualifiedName(), owner))) { methodsAndFieldsUsed.add(variable.getName()); } } @@ -101,8 +101,8 @@ public RemoveImport(String type, boolean force) { JavaType.FullyQualified fullyQualified = (JavaType.FullyQualified) javaType; if (TypeUtils.fullyQualifiedNamesAreEqual(fullyQualified.getFullyQualifiedName(), type)) { typeUsed = true; - } else if (TypeUtils.fullyQualifiedNamesAreEqual(fullyQualified.getFullyQualifiedName(), owner) - || TypeUtils.fullyQualifiedNamesAreEqual(fullyQualified.getPackageName(), owner)) { + } else if (TypeUtils.fullyQualifiedNamesAreEqual(fullyQualified.getFullyQualifiedName(), owner) || + TypeUtils.fullyQualifiedNamesAreEqual(fullyQualified.getPackageName(), owner)) { if (!originalImports.contains(fullyQualified.getFullyQualifiedName().replace("$", "."))) { otherTypesInPackageUsed.add(fullyQualified.getClassName()); } @@ -132,8 +132,8 @@ public RemoveImport(String type, boolean force) { // e.g. remove java.util.Collections.emptySet when type is java.util.Collections.emptySet spaceForNextImport.set(import_.getPrefix()); return null; - } else if ("*".equals(imported) && (TypeUtils.fullyQualifiedNamesAreEqual(typeName, type) - || TypeUtils.fullyQualifiedNamesAreEqual(typeName + type.substring(type.lastIndexOf('.')), type))) { + } else if ("*".equals(imported) && (TypeUtils.fullyQualifiedNamesAreEqual(typeName, type) || + TypeUtils.fullyQualifiedNamesAreEqual(typeName + type.substring(type.lastIndexOf('.')), type))) { if (methodsAndFieldsUsed.isEmpty() && otherMethodsAndFieldsInTypeUsed.isEmpty()) { spaceForNextImport.set(import_.getPrefix()); return null; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/ShortenFullyQualifiedTypeReferences.java b/rewrite-java/src/main/java/org/openrewrite/java/ShortenFullyQualifiedTypeReferences.java index a765e31e9d8..9d393883520 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/ShortenFullyQualifiedTypeReferences.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/ShortenFullyQualifiedTypeReferences.java @@ -44,9 +44,9 @@ public String getDisplayName() { @Override public String getDescription() { - return "Any fully qualified references to Java types will be replaced with corresponding simple " - + "names and import statements, provided that it doesn't result in " - + "any conflicts with other imports or types declared in the local compilation unit."; + return "Any fully qualified references to Java types will be replaced with corresponding simple " + + "names and import statements, provided that it doesn't result in " + + "any conflicts with other imports or types declared in the local compilation unit."; } @Override diff --git a/rewrite-java/src/main/java/org/openrewrite/java/TreeVisitingPrinter.java b/rewrite-java/src/main/java/org/openrewrite/java/TreeVisitingPrinter.java index 1ec21a30afe..7c442b1004e 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/TreeVisitingPrinter.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/TreeVisitingPrinter.java @@ -269,9 +269,9 @@ private static String printComments(List comments) { } // print current visiting element - String typeName = tree instanceof J - ? tree.getClass().getCanonicalName().substring(tree.getClass().getPackage().getName().length() + 1) - : tree.getClass().getCanonicalName(); + String typeName = tree instanceof J ? + tree.getClass().getCanonicalName().substring(tree.getClass().getPackage().getName().length() + 1) : + tree.getClass().getCanonicalName(); if (skipUnvisitedElement) { boolean leftPadded = diffPos >= 0; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitor.java index 50808128be1..7934d78b055 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/cleanup/SimplifyBooleanExpressionVisitor.java @@ -231,9 +231,9 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu J j = super.visitMethodInvocation(method, executionContext); J.MethodInvocation asMethod = (J.MethodInvocation) j; Expression select = asMethod.getSelect(); - if (isEmpty.matches(asMethod) - && select instanceof J.Literal - && select.getType() == JavaType.Primitive.String) { + if (isEmpty.matches(asMethod) && + select instanceof J.Literal && + select.getType() == JavaType.Primitive.String) { return booleanLiteral(method, J.Literal.isLiteralValue(select, "")); } return j; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java index 92ce7c4fb03..3be2c6e2b0b 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java @@ -222,9 +222,9 @@ protected void contextFreeTemplate(Cursor cursor, J j, StringBuilder before, Str before.insert(0, "class Template {\n"); before.append("Object o = "); after.append(";\n}"); - } else if ((j instanceof J.MethodDeclaration || j instanceof J.VariableDeclarations || j instanceof J.Block || j instanceof J.ClassDeclaration) - && cursor.getValue() instanceof J.Block - && (cursor.getParent().getValue() instanceof J.ClassDeclaration || cursor.getParent().getValue() instanceof J.NewClass)) { + } else if ((j instanceof J.MethodDeclaration || j instanceof J.VariableDeclarations || j instanceof J.Block || j instanceof J.ClassDeclaration) && + cursor.getValue() instanceof J.Block && + (cursor.getParent().getValue() instanceof J.ClassDeclaration || cursor.getParent().getValue() instanceof J.NewClass)) { before.insert(0, "class Template {\n"); after.append("\n}"); } else if (j instanceof J.ClassDeclaration) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/PatternVariables.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/PatternVariables.java index 96ffa084fec..806ca787725 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/PatternVariables.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/PatternVariables.java @@ -197,12 +197,12 @@ private static boolean neverCompletesNormally0(@Nullable Statement statement, Se return true; } else if (statement instanceof J.Break) { J.Break breakStatement = (J.Break) statement; - return breakStatement.getLabel() != null && !labelsToIgnore.contains(breakStatement.getLabel().getSimpleName()) - || breakStatement.getLabel() == null && !labelsToIgnore.contains(DEFAULT_LABEL); + return breakStatement.getLabel() != null && !labelsToIgnore.contains(breakStatement.getLabel().getSimpleName()) || + breakStatement.getLabel() == null && !labelsToIgnore.contains(DEFAULT_LABEL); } else if (statement instanceof J.Continue) { J.Continue continueStatement = (J.Continue) statement; - return continueStatement.getLabel() != null && !labelsToIgnore.contains(continueStatement.getLabel().getSimpleName()) - || continueStatement.getLabel() == null && !labelsToIgnore.contains(DEFAULT_LABEL); + return continueStatement.getLabel() != null && !labelsToIgnore.contains(continueStatement.getLabel().getSimpleName()) || + continueStatement.getLabel() == null && !labelsToIgnore.contains(DEFAULT_LABEL); } else if (statement instanceof J.Block) { return neverCompletesNormally0(getLastStatement(statement), labelsToIgnore); } else if (statement instanceof Loop) { @@ -210,9 +210,9 @@ private static boolean neverCompletesNormally0(@Nullable Statement statement, Se return neverCompletesNormallyIgnoringLabel(loop.getBody(), DEFAULT_LABEL, labelsToIgnore); } else if (statement instanceof J.If) { J.If if_ = (J.If) statement; - return if_.getElsePart() != null - && neverCompletesNormally0(if_.getThenPart(), labelsToIgnore) - && neverCompletesNormally0(if_.getElsePart().getBody(), labelsToIgnore); + return if_.getElsePart() != null && + neverCompletesNormally0(if_.getThenPart(), labelsToIgnore) && + neverCompletesNormally0(if_.getElsePart().getBody(), labelsToIgnore); } else if (statement instanceof J.Switch) { J.Switch switch_ = (J.Switch) statement; if (switch_.getCases().getStatements().isEmpty()) { @@ -240,13 +240,13 @@ && neverCompletesNormally0(if_.getThenPart(), labelsToIgnore) return neverCompletesNormally0(getLastStatement(case_), labelsToIgnore); } else if (statement instanceof J.Try) { J.Try try_ = (J.Try) statement; - if (try_.getFinally() != null && !try_.getFinally().getStatements().isEmpty() - && neverCompletesNormally0(try_.getFinally(), labelsToIgnore)) { + if (try_.getFinally() != null && !try_.getFinally().getStatements().isEmpty() && + neverCompletesNormally0(try_.getFinally(), labelsToIgnore)) { return true; } boolean bodyHasExit = false; - if (!try_.getBody().getStatements().isEmpty() - && !(bodyHasExit = neverCompletesNormally0(try_.getBody(), labelsToIgnore))) { + if (!try_.getBody().getStatements().isEmpty() && + !(bodyHasExit = neverCompletesNormally0(try_.getBody(), labelsToIgnore))) { return false; } for (J.Try.Catch catch_ : try_.getCatches()) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java index 278e639c6a8..bb6c4cf4d3c 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java @@ -133,8 +133,8 @@ private String substituteTypedPattern(String key, int index, TemplateParameterPa if (param != null) { type = TypeParameter.toFullyQualifiedName(param); } else { - if (parameter instanceof J.NewClass && ((J.NewClass) parameter).getBody() != null - && ((J.NewClass) parameter).getClazz() != null) { + if (parameter instanceof J.NewClass && ((J.NewClass) parameter).getBody() != null && + ((J.NewClass) parameter).getClazz() != null) { // for anonymous classes get the type from the supertype type = ((J.NewClass) parameter).getClazz().getType(); } else if (parameter instanceof TypedTree) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/recipes/SourceSpecTextBlockIndentation.java b/rewrite-java/src/main/java/org/openrewrite/java/recipes/SourceSpecTextBlockIndentation.java index e9da6507a30..bc943d87670 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/recipes/SourceSpecTextBlockIndentation.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/recipes/SourceSpecTextBlockIndentation.java @@ -100,8 +100,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } J.Literal withFixedSource = source.withValueSource(fixedSource.toString()); - if (withFixedSource.getPrefix().getComments().isEmpty() - && withFixedSource.getPrefix().getWhitespace().isEmpty()) { + if (withFixedSource.getPrefix().getComments().isEmpty() && + withFixedSource.getPrefix().getWhitespace().isEmpty()) { return maybeAutoFormat(withFixedSource, withFixedSource.withPrefix(Space.format("\n")), ctx); } return withFixedSource; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyMethods.java b/rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyMethods.java index 46e4065a08d..02d2bccacb1 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyMethods.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyMethods.java @@ -95,9 +95,9 @@ private boolean isEmptyMethod(J.MethodDeclaration method) { private boolean isInterfaceMethod(J.MethodDeclaration method) { //noinspection ConstantConditions - return method.getMethodType().getDeclaringType() != null - && method.getMethodType().getDeclaringType().getKind() == JavaType.FullyQualified.Kind.Interface - && !method.hasModifier(J.Modifier.Type.Default); + return method.getMethodType().getDeclaringType() != null && + method.getMethodType().getDeclaringType().getKind() == JavaType.FullyQualified.Kind.Interface && + !method.hasModifier(J.Modifier.Type.Default); } private boolean hasSinglePublicNoArgsConstructor(List classStatements) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/FindMethods.java b/rewrite-java/src/main/java/org/openrewrite/java/search/FindMethods.java index 5eb4d09bd18..f5815c5ed82 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/FindMethods.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/FindMethods.java @@ -75,8 +75,8 @@ public TreeVisitor getVisitor() { public J.Identifier visitIdentifier(J.Identifier identifier, ExecutionContext ctx) { // In an annotation @Example(value = "") the identifier "value" may have a method type J.Identifier i = super.visitIdentifier(identifier, ctx); - if(i.getType() instanceof JavaType.Method && methodMatcher.matches((JavaType.Method) i.getType()) - && !(getCursor().getParentTreeCursor().getValue() instanceof J.MethodInvocation)) { + if(i.getType() instanceof JavaType.Method && methodMatcher.matches((JavaType.Method) i.getType()) && + !(getCursor().getParentTreeCursor().getValue() instanceof J.MethodInvocation)) { JavaType.Method m = (JavaType.Method) i.getType(); JavaSourceFile javaSourceFile = getCursor().firstEnclosing(JavaSourceFile.class); if(javaSourceFile != null) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/FindMissingTypes.java b/rewrite-java/src/main/java/org/openrewrite/java/search/FindMissingTypes.java index 10fe01d333c..036e98ef66a 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/FindMissingTypes.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/FindMissingTypes.java @@ -231,10 +231,10 @@ public J.ParameterizedType visitParameterizedType(J.ParameterizedType type, Exec } private boolean isAllowedToHaveNullType(J.Identifier ident) { - return inPackageDeclaration() || inImport() || isClassName() - || isMethodName() || isMethodInvocationName() || isFieldAccess(ident) || isBeingDeclared(ident) || isParameterizedType(ident) - || isNewClass(ident) || isTypeParameter() || isMemberReference(ident) || isCaseLabel() || isLabel() || isAnnotationField(ident) - || isInJavaDoc(ident); + return inPackageDeclaration() || inImport() || isClassName() || + isMethodName() || isMethodInvocationName() || isFieldAccess(ident) || isBeingDeclared(ident) || isParameterizedType(ident) || + isNewClass(ident) || isTypeParameter() || isMemberReference(ident) || isCaseLabel() || isLabel() || isAnnotationField(ident) || + isInJavaDoc(ident); } private boolean inPackageDeclaration() { @@ -262,8 +262,8 @@ private boolean isMethodInvocationName() { private boolean isFieldAccess(J.Identifier ident) { Tree value = getCursor().getParentTreeCursor().getValue(); - return value instanceof J.FieldAccess - && (ident == ((J.FieldAccess) value).getName() || + return value instanceof J.FieldAccess && + (ident == ((J.FieldAccess) value).getName() || ident == ((J.FieldAccess) value).getTarget() && !((J.FieldAccess) value).getSimpleName().equals("class")); } @@ -283,8 +283,8 @@ private boolean isNewClass(J.Identifier ident) { } private boolean isTypeParameter() { - return getCursor().getParent() != null - && getCursor().getParent().getValue() instanceof J.TypeParameter; + return getCursor().getParent() != null && + getCursor().getParent().getValue() instanceof J.TypeParameter; } private boolean isMemberReference(J.Identifier ident) { @@ -309,8 +309,8 @@ private boolean isLabel() { private boolean isAnnotationField(J.Identifier ident) { Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.Assignment - && (ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null); + return parent != null && parent.getValue() instanceof J.Assignment && + (ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null); } } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/SemanticallyEqual.java b/rewrite-java/src/main/java/org/openrewrite/java/search/SemanticallyEqual.java index 7513f29024d..b6bbcdce598 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/SemanticallyEqual.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/SemanticallyEqual.java @@ -616,8 +616,8 @@ public J.FieldAccess visitFieldAccess(J.FieldAccess fieldAccess, J j) { isEqual.set(false); return fieldAccess; } - } else if (!TypeUtils.isOfType(fieldAccess.getType(), compareTo.getType()) - || !TypeUtils.isOfType(fieldType, compareTo.getName().getFieldType())) { + } else if (!TypeUtils.isOfType(fieldAccess.getType(), compareTo.getType()) || + !TypeUtils.isOfType(fieldType, compareTo.getName().getFieldType())) { isEqual.set(false); return fieldAccess; } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/UsesType.java b/rewrite-java/src/main/java/org/openrewrite/java/search/UsesType.java index 6b5237e6697..34eac9f1058 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/UsesType.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/UsesType.java @@ -114,8 +114,8 @@ private JavaSourceFile maybeMark(JavaSourceFile c, @Nullable JavaType type) { return c; } - if (typePattern != null && TypeUtils.isAssignableTo(typePattern, type) - || fullyQualifiedType != null && TypeUtils.isAssignableTo(fullyQualifiedType, type)) { + if (typePattern != null && TypeUtils.isAssignableTo(typePattern, type) || + fullyQualifiedType != null && TypeUtils.isAssignableTo(fullyQualifiedType, type)) { return SearchResult.found(c); } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java b/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java index c0cf10fe56e..72573ead397 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java @@ -421,8 +421,8 @@ public Expression visitExpression(Expression expression, IndentStatistics stats) // (newline-separated) annotations on some common target are not continuations boolean isContinuation = !(expression instanceof J.Annotation && !( // ...but annotations which are *arguments* to other annotations can be continuations - getCursor().getParentTreeCursor().getValue() instanceof J.Annotation - || getCursor().getParentTreeCursor().getValue() instanceof J.NewArray + getCursor().getParentTreeCursor().getValue() instanceof J.Annotation || + getCursor().getParentTreeCursor().getValue() instanceof J.NewArray )); countIndents(expression.getPrefix().getWhitespace(), isContinuation, stats); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/style/CheckstyleConfigLoader.java b/rewrite-java/src/main/java/org/openrewrite/java/style/CheckstyleConfigLoader.java index 1d0b058b778..33065e80fe4 100755 --- a/rewrite-java/src/main/java/org/openrewrite/java/style/CheckstyleConfigLoader.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/style/CheckstyleConfigLoader.java @@ -551,8 +551,8 @@ public String getName() { } public boolean prop(String key, boolean defaultValue) { - return properties.containsKey(key) ? parseBoolean(properties.get(key)) - : defaultValue; + return properties.containsKey(key) ? parseBoolean(properties.get(key)) : + defaultValue; } @Override diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java index c8aa15fafa1..6b57a6bab86 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java @@ -5898,16 +5898,16 @@ public

J acceptJava(JavaVisitor

v, P p) { public Cursor getDeclaringScope(Cursor cursor) { return cursor.dropParentUntil(it -> - it instanceof J.Block - || it instanceof J.Lambda - || it instanceof J.MethodDeclaration - || it == Cursor.ROOT_VALUE); + it instanceof J.Block || + it instanceof J.Lambda || + it instanceof J.MethodDeclaration || + it == Cursor.ROOT_VALUE); } public boolean isField(Cursor cursor) { Cursor declaringScope = getDeclaringScope(cursor); - return declaringScope.getValue() instanceof J.Block - && declaringScope.getParentTreeCursor().getValue() instanceof J.ClassDeclaration; + return declaringScope.getValue() instanceof J.Block && + declaringScope.getParentTreeCursor().getValue() instanceof J.ClassDeclaration; } public Padding getPadding() { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java index 9ea02a41a1a..c4b432f87c5 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java @@ -326,8 +326,8 @@ public String getPackageName() { public boolean isAssignableTo(String fullyQualifiedName) { return TypeUtils.fullyQualifiedNamesAreEqual(getFullyQualifiedName(), fullyQualifiedName) || - getInterfaces().stream().anyMatch(anInterface -> anInterface.isAssignableTo(fullyQualifiedName)) - || (getSupertype() != null && getSupertype().isAssignableTo(fullyQualifiedName)); + getInterfaces().stream().anyMatch(anInterface -> anInterface.isAssignableTo(fullyQualifiedName)) || + (getSupertype() != null && getSupertype().isAssignableTo(fullyQualifiedName)); } public boolean isAssignableFrom(@Nullable JavaType type) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java index 117869d2f87..789c1bea8fe 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java @@ -89,8 +89,8 @@ public static String toFullyQualifiedName(String fqn) { public static boolean fullyQualifiedNamesAreEqual(@Nullable String fqn1, @Nullable String fqn2) { if (fqn1 != null && fqn2 != null) { - return fqn1.equals(fqn2) || fqn1.length() == fqn2.length() - && toFullyQualifiedName(fqn1).equals(toFullyQualifiedName(fqn2)); + return fqn1.equals(fqn2) || fqn1.length() == fqn2.length() && + toFullyQualifiedName(fqn1).equals(toFullyQualifiedName(fqn2)); } return fqn1 == null && fqn2 == null; } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddDependency.java index 3688a54111a..c8257bc8752 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddDependency.java @@ -218,8 +218,8 @@ public Xml visitDocument(Xml.Document document, ExecutionContext ctx) { // If the dependency is already in compile scope it will be available everywhere, no need to continue for (ResolvedDependency d : getResolutionResult().getDependencies().get(Scope.Compile)) { - if (hasAcceptableTransitivity(d, acc) - && groupId.equals(d.getGroupId()) && artifactId.equals(d.getArtifactId())) { + if (hasAcceptableTransitivity(d, acc) && + groupId.equals(d.getGroupId()) && artifactId.equals(d.getArtifactId())) { return maven; } } @@ -228,8 +228,8 @@ public Xml visitDocument(Xml.Document document, ExecutionContext ctx) { Scope resolvedScopeEnum = Scope.fromName(resolvedScope); if (resolvedScopeEnum == Scope.Provided || resolvedScopeEnum == Scope.Test) { for (ResolvedDependency d : getResolutionResult().getDependencies().get(resolvedScopeEnum)) { - if (hasAcceptableTransitivity(d, acc) - && groupId.equals(d.getGroupId()) && artifactId.equals(d.getArtifactId())) { + if (hasAcceptableTransitivity(d, acc) && + groupId.equals(d.getGroupId()) && artifactId.equals(d.getArtifactId())) { return maven; } } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java index f07b1f64752..10c49757fbb 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddManagedDependency.java @@ -238,9 +238,9 @@ public Xml visitDocument(Xml.Document document, ExecutionContext ctx) { .map(resolvedManagedDep -> { if (resolvedManagedDep.matches(groupId, artifactId, type, classifier)) { return resolvedManagedDep.getGav().getVersion(); - } else if (resolvedManagedDep.getRequestedBom() != null - && resolvedManagedDep.getRequestedBom().getGroupId().equals(groupId) - && resolvedManagedDep.getRequestedBom().getArtifactId().equals(artifactId)) { + } else if (resolvedManagedDep.getRequestedBom() != null && + resolvedManagedDep.getRequestedBom().getGroupId().equals(groupId) && + resolvedManagedDep.getRequestedBom().getArtifactId().equals(artifactId)) { return resolvedManagedDep.getRequestedBom().getVersion(); } return null; diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddPluginDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddPluginDependency.java index d224d282d16..dc6b15b2f3a 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddPluginDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddPluginDependency.java @@ -104,15 +104,15 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) { dependencies = Xml.Tag.build("").withPrefix("\n"); plugins = addToTag(plugins, plugin, dependencies, getCursor().getParentOrThrow()); } - Xml.Tag newDependencyTag = Xml.Tag.build("\n" + groupId + "\n" - + artifactId + "" + ((version == null) ? "\n" : "\n" + version + "\n") + "") + Xml.Tag newDependencyTag = Xml.Tag.build("\n" + groupId + "\n" + + artifactId + "" + ((version == null) ? "\n" : "\n" + version + "\n") + "") .withPrefix("\n"); // The dependency being added may already exist and may or may not need its version updated Optional maybeExistingDependency = dependencies.getChildren() .stream() - .filter(it -> groupId.equals(it.getChildValue("groupId").orElse(null)) - && artifactId.equals(it.getChildValue("artifactId").orElse(null))) + .filter(it -> groupId.equals(it.getChildValue("groupId").orElse(null)) && + artifactId.equals(it.getChildValue("artifactId").orElse(null))) .findAny(); if (maybeExistingDependency.isPresent() && areEqual(newDependencyTag, maybeExistingDependency.get())) { return plugins; diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddProperty.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddProperty.java index aa88e23ec83..fa4ce4e218d 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddProperty.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddProperty.java @@ -76,8 +76,8 @@ public TreeVisitor getVisitor() { @Override public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { String parentValue = getResolutionResult().getPom().getRequested().getProperties().get(key); - if ((Boolean.TRUE.equals(trustParent) && (parentValue == null || value.equals(parentValue))) - || value.equals(getResolutionResult().getPom().getProperties().get(key))) { + if ((Boolean.TRUE.equals(trustParent) && (parentValue == null || value.equals(parentValue))) || + value.equals(getResolutionResult().getPom().getProperties().get(key))) { return document; } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddPropertyVisitor.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddPropertyVisitor.java index c4c9c842d84..b444d5f1ef9 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddPropertyVisitor.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddPropertyVisitor.java @@ -54,9 +54,9 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { @Override public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { - if (!Boolean.TRUE.equals(preserveExistingValue) - && isPropertyTag() && key.equals(tag.getName()) - && !value.equals(tag.getValue().orElse(null))) { + if (!Boolean.TRUE.equals(preserveExistingValue) && + isPropertyTag() && key.equals(tag.getName()) && + !value.equals(tag.getValue().orElse(null))) { doAfterVisit(new ChangeTagValueVisitor<>(tag, value)); } return super.visitTag(tag, ctx); diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddRepository.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddRepository.java index 2c8011df374..e42ac01d111 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddRepository.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddRepository.java @@ -267,9 +267,9 @@ private boolean isReleasesEqual(Xml.Tag repo) { if (releases == null) { return isNoReleases(); } else { - return Objects.equals(releasesEnabled == null ? null : String.valueOf(releasesEnabled.booleanValue()), releases.getChildValue("enabled").orElse(null)) - && Objects.equals(releasesUpdatePolicy, releases.getChildValue("updatePolicy").orElse(null)) - && Objects.equals(releasesChecksumPolicy, releases.getChildValue("checksumPolicy").orElse(null)); + return Objects.equals(releasesEnabled == null ? null : String.valueOf(releasesEnabled.booleanValue()), releases.getChildValue("enabled").orElse(null)) && + Objects.equals(releasesUpdatePolicy, releases.getChildValue("updatePolicy").orElse(null)) && + Objects.equals(releasesChecksumPolicy, releases.getChildValue("checksumPolicy").orElse(null)); } } @@ -282,9 +282,9 @@ private boolean isSnapshotsEqual(Xml.Tag repo) { if (snapshots == null) { return isNoSnapshots(); } else { - return Objects.equals(snapshotsEnabled == null ? null : String.valueOf(snapshotsEnabled.booleanValue()), snapshots.getChildValue("enabled").orElse(null)) - && Objects.equals(snapshotsUpdatePolicy, snapshots.getChildValue("updatePolicy").orElse(null)) - && Objects.equals(snapshotsChecksumPolicy, snapshots.getChildValue("checksumPolicy").orElse(null)); + return Objects.equals(snapshotsEnabled == null ? null : String.valueOf(snapshotsEnabled.booleanValue()), snapshots.getChildValue("enabled").orElse(null)) && + Objects.equals(snapshotsUpdatePolicy, snapshots.getChildValue("updatePolicy").orElse(null)) && + Objects.equals(snapshotsChecksumPolicy, snapshots.getChildValue("checksumPolicy").orElse(null)); } } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java index d58d187a4dc..b5e517c0ced 100755 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java @@ -309,8 +309,8 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { } private boolean isGlobalProperty(String propertyName) { - return propertyName.startsWith("project.") || propertyName.startsWith("env.") - || propertyName.startsWith("settings.") || propertyName.equals("basedir"); + return propertyName.startsWith("project.") || propertyName.startsWith("env.") || + propertyName.startsWith("settings.") || propertyName.equals("basedir"); } }.visit(pomXml, ctx); return properties; @@ -384,8 +384,8 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { @Override public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Xml.Tag t = super.visitTag(tag, ctx); - if (isPropertyTag() && key.equals(tag.getName()) - && !value.equals(tag.getValue().orElse(null))) { + if (isPropertyTag() && key.equals(tag.getName()) && + !value.equals(tag.getValue().orElse(null))) { t = (Xml.Tag) new ChangeTagValueVisitor<>(tag, value).visitNonNull(t, ctx); } return t; diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java b/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java index c5028ac981d..df6b9fa3c8d 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java @@ -165,8 +165,8 @@ public TreeVisitor getVisitor(Map ac public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Xml.Tag t = super.visitTag(tag, ctx); - if ((!(PROJECT_MATCHER.matches(getCursor()) || PARENT_MATCHER.matches(getCursor()))) - || t.getMarkers().findFirst(AlreadyIncremented.class).isPresent()) { + if ((!(PROJECT_MATCHER.matches(getCursor()) || PARENT_MATCHER.matches(getCursor()))) || + t.getMarkers().findFirst(AlreadyIncremented.class).isPresent()) { return t; } String newVersion = acc.get(new GroupArtifact( diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java index 559586b65b1..342e08ddb04 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenVisitor.java @@ -201,8 +201,8 @@ public boolean isManagedDependencyImportTag(String groupId, String artifactId) { return false; } Xml.Tag tag = getCursor().getValue(); - return tag.getChildValue("type").map("pom"::equalsIgnoreCase).orElse(false) - && tag.getChildValue("scope").map("import"::equalsIgnoreCase).orElse(false); + return tag.getChildValue("type").map("pom"::equalsIgnoreCase).orElse(false) && + tag.getChildValue("scope").map("import"::equalsIgnoreCase).orElse(false); } public void maybeUpdateModel() { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemovePluginDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemovePluginDependency.java index 258314db4f0..b8d76551955 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemovePluginDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemovePluginDependency.java @@ -100,8 +100,8 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { } Xml.Tag dependencies = maybeDependencies.get(); plugins = filterTagChildren(plugins, dependencies, dependencyTag -> - !(childValueMatches(dependencyTag, "groupId", groupId) - && childValueMatches(dependencyTag, "artifactId", artifactId)) + !(childValueMatches(dependencyTag, "groupId", groupId) && + childValueMatches(dependencyTag, "artifactId", artifactId)) ); plugins = filterTagChildren(plugins, plugin, pluginChildTag -> !(pluginChildTag.getName().equals("dependencies") && pluginChildTag.getChildren().isEmpty())); diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java index 4f4f8df299e..f3f16dd54fe 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java @@ -74,8 +74,8 @@ public class RemoveRedundantDependencyVersions extends Recipe { Comparator onlyIfManagedVersionIs; @Option(displayName = "Except", - description = "Accepts a list of GAVs. Dependencies matching a GAV will be ignored by this recipe." - + " GAV versions are ignored if provided.", + description = "Accepts a list of GAVs. Dependencies matching a GAV will be ignored by this recipe." + + " GAV versions are ignored if provided.", example = "com.jcraft:jsch", required = false) @Nullable diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/UpdateMavenWrapper.java b/rewrite-maven/src/main/java/org/openrewrite/maven/UpdateMavenWrapper.java index 759f79feef0..9a9d0dec924 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/UpdateMavenWrapper.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/UpdateMavenWrapper.java @@ -494,8 +494,8 @@ public Properties.Entry visitEntry(Properties.Entry entry, ExecutionContext ctx) return null; } } else if (WRAPPER_SHA_256_SUM_KEY.equals(entry.getKey())) { - if (mavenWrapper.getWrapperDistributionType() != DistributionType.OnlyScript - && Boolean.TRUE.equals(enforceWrapperChecksumVerification)) { + if (mavenWrapper.getWrapperDistributionType() != DistributionType.OnlyScript && + Boolean.TRUE.equals(enforceWrapperChecksumVerification)) { Properties.Value value = entry.getValue(); Checksum wrapperJarChecksum = mavenWrapper.getWrapperChecksum(); if (wrapperJarChecksum != null && !wrapperJarChecksum.getHexValue().equals(value.getText())) { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java b/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java index 574a1422661..2fa42d3482a 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java @@ -91,9 +91,9 @@ public class UpgradeDependencyVersion extends ScanningRecipe incomingRequestedDepend for (Dependency incReqDep : incomingRequestedDependencies) { boolean found = false; for (Dependency reqDep : requestedDependencies) { - if (reqDep.getGav().getGroupId().equals(incReqDep.getGav().getGroupId()) - && reqDep.getArtifactId().equals(incReqDep.getArtifactId())) { + if (reqDep.getGav().getGroupId().equals(incReqDep.getGav().getGroupId()) && + reqDep.getArtifactId().equals(incReqDep.getArtifactId())) { found = true; break; } @@ -831,9 +831,9 @@ private boolean isAlreadyResolved(GroupArtifactVersion groupArtifactVersion, Lis for (int i = 1; i < pomAncestry.size(); i++) { // skip current pom Pom pom = pomAncestry.get(i); ResolvedGroupArtifactVersion alreadyResolvedGav = pom.getGav(); - if (alreadyResolvedGav.getGroupId().equals(groupArtifactVersion.getGroupId()) - && alreadyResolvedGav.getArtifactId().equals(groupArtifactVersion.getArtifactId()) - && alreadyResolvedGav.getVersion().equals(groupArtifactVersion.getVersion())) { + if (alreadyResolvedGav.getGroupId().equals(groupArtifactVersion.getGroupId()) && + alreadyResolvedGav.getArtifactId().equals(groupArtifactVersion.getArtifactId()) && + alreadyResolvedGav.getVersion().equals(groupArtifactVersion.getVersion())) { return true; } } diff --git a/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyKey.java b/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyKey.java index 729d5ddc982..24d9e7cdbf3 100755 --- a/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyKey.java +++ b/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyKey.java @@ -74,16 +74,16 @@ public ChangePropertyKeyVisitor() { @Override public Properties visitEntry(Properties.Entry entry, P p) { if (Boolean.TRUE.equals(regex)) { - if (!Boolean.FALSE.equals(relaxedBinding) - ? NameCaseConvention.matchesRegexRelaxedBinding(entry.getKey(), oldPropertyKey) - : entry.getKey().matches(oldPropertyKey)) { + if (!Boolean.FALSE.equals(relaxedBinding) ? + NameCaseConvention.matchesRegexRelaxedBinding(entry.getKey(), oldPropertyKey) : + entry.getKey().matches(oldPropertyKey)) { entry = entry.withKey(entry.getKey().replaceFirst(oldPropertyKey, newPropertyKey)) .withPrefix(entry.getPrefix()); } } else { - if (!Boolean.FALSE.equals(relaxedBinding) - ? NameCaseConvention.equalsRelaxedBinding(entry.getKey(), oldPropertyKey) - : entry.getKey().equals(oldPropertyKey)) { + if (!Boolean.FALSE.equals(relaxedBinding) ? + NameCaseConvention.equalsRelaxedBinding(entry.getKey(), oldPropertyKey) : + entry.getKey().equals(oldPropertyKey)) { entry = entry.withKey(newPropertyKey) .withPrefix(entry.getPrefix()); } diff --git a/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyValue.java b/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyValue.java index 68b5186c26b..4ddcb852df4 100755 --- a/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyValue.java +++ b/rewrite-properties/src/main/java/org/openrewrite/properties/ChangePropertyValue.java @@ -98,23 +98,23 @@ public Properties visitEntry(Properties.Entry entry, P p) { // returns null if value should not change private Properties.@Nullable Value updateValue(Properties.Value value) { - Properties.Value updatedValue = value.withText(Boolean.TRUE.equals(regex) - ? value.getText().replaceAll(oldValue, newValue) - : newValue); + Properties.Value updatedValue = value.withText(Boolean.TRUE.equals(regex) ? + value.getText().replaceAll(oldValue, newValue) : + newValue); return updatedValue.getText().equals(value.getText()) ? null : updatedValue; } private boolean matchesPropertyKey(String prop) { - return !Boolean.FALSE.equals(relaxedBinding) - ? NameCaseConvention.matchesGlobRelaxedBinding(prop, propertyKey) - : StringUtils.matchesGlob(prop, propertyKey); + return !Boolean.FALSE.equals(relaxedBinding) ? + NameCaseConvention.matchesGlobRelaxedBinding(prop, propertyKey) : + StringUtils.matchesGlob(prop, propertyKey); } private boolean matchesOldValue(Properties.Value value) { return StringUtils.isNullOrEmpty(oldValue) || - (Boolean.TRUE.equals(regex) - ? Pattern.compile(oldValue).matcher(value.getText()).find() - : value.getText().equals(oldValue)); + (Boolean.TRUE.equals(regex) ? + Pattern.compile(oldValue).matcher(value.getText()).find() : + value.getText().equals(oldValue)); } } diff --git a/rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java b/rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java index 42af9090ac9..a1259aecdac 100644 --- a/rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java +++ b/rewrite-test/src/main/java/org/openrewrite/test/RewriteTest.java @@ -428,8 +428,8 @@ default void rewriteRun(Consumer spec, SourceSpec... sourceSpecs) return " " + beforePath + " -> " + afterPath; }) .collect(Collectors.joining("\n")); - fail("Expected a new source file with the source path: " + sourceSpec.getSourcePath() - +"\nAll source file paths, before and after recipe run:\n" + paths); + fail("Expected a new source file with the source path: " + sourceSpec.getSourcePath() + + "\nAll source file paths, before and after recipe run:\n" + paths); } // If the source spec has not defined a source path, look for a result with the exact contents. This logic @@ -579,10 +579,10 @@ default void rewriteRun(Consumer spec, SourceSpec... sourceSpecs) newFilesGenerated.assertAll(); Map resultToUnexpected = allResults.stream() - .collect(Collectors.toMap(result -> result, result -> result.getBefore() == null - && !(result.getAfter() instanceof Remote) - && !expectedNewResults.contains(result) - && testMethodSpec.afterRecipes.isEmpty())); + .collect(Collectors.toMap(result -> result, result -> result.getBefore() == null && + !(result.getAfter() instanceof Remote) && + !expectedNewResults.contains(result) && + testMethodSpec.afterRecipes.isEmpty())); if (resultToUnexpected.values().stream().anyMatch(unexpected -> unexpected)) { String paths = resultToUnexpected.entrySet().stream() .map(it -> { diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java b/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java index 7f7b4e49fbe..b9941bfb8ae 100644 --- a/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java +++ b/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeNamespaceValue.java @@ -225,8 +225,8 @@ private Optional maybeGetSchemaLocation(Namespaced n) { Map namespaces = n.getNamespaces(); for (Xml.Attribute attribute : n.getAttributes()) { String attributeNamespace = namespaces.get(Namespaced.extractNamespacePrefix(attribute.getKeyAsString())); - if(XML_SCHEMA_INSTANCE_URI.equals(attributeNamespace) - && attribute.getKeyAsString().endsWith("schemaLocation")) { + if(XML_SCHEMA_INSTANCE_URI.equals(attributeNamespace) && + attribute.getKeyAsString().endsWith("schemaLocation")) { return Optional.of(attribute); } } @@ -280,9 +280,9 @@ public Xml.Tag withNamespaces(Xml.Tag tag, Map namespaces) { if (attributeByKey.containsKey(key)) { Xml.Attribute attribute = attributeByKey.get(key); if (!ns.getValue().equals(attribute.getValueAsString())) { - ListUtils.map(attributes, a -> a.getKeyAsString().equals(key) - ? attribute.withValue(new Xml.Attribute.Value(randomId(), "", Markers.EMPTY, Xml.Attribute.Value.Quote.Double, ns.getValue())) - : a + ListUtils.map(attributes, a -> a.getKeyAsString().equals(key) ? + attribute.withValue(new Xml.Attribute.Value(randomId(), "", Markers.EMPTY, Xml.Attribute.Value.Quote.Double, ns.getValue())) : + a ); } } else { diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeTagAttribute.java b/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeTagAttribute.java index 1c8a6b93a39..deda5df7396 100644 --- a/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeTagAttribute.java +++ b/rewrite-xml/src/main/java/org/openrewrite/xml/ChangeTagAttribute.java @@ -102,9 +102,9 @@ public Xml.Attribute visitChosenElementAttribute(Xml.Attribute attribute) { return null; } - String changedValue = oldValue != null - ? (Boolean.TRUE.equals(regex) ? stringValue.replaceAll(oldValue, newValue) : stringValue.replace(oldValue, newValue)) - : newValue; + String changedValue = oldValue != null ? + (Boolean.TRUE.equals(regex) ? stringValue.replaceAll(oldValue, newValue) : stringValue.replace(oldValue, newValue)) : + newValue; return attribute.withValue( new Xml.Attribute.Value(attribute.getId(), diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/XPathMatcher.java b/rewrite-xml/src/main/java/org/openrewrite/xml/XPathMatcher.java index 8ca660a975d..b3c184b9038 100644 --- a/rewrite-xml/src/main/java/org/openrewrite/xml/XPathMatcher.java +++ b/rewrite-xml/src/main/java/org/openrewrite/xml/XPathMatcher.java @@ -123,8 +123,8 @@ public boolean matches(Cursor cursor) { boolean matchedCondition = false; Matcher matcher; - if (tagForCondition != null && partWithCondition.endsWith("]") - && (matcher = ELEMENT_WITH_CONDITION_PATTERN.matcher(partWithCondition)).matches()) { + if (tagForCondition != null && partWithCondition.endsWith("]") && + (matcher = ELEMENT_WITH_CONDITION_PATTERN.matcher(partWithCondition)).matches()) { String optionalPartName = matchesElementWithConditionFunction(matcher, tagForCondition, cursor); if (optionalPartName == null) { return false; @@ -150,16 +150,16 @@ public boolean matches(Cursor cursor) { continue; } - boolean conditionNotFulfilled = tagForCondition == null - || (!part.equals(partName) && !tagForCondition.getName().equals(partName)); + boolean conditionNotFulfilled = tagForCondition == null || + (!part.equals(partName) && !tagForCondition.getName().equals(partName)); int idx = part.indexOf("["); if (idx > 0) { part = part.substring(0, idx); } - if (path.size() < i + 1 - || (!(path.get(pathIndex).getName().equals(part)) && !"*".equals(part)) - || conditionIsBefore && conditionNotFulfilled) { + if (path.size() < i + 1 || + (!(path.get(pathIndex).getName().equals(part)) && !"*".equals(part)) || + conditionIsBefore && conditionNotFulfilled) { return false; } } diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/trait/Namespaced.java b/rewrite-xml/src/main/java/org/openrewrite/xml/trait/Namespaced.java index 9595f6c0da5..f7b50498487 100644 --- a/rewrite-xml/src/main/java/org/openrewrite/xml/trait/Namespaced.java +++ b/rewrite-xml/src/main/java/org/openrewrite/xml/trait/Namespaced.java @@ -234,8 +234,8 @@ public Matcher xPath(@Nullable XPathMatcher xPath) { Namespaced namespaced = new Namespaced(cursor); if (uri != null || prefix != null) { Map namespaces = namespaced.getNamespaces(); - if ((uri != null && !namespaces.containsValue(uri)) - || (prefix != null && !namespaces.containsKey(prefix))) { + if ((uri != null && !namespaces.containsValue(uri)) || + (prefix != null && !namespaces.containsKey(prefix))) { return null; } } diff --git a/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyKey.java b/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyKey.java index cee27689614..93a1f40c14b 100755 --- a/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyKey.java +++ b/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyKey.java @@ -110,8 +110,8 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, P p) { .map(e2 -> e2.getKey().getValue()) .collect(Collectors.joining(".")); - if (newPropertyKey.startsWith(oldPropertyKey) - && (matches(prop, newPropertyKey) || matches(prop, newPropertyKey + ".*") || childMatchesNewPropertyKey(entry, prop))) { + if (newPropertyKey.startsWith(oldPropertyKey) && + (matches(prop, newPropertyKey) || matches(prop, newPropertyKey + ".*") || childMatchesNewPropertyKey(entry, prop))) { return e; } @@ -122,8 +122,8 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, P p) { Yaml.Mapping.Entry propertyEntry = propertyEntriesLeftToRight.next(); String value = propertyEntry.getKey().getValue() + "."; - if ((!propertyToTest.startsWith(value ) || (propertyToTest.startsWith(value) && !propertyEntriesLeftToRight.hasNext())) - && hasNonExcludedValues(propertyEntry)) { + if ((!propertyToTest.startsWith(value ) || (propertyToTest.startsWith(value) && !propertyEntriesLeftToRight.hasNext())) && + hasNonExcludedValues(propertyEntry)) { doAfterVisit(new InsertSubpropertyVisitor<>( propertyEntry, propertyToTest, @@ -193,8 +193,8 @@ private boolean hasExcludedValues(Yaml.Mapping.Entry propertyEntry) { private boolean anyMatch(Yaml.Mapping.Entry entry, List subKeys) { for (String subKey : subKeys) { - if (entry.getKey().getValue().equals(subKey) - || entry.getKey().getValue().startsWith(subKey + ".")) { + if (entry.getKey().getValue().equals(subKey) || + entry.getKey().getValue().startsWith(subKey + ".")) { return true; } } @@ -203,8 +203,8 @@ private boolean anyMatch(Yaml.Mapping.Entry entry, List subKeys) { private static boolean noneMatch(Yaml.Mapping.Entry entry, List subKeys) { for (String subKey : subKeys) { - if (entry.getKey().getValue().equals(subKey) - || entry.getKey().getValue().startsWith(subKey + ".")) { + if (entry.getKey().getValue().equals(subKey) || + entry.getKey().getValue().startsWith(subKey + ".")) { return false; } } diff --git a/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyValue.java b/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyValue.java index cf28ca0ed20..0450162b720 100644 --- a/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyValue.java +++ b/rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyValue.java @@ -113,16 +113,16 @@ public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, ExecutionC return null; } Yaml.Scalar scalar = (Yaml.Scalar) value; - Yaml.Scalar newScalar = scalar.withValue(Boolean.TRUE.equals(regex) - ? scalar.getValue().replaceAll(Objects.requireNonNull(oldValue), newValue) - : newValue); + Yaml.Scalar newScalar = scalar.withValue(Boolean.TRUE.equals(regex) ? + scalar.getValue().replaceAll(Objects.requireNonNull(oldValue), newValue) : + newValue); return scalar.getValue().equals(newScalar.getValue()) ? null : newScalar; } private boolean matchesPropertyKey(String prop) { - return !Boolean.FALSE.equals(relaxedBinding) - ? NameCaseConvention.matchesGlobRelaxedBinding(prop, propertyKey) - : StringUtils.matchesGlob(prop, propertyKey); + return !Boolean.FALSE.equals(relaxedBinding) ? + NameCaseConvention.matchesGlobRelaxedBinding(prop, propertyKey) : + StringUtils.matchesGlob(prop, propertyKey); } private boolean matchesOldValue(Yaml.Block value) { @@ -131,9 +131,9 @@ private boolean matchesOldValue(Yaml.Block value) { } Yaml.Scalar scalar = (Yaml.Scalar) value; return StringUtils.isNullOrEmpty(oldValue) || - (Boolean.TRUE.equals(regex) - ? Pattern.compile(oldValue).matcher(scalar.getValue()).find() - : scalar.getValue().equals(oldValue)); + (Boolean.TRUE.equals(regex) ? + Pattern.compile(oldValue).matcher(scalar.getValue()).find() : + scalar.getValue().equals(oldValue)); } private static String getProperty(Cursor cursor) { diff --git a/rewrite-yaml/src/main/java/org/openrewrite/yaml/DeleteProperty.java b/rewrite-yaml/src/main/java/org/openrewrite/yaml/DeleteProperty.java index de995db8fa9..c262102d3e8 100755 --- a/rewrite-yaml/src/main/java/org/openrewrite/yaml/DeleteProperty.java +++ b/rewrite-yaml/src/main/java/org/openrewrite/yaml/DeleteProperty.java @@ -42,8 +42,8 @@ public class DeleteProperty extends Recipe { @Deprecated @Option(displayName = "Coalesce", - description = "(Deprecated: in a future version, this recipe will always use the `false` behavior)" - + " Simplify nested map hierarchies into their simplest dot separated property form.", + description = "(Deprecated: in a future version, this recipe will always use the `false` behavior)" + + " Simplify nested map hierarchies into their simplest dot separated property form.", required = false) @Nullable Boolean coalesce;