use of org.eclipse.text.edits.InsertEdit in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method replaceLineCommentBeforeJavaElement.
private void replaceLineCommentBeforeJavaElement(List<TextEdit> commentEdits, LineComment lineComment, List<LineComment> lineComments, int i, String source, TreeSet<Integer> lineStarts) {
final int replaceLength = "//".length();
final boolean isFirst = i == 0;
String replacementText;
final SourceLocation indentLoc = getIndentForJavadoc(lineComment, source, lineStarts);
if (isFirst) {
// TODO JNR how to obey configured indentation?
replacementText = "/**" + lineSeparator + indentLoc.substring(source) + " *";
} else {
replacementText = " *";
}
final boolean commentStartsWithSlash = source.charAt(lineComment.getStartPosition() + replaceLength) == '/';
if (commentStartsWithSlash) {
replacementText += " ";
}
commentEdits.add(new ReplaceEdit(lineComment.getStartPosition(), replaceLength, replacementText));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
final boolean isLast = i == lineComments.size() - 1;
if (isLast) {
// TODO JNR how to obey configured indentation?
final int position = getEndPosition(lineComment);
commentEdits.add(new InsertEdit(position, lineSeparator + indentLoc.substring(source) + " */"));
}
}
use of org.eclipse.text.edits.InsertEdit in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addSingleLineCommentToJavadocEdits.
private void addSingleLineCommentToJavadocEdits(List<TextEdit> commentEdits, ASTNode nextNode, List<LineComment> lineComments, String source, TreeSet<Integer> lineStarts) {
final int nodeStart = nextNode.getStartPosition();
final LineComment lineComment = lineComments.get(0);
// TODO JNR how to obey configured indentation?
// TODO JNR how to obey configured line length?
final int commentStart = lineComment.getStartPosition();
if (commentStart < nodeStart) {
// assume comment is situated exactly before target node for javadoc
final String spaceAtStart = getSpaceAtStart(source, lineComment);
commentEdits.add(new ReplaceEdit(commentStart, "//".length(), "/**" + spaceAtStart));
commentEdits.add(new InsertEdit(getEndPosition(lineComment), getSpaceAtEnd(source, lineComment) + "*/"));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
} else {
// assume comment is situated exactly after target node for javadoc
final StringBuilder newJavadoc = new StringBuilder().append("/**").append(getSpaceAtStart(source, lineComment));
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
SourceLocation indent = getIndent(nextNode, lineStarts);
newJavadoc.append(getSpaceAtEnd(source, lineComment)).append("*/").append(lineSeparator).append(source, indent.getStartPosition(), indent.getEndPosition());
commentEdits.add(new InsertEdit(nodeStart, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
}
use of org.eclipse.text.edits.InsertEdit in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addBlockCommentToJavadocEdits.
private void addBlockCommentToJavadocEdits(List<TextEdit> commentEdits) {
for (BlockComment blockComment : this.blockCommentToJavadoc) {
final int offset = blockComment.getStartPosition() + "/*".length();
commentEdits.add(new InsertEdit(offset, "*"));
}
}
use of org.eclipse.text.edits.InsertEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testInsertReplace1.
@Test
public void testInsertReplace1() throws Exception {
TextEdit e1 = new ReplaceEdit(2, 1, "y");
TextEdit e2 = new InsertEdit(2, "xx");
fRoot.addChild(e1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(fRoot, 2, 3);
assertEquals(e1, 4, 1);
assertEquals(e2, 2, 2);
Assert.assertEquals("Buffer content", "01xxy3456789", fDocument.get());
doUndoRedo(undo, "01xxy3456789");
}
use of org.eclipse.text.edits.InsertEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testNestedCopySourceWithInsert.
@Test
public void testNestedCopySourceWithInsert() throws Exception {
CopySourceEdit s1 = new CopySourceEdit(1, 5);
CopySourceEdit s2 = new CopySourceEdit(2, 3);
CopySourceEdit s3 = new CopySourceEdit(3, 1);
InsertEdit i1 = new InsertEdit(4, "x");
s1.addChild(s2);
s2.addChild(s3);
s3.addChild(i1);
CopyTargetEdit t1 = new CopyTargetEdit(9, s1);
CopyTargetEdit t2 = new CopyTargetEdit(8, s2);
CopyTargetEdit t3 = new CopyTargetEdit(7, s3);
fRoot.addChild(s1);
fRoot.addChild(t1);
fRoot.addChild(t2);
fRoot.addChild(t3);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 1, 6);
assertEquals(s2, 2, 4);
assertEquals(s3, 3, 2);
assertEquals(i1, 4, 1);
assertEquals(t1, 16, 6);
assertEquals(t2, 11, 4);
assertEquals(t3, 8, 2);
String result = "0123x4563x723x48123x459";
Assert.assertEquals("Buffer content", result, fDocument.get());
doUndoRedo(undo, result);
}
Aggregations