Search in sources :

Example 66 with ReplaceEdit

use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.

the class TextMatchUpdater method addTextUpdates.

private void addTextUpdates(ICompilationUnit cu, Set<TextMatch> matches) {
    for (Iterator<TextMatch> resultIter = matches.iterator(); resultIter.hasNext(); ) {
        TextMatch match = resultIter.next();
        if (!match.isQualified() && fOnlyQualified)
            continue;
        int matchStart = match.getStartPosition();
        ReplaceEdit edit = new ReplaceEdit(matchStart, fCurrentNameLength, fNewName);
        try {
            TextChangeCompatibility.addTextEdit(fManager.get(cu), TEXT_EDIT_LABEL, edit, TEXTUAL_MATCHES);
        } catch (MalformedTreeException e) {
        // conflicting update -> omit text match
        }
    }
}
Also used : ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) TextMatch(org.eclipse.jdt.internal.corext.refactoring.rename.RefactoringScanner.TextMatch)

Example 67 with ReplaceEdit

use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.

the class CorrectPackageDeclarationProposal method addEdits.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#addEdits(org.eclipse.jdt.internal.corext.textmanipulation
	 * .TextBuffer)
	 */
@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);
        //$NON-NLS-1$
        String str = "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim;
        root.addChild(new InsertEdit(0, str));
        return;
    }
    root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) InsertEdit(org.eclipse.text.edits.InsertEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration) DeleteEdit(org.eclipse.text.edits.DeleteEdit) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 68 with ReplaceEdit

use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.

the class StringFix method getReplace.

private static ReplaceEdit getReplace(int offset, int length, IBuffer buffer, boolean removeLeadingIndents) {
    String replaceString = new String();
    boolean hasMoreInComment = false;
    // look after the tag
    int next = offset + length;
    while (next < buffer.getLength()) {
        char ch = buffer.getChar(next);
        if (IndentManipulation.isIndentChar(ch)) {
            // remove all whitespace
            next++;
        } else if (IndentManipulation.isLineDelimiterChar(ch)) {
            length = next - offset;
            break;
        } else if (ch == '/') {
            next++;
            if (next == buffer.getLength() || buffer.getChar(next) != '/') {
                //$NON-NLS-1$
                replaceString = "//";
            } else {
                length = next - offset - 1;
            }
            hasMoreInComment = true;
            break;
        } else {
            //$NON-NLS-1$
            replaceString = "//";
            hasMoreInComment = true;
            break;
        }
    }
    if (!hasMoreInComment && removeLeadingIndents) {
        while (offset > 0 && IndentManipulation.isIndentChar(buffer.getChar(offset - 1))) {
            offset--;
            length++;
        }
    }
    if (length > 0) {
        ReplaceEdit replaceEdit = new ReplaceEdit(offset, length, replaceString);
        return replaceEdit;
    } else {
        return null;
    }
}
Also used : ReplaceEdit(org.eclipse.text.edits.ReplaceEdit)

Example 69 with ReplaceEdit

use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.

the class RenameNonVirtualMethodProcessor method addReferenceUpdates.

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();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch)

Example 70 with ReplaceEdit

use of org.eclipse.text.edits.ReplaceEdit in project che by eclipse.

the class RenameFieldProcessor method addDeclarationUpdate.

private void addDeclarationUpdate() throws CoreException {
    ISourceRange nameRange = fField.getNameRange();
    TextEdit textEdit = new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
    ICompilationUnit cu = fField.getCompilationUnit();
    String groupName = RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration;
    addTextEdit(fChangeManager.get(cu), groupName, textEdit);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)131 TextEdit (org.eclipse.text.edits.TextEdit)53 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)43 Test (org.junit.Test)34 InsertEdit (org.eclipse.text.edits.InsertEdit)25 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)22 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15 BadLocationException (org.eclipse.jface.text.BadLocationException)14 IDocument (org.eclipse.jface.text.IDocument)14 DeleteEdit (org.eclipse.text.edits.DeleteEdit)13 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)13 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)13 UndoEdit (org.eclipse.text.edits.UndoEdit)13 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)11 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)10 ArrayList (java.util.ArrayList)9 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)8 TextChange (org.eclipse.ltk.core.refactoring.TextChange)8 List (java.util.List)7 Document (org.eclipse.jface.text.Document)7