Skip to content

Commit 6117b71

Browse files
authored
Fix insert of annotation to not change indent of following line (eclipse-jdt#3566)
- 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
1 parent 9f348f1 commit 6117b71

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java

+3
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,9 @@ else if (parent instanceof Block || parent instanceof TryStatement || parent ins
17331733
String separator;
17341734
if (lastChild.getNewValue() instanceof Annotation) {
17351735
separator= formatterPrefix.getPrefix(getIndent(pos));
1736+
for (int i= 0; i < this.formatter.computeIndentInSpaces(getIndentOfLine(pos)) % this.formatter.getTabWidth(); ++i) {
1737+
separator += " "; //$NON-NLS-1$
1738+
}
17361739
} else {
17371740
separator= String.valueOf(' ');
17381741
}

org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ public int computeIndentUnits(String line) {
212212
return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth);
213213
}
214214

215+
public int computeIndentInSpaces(String line) {
216+
return IndentManipulation.measureIndentInSpaces(line, this.tabWidth);
217+
}
218+
215219
/**
216220
* Evaluates the edit on the given string.
217221
* @param string The string to format

0 commit comments

Comments
 (0)