diff options
Diffstat (limited to 'platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java')
-rw-r--r-- | platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java new file mode 100644 index 000000000000..4b5ad7c64545 --- /dev/null +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java @@ -0,0 +1,59 @@ +package com.intellij.structuralsearch.impl.matcher.compiler; + +import com.intellij.psi.PsiElement; + +import java.util.ArrayList; + +/** + * Created by IntelliJ IDEA. + * User: maxim + * Date: 17.11.2004 + * Time: 19:24:40 + * To change this template use File | Settings | File Templates. + */ +class DeleteNodesAction implements Runnable { + private final ArrayList elements; + + DeleteNodesAction(ArrayList _elements) { + elements = _elements; + } + + private void delete(PsiElement first, PsiElement last) throws Exception { + if (last==first) { + first.delete(); + } else { + first.getParent().deleteChildRange(first,last); + } + } + public void run() { + try { + PsiElement first= null; + PsiElement last = null; + + for(int i = 0;i < elements.size(); ++i) { + final PsiElement el = (PsiElement)elements.get(i); + + if (!el.isValid()) continue; + + if (first==null) { + first = last = el; + } else if (last.getNextSibling()==el) { + last = el; + } else { + delete(first,last); + first = last = null; + --i; + continue; + } + } + + if (first!=null) { + delete(first,last); + } + } catch(Throwable ex) { + ex.printStackTrace(); + } finally { + elements.clear(); + } + } +} |