本文整理汇总了Java中org.eclipse.text.edits.InsertEdit类的典型用法代码示例。如果您正苦于以下问题:Java InsertEdit类的具体用法?Java InsertEdit怎么用?Java InsertEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InsertEdit类属于org.eclipse.text.edits包,在下文中一共展示了InsertEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = "\n";
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例2: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
try {
String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
final IJavaProject project= getCompilationUnit().getJavaProject();
IRegion region= document.getLineInformationOfOffset(fInsertPosition);
String lineContent= document.get(region.getOffset(), region.getLength());
String indentString= Strings.getIndentString(lineContent, project);
String str= Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
InsertEdit edit= new InsertEdit(fInsertPosition, str);
rootEdit.addChild(edit);
if (fComment.charAt(fComment.length() - 1) != '\n') {
rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
}
} catch (BadLocationException e) {
throw new CoreException(StatusFactory.newErrorStatus("Invalid edit", e));
}
}
示例3: toTextEdit
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
private static void toTextEdit(CodeEdit codeEdit, IDocument document, MultiTextEdit textEdit)
throws TypeScriptException {
String newText = codeEdit.getNewText();
int startLine = codeEdit.getStart().getLine();
int startOffset = codeEdit.getStart().getOffset();
int endLine = codeEdit.getEnd().getLine();
int endOffset = codeEdit.getEnd().getOffset();
int start = DocumentUtils.getPosition(document, startLine, startOffset);
int end = DocumentUtils.getPosition(document, endLine, endOffset);
int length = end - start;
if (newText.isEmpty()) {
if (length > 0) {
textEdit.addChild(new DeleteEdit(start, length));
}
} else {
if (length > 0) {
textEdit.addChild(new ReplaceEdit(start, length, newText));
} else if (length == 0) {
textEdit.addChild(new InsertEdit(start, newText));
}
}
}
示例4: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
try {
String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);
final IJavaProject project = getCompilationUnit().getJavaProject();
IRegion region = document.getLineInformationOfOffset(fInsertPosition);
String lineContent = document.get(region.getOffset(), region.getLength());
String indentString = Strings.getIndentString(lineContent, project);
String str = Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
InsertEdit edit = new InsertEdit(fInsertPosition, str);
rootEdit.addChild(edit);
if (fComment.charAt(fComment.length() - 1) != '\n') {
rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
}
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
}
}
示例5: insert
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
/**
* Inserts the given key value pairs into this model at appropriate
* positions. Records all required text changes in the given change
*
* @param keyValuePairs the key value pairs to insert
* @param change the change to use to record text changes
*/
public void insert(KeyValuePair[] keyValuePairs, TextChange change) {
ArrayList<KeyValuePair> sorted= new ArrayList<KeyValuePair>(Arrays.asList(keyValuePairs));
Collections.sort(sorted, new Comparator<KeyValuePair>() {
public int compare(KeyValuePair p1, KeyValuePair p2) {
return Collator.getInstance().compare(p1.fKey, p2.fKey);
}
});
for (int i = 0; i < sorted.size(); i++) {
KeyValuePair curr= sorted.get(i);
InsertEdit insertEdit= insert(curr);
String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey()));
TextChangeCompatibility.addTextEdit(change, message, insertEdit);
}
}
示例6: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
try {
String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
final IJavaProject project= getCompilationUnit().getJavaProject();
IRegion region= document.getLineInformationOfOffset(fInsertPosition);
String lineContent= document.get(region.getOffset(), region.getLength());
String indentString= Strings.getIndentString(lineContent, project);
String str= Strings.changeIndent(fComment, 0, project, indentString, lineDelimiter);
InsertEdit edit= new InsertEdit(fInsertPosition, str);
rootEdit.addChild(edit);
if (fComment.charAt(fComment.length() - 1) != '\n') {
rootEdit.addChild(new InsertEdit(fInsertPosition, lineDelimiter));
rootEdit.addChild(new InsertEdit(fInsertPosition, indentString));
}
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
}
}
示例7: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim= StubUtility.getLineDelimiterUsed(cu);
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:CorrectPackageDeclarationProposal.java
示例8: removeAndInsertNew
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
private void removeAndInsertNew(IBuffer buffer, int contentOffset, int contentEnd, ArrayList stringsToInsert, MultiTextEdit resEdit) {
int pos= contentOffset;
for (int i= 0; i < stringsToInsert.size(); i++) {
String curr= (String) stringsToInsert.get(i);
int idx= findInBuffer(buffer, curr, pos, contentEnd);
if (idx != -1) {
if (idx != pos) {
resEdit.addChild(new DeleteEdit(pos, idx - pos));
}
pos= idx + curr.length();
} else {
resEdit.addChild(new InsertEdit(pos, curr));
}
}
if (pos < contentEnd) {
resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
}
}
示例9: addNewImportDeclaration
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
private AliasLocation addNewImportDeclaration(QualifiedName moduleName, QualifiedName qualifiedName,
String optionalAlias,
int insertionOffset, MultiTextEdit result) {
final String spacer = lazySpacer.get();
String syntacticModuleName = syntacticModuleName(moduleName);
AliasLocation aliasLocation = null;
String importSpec = (insertionOffset != 0 ? lineDelimiter : "") + "import ";
if (!N4JSLanguageUtils.isDefaultExport(qualifiedName)) { // not an 'default' export
importSpec = importSpec + "{" + spacer + qualifiedName.getLastSegment();
if (optionalAlias != null) {
importSpec = importSpec + " as ";
aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
importSpec = importSpec + optionalAlias;
}
importSpec = importSpec + spacer + "}";
} else { // import default exported element
if (optionalAlias == null) {
importSpec = importSpec + N4JSLanguageUtils.lastSegmentOrDefaultHost(qualifiedName);
} else {
aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
importSpec = importSpec + optionalAlias;
}
}
result.addChild(new InsertEdit(insertionOffset, importSpec + " from "
+ syntacticModuleName + ";"
+ (insertionOffset != 0 ? "" : lineDelimiter)));
return aliasLocation;
}
示例10: visit
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
public boolean visit(InsertEdit edit) {
try {
org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit();
te.setNewText(edit.getText());
te.setRange(JDTUtils.toRange(compilationUnit,edit.getOffset(),edit.getLength()));
converted.add(te);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Error converting TextEdits", e);
}
return super.visit(edit);
}
示例11: createTextChange
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected TextChange createTextChange() throws CoreException {
init(fRefactoring);
fRefactoringStatus = fRefactoring.checkFinalConditions(new NullProgressMonitor());
if (fRefactoringStatus.hasFatalError()) {
TextFileChange dummyChange = new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$
dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$
return dummyChange;
}
return (TextChange) fRefactoring.createChange(new NullProgressMonitor());
}
示例12: doCommand
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void doCommand(IDocument document) throws BadLocationException {
ISourceRange srTarget = target.getSourceRange();
int insertOffset = srTarget.getOffset(); // BEFORE
if (location == Insert.AFTER) {
insertOffset += target.getLengthWithSep();
}
int docLen = document.getLength();
String prefix = "";
if (insertOffset > docLen) {
insertOffset -= target.getLineDelim().length();
prefix = target.getLineDelim();
}
TextEdit edit = new MultiTextEdit();
String suffix = "";
for (PagePart part : parts) {
ISourceRange range = part.getSourceRange();
int offset = range.getOffset();
int len = part.getLengthWithSep();
if (offset + len > docLen) {
len -= target.getLineDelim().length();
suffix = target.getLineDelim();
}
String text = prefix + document.get(offset, len) + suffix;
edit.addChild(new DeleteEdit(offset, len));
edit.addChild(new InsertEdit(insertOffset, text));
}
edit.apply(document);
}
示例13: addComment
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
private void addComment(IDocument doc, int beg, int len) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, getCommentBeg()));
edit.addChild(new InsertEdit(beg + len, getCommentEnd()));
try {
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure creating comment " + e.getMessage());
}
}
示例14: addEdits
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu = getCompilationUnit();
IPackageFragment parentPack = (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls = cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i = 0; i < decls.length; i++) {
ISourceRange range = decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = StubUtility.getLineDelimiterUsed(cu);
String str =
"package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; // $NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(
new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例15: createTextChange
import org.eclipse.text.edits.InsertEdit; //导入依赖的package包/类
@Override
protected TextChange createTextChange() throws CoreException {
init(fRefactoring);
fRefactoringStatus = fRefactoring.checkFinalConditions(new NullProgressMonitor());
if (fRefactoringStatus.hasFatalError()) {
TextFileChange dummyChange =
new TextFileChange(
"fatal error", (IFile) getCompilationUnit().getResource()); // $NON-NLS-1$
dummyChange.setEdit(new InsertEdit(0, "")); // $NON-NLS-1$
return dummyChange;
}
return (TextChange) fRefactoring.createChange(new NullProgressMonitor());
}