Java Code Examples for com.intellij.openapi.util.Pair#create()
The following examples show how to use
com.intellij.openapi.util.Pair#create() .
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: XBreakpointUtil.java From consulo with Apache License 2.0 | 7 votes |
@Nonnull public static Pair<GutterIconRenderer, Object> findSelectedBreakpoint(@Nonnull final Project project, @Nonnull final Editor editor) { int offset = editor.getCaretModel().getOffset(); Document editorDocument = editor.getDocument(); List<DebuggerSupport> debuggerSupports = DebuggerSupport.getDebuggerSupports(); for (DebuggerSupport debuggerSupport : debuggerSupports) { final BreakpointPanelProvider<?> provider = debuggerSupport.getBreakpointPanelProvider(); final int textLength = editor.getDocument().getTextLength(); if (offset > textLength) { offset = textLength; } Object breakpoint = provider.findBreakpoint(project, editorDocument, offset); if (breakpoint != null) { final GutterIconRenderer iconRenderer = provider.getBreakpointGutterIconRenderer(breakpoint); return Pair.create(iconRenderer, breakpoint); } } return Pair.create(null, null); }
Example 2
Source File: ElmMixedCasePathImpl.java From elm-plugin with MIT License | 6 votes |
private Pair<Stack<ElmUpperCaseId>, Stack<ElmLowerCaseId>> getGroupedChildren() { Stack<ElmUpperCaseId> upperCaseIds = new Stack<>(); Stack<ElmLowerCaseId> lowerCaseIds = new Stack<>(); PsiElement child = this.getFirstChild(); while (child != null) { if (child instanceof ElmUpperCaseId) { upperCaseIds.push((ElmUpperCaseId) child); } else if (child instanceof ElmLowerCaseId) { lowerCaseIds.push((ElmLowerCaseId) child); } child = child.getNextSibling(); } return Pair.create(upperCaseIds, lowerCaseIds); }
Example 3
Source File: BeanBinding.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static Pair<String, Boolean> getPropertyData(@Nonnull String methodName) { String part = ""; boolean isSetter = false; if (methodName.startsWith("get")) { part = methodName.substring(3, methodName.length()); } else if (methodName.startsWith("is")) { part = methodName.substring(2, methodName.length()); } else if (methodName.startsWith("set")) { part = methodName.substring(3, methodName.length()); isSetter = true; } return part.isEmpty() ? null : Pair.create(StringUtil.decapitalize(part), isSetter); }
Example 4
Source File: CodeStyleManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static Pair<PsiElement, CharTable> doFindWhiteSpaceNode(@Nonnull PsiFile file, int offset) { ASTNode astNode = SourceTreeToPsiMap.psiElementToTree(file); if (!(astNode instanceof FileElement)) { return new Pair<>(null, null); } PsiElement elementAt = InjectedLanguageManager.getInstance(file.getProject()).findInjectedElementAt(file, offset); final CharTable charTable = ((FileElement)astNode).getCharTable(); if (elementAt == null) { elementAt = findElementInTreeWithFormatterEnabled(file, offset); } if (elementAt == null) { return new Pair<>(null, charTable); } ASTNode node = elementAt.getNode(); if (node == null || node.getElementType() != TokenType.WHITE_SPACE) { return new Pair<>(null, charTable); } return Pair.create(elementAt, charTable); }
Example 5
Source File: BekChecker.java From consulo with Apache License 2.0 | 6 votes |
@javax.annotation.Nullable public static Pair<Integer, Integer> findReversedEdge(@Nonnull LinearGraph linearGraph) { for (int i = 0; i < linearGraph.nodesCount(); i++) { for (int downNode : getDownNodes(linearGraph, i)) { if (downNode <= i) { return Pair.create(i, downNode); } } for (int upNode : getUpNodes(linearGraph, i)) { if (upNode >= i) { return Pair.create(upNode, i); } } } return null; }
Example 6
Source File: GotoActionBase.java From consulo with Apache License 2.0 | 5 votes |
protected static Pair<String, Integer> getInitialText(boolean useEditorSelection, AnActionEvent e) { final String predefined = e.getData(PlatformDataKeys.PREDEFINED_TEXT); if (!StringUtil.isEmpty(predefined)) { return Pair.create(predefined, 0); } if (useEditorSelection) { final Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor != null) { final String selectedText = editor.getSelectionModel().getSelectedText(); if (selectedText != null && !selectedText.contains("\n")) { return Pair.create(selectedText, 0); } } } final String query = e.getData(SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY); if (!StringUtil.isEmpty(query)) { return Pair.create(query, 0); } final Component focusOwner = IdeFocusManager.getInstance(getEventProject(e)).getFocusOwner(); if (focusOwner instanceof JComponent) { final SpeedSearchSupply supply = SpeedSearchSupply.getSupply((JComponent)focusOwner); if (supply != null) { return Pair.create(supply.getEnteredPrefix(), 0); } } if (myInAction != null) { final Pair<String, Integer> lastString = ourLastStrings.get(myInAction); if (lastString != null) { return lastString; } } return Pair.create("", 0); }
Example 7
Source File: PersistentFSImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable // null when file not found private static Pair<FileAttributes, String> getChildData(@Nonnull NewVirtualFileSystem fs, @Nonnull VirtualFile parent, @Nonnull String name, @Nullable FileAttributes attributes, @Nullable String symlinkTarget) { if (attributes == null) { FakeVirtualFile virtualFile = new FakeVirtualFile(parent, name); attributes = fs.getAttributes(virtualFile); symlinkTarget = attributes != null && attributes.isSymLink() ? fs.resolveSymLink(virtualFile) : null; } return attributes == null ? null : Pair.create(attributes, symlinkTarget); }
Example 8
Source File: AnalyzeDependenciesComponent.java From consulo with Apache License 2.0 | 5 votes |
/** * @return the analyzer for the current settings */ public ModuleDependenciesAnalyzer getAnalyzer() { final Pair<ClasspathType, Boolean> key = Pair.create(getClasspathType(), mySettings.isSdkIncluded()); ModuleDependenciesAnalyzer a = myClasspaths.get(key); if (a == null) { a = new ModuleDependenciesAnalyzer(myModule, !mySettings.isTest(), !mySettings.isRuntime(), mySettings.isSdkIncluded()); myClasspaths.put(key, a); } return a; }
Example 9
Source File: ArrayValueWithKeyAndNewExpressionMatcher.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable private static Pair<NewExpressionCall, NewExpression> matchesMethodCall(@NotNull ArrayCreationExpression arrayCreationExpression, @NotNull NewExpressionCall[] classes) { // get parameter, we less then 0 we are not inside method reference int parameterIndex = PsiElementUtils.getParameterIndexValue(arrayCreationExpression); if(parameterIndex < 0) { return null; } // filter index List<NewExpressionCall> filter = ContainerUtil.filter(classes, expressionCall -> expressionCall.getIndex() == parameterIndex ); if(filter.size() == 0) { return null; } PsiElement parameterList = arrayCreationExpression.getParent(); if(!(parameterList instanceof ParameterList)) { return null; } PsiElement newExpression = parameterList.getParent(); if (!(newExpression instanceof NewExpression)) { return null; } for (NewExpressionCall aClass : filter) { if(PhpElementsUtil.getNewExpressionPhpClassWithInstance((NewExpression) newExpression, aClass.getClazz()) == null) { continue; } return Pair.create(aClass, (NewExpression) newExpression); } return null; }
Example 10
Source File: RootIndex.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Pair<DirectoryInfo, String> calcDirectoryInfo(@Nonnull final VirtualFile root, @Nonnull final List<VirtualFile> hierarchy, @Nonnull RootInfo info) { VirtualFile moduleContentRoot = info.findModuleRootInfo(hierarchy); VirtualFile libraryClassRoot = info.findLibraryRootInfo(hierarchy, false); VirtualFile librarySourceRoot = info.findLibraryRootInfo(hierarchy, true); boolean inProject = moduleContentRoot != null || libraryClassRoot != null || librarySourceRoot != null; VirtualFile nearestContentRoot; if (inProject) { nearestContentRoot = moduleContentRoot; } else { nearestContentRoot = info.findNearestContentRootForExcluded(hierarchy); if (nearestContentRoot == null) { return Pair.create(NonProjectDirectoryInfo.EXCLUDED, null); } } VirtualFile sourceRoot = info.findPackageRootInfo(hierarchy, moduleContentRoot, null, librarySourceRoot); VirtualFile moduleSourceRoot = info.findPackageRootInfo(hierarchy, moduleContentRoot, null, null); boolean inModuleSources = moduleSourceRoot != null; boolean inLibrarySource = librarySourceRoot != null; ContentFolder folder = moduleSourceRoot != null ? info.contentFolders.get(moduleSourceRoot) : null; ContentFolderTypeProvider typeId = folder == null ? null : folder.getType(); Module module = info.contentRootOf.get(nearestContentRoot); DirectoryInfo directoryInfo = new DirectoryInfoImpl(root, module, nearestContentRoot, sourceRoot, folder, libraryClassRoot, inModuleSources, inLibrarySource, !inProject, typeId, null); String packagePrefix = info.calcPackagePrefix(root, hierarchy, moduleContentRoot, libraryClassRoot, librarySourceRoot); return Pair.create(directoryInfo, packagePrefix); }
Example 11
Source File: BekBranchCreator.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public Pair<List<BekBranch>, BekEdgeRestrictions> getResult() { List<BekBranch> bekBranches = ContainerUtil.newArrayList(); for (int headNode : myGraphLayout.getHeadNodeIndex()) { List<Integer> nextBranch = createNextBranch(headNode); bekBranches.add(new BekBranch(myPermanentGraph, nextBranch)); } return Pair.create(bekBranches, myEdgeRestrictions); }
Example 12
Source File: PullRequestHelper.java From azure-devops-intellij with MIT License | 5 votes |
/** * Parse the exception we got when generating pull request * <p/> * if we have a duplicate pr on server, try locate its id and generate a link to it * * @return status and string message as a pair */ public Pair<PRCreateStatus, String> parseException(final Throwable t, final String sourceBranch, final GitRemoteBranch targetBranch, final ServerContext context, final GitHttpClient gitClient) { if (t == null) { // if there is no throwale, why are we here? return Pair.create(PRCreateStatus.UNKNOWN, StringUtils.EMPTY); } if ((StringUtils.contains(t.getMessage(), PR_EXISTS_EXCEPTION_NAME)) || (StringUtils.contains(t.getMessage(), PR_EXISTS_EXCEPTION_CODE))) { try { // look for the existing PR final UUID repoId = context.getGitRepository().getId(); final GitPullRequestSearchCriteria searchCriteria = new GitPullRequestSearchCriteria(); searchCriteria.setRepositoryId(repoId); searchCriteria.setStatus(PullRequestStatus.ACTIVE); searchCriteria.setSourceRefName(getVSORefName(sourceBranch)); searchCriteria.setTargetRefName(getVSORefName(targetBranch.getNameForRemoteOperations())); List<GitPullRequest> pullRequests = gitClient.getPullRequests(repoId, searchCriteria, null, 0, 1); if (pullRequests != null && pullRequests.size() > 0) { final String repositoryRemoteUrl = context.getGitRepository().getRemoteUrl(); final String notifyMsgInHtml = getHtmlMsg(repositoryRemoteUrl, pullRequests.get(0).getPullRequestId()); return Pair.create(PRCreateStatus.DUPLICATE, notifyMsgInHtml); } } catch (Throwable innerT) { logger.error("Failed to retrieve existing pull request", innerT); // since we are making server calls, it's possible this call will fail, in that case, just return // the original exception, never let any exception bubble up to intellij return Pair.create(PRCreateStatus.FAILED, t.getMessage()); } } return Pair.create(PRCreateStatus.FAILED, t.getMessage()); }
Example 13
Source File: VirtualFilePointerManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private synchronized VirtualFilePointerImpl getOrCreate(VirtualFile file, String path, String url, boolean recursive, @Nonnull Disposable parentDisposable, @Nullable VirtualFilePointerListener listener, @Nonnull NewVirtualFileSystem fs) { VirtualFilePointerListener nl = ObjectUtils.notNull(listener, NULL_LISTENER); Map<VirtualFilePointerListener, FilePointerPartNode> myPointers = myRoots.computeIfAbsent(fs, __ -> new THashMap<>()); FilePointerPartNode root = myPointers.computeIfAbsent(nl, __ -> FilePointerPartNode.createFakeRoot()); FilePointerPartNode node = file == null ? FilePointerPartNode.findOrCreateNodeByPath(root, path, fs) : root.findOrCreateNodeByFile(file, fs); VirtualFilePointerImpl pointer = node.getAnyPointer(); if (pointer == null) { pointer = new VirtualFilePointerImpl(); Pair<VirtualFile, String> fileAndUrl = Pair.create(file, file == null ? url : file.getUrl()); node.associate(pointer, fileAndUrl); for (FilePointerPartNode n = node; n != null; n = n.parent) { n.pointersUnder++; } } pointer.incrementUsageCount(1); pointer.recursive = recursive; root.checkConsistency(); DelegatingDisposable.registerDisposable(parentDisposable, pointer); myPointerSetModCount++; return pointer; }
Example 14
Source File: RunContextAction.java From consulo with Apache License 2.0 | 5 votes |
private Pair<Boolean, Boolean> isEnabledAndVisible(ConfigurationContext context) { RunnerAndConfigurationSettings configuration = context.findExisting(); if (configuration == null) { configuration = context.getConfiguration(); } ProgramRunner runner = configuration == null ? null : getRunner(configuration.getConfiguration()); if (runner == null) { return Pair.create(false, false); } return Pair.create(!ExecutorRegistry.getInstance().isStarting(context.getProject(), myExecutor.getId(), runner.getRunnerId()), true); }
Example 15
Source File: YamlServiceTagIntention.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable private static Pair<PhpClass, Set<String>> invoke(@NotNull Project project, @NotNull YAMLKeyValue serviceKeyValue) { String aClass = YamlHelper.getYamlKeyValueAsString(serviceKeyValue, "class"); if(aClass == null || StringUtils.isBlank(aClass)) { PsiElement key = serviceKeyValue.getKey(); if (key != null) { String text = key.getText(); if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text)) { aClass = text; } } } if(aClass == null) { return null; } PhpClass resolvedClassDefinition = ServiceUtil.getResolvedClassDefinition(project, aClass, new ContainerCollectionResolver.LazyServiceCollector(project)); if(resolvedClassDefinition == null) { return null; } Set<String> phpClassServiceTags = ServiceUtil.getPhpClassServiceTags(resolvedClassDefinition); Set<String> strings = YamlHelper.collectServiceTags(serviceKeyValue); if(strings.size() > 0) { for (String s : strings) { if(phpClassServiceTags.contains(s)) { phpClassServiceTags.remove(s); } } } return Pair.create(resolvedClassDefinition, phpClassServiceTags); }
Example 16
Source File: CommittedChangesCache.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Pair<CommittedChangeList, Change> getIncomingChangeList(final VirtualFile file) { if (myCachedIncomingChangeLists != null) { File ioFile = new File(file.getPath()); for (CommittedChangeList changeList : myCachedIncomingChangeLists) { for (Change change : changeList.getChanges()) { if (change.affectsFile(ioFile)) { return Pair.create(changeList, change); } } } } return null; }
Example 17
Source File: VcsHistoryUtil.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable private static Pair<FilePath, VcsRevisionNumber> getRevisionInfo(@Nonnull VcsFileRevision revision) { if (revision instanceof VcsFileRevisionEx) { return Pair.create(((VcsFileRevisionEx)revision).getPath(), revision.getRevisionNumber()); } return null; }
Example 18
Source File: DelimitedListAction.java From StringManipulation with Apache License 2.0 | 4 votes |
private Pair<Boolean, Settings> showDialog(Editor editor) { final DelimitedListDialog dialog = new DelimitedListDialog(this, editor); DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) { { init(); setTitle("Delimited List Options"); } @Override protected void dispose() { super.dispose(); dialog.dispose(); } @Override public JComponent getPreferredFocusedComponent() { return dialog.destDelimiter; } @Override protected String getDimensionServiceKey() { return "StringManipulation.DelimitedListDialog"; } @Override protected JComponent createCenterPanel() { return dialog.contentPane; } @Override protected void doOKAction() { super.doOKAction(); } }; boolean okPressed = dialogWrapper.showAndGet(); if (!okPressed) { return Pair.create(false, null); } return Pair.create(true, dialog.toSettings()); }
Example 19
Source File: Revision.java From consulo with Apache License 2.0 | 4 votes |
public Pair<List<String>, Integer> getAffectedFileNames() { return Pair.create(Collections.<String>emptyList(), 0); }
Example 20
Source File: PhpStanValidatorConfigurableForm.java From idea-php-generics-plugin with MIT License | 4 votes |
@NotNull public Pair<Boolean, String> validateMessage(String message) { return message.contains("PHPStan") ? Pair.create(true, "OK, " + message) : Pair.create(false, message); }