Search in sources :

Example 1 with PsiRewrite

use of il.org.spartan.Leonidas.auxilary_layer.PsiRewrite in project Main by SpartanRefactoring.

the class Toolbox method executeSingleTipper.

/**
     * @param e Psi tree
     * @param tipperName The name of the tipper to execure on e.
     * @return True if the tipper changed anything, false otherwise.
     * */
public boolean executeSingleTipper(PsiElement e, String tipperName) {
    Tipper tipper = getTipperByName(tipperName);
    if (tipper == null) {
        System.out.println("\nNull tipper!\n");
        return false;
    }
    if (e == null) {
        System.out.println("\nNull element!\n");
        return false;
    }
    Wrapper<PsiElement> toReplace = new Wrapper<>(null);
    Wrapper<Boolean> modified = new Wrapper<>(false);
    e.accept(new JavaRecursiveElementVisitor() {

        @Override
        public void visitElement(PsiElement el) {
            super.visitElement(el);
            if (modified.get()) {
                return;
            }
            if (tipper.canTip(el)) {
                toReplace.set(el);
                modified.set(true);
            }
        }
    });
    if (!modified.get()) {
        return false;
    }
    tipper.tip(toReplace.get()).go(new PsiRewrite().psiFile(e.getContainingFile()).project(e.getProject()));
    return true;
}
Also used : Tipper(il.org.spartan.Leonidas.plugin.tipping.Tipper) Wrapper(il.org.spartan.Leonidas.auxilary_layer.Wrapper) PsiRewrite(il.org.spartan.Leonidas.auxilary_layer.PsiRewrite) JavaRecursiveElementVisitor(com.intellij.psi.JavaRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JavaRecursiveElementVisitor (com.intellij.psi.JavaRecursiveElementVisitor)1 PsiElement (com.intellij.psi.PsiElement)1 PsiRewrite (il.org.spartan.Leonidas.auxilary_layer.PsiRewrite)1 Wrapper (il.org.spartan.Leonidas.auxilary_layer.Wrapper)1 Tipper (il.org.spartan.Leonidas.plugin.tipping.Tipper)1