Search in sources :

Example 21 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class GrClosureSignatureUtil method getSignatureApplicabilities.

private static List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> getSignatureApplicabilities(@NotNull GrSignature signature, @NotNull final PsiType[] args, @NotNull final PsiElement context) {
    final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = new ArrayList<>();
    signature.accept(new GrRecursiveSignatureVisitor() {

        @Override
        public void visitClosureSignature(GrClosureSignature signature) {
            ArgInfo<PsiType>[] map = mapArgTypesToParameters(signature, args, context, false);
            if (map != null) {
                results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
                return;
            }
            // check for the case foo([1, 2, 3]) if foo(int, int, int)
            if (args.length == 1 && PsiUtil.isInMethodCallContext(context)) {
                final GrClosureParameter[] parameters = signature.getParameters();
                if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) {
                    return;
                }
                PsiType arg = args[0];
                if (arg instanceof GrTupleType) {
                    PsiType[] _args = ((GrTupleType) arg).getComponentTypes();
                    map = mapArgTypesToParameters(signature, _args, context, false);
                    if (map != null) {
                        results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
                    }
                }
            }
        }
    });
    return results;
}
Also used : Trinity(com.intellij.openapi.util.Trinity) GrRecursiveSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType)

Example 22 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class MavenProjectModelModifier method addDependency.

private Promise<Void> addDependency(@NotNull Collection<Module> fromModules, @NotNull final MavenId mavenId, @Nullable String minVersion, @Nullable String maxVersion, @NotNull final DependencyScope scope) {
    final List<Trinity<MavenDomProjectModel, MavenId, String>> models = new ArrayList<>(fromModules.size());
    List<XmlFile> files = new ArrayList<>(fromModules.size());
    List<MavenProject> projectToUpdate = new ArrayList<>(fromModules.size());
    final String mavenScope = getMavenScope(scope);
    for (Module from : fromModules) {
        if (!myProjectsManager.isMavenizedModule(from))
            return null;
        MavenProject fromProject = myProjectsManager.findProject(from);
        if (fromProject == null)
            return null;
        final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, fromProject.getFile());
        if (model == null)
            return null;
        String scopeToSet = null;
        String version = null;
        if (mavenId.getGroupId() != null && mavenId.getArtifactId() != null) {
            MavenDomDependency managedDependency = MavenDependencyCompletionUtil.findManagedDependency(model, myProject, mavenId.getGroupId(), mavenId.getArtifactId());
            if (managedDependency != null) {
                String managedScope = StringUtil.nullize(managedDependency.getScope().getStringValue(), true);
                scopeToSet = (managedScope == null && MavenConstants.SCOPE_COMPILE.equals(mavenScope)) || StringUtil.equals(managedScope, mavenScope) ? null : mavenScope;
            }
            if (managedDependency == null || StringUtil.isEmpty(managedDependency.getVersion().getStringValue())) {
                version = selectVersion(mavenId, minVersion, maxVersion);
            }
        }
        models.add(Trinity.create(model, new MavenId(mavenId.getGroupId(), mavenId.getArtifactId(), version), scopeToSet));
        files.add(DomUtil.getFile(model));
        projectToUpdate.add(fromProject);
    }
    new WriteCommandAction(myProject, "Add Maven Dependency", PsiUtilCore.toPsiFileArray(files)) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            for (Trinity<MavenDomProjectModel, MavenId, String> trinity : models) {
                final MavenDomProjectModel model = trinity.first;
                MavenDomDependency dependency = MavenDomUtil.createDomDependency(model, null, trinity.second);
                String mavenScope = trinity.third;
                if (mavenScope != null) {
                    dependency.getScope().setStringValue(mavenScope);
                }
                Document document = PsiDocumentManager.getInstance(myProject).getDocument(DomUtil.getFile(model));
                if (document != null) {
                    FileDocumentManager.getInstance().saveDocument(document);
                }
            }
        }
    }.execute();
    return myProjectsManager.forceUpdateProjects(projectToUpdate);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Trinity(com.intellij.openapi.util.Trinity) XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) Result(com.intellij.openapi.application.Result) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Module(com.intellij.openapi.module.Module)

Example 23 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-plugins by JetBrains.

the class KeystorePasswordDialog method createPasswordFields.

