Skip to content

Commit

Permalink
refactor: Use Tree.randomId() in LST constructors
Browse files Browse the repository at this point in the history
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.recipes.UseTreeRandomId?organizationId=T3BlblJld3JpdGU%3D

Co-authored-by: Moderne <team@moderne.io>
  • Loading branch information
2 people authored and app committed Feb 4, 2024
1 parent c96deb2 commit b71b4e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
// If the method is an init-method then add a static modifier if necessary
if (initMethods.contains(m.getSimpleName()) || initMethodReferences.containsValue(m.getSimpleName())) {
if (m.getModifiers().stream().noneMatch(it -> J.Modifier.Type.Static.equals(it.getType()))) {
J.Modifier staticModifier = new J.Modifier(UUID.randomUUID(), Space.format(" "), Markers.EMPTY, null, J.Modifier.Type.Static, new ArrayList<>());
J.Modifier staticModifier = new J.Modifier(Tree.randomId(), Space.format(" "), Markers.EMPTY, null, J.Modifier.Type.Static, new ArrayList<>());
m = maybeAutoFormat(m, m.withModifiers(ListUtils.concat(m.getModifiers(), staticModifier)), ctx, getCursor().getParentTreeCursor());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
package org.openrewrite.java.testing.junit5;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.AnnotationMatcher;
Expand All @@ -31,7 +28,6 @@
import org.openrewrite.marker.Markers;

import java.util.List;
import java.util.UUID;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -127,7 +123,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
if (method.getBody() != null) {
if (method.getThrows() == null || method.getThrows().stream()
.noneMatch(n -> TypeUtils.isOfClassType(n.getType(), IO_EXCEPTION_FQN))) {
J.Identifier ioExceptionIdent = new J.Identifier(UUID.randomUUID(),
J.Identifier ioExceptionIdent = new J.Identifier(Tree.randomId(),
Space.format(" "),
Markers.EMPTY,
emptyList(),
Expand Down

0 comments on commit b71b4e8

Please sign in to comment.