本文整理汇总了Java中org.eclipse.text.edits.ReplaceEdit类的典型用法代码示例。如果您正苦于以下问题:Java ReplaceEdit类的具体用法?Java ReplaceEdit怎么用?Java ReplaceEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReplaceEdit类属于org.eclipse.text.edits包,在下文中一共展示了ReplaceEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
/**
* This method makes sure that no changes are applied (no dirty state), if there are no changes. This fixes bug
* GHOLD-272
*/
@Override
public void format(IDocument document, IRegion region) {
IXtextDocument doc = (IXtextDocument) document;
TextEdit e = doc.priorityReadOnly(new FormattingUnitOfWork(doc, region));
if (e == null)
return;
if (e instanceof ReplaceEdit) {
ReplaceEdit r = (ReplaceEdit) e;
if ((r.getOffset() == 0) && (r.getLength() == 0) && (r.getText().isEmpty())) {
return;
}
}
try {
e.apply(document);
} catch (BadLocationException ex) {
throw new RuntimeException(ex);
}
}
示例2: enhanceExistingImportDeclaration
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
QualifiedName qualifiedName,
String optionalAlias, MultiTextEdit result) {
addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
int offset = replaceMe.getOffset();
AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
optionalAlias,
offset,
grammarAccess);
try {
serializer.serialize(
importDeclaration,
observableBuffer,
SaveOptions.newBuilder().noValidation().getOptions());
} catch (IOException e) {
throw new RuntimeException("Should never happen since we write into memory", e);
}
result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
return observableBuffer.getAliasLocation();
}
示例3: addEdits
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
// build a full AST
CompilationUnit unit = SharedASTProvider.getInstance().getAST(getCompilationUnit(), null);
ASTNode name= NodeFinder.perform(unit, fOffset, fLength);
if (name instanceof SimpleName) {
SimpleName[] names= LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
if (names != null) {
for (int i= 0; i < names.length; i++) {
SimpleName curr= names[i];
root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
}
return;
}
}
root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
示例4: addEdits
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的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()));
}
示例5: toTextEdit
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的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));
}
}
}
示例6: getObjectEdits
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
protected List<TextEdit> getObjectEdits() {
final Collection<EObject> modifiedObjects = getModifiedObjects();
Collection<EObject> topLevelObjects = EcoreUtil.filterDescendants(modifiedObjects);
Iterable<EObject> containedModifiedObjects = Iterables.filter(topLevelObjects, new Predicate<EObject>() {
public boolean apply(EObject input) {
return input.eResource() == resource;
}
});
List<TextEdit> edits = Lists.newArrayListWithExpectedSize(Iterables.size(containedModifiedObjects));
for (EObject modifiedObject : containedModifiedObjects) {
ReplaceRegion replaceRegion = serializer.serializeReplacement(modifiedObject, getSaveOptions());
TextEdit edit = new ReplaceEdit(replaceRegion.getOffset(), replaceRegion.getLength(), replaceRegion.getText());
edits.add(edit);
}
return edits;
}
示例7: addReferenceUpdates
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
SearchResultGroup[] grouped = getOccurrences();
for (int i = 0; i < grouped.length; i++) {
SearchResultGroup group = grouped[i];
SearchMatch[] results = group.getSearchResults();
ICompilationUnit cu = group.getCompilationUnit();
TextChange change = manager.get(cu);
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
if (!(match instanceof MethodDeclarationMatch)) {
ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
addTextEdit(change, editName, replaceEdit);
}
}
}
pm.done();
}
示例8: createReplaceEdit
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
protected final ReplaceEdit createReplaceEdit(SearchMatch searchResult, ICompilationUnit cu) {
if (searchResult.isImplicit()) { // handle Annotation Element references, see bug 94062
StringBuffer sb = new StringBuffer(getNewElementName());
if (JavaCore.INSERT.equals(
cu.getJavaProject()
.getOption(
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR,
true))) sb.append(' ');
sb.append('=');
if (JavaCore.INSERT.equals(
cu.getJavaProject()
.getOption(
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR,
true))) sb.append(' ');
return new ReplaceEdit(searchResult.getOffset(), 0, sb.toString());
} else {
return new ReplaceEdit(
searchResult.getOffset(), searchResult.getLength(), getNewElementName());
}
}
示例9: addConstructorRenames
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
private void addConstructorRenames(TextChangeManager manager) throws CoreException {
ICompilationUnit cu = fType.getCompilationUnit();
IMethod[] methods = fType.getMethods();
int typeNameLength = fType.getElementName().length();
for (int i = 0; i < methods.length; i++) {
if (methods[i].isConstructor()) {
/*
* constructor declarations cannot be fully qualified so we can use simple replace here
*
* if (methods[i].getNameRange() == null), then it's a binary file so it's wrong anyway
* (checked as a precondition)
*/
String name = RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor;
TextChangeCompatibility.addTextEdit(
manager.get(cu),
name,
new ReplaceEdit(
methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName()));
}
}
}
示例10: addReferenceUpdates
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
pm.beginTask("", fReferences.length); // $NON-NLS-1$
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null) continue;
String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
ReplaceEdit replaceEdit =
new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(
manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
示例11: addEdits
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
// build a full AST
CompilationUnit unit =
SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null);
ASTNode name = NodeFinder.perform(unit, fOffset, fLength);
if (name instanceof SimpleName) {
SimpleName[] names = LinkedNodeFinder.findByProblems(unit, (SimpleName) name);
if (names != null) {
for (int i = 0; i < names.length; i++) {
SimpleName curr = names[i];
root.addChild(new ReplaceEdit(curr.getStartPosition(), curr.getLength(), fNewName));
}
return;
}
}
root.addChild(new ReplaceEdit(fOffset, fLength, fNewName));
}
示例12: addEdits
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
@Override
protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException {
super.addEdits(document, rootEdit);
try {
Position pos = getUpdatedPosition(document);
if (pos != null) {
rootEdit.addChild(new ReplaceEdit(pos.getOffset(), pos.getLength(), "")); // $NON-NLS-1$
} else {
rootEdit.addChild(
new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), "")); // $NON-NLS-1$
}
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
}
}
示例13: testPerform
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
public void testPerform() throws CoreException {
// Create a dummy change for updating references in RefactorTest.java
// to the class R to its new name 'RRR'
ICompilationUnit cu = refactorTestClass.getCompilationUnit();
GWTRefactoringSupport support = new DummyRefactoringSupport();
JsniReferenceChangeFactory factory = new JsniReferenceChangeFactory(support);
IJsniReferenceChange jsniChange = factory.createChange(cu);
// Add one dummy edit to the change
TextEdit oldRootEdit = new MultiTextEdit();
oldRootEdit.addChild(new ReplaceEdit(252, 0, ""));
((TextFileChange)jsniChange).setEdit(oldRootEdit);
// Perform the change (this should replace the original edits with new ones
// with the correct offsets).
((TextFileChange)jsniChange).perform(new NullProgressMonitor());
// Verify that the change still has one edit
TextEdit newRootEdit = ((TextFileChange)jsniChange).getEdit();
assertEquals(1, newRootEdit.getChildrenSize());
}
示例14: testCreateEdit
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
public void testCreateEdit() {
GWTTypeRefactoringSupport support = new GWTTypeRefactoringSupport();
// Change the name of the R class to RRR
IType oldType = rClass.getCompilationUnit().getType("R");
support.setOldElement(oldType);
IType newType = rClass.getCompilationUnit().getType("RRR");
support.setNewElement(newType);
String rawRef = "@com.hello.client.R.B::getNumber()";
IIndexedJavaRef ref = new IndexedJsniJavaRef(JsniJavaRef.parse(rawRef));
ReplaceEdit edit = (ReplaceEdit) support.createEdit(ref);
assertEquals(1, edit.getOffset());
assertEquals(18, edit.getLength());
assertEquals("com.hello.client.RRR", edit.getText());
}
示例15: testCreateEditForInnerClass
import org.eclipse.text.edits.ReplaceEdit; //导入依赖的package包/类
public void testCreateEditForInnerClass() {
GWTTypeRefactoringSupport support = new GWTTypeRefactoringSupport();
// Change the name of the inner class B to BBB
IType r = rClass.getCompilationUnit().getType("R");
IType oldType = r.getType("B");
support.setOldElement(oldType);
IType newType = r.getType("BBB");
support.setNewElement(newType);
String rawRef = "@com.hello.client.R.B::getNumber()";
IIndexedJavaRef ref = new IndexedJsniJavaRef(JsniJavaRef.parse(rawRef));
ReplaceEdit edit = (ReplaceEdit) support.createEdit(ref);
assertEquals(1, edit.getOffset());
assertEquals(20, edit.getLength());
assertEquals("com.hello.client.R.BBB", edit.getText());
}