Java Code Examples for com.intellij.util.ArrayUtil#getFirstElement()
The following examples show how to use
com.intellij.util.ArrayUtil#getFirstElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractEditAction.java From leetcode-editor with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent, Config config) { VirtualFile vf = ArrayUtil.getFirstElement(FileEditorManager.getInstance(anActionEvent.getProject()).getSelectedFiles()); if(vf == null){ return; } LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); if (leetcodeEditor == null) { return; } Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); if (question == null) { MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); return; } actionPerformed(anActionEvent, config, question); }
Example 2
Source File: CSharpCopyClassHandlerDelegate.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction private static PsiDirectory tryNotNullizeDirectory(@Nonnull Project project, @Nullable PsiDirectory defaultTargetDirectory) { if(defaultTargetDirectory == null) { VirtualFile root = ArrayUtil.getFirstElement(ProjectRootManager.getInstance(project).getContentRoots()); if(root == null) { root = project.getBaseDir(); } if(root == null) { root = VfsUtil.getUserHomeDir(); } defaultTargetDirectory = root != null ? PsiManager.getInstance(project).findDirectory(root) : null; if(defaultTargetDirectory == null) { LOG.warn("No directory found for project: " + project.getName() + ", root: " + root); } } return defaultTargetDirectory; }
Example 3
Source File: CopyFilesOrDirectoriesHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @RequiredReadAction private static PsiDirectory tryNotNullizeDirectory(@Nonnull Project project, @Nullable PsiDirectory defaultTargetDirectory) { if (defaultTargetDirectory == null) { VirtualFile root = ArrayUtil.getFirstElement(ProjectRootManager.getInstance(project).getContentRoots()); if (root == null) root = project.getBaseDir(); if (root == null) root = VfsUtil.getUserHomeDir(); defaultTargetDirectory = root != null ? PsiManager.getInstance(project).findDirectory(root) : null; if (defaultTargetDirectory == null) { LOG.warn("No directory found for project: " + project.getName() + ", root: " + root); } } return defaultTargetDirectory; }
Example 4
Source File: PositionAction.java From leetcode-editor with Apache License 2.0 | 5 votes |
@Override public void update(@NotNull AnActionEvent e) { VirtualFile vf = ArrayUtil.getFirstElement(FileEditorManager.getInstance(e.getProject()).getSelectedFiles()); if (vf == null) { e.getPresentation().setEnabled(false); return; } LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(e.getProject()).getEditor(vf.getPath()); if (leetcodeEditor == null) { e.getPresentation().setEnabled(false); return; } e.getPresentation().setEnabled(true); }
Example 5
Source File: SelectInContextImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Supplier<FileEditor> getFileEditorProvider() { return () -> { final VirtualFile file = myElementToSelect.getContainingFile().getVirtualFile(); if (file == null) { return null; } return ArrayUtil.getFirstElement(FileEditorManager.getInstance(getProject()).openFile(file, false)); }; }
Example 6
Source File: ShowUsagesAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(@Nonnull AnActionEvent e) { FindUsagesInFileAction.updateFindUsagesAction(e); if (e.getPresentation().isEnabled()) { UsageTarget[] usageTargets = e.getData(UsageView.USAGE_TARGETS_KEY); if (usageTargets != null && !(ArrayUtil.getFirstElement(usageTargets) instanceof PsiElementUsageTarget)) { e.getPresentation().setEnabled(false); } } }
Example 7
Source File: EditorSearchSession.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private String getEmptyText() { if (myFindModel.isGlobal() || !myFindModel.getStringToFind().isEmpty()) return ""; String text = getEditor().getSelectionModel().getSelectedText(); if (text != null && text.contains("\n")) { boolean replaceState = myFindModel.isReplaceState(); AnAction action = ActionManager.getInstance().getAction(replaceState ? IdeActions.ACTION_REPLACE : IdeActions.ACTION_TOGGLE_FIND_IN_SELECTION_ONLY); Shortcut shortcut = ArrayUtil.getFirstElement(action.getShortcutSet().getShortcuts()); if (shortcut != null) { return ApplicationBundle.message("editorsearch.in.selection.with.hint", KeymapUtil.getShortcutText(shortcut)); } } return ApplicationBundle.message("editorsearch.in.selection"); }
Example 8
Source File: VcsContextWrapper.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @Override public File getSelectedIOFile() { File file = myContext.getData(VcsDataKeys.IO_FILE); return file != null ? file : ArrayUtil.getFirstElement(myContext.getData(VcsDataKeys.IO_FILE_ARRAY)); }
Example 9
Source File: KeymapUtil.java From consulo with Apache License 2.0 | 5 votes |
/** * @param actionId action to find the shortcut for * @return first keyboard shortcut that activates given action in active keymap; null if not found */ @Nullable public static Shortcut getPrimaryShortcut(@Nullable String actionId) { KeymapManager keymapManager = KeymapManager.getInstance(); if (keymapManager == null || actionId == null) return null; return ArrayUtil.getFirstElement(keymapManager.getActiveKeymap().getShortcuts(actionId)); }
Example 10
Source File: ModuleDeploymentSourceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public VirtualFile getContentRoot() { Module module = myPointer.get(); if (module == null) { return null; } return ArrayUtil.getFirstElement(ModuleRootManager.getInstance(module).getContentRoots()); }
Example 11
Source File: CSharpIfStatementImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable public DotNetStatement getTrueStatement() { DotNetStatement[] childrenByClass = findChildrenByClass(DotNetStatement.class); if(childrenByClass.length == 2) { return childrenByClass[0]; } DotNetStatement firstElement = ArrayUtil.getFirstElement(childrenByClass); if(firstElement == null || firstElement == getFalseStatement()) { return null; } return firstElement; }
Example 12
Source File: FileChooser.java From consulo with Apache License 2.0 | 4 votes |
@Nullable @Deprecated public static VirtualFile chooseFile(@Nonnull final FileChooserDescriptor descriptor, @Nullable final Component parent, @Nullable final Project project, @Nullable final VirtualFile toSelect) { LOG.assertTrue(!descriptor.isChooseMultiple()); return ArrayUtil.getFirstElement(chooseFiles(descriptor, parent, project, toSelect)); }
Example 13
Source File: PopupListElementRenderer.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void customizeComponent(JList<? extends E> list, E value, boolean isSelected) { ListPopupStep<Object> step = myPopup.getListStep(); boolean isSelectable = step.isSelectable(value); myTextLabel.setEnabled(isSelectable); if (step instanceof BaseListPopupStep) { Color bg = ((BaseListPopupStep<E>)step).getBackgroundFor(value); Color fg = ((BaseListPopupStep<E>)step).getForegroundFor(value); if (!isSelected && fg != null) myTextLabel.setForeground(fg); if (!isSelected && bg != null) UIUtil.setBackgroundRecursively(myComponent, bg); if (bg != null && mySeparatorComponent.isVisible() && myCurrentIndex > 0) { E prevValue = list.getModel().getElementAt(myCurrentIndex - 1); // separator between 2 colored items shall get color too if (Comparing.equal(bg, ((BaseListPopupStep<E>)step).getBackgroundFor(prevValue))) { myRendererComponent.setBackground(bg); } } } if (step.isMnemonicsNavigationEnabled()) { MnemonicNavigationFilter<Object> filter = step.getMnemonicNavigationFilter(); int pos = filter == null ? -1 : filter.getMnemonicPos(value); if (pos != -1) { String text = myTextLabel.getText(); text = text.substring(0, pos) + text.substring(pos + 1); myTextLabel.setText(text); myTextLabel.setDisplayedMnemonicIndex(pos); } } else { myTextLabel.setDisplayedMnemonicIndex(-1); } if (step.hasSubstep(value) && isSelectable) { myNextStepLabel.setVisible(true); final boolean isDark = ColorUtil.isDark(UIUtil.getListSelectionBackground()); myNextStepLabel.setIcon(isSelected ? isDark ? AllIcons.Icons.Ide.NextStepInverted : AllIcons.Icons.Ide.NextStep : AllIcons.Icons.Ide.NextStepGrayed); } else { myNextStepLabel.setVisible(false); //myNextStepLabel.setIcon(PopupIcons.EMPTY_ICON); } setSelected(myComponent, isSelected && isSelectable); setSelected(myTextLabel, isSelected && isSelectable); setSelected(myNextStepLabel, isSelected && isSelectable); if (myShortcutLabel != null) { myShortcutLabel.setEnabled(isSelectable); myShortcutLabel.setText(""); if (value instanceof ShortcutProvider) { ShortcutSet set = ((ShortcutProvider)value).getShortcut(); if (set != null) { Shortcut shortcut = ArrayUtil.getFirstElement(set.getShortcuts()); if (shortcut != null) { myShortcutLabel.setText(" " + KeymapUtil.getShortcutText(shortcut)); } } } setSelected(myShortcutLabel, isSelected && isSelectable); myShortcutLabel.setForeground(isSelected && isSelectable ? UIManager.getColor("MenuItem.acceleratorSelectionForeground") : UIManager.getColor("MenuItem.acceleratorForeground")); } }
Example 14
Source File: VcsContextWrapper.java From consulo with Apache License 2.0 | 4 votes |
@javax.annotation.Nullable @Override public FilePath getSelectedFilePath() { return ArrayUtil.getFirstElement(getSelectedFilePaths()); }
Example 15
Source File: CSharpLineMarkerProvider.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction @Nullable @Override public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element) { if(myDaemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && (element instanceof DotNetQualifiedElement)) { if(element.getNode().getTreeParent() == null) { return null; } final PsiElement parent = element.getParent(); if(!(parent instanceof DotNetMemberOwner)) { return null; } if(ArrayUtil.getFirstElement(((DotNetMemberOwner) parent).getMembers()) == element) { return null; } LineMarkerInfo info = new LineMarkerInfo<PsiElement>(element, element.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT); EditorColorsScheme scheme = myEditorColorsManager.getGlobalScheme(); info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR); info.separatorPlacement = SeparatorPlacement.TOP; return info; } final Ref<LineMarkerInfo> ref = Ref.create(); Consumer<LineMarkerInfo> consumer = new Consumer<LineMarkerInfo>() { @Override public void consume(LineMarkerInfo markerInfo) { ref.set(markerInfo); } }; //noinspection ForLoopReplaceableByForEach for(int j = 0; j < ourSingleCollector.length; j++) { LineMarkerCollector ourCollector = ourSingleCollector[j]; ourCollector.collect(element, consumer); } return ref.get(); }
Example 16
Source File: FindInProjectUtil.java From consulo with Apache License 2.0 | 4 votes |
public static void setDirectoryName(@Nonnull FindModel model, @Nonnull DataContext dataContext) { PsiElement psiElement = null; Project project = dataContext.getData(CommonDataKeys.PROJECT); Editor editor = dataContext.getData(CommonDataKeys.EDITOR); if (project != null && editor == null && !DumbServiceImpl.getInstance(project).isDumb()) { try { psiElement = dataContext.getData(CommonDataKeys.PSI_ELEMENT); } catch (IndexNotReadyException ignore) { } } String directoryName = null; if (psiElement instanceof PsiDirectory) { directoryName = ((PsiDirectory)psiElement).getVirtualFile().getPresentableUrl(); } if (directoryName == null && psiElement instanceof PsiDirectoryContainer) { final PsiDirectory[] directories = ((PsiDirectoryContainer)psiElement).getDirectories(); directoryName = directories.length == 1 ? directories[0].getVirtualFile().getPresentableUrl() : null; } if (directoryName == null) { VirtualFile virtualFile = dataContext.getData(CommonDataKeys.VIRTUAL_FILE); if (virtualFile != null && virtualFile.isDirectory()) directoryName = virtualFile.getPresentableUrl(); } Module module = dataContext.getData(LangDataKeys.MODULE_CONTEXT); if (module != null) { model.setModuleName(module.getName()); model.setDirectoryName(null); model.setCustomScope(false); } if (model.getModuleName() == null || editor == null) { if (directoryName != null) { model.setDirectoryName(directoryName); model.setCustomScope(false); // to select "Directory: " radio button } } if (directoryName == null && module == null && project != null) { ChangeList changeList = ArrayUtil.getFirstElement(dataContext.getData(VcsDataKeys.CHANGE_LISTS)); if (changeList == null) { Change change = ArrayUtil.getFirstElement(dataContext.getData(VcsDataKeys.CHANGES)); changeList = change == null ? null : ChangeListManager.getInstance(project).getChangeList(change); } if (changeList != null) { String changeListName = changeList.getName(); DefaultSearchScopeProviders.ChangeLists changeListsScopeProvider = SearchScopeProvider.EP_NAME.findExtension(DefaultSearchScopeProviders.ChangeLists.class); if (changeListsScopeProvider != null) { SearchScope changeListScope = ContainerUtil.find(changeListsScopeProvider.getSearchScopes(project), scope -> scope.getDisplayName().equals(changeListName)); if (changeListScope != null) { model.setCustomScope(true); model.setCustomScopeName(changeListScope.getDisplayName()); model.setCustomScope(changeListScope); } } } } // set project scope if we have no other settings model.setProjectScope(model.getDirectoryName() == null && model.getModuleName() == null && !model.isCustomScope()); }
Example 17
Source File: StructureViewComposite.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public StructureView getSelectedStructureView() { StructureViewDescriptor descriptor = ArrayUtil.getFirstElement(myStructureViews); return descriptor == null ? null : descriptor.structureView; }
Example 18
Source File: PantsProjectCacheTest.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
@NotNull public VirtualFile getMainContentRoot() { final VirtualFile result = ArrayUtil.getFirstElement(ModuleRootManager.getInstance(getModule()).getContentRoots()); assertNotNull(result); return result; }
Example 19
Source File: MuleElementDefinitionService.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@NotNull private List<MuleModuleDefinition> getModuleDefinitions(Project project, GlobalSearchScope searchScope) { final List<MuleModuleDefinition> result = new ArrayList<>(); final Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, searchScope); for (VirtualFile file : files) { final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file); if (xmlFile != null && isMuleSchema(xmlFile)) { // System.out.println("xmlFile = " + xmlFile.getName()); final PsiElement[] children = xmlFile.getChildren(); final XmlTag rootTag = ((XmlDocument) children[0]).getRootTag(); if (rootTag != null) { final String namespace = getNamespace(rootTag); final String name = ArrayUtil.getLastElement(namespace.split("/")); // System.out.println("namespace = " + namespace); // System.out.println("name = " + name); final XmlTag[] elements = rootTag.findSubTags("element", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA); final List<MuleElementDefinition> definitions = new ArrayList<>(); for (XmlTag element : elements) { final String elementName = element.getAttributeValue("name"); // System.out.println("name = " + elementName); final MuleElementType muleElementType = MuleSchemaUtils.getMuleElementTypeFromElement(element); if (muleElementType != null) { String description = ""; final XmlTag annotation = ArrayUtil.getFirstElement(element.findSubTags("annotation", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA)); if (annotation != null) { final XmlTag documentation = ArrayUtil.getFirstElement(annotation.findSubTags("documentation", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA)); if (documentation != null) { description = documentation.getValue().getText(); } } definitions.add(new MuleElementDefinition(element, elementName, description, muleElementType)); // System.out.println("muleElementType = " + muleElementType); // System.out.println("description = " + description); } } result.add(new MuleModuleDefinition(name, StringUtil.capitalize(name), namespace, xmlFile, definitions)); } } } return result; }