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;
}
Aggregations