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;
}
}
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;
}
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());
}
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;
}
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;
});
}
Aggregations