Search in sources :

Example 51 with HashMap

use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.

the class CucumberCreateStepFixBase method askUserForFilePath.

@Nullable
private static CreateStepDefinitionFileModel askUserForFilePath(@NotNull final GherkinStep step) {
    final InputValidator validator = new InputValidator() {

        public boolean checkInput(final String filePath) {
            return !StringUtil.isEmpty(filePath);
        }

        public boolean canClose(final String fileName) {
            return true;
        }
    };
    Map<BDDFrameworkType, String> supportedFileTypesAndDefaultFileNames = new HashMap<>();
    Map<BDDFrameworkType, PsiDirectory> fileTypeToDefaultDirectoryMap = new HashMap<>();
    for (CucumberJvmExtensionPoint e : Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME)) {
        if (e instanceof OptionalStepDefinitionExtensionPoint) {
            // Skip if framework file creation support is optional
            if (!((OptionalStepDefinitionExtensionPoint) e).participateInStepDefinitionCreation(step)) {
                continue;
            }
        }
        supportedFileTypesAndDefaultFileNames.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepFileName(step));
        fileTypeToDefaultDirectoryMap.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepDefinitionFolder(step));
    }
    CreateStepDefinitionFileModel model = new CreateStepDefinitionFileModel(step.getProject(), supportedFileTypesAndDefaultFileNames, fileTypeToDefaultDirectoryMap);
    CreateStepDefinitionFileDialog createStepDefinitionFileDialog = new CreateStepDefinitionFileDialog(step.getProject(), model, validator);
    if (createStepDefinitionFileDialog.showAndGet()) {
        return model;
    } else {
        return null;
    }
}
Also used : InputValidator(com.intellij.openapi.ui.InputValidator) HashMap(com.intellij.util.containers.HashMap) PsiDirectory(com.intellij.psi.PsiDirectory) CreateStepDefinitionFileModel(org.jetbrains.plugins.cucumber.inspections.model.CreateStepDefinitionFileModel) CreateStepDefinitionFileDialog(org.jetbrains.plugins.cucumber.inspections.ui.CreateStepDefinitionFileDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with HashMap

use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.

the class FlexCssPropertyDescriptor method getDeclarations.

@NotNull
@Override
public PsiElement[] getDeclarations(@NotNull PsiElement context) {
    Map<PsiElement, PairInfo> navElement2pairInfo = new HashMap<>();
    final Project project = context.getProject();
    GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
    Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
    for (String className : myClassNames) {
        Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, className.hashCode(), project, scope, JSQualifiedNamedElement.class);
        findStyleAttributes(candidates, visited, navElement2pairInfo);
        // search in MXML files
        PsiElement jsClass = ActionScriptClassResolver.findClassByQNameStatic(className, scope);
        if (jsClass instanceof JSClass) {
            findStyleAttributesInClassOrSuper((JSClass) jsClass, visited, navElement2pairInfo);
        }
    }
    Set<JSFile> visitedFiles = ContainerUtil.newLinkedHashSet();
    for (String fileName : myFileNames) {
        Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, fileName, scope);
        for (final VirtualFile file : files) {
            PsiFile psiFile = ReadAction.compute(() -> PsiManager.getInstance(project).findFile(file));
            if (psiFile instanceof JSFile) {
                findStyleAttributesInFile((JSFile) psiFile, visitedFiles, navElement2pairInfo);
            }
        }
    }
    Set<PsiElement> navPairs = navElement2pairInfo.keySet();
    Map<String, PsiElement> qName2ResultElement = new HashMap<>();
    for (PsiElement navPair : navPairs) {
        PairInfo pairInfo = navElement2pairInfo.get(navPair);
        String jsClassQName = pairInfo.myJsClassQName;
        PsiElement navPairInOtherClassWithSameQName = jsClassQName != null ? qName2ResultElement.get(jsClassQName) : null;
        if (navPairInOtherClassWithSameQName == null || navPairInOtherClassWithSameQName == navElement2pairInfo.get(navPairInOtherClassWithSameQName) && pairInfo.myPair != navPair) {
            qName2ResultElement.put(jsClassQName, navPair);
        }
    }
    Collection<PsiElement> result = qName2ResultElement.values();
    return PsiUtilCore.toPsiElementArray(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with HashMap

use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.

the class FlexBCConfigurator method canBeRemoved.

public boolean canBeRemoved(ModifiableFlexBuildConfiguration[] configurations) {
    Map<Module, Integer> module2ConfigCount = new HashMap<>();
    for (ModifiableFlexBuildConfiguration bc : configurations) {
        Module module = myConfigEditor.getModule(bc);
        Integer count = module2ConfigCount.get(module);
        module2ConfigCount.put(module, count != null ? count + 1 : 1);
    }
    for (Map.Entry<Module, Integer> entry : module2ConfigCount.entrySet()) {
        Module module = entry.getKey();
        if (myConfigEditor.getConfigurations(module).length == entry.getValue()) {
            return false;
        }
    }
    return true;
}
Also used : HashMap(com.intellij.util.containers.HashMap) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) BidirectionalMap(com.intellij.util.containers.BidirectionalMap) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 54 with HashMap

