Search in sources :

Example 1 with Pair

use of com.intellij.openapi.util.Pair in project freeline by alibaba.

the class FreelineUtil method checkInstall.

/**
     * 检查是否需要载入Freeline
     *
     * @param project
     * @return
     */
public static boolean checkInstall(@NotNull final Project project) {
    final FreelineStatus status = getFreelineStatus(project);
    if (GradleUtil.isSyncInProgress(project)) {
        NotificationUtils.errorMsgDialog("Waiting for sync project to complete");
        return false;
    }
    if (status.hasInitFreeline()) {
        return true;
    }
    if (status.getGradleBuildFiles().size() < 1) {
        NotificationUtils.errorMsgDialog("It's not an Android Gradle project Currently?");
        return false;
    }
    if (status.isExistClasspath() && status.isExistPlugin() && !status.isExistFreelineCore()) {
        NotificationUtils.errorNotification("Execute task initFreeline and download freeline dependencies...");
        initFreeline(project);
        return false;
    }
    if (DialogUtil.createDialog("Detected that you did not installFreeline Freeline, Whether installFreeline Automatically?", "Install Freeline Automatically", "Cancel")) {
        Module[] modules = ModuleManager.getInstance(project).getModules();
        List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
        for (Module module : modules) {
            GradleBuildFile file = GradleBuildFile.get(module);
            if (file != null && !GradleUtil.isLibrary(file)) {
                selectModulesList.add(Pair.create(module, file.getPsiFile()));
            }
        }
        // 多个app模块的情况
        if (selectModulesList.size() > 1) {
            final DialogBuilder builder = new DialogBuilder();
            builder.setTitle("Install Freeline");
            builder.resizable(false);
            builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the module to be installed Freeline.", Messages.getInformationIcon(), SwingConstants.CENTER));
            builder.addOkAction().setText("Cancel");
            for (final Pair<Module, PsiFile> pair : selectModulesList) {
                builder.addAction(new AbstractAction(":" + pair.first.getName()) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
                        installFreeline(project, status, pair.getSecond());
                    }
                });
            }
            if (builder.show() > -1) {
                return false;
            }
        } else if (selectModulesList.size() == 1) {
            installFreeline(project, status, selectModulesList.get(0).getSecond());
        } else {
            NotificationUtils.errorMsgDialog("Can not found Application Module! Please Sync Project.");
            return false;
        }
    }
    return false;
}
Also used : GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ActionEvent(java.awt.event.ActionEvent) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Pair(com.intellij.openapi.util.Pair)

Example 2 with Pair

use of com.intellij.openapi.util.Pair in project freeline by alibaba.

the class UsingReportAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    Module[] modules = ModuleManager.getInstance(project).getModules();
    List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
    for (Module module : modules) {
        GradleBuildFile file = GradleBuildFile.get(module);
        if (file != null && !GradleUtil.isLibrary(file)) {
            selectModulesList.add(Pair.create(module, file.getPsiFile()));
        }
    }
    if (selectModulesList.size() > 1) {
        final DialogBuilder builder = new DialogBuilder();
        builder.setTitle("Freeline Reporter");
        builder.resizable(false);
        builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER));
        builder.addOkAction().setText("Cancel");
        for (final Pair<Module, PsiFile> pair : selectModulesList) {
            builder.addAction(new AbstractAction(":" + pair.first.getName()) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
                    report(project, pair.getSecond());
                }
            });
        }
        if (builder.show() > -1) {
        //return false;
        }
    } else if (selectModulesList.size() == 1) {
        report(project, selectModulesList.get(0).getSecond());
    }
}
Also used : GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Pair(com.intellij.openapi.util.Pair)

Example 3 with Pair

use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.

the class CreateElixirModuleAction method buildDialog.

/*
     * Protected Instance Methods
     */
/**
     * todo: the Application-template, Supervisor-template, GenServer-template, GenEvent-template should be improved
     */
