Java Code Examples for com.intellij.util.containers.ContainerUtil#find()
The following examples show how to use
com.intellij.util.containers.ContainerUtil#find() .
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: QuickEditAction.java From consulo with Apache License 2.0 | 6 votes |
@Nullable protected Pair<PsiElement, TextRange> getRangePair(final PsiFile file, final Editor editor) { final int offset = editor.getCaretModel().getOffset(); final PsiLanguageInjectionHost host = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false); if (host == null || ElementManipulators.getManipulator(host) == null) return null; final List<Pair<PsiElement, TextRange>> injections = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host); if (injections == null || injections.isEmpty()) return null; final int offsetInElement = offset - host.getTextRange().getStartOffset(); final Pair<PsiElement, TextRange> rangePair = ContainerUtil.find(injections, new Condition<Pair<PsiElement, TextRange>>() { @Override public boolean value(final Pair<PsiElement, TextRange> pair) { return pair.second.containsRange(offsetInElement, offsetInElement); } }); if (rangePair != null) { final Language language = rangePair.first.getContainingFile().getLanguage(); final Object action = language.getUserData(EDIT_ACTION_AVAILABLE); if (action != null && action.equals(false)) return null; myLastLanguageName = language.getDisplayName(); } return rangePair; }
Example 2
Source File: ExtensionProviderUtil.java From idea-php-toolbox with MIT License | 6 votes |
@NotNull private static Collection<JsonRegistrar> getTypesInner(@NotNull Project project) { Collection<JsonRegistrar> jsonRegistrars = new ArrayList<>(); PhpToolboxApplicationService component = ApplicationManager.getApplication().getComponent(PhpToolboxApplicationService.class); if(component == null) { return jsonRegistrars; } for(JsonConfigFile jsonConfig: getJsonConfigs(project, component)) { Collection<JsonRegistrar> registrar = jsonConfig.getRegistrar(); for (JsonRegistrar jsonRegistrar : registrar) { if( !"php".equals(jsonRegistrar.getLanguage()) || ContainerUtil.find(jsonRegistrar.getSignatures(), ContainerConditions.RETURN_TYPE_TYPE) == null ) { continue; } jsonRegistrars.addAll(registrar); } } return jsonRegistrars; }
Example 3
Source File: YamlUpdateArgumentServicesCallbackTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void invokeInsert(YAMLFile yamlFile) { Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.collectElementsOfType(yamlFile, YAMLKeyValue.class); final YamlUpdateArgumentServicesCallback callback = new YamlUpdateArgumentServicesCallback( getProject(), ContainerUtil.find(yamlKeyValues, new YAMLKeyValueCondition("arguments")), ContainerUtil.find(yamlKeyValues, new YAMLKeyValueCondition("foo")) ); CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { callback.insert(Arrays.asList("foo", "bar")); } }); } }, null, null); }
Example 4
Source File: IdeEventQueue.java From consulo with Apache License 2.0 | 5 votes |
private void ifFocusEventsInTheQueue(@Nonnull Consumer<? super AWTEvent> yes, @Nonnull Runnable no) { if (!focusEventsList.isEmpty()) { if (FOCUS_AWARE_RUNNABLES_LOG.isDebugEnabled()) { FOCUS_AWARE_RUNNABLES_LOG.debug("Focus event list (trying to execute runnable): " + runnablesWaitingForFocusChangeState()); } // find the latest focus gained AWTEvent first = ContainerUtil.find(focusEventsList, e -> e.getID() == FocusEvent.FOCUS_GAINED); if (first != null) { if (FOCUS_AWARE_RUNNABLES_LOG.isDebugEnabled()) { FOCUS_AWARE_RUNNABLES_LOG.debug(" runnable saved for : [" + first.getID() + "; " + first.getSource() + "] -> " + no.getClass().getName()); } yes.accept(first); } else { if (FOCUS_AWARE_RUNNABLES_LOG.isDebugEnabled()) { FOCUS_AWARE_RUNNABLES_LOG.debug(" runnable is run on EDT if needed : " + no.getClass().getName()); } UIUtil.invokeLaterIfNeeded(no); } } else { if (FOCUS_AWARE_RUNNABLES_LOG.isDebugEnabled()) { FOCUS_AWARE_RUNNABLES_LOG.debug("Focus event list is empty: runnable is run right away : " + no.getClass().getName()); } UIUtil.invokeLaterIfNeeded(no); } }
Example 5
Source File: RouteHelperTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#getXmlRouteDefinitions */ public void testGetXmlRouteDefinitionsWithoutController() { StubIndexedRoute route1 = ContainerUtil.find(RouteHelper.getXmlRouteDefinitions(createXmlFile("" + "<routes>\n" + " <route id=\"foo2\" pattern=\"/blog/{slug}\"/>\n" + "</routes>" )), new MyEqualStubIndexedRouteCondition("foo2")); assertNotNull(route1); assertNull(route1.getController()); assertEquals("foo2", route1.getName()); assertEquals("/blog/{slug}", route1.getPath()); }
Example 6
Source File: Utils.java From idea-gitignore with MIT License | 5 votes |
/** * Searches for the module in the project that contains given file. * * @param file file * @param project project * @return module containing passed file or null */ @Nullable public static Module getModuleForFile(@NotNull final VirtualFile file, @NotNull final Project project) { return ContainerUtil.find( ModuleManager.getInstance(project).getModules(), module -> module.getModuleContentScope().contains(file) ); }
Example 7
Source File: VcsRootErrorsFinder.java From consulo with Apache License 2.0 | 5 votes |
private boolean isRoot(@Nonnull final VcsDirectoryMapping mapping) { List<VcsRootChecker> checkers = VcsRootChecker.EXTENSION_POINT_NAME.getExtensionList(); final String pathToCheck = mapping.isDefaultMapping() ? myProject.getBasePath() : mapping.getDirectory(); return ContainerUtil.find(checkers, new Condition<VcsRootChecker>() { @Override public boolean value(VcsRootChecker checker) { return checker.getSupportedVcs().getName().equalsIgnoreCase(mapping.getVcs()) && checker.isRoot(pathToCheck); } }) != null; }
Example 8
Source File: JsonFileIndexTwigNamespacesTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void testThatBundleNamespaceIsSupported() { TwigPath fooBundle = ContainerUtil.find(TwigUtil.getTwigNamespaces(getProject()), new MyTwigPathNamespaceCondition("FooBundle")); assertNotNull(fooBundle); assertEquals("src/foo/res", fooBundle.getPath()); assertEquals("FooBundle", fooBundle.getNamespace()); assertEquals(TwigUtil.NamespaceType.BUNDLE, fooBundle.getNamespaceType()); }
Example 9
Source File: EventDispatcherSubscriberUtilTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * @see EventDispatcherSubscriberUtil#getEventNameLookupElements */ public void testGetEventNameLookupElementsForTaggedKernelListener() { Collection<LookupElement> eventNameLookupElements = EventDispatcherSubscriberUtil.getEventNameLookupElements(getProject()); ContainerUtil.find(eventNameLookupElements, lookupElement -> lookupElement.getLookupString().equals("kernel.exception.xml") ); ContainerUtil.find(eventNameLookupElements, lookupElement -> lookupElement.getLookupString().equals("kernel.exception.yml") ); }
Example 10
Source File: GlobalSearchScope.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isSearchInLibraries() { return ContainerUtil.find(myScopes, new Condition<GlobalSearchScope>() { @Override public boolean value(GlobalSearchScope scope) { return scope.isSearchInLibraries(); } }) != null; }
Example 11
Source File: PushController.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable private <R extends Repository, S extends PushSource, T extends PushTarget> PushSupport<R, S, T> getPushSupportByRepository(@Nonnull final R repository) { //noinspection unchecked return (PushSupport<R, S, T>)ContainerUtil.find( myPushSupports, new Condition<PushSupport<? extends Repository, ? extends PushSource, ? extends PushTarget>>() { @Override public boolean value(PushSupport<? extends Repository, ? extends PushSource, ? extends PushTarget> support) { return support.getVcs().equals(repository.getVcs()); } }); }
Example 12
Source File: RouteHelperTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#getXmlRouteDefinitions */ public void testGetXmlRouteDefinitions() { Collection<XmlFile> xmlFiles = new ArrayList<XmlFile>(); xmlFiles.add(createXmlFile("" + "<routes>\n" + " <route id=\"foo2\" path=\"/blog/{slug}\">\n" + " <default key=\"_controller\">MyController::fooAction</default>\n" + " </route>\n" + "</routes>" )); xmlFiles.add(createXmlFile("" + "<routes>\n" + " <route id=\"foo2\" pattern=\"/blog/{slug}\">\n" + " <default key=\"_controller\">MyController::fooAction</default>\n" + " </route>\n" + "</routes>" )); for (XmlFile xmlFile : xmlFiles) { StubIndexedRoute route1 = ContainerUtil.find(RouteHelper.getXmlRouteDefinitions(xmlFile), new MyEqualStubIndexedRouteCondition("foo2")); assertNotNull(route1); assertEquals("MyController::fooAction", route1.getController()); assertEquals("foo2", route1.getName()); assertEquals("/blog/{slug}", route1.getPath()); } }
Example 13
Source File: ServiceContainerUtilTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void testDecoratorPatternCustomLanguageUnderscoreKeys() { for (PsiFile psiFile : new PsiFile[]{xmlFile, ymlFile}) { ServiceInterface bar = ContainerUtil.find(ServiceContainerUtil.getServicesInFile(psiFile), MyStringServiceInterfaceCondition.create("bar")); assertEquals("bar", bar.getId()); assertEquals("stdClass", bar.getClassName()); assertEquals("foo", bar.getDecorates()); assertEquals("bar.wooz", bar.getDecorationInnerName()); assertEquals(false, bar.isPublic()); } }
Example 14
Source File: GlobalSearchScope.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isSearchInModuleContent(@Nonnull final Module module, final boolean testSources) { return ContainerUtil.find(myScopes, new Condition<GlobalSearchScope>() { @Override public boolean value(GlobalSearchScope scope) { return scope.isSearchInModuleContent(module, testSources); } }) != null; }
Example 15
Source File: ServiceContainerUtilTest.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void testNonDefaultValuesAreSerialized() { for (PsiFile psiFile : new PsiFile[]{xmlFile, ymlFile}) { ServiceInterface bar = ContainerUtil.find(ServiceContainerUtil.getServicesInFile(psiFile), MyStringServiceInterfaceCondition.create("non.defaults")); assertEquals( "{\"id\":\"non.defaults\",\"class\":\"DateTime\",\"public\":false,\"lazy\":true,\"abstract\":true,\"autowire\":true,\"deprecated\":true,\"alias\":\"foo\",\"decorates\":\"foo\",\"decoration_inner_name\":\"foo\",\"parent\":\"foo\",\"tags\":[]}", new Gson().toJson(bar) ); } }
Example 16
Source File: RTRequireTagDescriptor.java From react-templates-plugin with MIT License | 5 votes |
@Nullable @Override public XmlAttributeDescriptor getAttributeDescriptor(@NonNls final String attributeName, @Nullable XmlTag context) { return ContainerUtil.find(getAttributesDescriptors(context), new Condition<XmlAttributeDescriptor>() { @Override public boolean value(XmlAttributeDescriptor descriptor) { return attributeName.equals(descriptor.getName()); } }); }
Example 17
Source File: L2GitUtil.java From azure-devops-intellij with MIT License | 5 votes |
@Nullable Project findProjectByBaseDirLocation(@NotNull File directory) { return ContainerUtil.find(ProjectManager.getInstance().getOpenProjects(), project -> { VirtualFile baseDir = project.getBaseDir(); return baseDir != null && FileUtil.filesEqual(VfsUtilCore.virtualToIoFile(baseDir), directory); }); }
Example 18
Source File: RootIndex.java From consulo with Apache License 2.0 | 4 votes |
private boolean shouldMarkAsProjectExcluded(@Nonnull VirtualFile root, @Nullable List<VirtualFile> hierarchy) { if (hierarchy == null) return false; if (!excludedFromProject.contains(root) && !excludedFromModule.containsKey(root)) return false; return ContainerUtil.find(hierarchy, contentRootOf::containsKey) == null; }
Example 19
Source File: VcsCherryPickAction.java From consulo with Apache License 2.0 | 4 votes |
@Nullable private static VcsCherryPicker getActiveCherryPicker(@Nonnull List<VcsCherryPicker> cherryPickers, @Nonnull Collection<VirtualFile> roots) { return ContainerUtil.find(cherryPickers, picker -> picker.canHandleForRoots(roots)); }
Example 20
Source File: RouteSettingDeprecatedInspection.java From idea-php-symfony2-plugin with MIT License | 2 votes |
/** * Find child token which stores value * * XmlToken: "'" * XmlToken: "attributeText" * XmlToken: "'" */ private PsiElement findAttributeValueToken(@NotNull XmlAttributeValue xmlAttributeValue, @NotNull final String attributeText) { return ContainerUtil.find(xmlAttributeValue.getChildren(), psiElement -> psiElement instanceof XmlToken && attributeText.equals(psiElement.getText()) ); }