Search in sources :

Example 16 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.

the class JavaRuntimeConfigurationProducerBase method checkPackage.

@Nullable
public static PsiPackage checkPackage(final PsiElement element) {
    if (element == null || !element.isValid())
        return null;
    final Project project = element.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    if (element instanceof PsiPackage) {
        final PsiPackage aPackage = (PsiPackage) element;
        final PsiDirectory[] directories = aPackage.getDirectories(GlobalSearchScope.projectScope(project));
        for (final PsiDirectory directory : directories) {
            if (isSource(directory, fileIndex))
                return aPackage;
        }
        return null;
    } else if (element instanceof PsiDirectory) {
        final PsiDirectory directory = (PsiDirectory) element;
        if (isSource(directory, fileIndex)) {
            return JavaDirectoryService.getInstance().getPackage(directory);
        } else {
            final VirtualFile virtualFile = directory.getVirtualFile();
            //choose default package when selection on content root
            if (virtualFile.equals(fileIndex.getContentRootForFile(virtualFile))) {
                final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
                if (module != null) {
                    for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
                        if (virtualFile.equals(entry.getFile())) {
                            final SourceFolder[] folders = entry.getSourceFolders();
                            Set<String> packagePrefixes = new HashSet<>();
                            for (SourceFolder folder : folders) {
                                packagePrefixes.add(folder.getPackagePrefix());
                            }
                            if (packagePrefixes.size() != 1)
                                return null;
                            return JavaPsiFacade.getInstance(project).findPackage(packagePrefixes.iterator().next());
                        }
                    }
                }
            }
            return null;
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Set(java.util.Set) HashSet(com.intellij.util.containers.hash.HashSet) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.

the class GutterIconsConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    ExtensionPoint<LineMarkerProvider> point = Extensions.getRootArea().getExtensionPoint(LineMarkerProviders.EP_NAME);
    @SuppressWarnings("unchecked") LanguageExtensionPoint<LineMarkerProvider>[] extensions = (LanguageExtensionPoint<LineMarkerProvider>[]) point.getExtensions();
    NullableFunction<LanguageExtensionPoint<LineMarkerProvider>, PluginDescriptor> function = point1 -> {
        LineMarkerProvider instance = point1.getInstance();
        return instance instanceof LineMarkerProviderDescriptor && ((LineMarkerProviderDescriptor) instance).getName() != null ? point1.getPluginDescriptor() : null;
    };
    MultiMap<PluginDescriptor, LanguageExtensionPoint<LineMarkerProvider>> map = ContainerUtil.groupBy(Arrays.asList(extensions), function);
    Map<GutterIconDescriptor, PluginDescriptor> pluginDescriptorMap = ContainerUtil.newHashMap();
    Set<String> ids = new HashSet<>();
    myDescriptors = new ArrayList<>();
    for (final PluginDescriptor descriptor : map.keySet()) {
        Collection<LanguageExtensionPoint<LineMarkerProvider>> points = map.get(descriptor);
        for (LanguageExtensionPoint<LineMarkerProvider> extensionPoint : points) {
            GutterIconDescriptor instance = (GutterIconDescriptor) extensionPoint.getInstance();
            if (instance.getOptions().length > 0) {
                for (GutterIconDescriptor option : instance.getOptions()) {
                    if (ids.add(option.getId())) {
                        myDescriptors.add(option);
                    }
                    pluginDescriptorMap.put(option, descriptor);
                }
            } else {
                if (ids.add(instance.getId())) {
                    myDescriptors.add(instance);
                }
                pluginDescriptorMap.put(instance, descriptor);
            }
        }
    }
    /*
    List<GutterIconDescriptor> options = new ArrayList<GutterIconDescriptor>();
    for (Iterator<GutterIconDescriptor> iterator = myDescriptors.iterator(); iterator.hasNext(); ) {
      GutterIconDescriptor descriptor = iterator.next();
      if (descriptor.getOptions().length > 0) {
        options.addAll(Arrays.asList(descriptor.getOptions()));
        iterator.remove();
      }
    }
    myDescriptors.addAll(options);
    */
    myDescriptors.sort((o1, o2) -> {
        if (pluginDescriptorMap.get(o1) != pluginDescriptorMap.get(o2))
            return 0;
        return Comparing.compare(o1.getName(), o2.getName());
    });
    PluginDescriptor current = null;
    for (GutterIconDescriptor descriptor : myDescriptors) {
        PluginDescriptor pluginDescriptor = pluginDescriptorMap.get(descriptor);
        if (pluginDescriptor != current) {
            myFirstDescriptors.put(descriptor, pluginDescriptor);
            current = pluginDescriptor;
        }
    }
    myList.setItems(myDescriptors, GutterIconDescriptor::getName);
    myShowGutterIconsJBCheckBox.addChangeListener(e -> myList.setEnabled(myShowGutterIconsJBCheckBox.isSelected()));
    return myPanel;
}
Also used : java.util(java.util) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nls(org.jetbrains.annotations.Nls) ProjectManager(com.intellij.openapi.project.ProjectManager) Comparing(com.intellij.openapi.util.Comparing) CheckBoxList(com.intellij.ui.CheckBoxList) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable) Project(com.intellij.openapi.project.Project) HashSet(com.intellij.util.containers.hash.HashSet) ChangeListener(javax.swing.event.ChangeListener) MultiMap(com.intellij.util.containers.MultiMap) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) Extensions(com.intellij.openapi.extensions.Extensions) EmptyIcon(com.intellij.util.ui.EmptyIcon) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) JBCheckBox(com.intellij.ui.components.JBCheckBox) NullableFunction(com.intellij.util.NullableFunction) Configurable(com.intellij.openapi.options.Configurable) SeparatorWithText(com.intellij.ui.SeparatorWithText) com.intellij.codeInsight.daemon(com.intellij.codeInsight.daemon) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) HashSet(com.intellij.util.containers.hash.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.

the class BeforeRunStepsPanel method doAddAction.

void doAddAction(AnActionButton button) {
    if (isUnknown()) {
        return;
    }
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject());
    Set<Key> activeProviderKeys = getActiveProviderKeys();
    DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
    for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
        if (provider.createTask(myRunConfiguration) == null)
            continue;
        if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton())
            continue;
        AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                BeforeRunTask task = provider.createTask(myRunConfiguration);
                if (task != null) {
                    provider.configureTask(myRunConfiguration, task);
                    if (!provider.canExecuteTask(myRunConfiguration, task))
                        return;
                } else {
                    return;
                }
                task.setEnabled(true);
                Set<RunConfiguration> configurationSet = new HashSet<>();
                getAllRunBeforeRuns(task, configurationSet);
                if (configurationSet.contains(myRunConfiguration)) {
                    JOptionPane.showMessageDialog(BeforeRunStepsPanel.this, ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)), ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE);
                    return;
                }
                addTask(task);
                myListener.fireStepsBeforeRunChanged();
            }
        };
        actionGroup.add(providerAction);
    }
    final ListPopup popup = popupFactory.createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1, Conditions.<AnAction>alwaysTrue());
    popup.show(button.getPreferredPopupPoint());
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) BeforeRunTask(com.intellij.execution.BeforeRunTask) UnknownRunConfiguration(com.intellij.execution.configurations.UnknownRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) Key(com.intellij.openapi.util.Key) HashSet(com.intellij.util.containers.hash.HashSet)

