Skip to content

Commit

Permalink
Do not compute unnecessary UUID for Range
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Feb 26, 2025
1 parent 07f930f commit b484f98
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean visit(MethodInvocation node) {
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(getRecipeId(), List.of(uri),
ReconcileUtils.buildLabel(getFixLabel(), RecipeScope.NODE))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, topMethodInvocation))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, topMethodInvocation, null))
.withRecipeScope(RecipeScope.NODE),
new FixDescriptor(getRecipeId(), List.of(uri),
ReconcileUtils.buildLabel(getFixLabel(), RecipeScope.FILE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private ReconcileProblemImpl createProblem(CompilationUnit cu, FieldDeclaration
: "") + typeDecl.getName().getFullyQualifiedName();
ReconcileUtils.setRewriteFixes(registry, problem,
List.of(new FixDescriptor(ConvertAutowiredFieldIntoConstructorParameter.class.getName(), List.of(docUri.toASCIIString()), LABEL)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl, null))
.withParameters(Map.of("classFqName", typeFqName, "fieldName", fieldName))
.withRecipeScope(RecipeScope.NODE)));
return problem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ private void addQuickFixes(CompilationUnit cu, URI docUri, ReconcileProblemImpl

FixDescriptor fix1 = new FixDescriptor(id, List.of(docUri.toASCIIString()), LABEL)
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method));
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method, null));

Range methodRange = ReconcileUtils.createOpenRewriteRange(cu, method);
Range methodRange = ReconcileUtils.createOpenRewriteRange(cu, method, null);
fix1 = fix1.withRangeScope(methodRange);

FixDescriptor fix2 = new FixDescriptor(id, List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean visit(ReturnStatement node) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), LABEL, typeDecl.getName().getStartPosition(), typeDecl.getName().getLength());
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(BeanPostProcessingIgnoreInAot.class.getName(), List.of(docUri.toASCIIString()), ReconcileUtils.buildLabel(LABEL, RecipeScope.NODE))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl, null))
.withRecipeScope(RecipeScope.NODE)
));
problemCollector.accept(problem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void processWebAnnotation(Annotation a) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), PROBLEM_LABEL, nodeForProblemRange.getStartPosition(), nodeForProblemRange.getLength());

String uri = docUri.toASCIIString();
Range range = ReconcileUtils.createOpenRewriteRange(cu, a);
Range range = ReconcileUtils.createOpenRewriteRange(cu, a, null);
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(org.openrewrite.java.spring.ImplicitWebAnnotationNames.class.getName(), List.of(uri), FIX_LABEL)
.withRangeScope(range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public boolean visit(TypeDeclaration typeDecl) {
ReconcileUtils.setRewriteFixes(registry, problem,
List.of(new FixDescriptor(NoAutowiredOnConstructor.class.getName(), List.of(docUri.toASCIIString()), FIX_LABEL)
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl))));
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, typeDecl, null))));
problemCollector.accept(problem);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void processAnnotation(Annotation a) {
List<String> requestMethods = getRequestMethods(cu, a);
if (!requestMethods.isEmpty() && !requestMethods.contains(UNSUPPORTED_REQUEST_METHOD)) {
String uri = docUri.toASCIIString();
Range range = ReconcileUtils.createOpenRewriteRange(cu, a);
Range range = ReconcileUtils.createOpenRewriteRange(cu, a, null);
if (requestMethods.size() == 1 && SUPPORTED_REQUEST_METHODS.contains(requestMethods.get(0))) {
ReconcileProblemImpl problem = new ReconcileProblemImpl(getProblemType(), PROBLEM_LABEL, a.getStartPosition(), a.getLength());
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void endVisit(MethodDeclaration method) {
ReconcileUtils.setRewriteFixes(registry, problem, List.of(
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel("Replace return type with '" + replacementType + "'", RecipeScope.NODE))
.withRecipeScope(RecipeScope.NODE)
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method)),
.withRangeScope(ReconcileUtils.createOpenRewriteRange(cu, method, null)),
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.FILE))
.withRecipeScope(RecipeScope.FILE),
new FixDescriptor(recipeId, List.of(uri), ReconcileUtils.buildLabel(LABEL, RecipeScope.PROJECT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.jdt.core.dom.ASTNode;
Expand All @@ -23,7 +24,6 @@
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.SimpleType;
import org.openrewrite.Tree;
import org.openrewrite.marker.Range;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
import org.springframework.ide.vscode.boot.java.rewrite.RewriteRefactorings;
Expand All @@ -36,7 +36,7 @@

public class ReconcileUtils {

public static Range createOpenRewriteRange(CompilationUnit cu, ASTNode node) {
public static Range createOpenRewriteRange(CompilationUnit cu, ASTNode node, UUID id) {

int startOffset = node.getStartPosition();
int startLine = cu.getLineNumber(startOffset);
Expand All @@ -49,7 +49,7 @@ public static Range createOpenRewriteRange(CompilationUnit cu, ASTNode node) {
Range.Position startPosition = new Range.Position(startOffset, startLine, startColumn);
Range.Position endPosition = new Range.Position(endOffset, endLine, endColumn);

return new Range(Tree.randomId(), startPosition, endPosition);
return new Range(id, startPosition, endPosition);
}

public static QuickfixType getRewriteQuickFixType(QuickfixRegistry registry) {
Expand Down

0 comments on commit b484f98

Please sign in to comment.