@Override
protected void buildDialog(@NotNull Project project, @NotNull final PsiDirectory directory, @NotNull CreateFileFromTemplateDialog.Builder builder) {
    builder.setTitle(NEW_ELIXIR_MODULE).addKind("Empty module", ElixirIcons.FILE, "Elixir Module").addKind("Elixir Application", ElixirIcons.ELIXIR_APPLICATION, "Elixir Application").addKind("Elixir Supervisor", ElixirIcons.ELIXIR_SUPERVISOR, "Elixir Supervisor").addKind("Elixir GenServer", ElixirIcons.ELIXIR_GEN_SERVER, "Elixir GenServer").addKind("Elixir GenEvent", ElixirIcons.ELIXIR_GEN_EVENT, "Elixir GenEvent").setValidator(new InputValidatorEx() {

        /*
                     * Public Instance Methods
                     */
        @Override
        public boolean canClose(String inputString) {
            return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null;
        }

        @Override
        public boolean checkInput(String inputString) {
            return checkFormat(inputString) && checkDoesNotExist(inputString);
        }

        @Nullable
        @Override
        public String getErrorText(String inputString) {
            String errorText = null;
            if (!StringUtil.isEmpty(inputString)) {
                if (!checkFormat(inputString)) {
                    errorText = String.format(INVALID_MODULE_MESSAGE_FMT, inputString);
                } else if (!checkDoesNotExist(inputString)) {
                    String fullPath = fullPath(directory, ancestorDirectoryNamesBaseNamePair(inputString));
                    errorText = String.format(EXISTING_MODULE_MESSAGE_FMT, fullPath);
                }
            }
            return errorText;
        }

        /*
                     * Private Instance Methods
                     */
        private boolean checkDoesNotExist(@NotNull String moduleName) {
            Pair<List<String>, String> ancestorDirectoryNamesBaseNamePair = ancestorDirectoryNamesBaseNamePair(moduleName);
            List<String> ancestorDirectoryNames = ancestorDirectoryNamesBaseNamePair.first;
            PsiDirectory currentDirectory = directory;
            boolean doesNotExists = false;
            for (String ancestorDirectoryName : ancestorDirectoryNames) {
                PsiDirectory subdirectory = currentDirectory.findSubdirectory(ancestorDirectoryName);
                if (subdirectory == null) {
                    doesNotExists = true;
                    break;
                }
                currentDirectory = subdirectory;
            }
            // if all the directories exist
            if (!doesNotExists) {
                String baseName = ancestorDirectoryNamesBaseNamePair.second;
                doesNotExists = currentDirectory.findFile(baseName) == null;
            }
            return doesNotExists;
        }

        private boolean checkFormat(@NotNull String inputString) {
            Matcher matcher = MODULE_NAME_PATTERN.matcher(inputString);
            return matcher.matches();
        }
    });
}
Also used : Matcher(java.util.regex.Matcher) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) List(java.util.List) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx) Nullable(org.jetbrains.annotations.Nullable) Pair(com.intellij.openapi.util.Pair)

Example 4 with Pair

use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.

the class Module method childCallTreeElements.

/*
     * Private Static Methods
     */
