All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hexffff0.eggs.action.RunCodeAction Maven / Gradle / Ivy

Go to download

Eggs是一个强大的Intellij IDEA 插件,它允许你在运行时编写Java代码与IDEA进行交互,最终得到你想要的效果,例如生成代码。

The newest version!
package com.github.hexffff0.eggs.action;

import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.github.hexffff0.eggs.core.RunCodeHelper;
import com.github.hexffff0.eggs.persistence.ExecuteUnit;
import com.github.hexffff0.eggs.persistence.ExecuteUnitRepository;
import com.google.common.collect.Maps;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.util.NlsActions.ActionDescription;
import com.intellij.openapi.util.NlsActions.ActionText;
/**
 * @author hyc
 */
public class RunCodeAction extends AnAction {

    private String codeTemplateId;

    /** you should never call this constructor on your code */
    public RunCodeAction() {
    }

    public static RunCodeAction of(String codeTemplateId) {
        ExecuteUnitRepository executeUnitRepository = ServiceManager.getService(ExecuteUnitRepository.class);
        Map codeTemplateMap = executeUnitRepository.getExecuteUnitMap();
        ExecuteUnit executeUnit = codeTemplateMap.get(codeTemplateId);
        RunCodeAction runCodeAction = new RunCodeAction(executeUnit.name, executeUnit.desc, null);
        runCodeAction.codeTemplateId = executeUnit.uuid;
        return runCodeAction;
    }


    private RunCodeAction(@Nullable @ActionText String text,
        @Nullable @ActionDescription String description,
        @Nullable Icon icon) {
        super(text, description, icon);
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        ExecuteUnitRepository executeUnitRepository = ServiceManager.getService(ExecuteUnitRepository.class);
        Map executeUnitMap = executeUnitRepository.getExecuteUnitMap();
        ExecuteUnit executeUnit = executeUnitMap.get(codeTemplateId);
        HashMap context = Maps.newHashMap();
        context.put("AnActionEvent", e);
        RunCodeHelper.compileAndRunCode(executeUnit, context);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy