Search in sources :

Example 1 with Tipper

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

Example 2 with Tipper

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);
}
Also used : java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Reflections(org.reflections.Reflections) Constructor(java.lang.reflect.Constructor) JavaRecursiveElementVisitor(com.intellij.psi.JavaRecursiveElementVisitor) Gson(com.google.gson.Gson) PsiElement(com.intellij.psi.PsiElement) PsiRewrite(il.org.spartan.Leonidas.auxilary_layer.PsiRewrite) PsiFile(com.intellij.psi.PsiFile) Modifier.isAbstract(java.lang.reflect.Modifier.isAbstract) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) ApplicationComponent(com.intellij.openapi.components.ApplicationComponent) TipperUnderConstruction(il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition.TipperUnderConstruction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) Leonidas.plugin.tippers(il.org.spartan.Leonidas.plugin.tippers) Utils(il.org.spartan.Leonidas.auxilary_layer.Utils) Tipper(il.org.spartan.Leonidas.plugin.tipping.Tipper) Wrapper(il.org.spartan.Leonidas.auxilary_layer.Wrapper) LeonidasTipperDefinition(il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition) Modifier(java.lang.reflect.Modifier) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Logger(il.org.spartan.Leonidas.plugin.utils.logging.Logger) GenericEncapsulator(il.org.spartan.Leonidas.plugin.leonidas.BasicBlocks.GenericEncapsulator) NotNull(org.jetbrains.annotations.NotNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Gson(com.google.gson.Gson) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

JavaRecursiveElementVisitor (com.intellij.psi.JavaRecursiveElementVisitor)2 PsiElement (com.intellij.psi.PsiElement)2 PsiRewrite (il.org.spartan.Leonidas.auxilary_layer.PsiRewrite)2 Wrapper (il.org.spartan.Leonidas.auxilary_layer.Wrapper)2 Tipper (il.org.spartan.Leonidas.plugin.tipping.Tipper)2 Gson (com.google.gson.Gson)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationComponent (com.intellij.openapi.components.ApplicationComponent)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 Utils (il.org.spartan.Leonidas.auxilary_layer.Utils)1 GenericEncapsulator (il.org.spartan.Leonidas.plugin.leonidas.BasicBlocks.GenericEncapsulator)1 Leonidas.plugin.tippers (il.org.spartan.Leonidas.plugin.tippers)1 LeonidasTipperDefinition (il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition)1 TipperUnderConstruction (il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition.TipperUnderConstruction)1 Logger (il.org.spartan.Leonidas.plugin.utils.logging.Logger)1 Constructor (java.lang.reflect.Constructor)1 Modifier (java.lang.reflect.Modifier)1 Modifier.isAbstract (java.lang.reflect.Modifier.isAbstract)1