@Contract(pure = true)
@Nullable
private static TreeElement[] childCallTreeElements(@NotNull Modular modular, Call[] childCalls) {
    TreeElement[] treeElements = null;
    if (childCalls != null) {
        int length = childCalls.length;
        final List<TreeElement> treeElementList = new ArrayList<TreeElement>(length);
        FunctionByNameArity functionByNameArity = new FunctionByNameArity(length, treeElementList, modular);
        MacroByNameArity macroByNameArity = new MacroByNameArity(length, treeElementList, modular);
        Set<Overridable> overridableSet = new HashSet<Overridable>();
        Set<org.elixir_lang.structure_view.element.Use> useSet = new HashSet<org.elixir_lang.structure_view.element.Use>();
        for (Call childCall : childCalls) {
            if (Callback.is(childCall)) {
                treeElementList.add(new Callback(modular, childCall));
            } else if (Delegation.is(childCall)) {
                functionByNameArity.addDelegationToTreeElementList(childCall);
            } else if (Exception.is(childCall)) {
                functionByNameArity.setException(new Exception(modular, childCall));
            } else if (CallDefinitionClause.isFunction(childCall)) {
                functionByNameArity.addClausesToCallDefinition(childCall);
            } else if (CallDefinitionSpecification.is(childCall)) {
                functionByNameArity.addSpecificationToCallDefinition(childCall);
            } else if (Implementation.is(childCall)) {
                treeElementList.add(new Implementation(modular, childCall));
            } else if (CallDefinitionClause.isMacro(childCall)) {
                macroByNameArity.addClausesToCallDefinition(childCall);
            } else if (Module.is(childCall)) {
                treeElementList.add(new Module(modular, childCall));
            } else if (Overridable.is(childCall)) {
                Overridable overridable = new Overridable(modular, childCall);
                overridableSet.add(overridable);
                treeElementList.add(overridable);
            } else if (Protocol.is(childCall)) {
                treeElementList.add(new Protocol(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Quote.is(childCall)) {
                treeElementList.add(new Quote(modular, childCall));
            } else if (Structure.is(childCall)) {
                treeElementList.add(new Structure(modular, childCall));
            } else if (Type.is(childCall)) {
                treeElementList.add(Type.fromCall(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Use.is(childCall)) {
                org.elixir_lang.structure_view.element.Use use = new org.elixir_lang.structure_view.element.Use(modular, childCall);
                useSet.add(use);
                treeElementList.add(use);
            } else if (Unknown.is(childCall)) {
                // Should always be last since it will match all macro calls
                treeElementList.add(new Unknown(modular, childCall));
            }
        }
        for (Overridable overridable : overridableSet) {
            for (TreeElement treeElement : overridable.getChildren()) {
                CallReference callReference = (CallReference) treeElement;
                Integer arity = callReference.arity();
                if (arity != null) {
                    String name = callReference.name();
                    CallDefinition function = functionByNameArity.get(pair(name, arity));
                    if (function != null) {
                        function.setOverridable(true);
                    }
                }
            }
        }
        Collection<TreeElement> useCollection = new HashSet<TreeElement>(useSet.size());
        useCollection.addAll(useSet);
        Collection<TreeElement> nodesFromUses = Used.provideNodesFromChildren(useCollection);
        Map<Pair<String, Integer>, CallDefinition> useFunctionByNameArity = Used.functionByNameArity(nodesFromUses);
        for (Map.Entry<Pair<String, Integer>, CallDefinition> useNameArityFunction : useFunctionByNameArity.entrySet()) {
            CallDefinition useFunction = useNameArityFunction.getValue();
            if (useFunction.isOverridable()) {
                Pair<String, Integer> useNameArity = useNameArityFunction.getKey();
                CallDefinition function = functionByNameArity.get(useNameArity);
                if (function != null) {
                    function.setOverride(true);
                }
            }
        }
        treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    }
    return treeElements;
}
Also used : MacroByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.MacroByNameArity) CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) FunctionByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.FunctionByNameArity) Structure(org.elixir_lang.structure_view.element.structure.Structure) org.elixir_lang.structure_view.element(org.elixir_lang.structure_view.element) Pair(com.intellij.openapi.util.Pair) Call(org.elixir_lang.psi.call.Call) ElixirPsiImplUtil.enclosingMacroCall(org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall) Overridable(org.elixir_lang.structure_view.element.Overridable) Exception(org.elixir_lang.structure_view.element.Exception) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Quote(org.elixir_lang.structure_view.element.Quote) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Pair

use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.

the class CallDefinition method getLineMarkerInfo.

@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull Call call) {
    LineMarkerInfo lineMarkerInfo = null;
    if (daemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && CallDefinitionClause.is(call)) {
        Call previousCallDefinitionClause = siblingCallDefinitionClause(call, PREVIOUS_SIBLING);
        boolean firstClause;
        if (previousCallDefinitionClause == null) {
            firstClause = true;
        } else {
            Pair<String, IntRange> callNameArityRange = nameArityRange(call);
            if (callNameArityRange != null) {
                Pair<String, IntRange> previousNameArityRange = nameArityRange(previousCallDefinitionClause);
                firstClause = previousNameArityRange == null || !previousNameArityRange.equals(callNameArityRange);
            } else {
                firstClause = true;
            }
        }
        if (firstClause) {
            PsiElement previousExpression = previousSiblingExpression(call);
            if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
                AtUnqualifiedNoParenthesesCall previousModuleAttributeDefinition = (AtUnqualifiedNoParenthesesCall) previousExpression;
                String moduleAttributeName = moduleAttributeName(previousModuleAttributeDefinition);
                if (moduleAttributeName.equals("@doc")) {
                    firstClause = false;
                } else if (moduleAttributeName.equals("@spec")) {
                    Pair<String, IntRange> callNameArityRange = nameArityRange(call);
                    if (callNameArityRange != null) {
                        Pair<String, Integer> specNameArity = moduleAttributeNameArity(previousModuleAttributeDefinition);
                        if (specNameArity != null) {
                            Integer specArity = specNameArity.second;
                            IntRange callArityRange = callNameArityRange.second;
                            if (callArityRange.containsInteger(specArity)) {
                                firstClause = false;
                            }
                        }
                    }
                }
            }
        }
        if (firstClause) {
            lineMarkerInfo = callDefinitionSeparator(call);
        }
    }
    return lineMarkerInfo;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) IntRange(org.apache.commons.lang.math.IntRange) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Pair (com.intellij.openapi.util.Pair)391 NotNull (org.jetbrains.annotations.NotNull)131 ArrayList (java.util.ArrayList)83 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 Project (com.intellij.openapi.project.Project)60 Nullable (org.jetbrains.annotations.Nullable)59 PsiElement (com.intellij.psi.PsiElement)47 TextRange (com.intellij.openapi.util.TextRange)43 File (java.io.File)42 List (java.util.List)37 Module (com.intellij.openapi.module.Module)34 ContainerUtil (com.intellij.util.containers.ContainerUtil)26 PsiFile (com.intellij.psi.PsiFile)25 StringUtil (com.intellij.openapi.util.text.StringUtil)20 IOException (java.io.IOException)19 java.util (java.util)19 ApplicationManager (com.intellij.openapi.application.ApplicationManager)18 THashSet (gnu.trove.THashSet)17 Map (java.util.Map)17 Document (com.intellij.openapi.editor.Document)15