private Collection<Trinity<AirSigningOptions, JPasswordField, JPasswordField>> createPasswordFields(final Collection<AirSigningOptions> signingOptionsWithUnknownPasswords) {
    final Collection<Trinity<AirSigningOptions, JPasswordField, JPasswordField>> result = new ArrayList<>();
    final JPanel panel = new JPanel(new GridBagLayout());
    myMainPanel.add(panel, BorderLayout.CENTER);
    int row = 0;
    for (AirSigningOptions signingOptions : signingOptionsWithUnknownPasswords) {
        if (row > 0) {
            panel.add(new JSeparator(SwingConstants.HORIZONTAL), new GridBagConstraints(0, row, 2, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(5, 0), 0, 0));
            row++;
        }
        panel.add(new JLabel("Keystore file:"), new GridBagConstraints(0, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
        panel.add(new JLabel(FileUtil.toSystemDependentName(signingOptions.getKeystorePath())), new GridBagConstraints(1, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
        row++;
        panel.add(new JLabel("Keystore password:"), new GridBagConstraints(0, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
        final JPasswordField keystorePasswordField = new JPasswordField();
        panel.add(keystorePasswordField, new GridBagConstraints(1, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(2, 0), 0, 0));
        if (row == 1) {
            myPreferredFocusedComponent = keystorePasswordField;
        }
        row++;
        if (signingOptions.getKeyAlias().isEmpty()) {
            result.add(Trinity.create(signingOptions, keystorePasswordField, (JPasswordField) null));
        } else {
            panel.add(new JLabel("Key alias:"), new GridBagConstraints(0, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
            panel.add(new JLabel(signingOptions.getKeyAlias()), new GridBagConstraints(1, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
            row++;
            panel.add(new JLabel("Key password:"), new GridBagConstraints(0, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(2, 0), 0, 0));
            final JPasswordField keyPasswordField = new JPasswordField();
            panel.add(keyPasswordField, new GridBagConstraints(1, row, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(2, 0), 0, 0));
            row++;
            result.add(Trinity.create(signingOptions, keystorePasswordField, keyPasswordField));
        }
    }
    return result;
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ArrayList(java.util.ArrayList) AirSigningOptions(com.intellij.lang.javascript.flex.projectStructure.model.AirSigningOptions)

Example 24 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-plugins by JetBrains.

the class ValidateFlashConfigurationsPrecompileTask method getProblems.

static Collection<Trinity<Module, FlexBuildConfiguration, FlashProjectStructureProblem>> getProblems(final CompileScope scope, final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCsToCompile) {
    final Collection<Trinity<Module, FlexBuildConfiguration, FlashProjectStructureProblem>> problems = new ArrayList<>();
    for (final Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCsToCompile) {
        final Module module = moduleAndBC.first;
        final FlexBuildConfiguration bc = moduleAndBC.second;
        final Consumer<FlashProjectStructureProblem> errorConsumer = problem -> problems.add(Trinity.create(module, bc, problem));
        checkConfiguration(module, bc, false, errorConsumer);
        final RunConfiguration runConfig = CompileStepBeforeRun.getRunConfiguration(scope);
        if (bc.getNature().isApp() && runConfig instanceof FlashRunConfiguration) {
            final FlashRunnerParameters params = ((FlashRunConfiguration) runConfig).getRunnerParameters();
            if (module.getName().equals(params.getModuleName()) && bc.getName().equals(params.getBCName())) {
                if (bc.getNature().isDesktopPlatform()) {
                    FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAirDesktopPackagingOptions(), errorConsumer, false, "does not matter");
                } else if (bc.getNature().isMobilePlatform()) {
                    switch(params.getMobileRunTarget()) {
                        case Emulator:
                            switch(params.getAppDescriptorForEmulator()) {
                                case Android:
                                    FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAndroidPackagingOptions(), errorConsumer, false, "does not matter");
                                    break;
                                case IOS:
                                    FlashRunnerParameters.checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getIosPackagingOptions(), errorConsumer, false, "does not matter");
                                    break;
                            }
                            break;
                        case AndroidDevice:
                            checkPackagingOptions(module, bc.getSdk(), bc.getAndroidPackagingOptions(), false, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
                            break;
                        case iOSSimulator:
                            checkPackagingOptions(module, bc.getSdk(), bc.getIosPackagingOptions(), true, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
                            break;
                        case iOSDevice:
                            checkPackagingOptions(module, bc.getSdk(), bc.getIosPackagingOptions(), false, PathUtil.getParentPath(bc.getActualOutputFilePath()), errorConsumer);
                            break;
                    }
                }
            }
        }
    }
    checkSimilarOutputFiles(modulesAndBCsToCompile, trinity -> problems.add(trinity));
    return problems;
}
Also used : Trinity(com.intellij.openapi.util.Trinity) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ReadAction(com.intellij.openapi.application.ReadAction) FlexCommonUtils(com.intellij.flex.FlexCommonUtils) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) Map(java.util.Map) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ProjectStructureProblemType(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureProblemType) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) com.intellij.openapi.compiler(com.intellij.openapi.compiler) Collection(java.util.Collection) Set(java.util.Set) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) NotificationListener(com.intellij.notification.NotificationListener) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) CompilerWorkspaceConfiguration(com.intellij.compiler.CompilerWorkspaceConfiguration) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) OutputType(com.intellij.flex.model.bc.OutputType) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) CompileStepBeforeRun(com.intellij.compiler.options.CompileStepBeforeRun) ArrayList(java.util.ArrayList) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) com.intellij.lang.javascript.flex.projectStructure.ui(com.intellij.lang.javascript.flex.projectStructure.ui) Project(com.intellij.openapi.project.Project) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) FlexCommonBundle(com.intellij.flex.FlexCommonBundle) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) FlashRunConfiguration(com.intellij.lang.javascript.flex.run.FlashRunConfiguration) com.intellij.lang.javascript.flex.projectStructure.model(com.intellij.lang.javascript.flex.projectStructure.model) FlashRunnerParameters(com.intellij.lang.javascript.flex.run.FlashRunnerParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) Place(com.intellij.ui.navigation.Place) Pair(com.intellij.openapi.util.Pair) ProjectStructureConfigurable(com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable) Navigatable(com.intellij.pom.Navigatable) PathUtil(com.intellij.util.PathUtil) Trinity(com.intellij.openapi.util.Trinity) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FlashRunConfiguration(com.intellij.lang.javascript.flex.run.FlashRunConfiguration) ArrayList(java.util.ArrayList) FlashRunConfiguration(com.intellij.lang.javascript.flex.run.FlashRunConfiguration) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) Module(com.intellij.openapi.module.Module) FlashRunnerParameters(com.intellij.lang.javascript.flex.run.FlashRunnerParameters)

Aggregations

Trinity (com.intellij.openapi.util.Trinity)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Pair (com.intellij.openapi.util.Pair)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 Language (com.intellij.lang.Language)3 FileType (com.intellij.openapi.fileTypes.FileType)3 TextRange (com.intellij.openapi.util.TextRange)3 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)2 ProcessHandler (com.intellij.execution.process.ProcessHandler)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)2 Module (com.intellij.openapi.module.Module)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2