protected PsiElement applyChanges(@NotNull final Project project, @NotNull final String localName, @Nullable final PsiExpression initializer, @NotNull final V variable, @NotNull final Collection<PsiReference> references, final boolean delete, @NotNull final NotNullFunction<PsiDeclarationStatement, PsiElement> action) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); return ApplicationManager.getApplication().runWriteAction( new Computable<PsiElement>() { @Override public PsiElement compute() { final PsiElement newDeclaration = moveDeclaration(elementFactory, localName, variable, initializer, action, references); if (delete) { beforeDelete(project, variable, newDeclaration); variable.normalizeDeclaration(); variable.delete(); } return newDeclaration; } } ); }
@NotNull private static PermanentGraph<Integer> buildPermanentGraph(@NotNull List<? extends GraphCommit<Integer>> commits, @NotNull RefsModel refsModel, @NotNull final VcsLogHashMap hashMap, @NotNull Map<VirtualFile, VcsLogProvider> providers) { if (commits.isEmpty()) { return EmptyPermanentGraph.getInstance(); } NotNullFunction<Integer, Hash> hashGetter = new NotNullFunction<Integer, Hash>() { @NotNull @Override public Hash fun(Integer commitIndex) { return hashMap.getHash(commitIndex); } }; GraphColorManagerImpl colorManager = new GraphColorManagerImpl(refsModel, hashGetter, getRefManagerMap(providers)); Set<Integer> branches = getBranchCommitHashIndexes(refsModel.getAllRefs(), hashMap); StopWatch sw = StopWatch.start("building graph"); PermanentGraphImpl<Integer> permanentGraph = PermanentGraphImpl.newInstance(commits, colorManager, branches); sw.report(); return permanentGraph; }
private void doTest(@NotNull Collection<FileType> fileTypes) throws CollectUsagesException { final Set<UsageDescriptor> usages = new FileTypeUsagesCollector().getProjectUsages(getProject()); for (UsageDescriptor usage : usages) { assertEquals(1, usage.getValue()); } assertEquals( ContainerUtil.map2Set(fileTypes, new NotNullFunction<FileType, String>() { @NotNull @Override public String fun(FileType fileType) { return fileType.getName(); } }), ContainerUtil.map2Set(usages, new NotNullFunction<UsageDescriptor, String>() { @NotNull @Override public String fun(UsageDescriptor usageDescriptor) { return usageDescriptor.getKey(); } }) ); }
public void iterateAllCaches(final NotNullFunction<ChangesCacheFile, Boolean> consumer) { final AbstractVcs[] vcses = myPlManager.getAllActiveVcss(); for (AbstractVcs vcs : vcses) { final CommittedChangesProvider provider = vcs.getCommittedChangesProvider(); if (provider instanceof CachingCommittedChangesProvider) { final Map<VirtualFile, RepositoryLocation> map = getAllRootsUnderVcs(vcs); for (VirtualFile root : map.keySet()) { final RepositoryLocation location = map.get(root); final ChangesCacheFile cacheFile = getCacheFile(vcs, root, location); if (Boolean.TRUE.equals(consumer.fun(cacheFile))) { return; } } } } }
private boolean hasCachesWithEmptiness(final boolean emptiness) { final Ref<Boolean> resultRef = new Ref<Boolean>(Boolean.FALSE); myCachesHolder.iterateAllCaches(new NotNullFunction<ChangesCacheFile, Boolean>() { @Override @NotNull public Boolean fun(final ChangesCacheFile changesCacheFile) { try { if (changesCacheFile.isEmpty() == emptiness) { resultRef.set(true); return true; } } catch (IOException e) { LOG.info(e); } return false; } }); return resultRef.get(); }
private void updateExtensionTabs() { final ChangesViewContentEP[] contentEPs = myProject.getExtensions(ChangesViewContentEP.EP_NAME); for(ChangesViewContentEP ep: contentEPs) { final NotNullFunction<Project,Boolean> predicate = ep.newPredicateInstance(myProject); if (predicate == null) continue; Content epContent = findEPContent(ep); final Boolean predicateResult = predicate.fun(myProject); if (predicateResult.equals(Boolean.TRUE) && epContent == null) { addExtensionTab(ep); } else if (predicateResult.equals(Boolean.FALSE) && epContent != null) { if (!(epContent.getComponent() instanceof ContentStub)) { ep.getInstance(myProject).disposeContent(); } myContentManager.removeContent(epContent, true); } } }
private static Collection<RunContentDescriptor> getConsoles(Project project) { PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project); if (toolWindow != null && toolWindow.getToolWindow().isVisible()) { RunContentDescriptor selectedContentDescriptor = toolWindow.getSelectedContentDescriptor(); return selectedContentDescriptor != null ? Lists.newArrayList(selectedContentDescriptor) : Lists.<RunContentDescriptor>newArrayList(); } Collection<RunContentDescriptor> descriptors = ExecutionHelper.findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() { @NotNull @Override public Boolean fun(RunContentDescriptor dom) { return dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom); } }); if (descriptors.isEmpty() && toolWindow != null) { return toolWindow.getConsoleContentDescriptors(); } else { return descriptors; } }
private static <T> NotNullLazyValue<List<SmartPsiElementPointer>> createPointersThunk(boolean lazy, final Project project, final Factory<Collection<T>> targets, final NotNullFunction<T, Collection<? extends PsiElement>> converter) { if (!lazy) { return NotNullLazyValue.createConstantValue(calcPsiTargets(project, targets.create(), converter)); } return new NotNullLazyValue<List<SmartPsiElementPointer>>() { @Override @NotNull public List<SmartPsiElementPointer> compute() { return calcPsiTargets(project, targets.create(), converter); } }; }
/** * Consider using {@link DomService#getXmlFileHeader(com.intellij.psi.xml.XmlFile)} when implementing this. */ @SuppressWarnings({"MethodMayBeStatic"}) @NotNull public List<String> getAllowedNamespaces(@NotNull String namespaceKey, @NotNull XmlFile file) { final NotNullFunction<XmlTag, List<String>> function = myNamespacePolicies.get(namespaceKey); if (function instanceof ConstantFunction) { return function.fun(null); } if (function != null) { final XmlDocument document = file.getDocument(); if (document != null) { final XmlTag tag = document.getRootTag(); if (tag != null) { return function.fun(tag); } } } else { return Collections.singletonList(namespaceKey); } return Collections.emptyList(); }
private void logClassPathOnce(@NotNull Project project) { List<VirtualFile> files = GradleBuildClasspathManager.getInstance(project).getAllClasspathEntries(); if (ContainerUtil.equalsIdentity(files, myLastClassPath)) { return; } myLastClassPath = files; List<String> paths = ContainerUtil.map(files, new NotNullFunction<VirtualFile, String>() { @NotNull @Override public String fun(VirtualFile vf) { return vf.getPath(); } }); String classPath = Joiner.on(':').join(paths); LOG.info(String.format("Android DSL resolver classpath (project %1$s): %2$s", project.getName(), classPath)); }
public void setRepositoryURLs(SVNURL[] urls, final boolean showFiles, @Nullable NotNullFunction<RepositoryBrowserComponent, Expander> defaultExpanderFactory, boolean expandFirst) { RepositoryTreeModel model = new RepositoryTreeModel(myVCS, showFiles, this); if (defaultExpanderFactory != null) { model.setDefaultExpanderFactory(defaultExpanderFactory); } model.setRoots(urls); Disposer.register(this, model); myRepositoryTree.setModel(model); if (expandFirst) { myRepositoryTree.expandRow(0); } }
public SvnRepositoryContentRevision createRevisionLazily(final String path, final boolean isBeforeRevision) { final boolean knownAsDirectory = myKnownAsDirectories.contains(path); final FilePath localPath = getLocalPath(path, new NotNullFunction<File, Boolean>() { @NotNull public Boolean fun(final File file) { if (knownAsDirectory) return Boolean.TRUE; // list will be next myWithoutDirStatus.add(new Pair<Integer, Boolean>(myList.size(), isBeforeRevision)); return Boolean.FALSE; } }); long revision = getRevision(isBeforeRevision); return localPath == null ? SvnRepositoryContentRevision.createForRemotePath(myVcs, myRepositoryRoot, path, knownAsDirectory, revision) : SvnRepositoryContentRevision.create(myVcs, myRepositoryRoot, path, localPath, revision); }
public SvnMergeInfoRootPanelManual(@NotNull Project project, @NotNull NotNullFunction<WCInfoWithBranches, WCInfoWithBranches> refresher, @NotNull Runnable listener, boolean onlyOneRoot, @NotNull WCInfoWithBranches info) { myOnlyOneRoot = onlyOneRoot; myInfo = info; myProject = project; myRefresher = refresher; myListener = listener; myBranchToLocal = ContainerUtil.newHashMap(); init(); myInclude.setVisible(!onlyOneRoot); initWithData(); }
/** @deprecated use lookup by user data (to remove in IDEA 13) */ public static Collection<RunContentDescriptor> findRunningConsoleByCmdLine(final Project project, @NotNull final NotNullFunction<String, Boolean> cmdLineMatcher) { return findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() { @NotNull @Override public Boolean fun(RunContentDescriptor selectedContent) { final ProcessHandler processHandler = selectedContent.getProcessHandler(); if (processHandler instanceof OSProcessHandler && !processHandler.isProcessTerminated()) { final String commandLine = ((OSProcessHandler)processHandler).getCommandLine(); return cmdLineMatcher.fun(commandLine); } return false; } }); }
public static Collection<RunContentDescriptor> findRunningConsole(final Project project, @NotNull final NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) { final ExecutionManager executionManager = ExecutionManager.getInstance(project); final RunContentDescriptor selectedContent = executionManager.getContentManager().getSelectedContent(); if (selectedContent != null) { final ToolWindow toolWindow = ExecutionManager.getInstance(project).getContentManager().getToolWindowByDescriptor(selectedContent); if (toolWindow != null && toolWindow.isVisible()) { if (descriptorMatcher.fun(selectedContent)) { return Collections.singletonList(selectedContent); } } } final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList(); for (RunContentDescriptor runContentDescriptor : executionManager.getContentManager().getAllDescriptors()) { if (descriptorMatcher.fun(runContentDescriptor)) { result.add(runContentDescriptor); } } return result; }
private Task[] getCases(String q) throws Exception { HttpClient client = login(getLoginMethod()); PostMethod method = new PostMethod(getUrl() + "/api.asp"); method.addParameter("token", token); method.addParameter("cmd", "search"); method.addParameter("q", q); method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory"); int status = client.executeMethod(method); if (status != 200) { throw new Exception("Error listing cases: " + method.getStatusLine()); } Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); XPath path = XPath.newInstance("/response/cases/case"); final XPath commentPath = XPath.newInstance("events/event"); @SuppressWarnings("unchecked") final List<Element> nodes = (List<Element>)path.selectNodes(document); final List<Task> tasks = ContainerUtil.mapNotNull(nodes, new NotNullFunction<Element, Task>() { @NotNull @Override public Task fun(Element element) { return createCase(element, commentPath); } }); return tasks.toArray(new Task[tasks.size()]); }
public SvnRepositoryContentRevision createRevisionLazily(final String path, final boolean isBeforeRevision) { final boolean knownAsDirectory = myKnownAsDirectories.contains(path); final FilePath localPath = getLocalPath(path, new NotNullFunction<File, Boolean>() { @NotNull public Boolean fun(final File file) { if (knownAsDirectory) return Boolean.TRUE; // list will be next myWithoutDirStatus.add(new Pair<Integer, Boolean>(myList.size(), isBeforeRevision)); return Boolean.FALSE; } }); final SvnRepositoryContentRevision contentRevision = SvnRepositoryContentRevision.create(myVcs, myRepositoryRoot, path, localPath, getRevision(isBeforeRevision)); if (knownAsDirectory) { ((FilePathImpl) contentRevision.getFile()).setIsDirectory(true); } return contentRevision; }
private HttpMethod build() { GetMethod method = new GetMethod(url); method.setPath(path.toString()); method.addRequestHeader("Accept", "application/json"); NameValuePair[] params = ContainerUtil.map2Array(parameters.entrySet(), NameValuePair.class, new NotNullFunction<Map.Entry<String, String>, NameValuePair>() { @NotNull @Override public NameValuePair fun(Map.Entry<String, String> entry) { return new NameValuePair(entry.getKey(), entry.getValue()); } }); method.setQueryString(params); return method; }
@Exported @NotNull @RequiredReadAction private static <E extends PsiElement> DotNetTypeRef getResultCacheResultImpl(@NotNull Key<CachedValue<DotNetTypeRef>> cachedValueKey, @NotNull E element, @NotNull Key dropKey, @NotNull final NotNullFunction<E, DotNetTypeRef> resolver) { Class<? extends NotNullFunction> aClass = resolver.getClass(); if(!BitUtil.isSet(aClass.getModifiers(), Modifier.STATIC)) { throw new IllegalArgumentException("Accepted only static resolver"); } CachedValue<DotNetTypeRef> cachedValue = element.getUserData(cachedValueKey); if(cachedValue == null) { DotNetTypeRefCachedValueProvider<E> provider = new DotNetTypeRefCachedValueProvider<>(dropKey, element, resolver); cachedValue = ((UserDataHolderEx) element).putUserDataIfAbsent(cachedValueKey, CachedValuesManager.getManager(element.getProject()).createCachedValue(provider, false)); return cachedValue.getValue(); } return cachedValue.getValue(); }
@RequiredReadAction @NotNull @Override public Collection<PsiElement> findChildren(@NotNull String name, @NotNull GlobalSearchScope globalSearchScope, @NotNull NotNullFunction<PsiElement, PsiElement> transformer, @NotNull ChildrenFilter filter) { Collection<Collection<PsiElement>> list = new SmartList<>(); for(DotNetNamespaceAsElement dotNetNamespaceAsElement : myList) { Collection<PsiElement> children = dotNetNamespaceAsElement.findChildren(name, globalSearchScope, transformer, filter); list.add(children); } return list.isEmpty() ? Collections.emptyList() : ContainerUtil.concat(list); }
@SuppressWarnings("unchecked") @NotNull public static List<PsiElement> transformData(@NotNull Iterable<? extends PsiElement> collection, int size, NotNullFunction<PsiElement, PsiElement> transformer) { if(size == 0) { return Collections.emptyList(); } List<PsiElement> list = new ArrayList<>(size); for(PsiElement element : collection) { list.add(transformer.fun(element)); } return list; }
@NotNull @RequiredReadAction public DotNetTypeDeclaration[] findTypes(@NotNull String vmQName, @NotNull GlobalSearchScope scope, @NotNull NotNullFunction<DotNetTypeDeclaration, DotNetTypeDeclaration> transformer) { Collection<? extends DotNetTypeDeclaration> declarations = findTypesImpl(vmQName, scope); if(declarations.isEmpty()) { return DotNetTypeDeclaration.EMPTY_ARRAY; } List<DotNetTypeDeclaration> list = new ArrayList<DotNetTypeDeclaration>(declarations.size()); for(DotNetTypeDeclaration declaration : declarations) { list.add(transformer.fun(declaration)); } return ContainerUtil.toArray(list, DotNetTypeDeclaration.ARRAY_FACTORY); }
private void doTest(@Nonnull Collection<FileType> fileTypes) throws CollectUsagesException { final Set<UsageDescriptor> usages = new FileTypeUsagesCollector().getProjectUsages(getProject()); for (UsageDescriptor usage : usages) { assertEquals(1, usage.getValue()); } assertEquals( ContainerUtil.map2Set(fileTypes, new NotNullFunction<FileType, String>() { @Nonnull @Override public String fun(FileType fileType) { return fileType.getName(); } }), ContainerUtil.map2Set(usages, new NotNullFunction<UsageDescriptor, String>() { @Nonnull @Override public String fun(UsageDescriptor usageDescriptor) { return usageDescriptor.getKey(); } }) ); }
@SuppressWarnings("unchecked") PrintElementManagerImpl(@Nonnull final LinearGraph linearGraph, @Nonnull final PermanentGraphInfo myPermanentGraph, @Nonnull GraphColorManager colorManager) { myLinearGraph = linearGraph; myColorGetter = new ColorGetterByLayoutIndex(linearGraph, myPermanentGraph, colorManager); myGraphElementComparator = new GraphElementComparatorByLayoutIndex(new NotNullFunction<Integer, Integer>() { @Nonnull @Override public Integer fun(Integer nodeIndex) { int nodeId = linearGraph.getNodeId(nodeIndex); if (nodeId < 0) return nodeId; return myPermanentGraph.getPermanentGraphLayout().getLayoutIndex(nodeId); } }); }
private boolean hasCachesWithEmptiness(final boolean emptiness) { final Ref<Boolean> resultRef = new Ref<Boolean>(Boolean.FALSE); myCachesHolder.iterateAllCaches(new NotNullFunction<ChangesCacheFile, Boolean>() { @Override @Nonnull public Boolean fun(final ChangesCacheFile changesCacheFile) { try { if (changesCacheFile.isEmpty() == emptiness) { resultRef.set(true); return true; } } catch (IOException e) { LOG.info(e); } return false; } }); return resultRef.get(); }
@Override public void actionPerformed(AnActionEvent e) { List<String> languages = IdeScriptEngineManager.getInstance().getLanguages(); if (languages.size() == 1) { runConsole(e, languages.iterator().next()); return; } DefaultActionGroup actions = new DefaultActionGroup(ContainerUtil.map(languages, (NotNullFunction<String, AnAction>)language -> new DumbAwareAction(language) { @Override public void actionPerformed(@Nonnull AnActionEvent e1) { runConsole(e1, language); } })); JBPopupFactory.getInstance().createActionGroupPopup("Script Engine", actions, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, false). showInBestPositionFor(e.getDataContext()); }
public static Collection<RunContentDescriptor> findRunningConsole(final Project project, @Nonnull final NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) { final ExecutionManager executionManager = ExecutionManager.getInstance(project); final RunContentDescriptor selectedContent = executionManager.getContentManager().getSelectedContent(); if (selectedContent != null) { final ToolWindow toolWindow = ExecutionManager.getInstance(project).getContentManager().getToolWindowByDescriptor(selectedContent); if (toolWindow != null && toolWindow.isVisible()) { if (descriptorMatcher.fun(selectedContent)) { return Collections.singletonList(selectedContent); } } } final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList(); for (RunContentDescriptor runContentDescriptor : executionManager.getContentManager().getAllDescriptors()) { if (descriptorMatcher.fun(runContentDescriptor)) { result.add(runContentDescriptor); } } return result; }
@Override public void initComponent() { for(final DescriptionByAnotherPsiElementProvider<?> provider : DescriptionByAnotherPsiElementProvider.EP_NAME.getExtensions()) { EditorNotificationProviders.registerProvider(new NotNullFunction<Project, EditorNotificationProvider<?>>() { @NotNull @Override public EditorNotificationProvider<?> fun(Project project) { //noinspection unchecked return new DescriptionByAnotherPsiElementEditorNotification(project, provider); } }); } }
protected PsiElement applyChanges(final @NotNull Project project, final @NotNull String localName, final @Nullable PsiExpression initializer, final @NotNull V variable, final @NotNull Collection<PsiReference> references, final @NotNull NotNullFunction<PsiDeclarationStatement, PsiElement> action) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); return ApplicationManager.getApplication().runWriteAction( new Computable<PsiElement>() { @Override public PsiElement compute() { final PsiElement newDeclaration = moveDeclaration(elementFactory, localName, variable, initializer, action, references); beforeDelete(project, variable, newDeclaration); variable.normalizeDeclaration(); variable.delete(); return newDeclaration; } } ); }
@Nullable private static NotNullFunction<OrderEntry, VirtualFile[]> computeRootProvider(int classPathType, final Sdk jdk) { return (classPathType & JDK_ONLY) == 0 ? null : orderEntry -> { if(orderEntry instanceof ModuleExtensionWithSdkOrderEntry) { final Sdk sdk = ((ModuleExtensionWithSdkOrderEntry) orderEntry).getSdk(); if(sdk == null) { return VirtualFile.EMPTY_ARRAY; } if(sdk.getSdkType() == jdk) { return jdk.getRootProvider().getFiles(BinariesOrderRootType.getInstance()); } return orderEntry.getFiles(BinariesOrderRootType.getInstance()); } return orderEntry.getFiles(BinariesOrderRootType.getInstance()); }; }
private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, int classPathType, Sdk jdk) { if((classPathType & JDK_ONLY) == 0) { enumerator = enumerator.withoutSdk(); } if((classPathType & TESTS_ONLY) == 0) { enumerator = enumerator.productionOnly(); } OrderRootsEnumerator rootsEnumerator = enumerator.classes(); final NotNullFunction<OrderEntry, VirtualFile[]> provider = computeRootProvider(classPathType, jdk); if(provider != null) { rootsEnumerator = rootsEnumerator.usingCustomRootProvider(provider); } return rootsEnumerator; }
private static String composeMessageText(Collection<? extends BuildTarget<?>> targets, Event event) { String targetsString = StringUtil.join(targets, new NotNullFunction<BuildTarget<?>, String>() { @NotNull @Override public String fun(BuildTarget<?> dom) { return dom.getPresentableName(); } }, ", "); return (event == Event.STARTED ? "Started" : "Finished") + " building " + targetsString; }