use of il.org.spartan.Leonidas.plugin.tipping.Tipper 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;
}
use of il.org.spartan.Leonidas.plugin.tipping.Tipper in project Main by SpartanRefactoring.
the class Toolbox method updateTipperList.
@SuppressWarnings("unchecked")
public void updateTipperList(List<String> list) {
this.tipperMap.values().forEach(element -> element.forEach(tipper -> {
if (!list.contains(tipper.name())) {
element.remove(tipper);
}
}));
this.allTipperMap.values().forEach(element -> element.forEach(tipper -> {
if (list.contains(tipper.name())) {
tipperMap.putIfAbsent(tipper.getOperableType(), new CopyOnWriteArrayList<>());
operableTypes.add(tipper.getOperableType());
tipperMap.get(tipper.getOperableType()).add(tipper);
}
}));
List<String> activeTippersNames = new ArrayList<>();
this.tipperMap.values().forEach(element -> element.forEach(tipper -> {
activeTippersNames.add(tipper.name());
}));
String jsonTips = new Gson().toJson(activeTippersNames);
PropertiesComponent.getInstance().setValue("savedTippers", jsonTips, "");
//TODO: @Amir Sagiv this should be uncommented
// toolboxStateService.updateAllTippers(list);
}
Aggregations