Example 19 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.

the class MoveClassesOrPackagesDialog method setData.

public void setData(PsiElement[] psiElements, String targetPackageName, PsiDirectory initialTargetDirectory, boolean isTargetDirectoryFixed, boolean suggestToMoveToAnotherRoot, boolean searchInComments, boolean searchForTextOccurences, String helpID) {
    myTargetDirectoryFixed = isTargetDirectoryFixed;
    mySuggestToMoveToAnotherRoot = suggestToMoveToAnotherRoot;
    if (targetPackageName.length() != 0) {
        myWithBrowseButtonReference.prependItem(targetPackageName);
        myClassPackageChooser.prependItem(targetPackageName);
    }
    String nameFromCallback = myMoveCallback instanceof MoveClassesOrPackagesCallback ? ((MoveClassesOrPackagesCallback) myMoveCallback).getElementsToMoveName() : null;
    if (nameFromCallback != null) {
        myNameLabel.setText(nameFromCallback);
    } else if (psiElements.length == 1) {
        PsiElement firstElement = psiElements[0];
        if (firstElement instanceof PsiClass) {
            LOG.assertTrue(!MoveClassesOrPackagesImpl.isClassInnerOrLocal((PsiClass) firstElement));
        } else {
            PsiElement parent = firstElement.getParent();
            LOG.assertTrue(parent != null);
        }
        myNameLabel.setText(RefactoringBundle.message("move.single.class.or.package.name.label", UsageViewUtil.getType(firstElement), UsageViewUtil.getLongName(firstElement)));
    } else if (psiElements.length > 1) {
        myNameLabel.setText(psiElements[0] instanceof PsiClass ? RefactoringBundle.message("move.specified.classes") : RefactoringBundle.message("move.specified.packages"));
    }
    selectInitialCard();
    myCbSearchInComments.setSelected(searchInComments);
    myCbSearchTextOccurences.setSelected(searchForTextOccurences);
    if (initialTargetDirectory != null && JavaMoveClassesOrPackagesHandler.packageHasMultipleDirectoriesInModule(myProject, initialTargetDirectory)) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
        final Set<VirtualFile> initialRoots = new HashSet<>();
        collectSourceRoots(psiElements, fileIndex, initialRoots);
        if (initialRoots.size() > 1) {
            initialTargetDirectory = null;
        }
    }
    ((DestinationFolderComboBox) myDestinationFolderCB).setData(myProject, initialTargetDirectory, new Pass<String>() {

        @Override
        public void pass(String s) {
            setErrorText(s, myDestinationFolderCB);
        }
    }, myHavePackages ? myWithBrowseButtonReference.getChildComponent() : myClassPackageChooser.getChildComponent());
    UIUtil.setEnabled(myTargetPanel, !getSourceRoots().isEmpty() && isMoveToPackage() && !isTargetDirectoryFixed, true);
    validateButtons();
    myHelpID = helpID;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) MoveClassesOrPackagesCallback(com.intellij.refactoring.move.MoveClassesOrPackagesCallback) HashSet(com.intellij.util.containers.hash.HashSet)