use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.

the class FlexProjectConfigurationEditor method setEntries.

public void setEntries(ModifiableDependencies dependant, List<? extends ModifiableDependencyEntry> newEntries) {
    assertAlive();
    Map<String, ModifiableDependencyEntry> existingModuleLibrariesEntries = new HashMap<>();
    Map<Pair<String, String>, ModifiableBuildConfigurationEntry> existingBcEntries = new HashMap<>();
    Map<Pair<String, String>, ModifiableSharedLibraryEntry> existingSharedLibrariesEntries = new HashMap<>();
    for (ModifiableDependencyEntry entry : dependant.getModifiableEntries()) {
        if (entry instanceof ModuleLibraryEntry) {
            existingModuleLibrariesEntries.put(((ModuleLibraryEntry) entry).getLibraryId(), entry);
        } else if (entry instanceof ModifiableSharedLibraryEntry) {
            final ModifiableSharedLibraryEntry e = (ModifiableSharedLibraryEntry) entry;
            existingSharedLibrariesEntries.put(Pair.create(e.getLibraryLevel(), e.getLibraryName()), e);
        } else if (entry instanceof ModifiableBuildConfigurationEntry) {
            final ModifiableBuildConfigurationEntry e = (ModifiableBuildConfigurationEntry) entry;
            existingBcEntries.put(Pair.create(e.getModuleName(), e.getBcName()), e);
        } else {
            assert false : entry;
        }
    }
    List<ModifiableDependencyEntry> entriesToRemove = new ArrayList<>(dependant.getModifiableEntries());
    for (Iterator<? extends ModifiableDependencyEntry> i = newEntries.iterator(); i.hasNext(); ) {
        ModifiableDependencyEntry newEntry = i.next();
        ModifiableDependencyEntry existingEntry = null;
        if (newEntry instanceof ModuleLibraryEntry) {
            existingEntry = existingModuleLibrariesEntries.get(((ModuleLibraryEntry) newEntry).getLibraryId());
        } else if (newEntry instanceof SharedLibraryEntry) {
            final SharedLibraryEntry e = (SharedLibraryEntry) newEntry;
            existingEntry = existingSharedLibrariesEntries.get(Pair.create(e.getLibraryLevel(), e.getLibraryName()));
        } else if (newEntry instanceof BuildConfigurationEntry) {
            final BuildConfigurationEntry bcEntry = (BuildConfigurationEntry) newEntry;
            existingEntry = existingBcEntries.get(Pair.create(bcEntry.getModuleName(), bcEntry.getBcName()));
        } else {
            assert false : newEntry;
        }
        if (existingEntry != null) {
            entriesToRemove.remove(existingEntry);
            existingEntry.getDependencyType().copyFrom(newEntry.getDependencyType());
            i.remove();
        }
    }
    Editor dependantEditor = getEditor(dependant);
    ModifiableRootModel dependantModifiableModel = myProvider.getModuleModifiableModel(dependantEditor.myModule);
    for (DependencyEntry entry : entriesToRemove) {
        if (entry instanceof ModuleLibraryEntry) {
            ModuleLibraryEntry libraryEntry = (ModuleLibraryEntry) entry;
            Library dependencyLibrary = findLibrary(dependantModifiableModel, libraryEntry.getLibraryId());
            if (dependencyLibrary != null) {
                List<Editor> otherEditors = new ArrayList<>(myModule2Editors.get(dependantEditor.myModule));
                otherEditors.remove(dependantEditor);
                if (!libraryIsUsed(libraryEntry.getLibraryId(), otherEditors)) {
                    LibraryOrderEntry orderEntry = dependantModifiableModel.findLibraryOrderEntry(dependencyLibrary);
                    LOG.assertTrue(orderEntry != null);
                    // TODO should we explicitly delete library as well?
                    dependantModifiableModel.removeOrderEntry(orderEntry);
                }
            }
        }
    }
    dependant.getModifiableEntries().removeAll(entriesToRemove);
    dependant.getModifiableEntries().addAll(newEntries);
}
Also used : HashMap(com.intellij.util.containers.HashMap) Library(com.intellij.openapi.roots.libraries.Library) Pair(com.intellij.openapi.util.Pair)

Example 55 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class AndroidLintGlobalInspectionContext method performPreRunActivities.

