Search in sources :

Example 1 with RegExpClosure

use of org.intellij.lang.regexp.psi.RegExpClosure in project intellij-community by JetBrains.

the class SimplifyQuantifierAction method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    if (myReplacement == null) {
        myQuantifier.delete();
    } else {
        final PsiFileFactory factory = PsiFileFactory.getInstance(project);
        final ASTNode modifier = myQuantifier.getModifier();
        final PsiFile f = factory.createFileFromText("dummy.regexp", RegExpFileType.INSTANCE, "a" + myReplacement + (modifier != null ? modifier.getText() : ""));
        final RegExpPattern pattern = PsiTreeUtil.getChildOfType(f, RegExpPattern.class);
        assert pattern != null;
        final RegExpClosure closure = (RegExpClosure) pattern.getBranches()[0].getAtoms()[0];
        myQuantifier.replace(closure.getQuantifier());
    }
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) RegExpPattern(org.intellij.lang.regexp.psi.RegExpPattern) RegExpClosure(org.intellij.lang.regexp.psi.RegExpClosure) ASTNode(com.intellij.lang.ASTNode) PsiFile(com.intellij.psi.PsiFile)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 PsiFile (com.intellij.psi.PsiFile)1 PsiFileFactory (com.intellij.psi.PsiFileFactory)1 RegExpClosure (org.intellij.lang.regexp.psi.RegExpClosure)1 RegExpPattern (org.intellij.lang.regexp.psi.RegExpPattern)1