Example 20 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-community by JetBrains.

the class ClassesWithAnnotatedMembersSearcher method processQuery.

@Override
public void processQuery(@NotNull ClassesWithAnnotatedMembersSearch.Parameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
    SearchScope scope = queryParameters.getScope();
    for (QueryExecutor executor : Extensions.getExtensions(ClassesWithAnnotatedMembersSearch.EP_NAME)) {
        if (executor instanceof ScopedQueryExecutor) {
            scope = scope.intersectWith(GlobalSearchScope.notScope(((ScopedQueryExecutor) executor).getScope(queryParameters)));
        }
    }
    final Set<PsiClass> processed = new HashSet<>();
    AnnotatedElementsSearch.searchPsiMembers(queryParameters.getAnnotationClass(), scope).forEach(member -> {
        PsiClass psiClass;
        AccessToken token = ReadAction.start();
        try {
            psiClass = member instanceof PsiClass ? (PsiClass) member : member.getContainingClass();
        } finally {
            token.finish();
        }
        if (psiClass != null && processed.add(psiClass)) {
            consumer.process(psiClass);
        }
        return true;
    });
}
Also used : QueryExecutor(com.intellij.util.QueryExecutor) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) AccessToken(com.intellij.openapi.application.AccessToken) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiClass(com.intellij.psi.PsiClass) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) HashSet(com.intellij.util.containers.hash.HashSet)

Aggregations

HashSet (com.intellij.util.containers.hash.HashSet)27 Project (com.intellij.openapi.project.Project)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Set (java.util.Set)4 Ref (com.intellij.openapi.util.Ref)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)2 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)2 Module (com.intellij.openapi.module.Module)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiClass (com.intellij.psi.PsiClass)2 PsiFile (com.intellij.psi.PsiFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Function (com.intellij.util.Function)2 Processor (com.intellij.util.Processor)2 SmartList (com.intellij.util.SmartList)2