Skip to content

Commit

Permalink
Fix insert of annotation to not change indent of following line (#3566)
Browse files Browse the repository at this point in the history
- add new method computeIndentInSpaces() to ASTRewriteFormatter
- modify ASTRewriteAnalyzer.rewriteModifiers2() to add spaces as
  needed to separator of added annotation to match current indent
- needed for eclipse-jdt/eclipse.jdt.ui#1940
  • Loading branch information
jjohnstn authored Jan 17, 2025
1 parent 9f348f1 commit 6117b71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,9 @@ else if (parent instanceof Block || parent instanceof TryStatement || parent ins
String separator;
if (lastChild.getNewValue() instanceof Annotation) {
separator= formatterPrefix.getPrefix(getIndent(pos));
for (int i= 0; i < this.formatter.computeIndentInSpaces(getIndentOfLine(pos)) % this.formatter.getTabWidth(); ++i) {
separator += " "; //$NON-NLS-1$
}
} else {
separator= String.valueOf(' ');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public int computeIndentUnits(String line) {
return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth);
}

public int computeIndentInSpaces(String line) {
return IndentManipulation.measureIndentInSpaces(line, this.tabWidth);
}

/**
* Evaluates the edit on the given string.
* @param string The string to format
Expand Down

0 comments on commit 6117b71

Please sign in to comment.