Search in sources :

Example 1 with ReplacementInfoImpl

use of com.intellij.structuralsearch.plugin.replace.impl.ReplacementInfoImpl in project intellij-community by JetBrains.

the class DocumentBasedReplaceHandler method replace.

public void replace(ReplacementInfo info, ReplaceOptions options) {
    if (info.getMatchesCount() == 0)
        return;
    assert info instanceof ReplacementInfoImpl;
    PsiElement element = info.getMatch(0);
    if (element == null)
        return;
    PsiFile file = element instanceof PsiFile ? (PsiFile) element : element.getContainingFile();
    assert file != null;
    RangeMarker rangeMarker = myRangeMarkers.get(info);
    Document document = rangeMarker.getDocument();
    document.replaceString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), info.getReplacement());
    PsiDocumentManager.getInstance(element.getProject()).commitDocument(document);
}
Also used : ReplacementInfoImpl(com.intellij.structuralsearch.plugin.replace.impl.ReplacementInfoImpl) PsiFile(com.intellij.psi.PsiFile) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ReplacementInfoImpl

use of com.intellij.structuralsearch.plugin.replace.impl.ReplacementInfoImpl in project intellij-community by JetBrains.

the class DocumentBasedReplaceHandler method prepare.

@Override
public void prepare(ReplacementInfo info) {
    assert info instanceof ReplacementInfoImpl;
    MatchResult result = ((ReplacementInfoImpl) info).getMatchResult();
    PsiElement element = result.getMatch();
    PsiFile file = element instanceof PsiFile ? (PsiFile) element : element.getContainingFile();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);
    TextRange textRange = result.getMatch().getTextRange();
    assert textRange != null;
    RangeMarker rangeMarker = document.createRangeMarker(textRange);
    rangeMarker.setGreedyToLeft(true);
    rangeMarker.setGreedyToRight(true);
    myRangeMarkers.put(info, rangeMarker);
}
Also used : ReplacementInfoImpl(com.intellij.structuralsearch.plugin.replace.impl.ReplacementInfoImpl) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Aggregations

Document (com.intellij.openapi.editor.Document)2 RangeMarker (com.intellij.openapi.editor.RangeMarker)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 ReplacementInfoImpl (com.intellij.structuralsearch.plugin.replace.impl.ReplacementInfoImpl)2 TextRange (com.intellij.openapi.util.TextRange)1