@Override
public void performPreRunActivities(@NotNull List<Tools> globalTools, @NotNull List<Tools> localTools, @NotNull final GlobalInspectionContext context) {
    final Project project = context.getProject();
    // Running a single inspection that's not lint? If so don't run lint
    if (localTools.isEmpty() && globalTools.size() == 1) {
        Tools tool = globalTools.get(0);
        if (!tool.getShortName().startsWith(LINT_INSPECTION_PREFIX)) {
            return;
        }
    }
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
        return;
    }
    List<Issue> issues = AndroidLintExternalAnnotator.getIssuesFromInspections(project, null);
    if (issues.size() == 0) {
        return;
    }
    // If running a single check by name, turn it on if it's off by default.
    if (localTools.isEmpty() && globalTools.size() == 1) {
        Tools tool = globalTools.get(0);
        String id = tool.getShortName().substring(LINT_INSPECTION_PREFIX.length());
        Issue issue = new LintIdeIssueRegistry().getIssue(id);
        if (issue != null && !issue.isEnabledByDefault()) {
            issues = Collections.singletonList(issue);
            issue.setEnabledByDefault(true);
            // And turn it back off again in cleanup
            myEnabledIssue = issue;
        }
    }
    final Map<Issue, Map<File, List<ProblemData>>> problemMap = new HashMap<>();
    AnalysisScope scope = context.getRefManager().getScope();
    if (scope == null) {
        scope = AndroidLintLintBaselineInspection.ourRerunScope;
        if (scope == null) {
            return;
        }
    }
    final LintIdeClient client = LintIdeClient.forBatch(project, problemMap, scope, issues);
    final LintDriver lint = new LintDriver(new LintIdeIssueRegistry(), client);
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        ProgressWrapper.unwrap(indicator).setText("Running Android Lint");
    }
    EnumSet<Scope> lintScope;
    //noinspection ConstantConditions
    if (!LintIdeProject.SUPPORT_CLASS_FILES) {
        lintScope = EnumSet.copyOf(Scope.ALL);
        // Can't run class file based checks
        lintScope.remove(Scope.CLASS_FILE);
        lintScope.remove(Scope.ALL_CLASS_FILES);
        lintScope.remove(Scope.JAVA_LIBRARIES);
    } else {
        lintScope = Scope.ALL;
    }
    List<VirtualFile> files = null;
    final List<Module> modules = Lists.newArrayList();
    int scopeType = scope.getScopeType();
    switch(scopeType) {
        case AnalysisScope.MODULE:
            {
                SearchScope searchScope = ReadAction.compute(scope::toSearchScope);
                if (searchScope instanceof ModuleWithDependenciesScope) {
                    ModuleWithDependenciesScope s = (ModuleWithDependenciesScope) searchScope;
                    if (!s.isSearchInLibraries()) {
                        modules.add(s.getModule());
                    }
                }
                break;
            }
        case AnalysisScope.FILE:
        case AnalysisScope.VIRTUAL_FILES:
        case AnalysisScope.UNCOMMITTED_FILES:
            {
                files = Lists.newArrayList();
                SearchScope searchScope = scope.toSearchScope();
                if (searchScope instanceof LocalSearchScope) {
                    final LocalSearchScope localSearchScope = (LocalSearchScope) searchScope;
                    final PsiElement[] elements = localSearchScope.getScope();
                    final List<VirtualFile> finalFiles = files;
                    ApplicationManager.getApplication().runReadAction(() -> {
                        for (PsiElement element : elements) {
                            if (element instanceof PsiFile) {
                                // should be the case since scope type is FILE
                                Module module = ModuleUtilCore.findModuleForPsiElement(element);
                                if (module != null && !modules.contains(module)) {
                                    modules.add(module);
                                }
                                VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
                                if (virtualFile != null) {
                                    if (virtualFile instanceof StringsVirtualFile) {
                                        StringsVirtualFile f = (StringsVirtualFile) virtualFile;
                                        if (!modules.contains(f.getFacet().getModule())) {
                                            modules.add(f.getFacet().getModule());
                                        }
                                    } else {
                                        finalFiles.add(virtualFile);
                                    }
                                }
                            }
                        }
                    });
                } else {
                    final List<VirtualFile> finalList = files;
                    scope.accept(new PsiElementVisitor() {

                        @Override
                        public void visitFile(PsiFile file) {
                            VirtualFile virtualFile = file.getVirtualFile();
                            if (virtualFile != null) {
                                finalList.add(virtualFile);
                            }
                        }
                    });
                }
                if (files.isEmpty()) {
                    files = null;
                } else {
                    // Lint will compute it lazily based on actual files in the request
                    lintScope = null;
                }
                break;
            }
        case AnalysisScope.PROJECT:
            {
                modules.addAll(Arrays.asList(ModuleManager.getInstance(project).getModules()));
                break;
            }
        case AnalysisScope.CUSTOM:
        case AnalysisScope.MODULES:
        case AnalysisScope.DIRECTORY:
            {
                // Handled by the getNarrowedComplementaryScope case below
                break;
            }
        case AnalysisScope.INVALID:
            break;
        default:
            Logger.getInstance(this.getClass()).warn("Unexpected inspection scope " + scope + ", " + scopeType);
    }
    if (modules.isEmpty()) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            if (scope.containsModule(module)) {
                modules.add(module);
            }
        }
        if (modules.isEmpty() && files != null) {
            for (VirtualFile file : files) {
                Module module = ModuleUtilCore.findModuleForFile(file, project);
                if (module != null && !modules.contains(module)) {
                    modules.add(module);
                }
            }
        }
        if (modules.isEmpty()) {
            AnalysisScope narrowed = scope.getNarrowedComplementaryScope(project);
            for (Module module : ModuleManager.getInstance(project).getModules()) {
                if (narrowed.containsModule(module)) {
                    modules.add(module);
                }
            }
        }
    }
    LintRequest request = new LintIdeRequest(client, project, files, modules, false);
    request.setScope(lintScope);
    // Baseline analysis?
    myBaseline = null;
    for (Module module : modules) {
        AndroidModuleModel model = AndroidModuleModel.get(module);
        if (model != null) {
            GradleVersion version = model.getModelVersion();
            if (version != null && version.isAtLeast(2, 3, 0, "beta", 2, true)) {
                LintOptions options = model.getAndroidProject().getLintOptions();
                try {
                    File baselineFile = options.getBaselineFile();
                    if (baselineFile != null && !AndroidLintLintBaselineInspection.ourSkipBaselineNextRun) {
                        if (!baselineFile.isAbsolute()) {
                            String path = module.getProject().getBasePath();
                            if (path != null) {
                                baselineFile = new File(FileUtil.toSystemDependentName(path), baselineFile.getPath());
                            }
                        }
                        myBaseline = new LintBaseline(client, baselineFile);
                        lint.setBaseline(myBaseline);
                        if (!baselineFile.isFile()) {
                            myBaseline.setWriteOnClose(true);
                        } else if (AndroidLintLintBaselineInspection.ourUpdateBaselineNextRun) {
                            myBaseline.setRemoveFixed(true);
                            myBaseline.setWriteOnClose(true);
                        }
                    }
                } catch (Throwable unsupported) {
                // During 2.3 development some builds may have this method, others may not
                }
            }
            break;
        }
    }
    lint.analyze(request);
    AndroidLintLintBaselineInspection.clearNextRunState();
    myResults = problemMap;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringsVirtualFile(com.android.tools.idea.editors.strings.StringsVirtualFile) Issue(com.android.tools.lint.detector.api.Issue) HashMap(com.intellij.util.containers.HashMap) LintOptions(com.android.builder.model.LintOptions) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) AnalysisScope(com.intellij.analysis.AnalysisScope) LintRequest(com.android.tools.lint.client.api.LintRequest) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiFile(com.intellij.psi.PsiFile) GradleVersion(com.android.ide.common.repository.GradleVersion) PsiElement(com.intellij.psi.PsiElement) LintDriver(com.android.tools.lint.client.api.LintDriver) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) ModuleWithDependenciesScope(com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope) Tools(com.intellij.codeInspection.ex.Tools) LintBaseline(com.android.tools.lint.client.api.LintBaseline) com.android.tools.idea.lint(com.android.tools.idea.lint) Project(com.intellij.openapi.project.Project) ModuleWithDependenciesScope(com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) Scope(com.android.tools.lint.detector.api.Scope) AnalysisScope(com.intellij.analysis.AnalysisScope) StringsVirtualFile(com.android.tools.idea.editors.strings.StringsVirtualFile) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) StringsVirtualFile(com.android.tools.idea.editors.strings.StringsVirtualFile)

Aggregations

HashMap (com.intellij.util.containers.HashMap)118 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 File (java.io.File)22 Nullable (org.jetbrains.annotations.Nullable)18 Map (java.util.Map)17 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)15 ArrayList (java.util.ArrayList)14 PsiElement (com.intellij.psi.PsiElement)11 HashSet (com.intellij.util.containers.HashSet)10 List (java.util.List)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 IOException (java.io.IOException)8 Pair (com.intellij.openapi.util.Pair)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 SearchScope (com.intellij.psi.search.SearchScope)6 Logger (com.intellij.openapi.diagnostic.Logger)5 PsiFile (com.intellij.psi.PsiFile)5 UsageInfo (com.intellij.usageView.UsageInfo)5