Java Code Examples for com.intellij.util.containers.ContainerUtilRt#newArrayList()
The following examples show how to use
com.intellij.util.containers.ContainerUtilRt#newArrayList() .
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: VcsUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static Collection<VcsDirectoryMapping> findRoots(@Nonnull VirtualFile rootDir, @Nonnull Project project) throws IllegalArgumentException { if (!rootDir.isDirectory()) { throw new IllegalArgumentException( "Can't find VCS at the target file system path. Reason: expected to find a directory there but it's not. The path: " + rootDir.getParent() ); } Collection<VcsRoot> roots = ServiceManager.getService(project, VcsRootDetector.class).detect(rootDir); Collection<VcsDirectoryMapping> result = ContainerUtilRt.newArrayList(); for (VcsRoot vcsRoot : roots) { VirtualFile vFile = vcsRoot.getPath(); AbstractVcs rootVcs = vcsRoot.getVcs(); if (rootVcs != null && vFile != null) { result.add(new VcsDirectoryMapping(vFile.getPath(), rootVcs.getName())); } } return result; }
Example 2
Source File: ExternalSystemRecentTaskListModelTest.java From consulo with Apache License 2.0 | 6 votes |
@Test public void testEnsureSize() throws Exception { List<ExternalTaskExecutionInfo> tasks = ContainerUtilRt.newArrayList(); // test task list widening myModel.setTasks(tasks); myModel.ensureSize(ExternalSystemConstants.RECENT_TASKS_NUMBER); Assert.assertEquals("task list widening failed", ExternalSystemConstants.RECENT_TASKS_NUMBER, myModel.getSize()); // test task list reduction for (int i = 0; i < ExternalSystemConstants.RECENT_TASKS_NUMBER + 1; i++) { tasks.add(new ExternalTaskExecutionInfo(new ExternalSystemTaskExecutionSettings(), "task" + i)); } myModel.setTasks(tasks); Assert.assertEquals(ExternalSystemConstants.RECENT_TASKS_NUMBER + 1, myModel.getSize()); myModel.ensureSize(ExternalSystemConstants.RECENT_TASKS_NUMBER); Assert.assertEquals("task list reduction failed", ExternalSystemConstants.RECENT_TASKS_NUMBER, myModel.getSize()); }
Example 3
Source File: ExternalSystemUtil.java From consulo with Apache License 2.0 | 6 votes |
private void processOrphanModules() { if (myProject.isDisposed()) return; if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) { LOG.info(String.format("Checking for orphan modules. External paths returned by external system: '%s'", myExternalModulePaths)); } List<Module> orphanIdeModules = ContainerUtilRt.newArrayList(); String externalSystemIdAsString = myExternalSystemId.toString(); for (Module module : ModuleManager.getInstance(myProject).getModules()) { String s = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY); String p = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.LINKED_PROJECT_PATH_KEY); if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) { LOG.info(String.format("IDE module: EXTERNAL_SYSTEM_ID_KEY - '%s', LINKED_PROJECT_PATH_KEY - '%s'.", s, p)); } if (externalSystemIdAsString.equals(s) && !myExternalModulePaths.contains(p)) { orphanIdeModules.add(module); if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) { LOG.info(String.format("External paths doesn't contain IDE module LINKED_PROJECT_PATH_KEY anymore => add to orphan IDE modules.")); } } } if (!orphanIdeModules.isEmpty()) { ruleOrphanModules(orphanIdeModules, myProject, myExternalSystemId); } }
Example 4
Source File: AbstractBlock.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private List<Block> buildInjectedBlocks() { if (myBuildIndentsOnly) { return EMPTY; } if (!(this instanceof SettingsAwareBlock)) { return EMPTY; } PsiElement psi = myNode.getPsi(); if (psi == null) { return EMPTY; } PsiFile file = psi.getContainingFile(); if (file == null) { return EMPTY; } if (InjectedLanguageUtil.getCachedInjectedDocuments(file).isEmpty()) { return EMPTY; } TextRange blockRange = myNode.getTextRange(); List<DocumentWindow> documentWindows = InjectedLanguageUtil.getCachedInjectedDocuments(file); for (DocumentWindow documentWindow : documentWindows) { int startOffset = documentWindow.injectedToHost(0); int endOffset = startOffset + documentWindow.getTextLength(); if (blockRange.containsRange(startOffset, endOffset)) { PsiFile injected = PsiDocumentManager.getInstance(psi.getProject()).getCachedPsiFile(documentWindow); if (injected != null) { List<Block> result = ContainerUtilRt.newArrayList(); DefaultInjectedLanguageBlockBuilder builder = new DefaultInjectedLanguageBlockBuilder(((SettingsAwareBlock)this).getSettings()); builder.addInjectedBlocks(result, myNode, getWrap(), getAlignment(), getIndent()); return result; } } } return EMPTY; }
Example 5
Source File: GraphQLBlockWrapper.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@NotNull private List<Block> buildInjectedBlocks() { PsiElement psi = myNode.getPsi(); if (psi == null) { return EMPTY; } PsiFile file = psi.getContainingFile(); if (file == null) { return EMPTY; } if (InjectedLanguageUtil.getCachedInjectedDocuments(file).isEmpty()) { return EMPTY; } TextRange blockRange = myNode.getTextRange(); List<DocumentWindow> documentWindows = InjectedLanguageUtil.getCachedInjectedDocuments(file); for (DocumentWindow documentWindow : documentWindows) { int startOffset = documentWindow.injectedToHost(0); int endOffset = startOffset + documentWindow.getTextLength(); if (blockRange.containsRange(startOffset, endOffset)) { PsiFile injected = PsiDocumentManager.getInstance(psi.getProject()).getCachedPsiFile(documentWindow); if (injected != null) { List<Block> result = ContainerUtilRt.newArrayList(); GraphQLInjectedLanguageBlockBuilder builder = new GraphQLInjectedLanguageBlockBuilder(settings); builder.addInjectedBlocks(result, myNode, getWrap(), getAlignment(), getIndent()); return result; } } } return EMPTY; }
Example 6
Source File: ArrangementUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static List<CompositeArrangementSettingsToken> flatten(@Nonnull CompositeArrangementSettingsToken base) { List<CompositeArrangementSettingsToken> result = ContainerUtilRt.newArrayList(); Queue<CompositeArrangementSettingsToken> toProcess = ContainerUtilRt.newLinkedList(base); while (!toProcess.isEmpty()) { CompositeArrangementSettingsToken token = toProcess.remove(); result.add(token); toProcess.addAll(token.getChildren()); } return result; }
Example 7
Source File: ExternalSystemUtil.java From consulo with Apache License 2.0 | 5 votes |
private void processOrphanProjectLibraries() { List<Library> orphanIdeLibraries = ContainerUtilRt.newArrayList(); LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(myProject); for (Library library : projectLibraryTable.getLibraries()) { if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, myExternalSystemId)) continue; if (ProjectStructureHelper.isOrphanProjectLibrary(library, ModuleManager.getInstance(myProject).getModules())) { orphanIdeLibraries.add(library); } } for (Library orphanIdeLibrary : orphanIdeLibraries) { projectLibraryTable.removeLibrary(orphanIdeLibrary); } }
Example 8
Source File: ExternalSystemRecentTaskListModel.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public List<ExternalTaskExecutionInfo> getTasks() { List<ExternalTaskExecutionInfo> result = ContainerUtilRt.newArrayList(); for (int i = 0; i < size(); i++) { Object e = getElementAt(i); if (e instanceof ExternalTaskExecutionInfo) { result.add((ExternalTaskExecutionInfo)e); } } return result; }
Example 9
Source File: AbstractExternalSystemFacadeImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void applySettings(@Nonnull S settings) throws RemoteException { mySettings.set(settings); List<RemoteExternalSystemService<S>> services = ContainerUtilRt.newArrayList(myRemotes.values()); for (RemoteExternalSystemService<S> service : services) { service.setSettings(settings); } }
Example 10
Source File: LibraryDependencyDataService.java From consulo with Apache License 2.0 | 5 votes |
private void importMissingProjectLibraries(@Nonnull Module module, @Nonnull Collection<DataNode<LibraryDependencyData>> nodesToImport, boolean synchronous) { LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject()); List<DataNode<LibraryData>> librariesToImport = ContainerUtilRt.newArrayList(); for (DataNode<LibraryDependencyData> dataNode : nodesToImport) { final LibraryDependencyData dependencyData = dataNode.getData(); if (dependencyData.getLevel() != LibraryLevel.PROJECT) { continue; } final Library library = libraryTable.getLibraryByName(dependencyData.getInternalName()); if (library == null) { DataNode<ProjectData> projectNode = dataNode.getDataNode(ProjectKeys.PROJECT); if (projectNode != null) { DataNode<LibraryData> libraryNode = ExternalSystemApiUtil.find(projectNode, ProjectKeys.LIBRARY, new BooleanFunction<DataNode<LibraryData>>() { @Override public boolean fun(DataNode<LibraryData> node) { return node.getData().equals(dependencyData.getTarget()); } }); if (libraryNode != null) { librariesToImport.add(libraryNode); } } } } if (!librariesToImport.isEmpty()) { LibraryDataService.getInstance().importData(librariesToImport, module.getProject(), synchronous); } }
Example 11
Source File: DefaultArrangementEntryMatcherSerializer.java From consulo with Apache License 2.0 | 5 votes |
@Override public void visit(@Nonnull ArrangementCompositeMatchCondition condition) { Element composite = new Element(COMPOSITE_CONDITION_NAME); register(composite); parent = composite; List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands()); ContainerUtil.sort(operands, CONDITION_COMPARATOR); for (ArrangementMatchCondition c : operands) { c.invite(this); } }
Example 12
Source File: ProjectDataManager.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public <T> void importData(@Nonnull Collection<DataNode<?>> nodes, @Nonnull Project project, boolean synchronous) { Map<Key<?>, List<DataNode<?>>> grouped = ExternalSystemApiUtil.group(nodes); for (Map.Entry<Key<?>, List<DataNode<?>>> entry : grouped.entrySet()) { // Simple class cast makes ide happy but compiler fails. Collection<DataNode<T>> dummy = ContainerUtilRt.newArrayList(); for (DataNode<?> node : entry.getValue()) { dummy.add((DataNode<T>)node); } importData((Key<T>)entry.getKey(), dummy, project, synchronous); } }
Example 13
Source File: ExternalSystemAutoImporter.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static void letTheMagicBegin(@Nonnull Project project) { List<MyEntry> autoImportAware = ContainerUtilRt.newArrayList(); Collection<ExternalSystemManager<?, ?, ?, ?, ?>> managers = ExternalSystemApiUtil.getAllManagers(); for (ExternalSystemManager<?, ?, ?, ?, ?> manager : managers) { AbstractExternalSystemSettings<?, ?, ?> systemSettings = manager.getSettingsProvider().fun(project); ExternalSystemAutoImportAware defaultImportAware = createDefault(systemSettings); final ExternalSystemAutoImportAware aware; if (manager instanceof ExternalSystemAutoImportAware) { aware = combine(defaultImportAware, (ExternalSystemAutoImportAware)manager); } else { aware = defaultImportAware; } autoImportAware.add(new MyEntry(manager.getSystemId(), systemSettings, aware)); } MyEntry[] entries = autoImportAware.toArray(new MyEntry[autoImportAware.size()]); ExternalSystemAutoImporter autoImporter = new ExternalSystemAutoImporter( project, ServiceManager.getService(ProjectDataManager.class), entries ); final MessageBus messageBus = project.getMessageBus(); messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, autoImporter); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(autoImporter, project); }
Example 14
Source File: ExternalSystemApiUtil.java From consulo with Apache License 2.0 | 5 votes |
/** * There is a possible case that methods of particular object should be executed with classpath different from the one implied * by the current class' class loader. External system offers {@link ParametersEnhancer#enhanceLocalProcessing(List)} method * for defining that custom classpath. * <p> * It's also possible that particular implementation of {@link ParametersEnhancer} is compiled using dependency to classes * which are provided by the {@link ParametersEnhancer#enhanceLocalProcessing(List) expanded classpath}. E.g. a class * <code>'A'</code> might use method of class <code>'B'</code> and 'A' is located at the current (system/plugin) classpath but * <code>'B'</code> is not. We need to reload <code>'A'</code> using its expanded classpath then, i.e. create new class loaded * with that expanded classpath and load <code>'A'</code> by it. * <p> * This method allows to do that. * * @param clazz custom classpath-aware class which instance should be created (is assumed to have a no-args constructor) * @param <T> target type * @return newly created instance of the given class loaded by custom classpath-aware loader * @throws IllegalAccessException as defined by reflection processing * @throws InstantiationException as defined by reflection processing * @throws NoSuchMethodException as defined by reflection processing * @throws InvocationTargetException as defined by reflection processing * @throws ClassNotFoundException as defined by reflection processing */ @Nonnull public static <T extends ParametersEnhancer> T reloadIfNecessary(@Nonnull final Class<T> clazz) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException { T instance = clazz.newInstance(); List<URL> urls = ContainerUtilRt.newArrayList(); instance.enhanceLocalProcessing(urls); if (urls.isEmpty()) { return instance; } final ClassLoader baseLoader = clazz.getClassLoader(); Method method = baseLoader.getClass().getMethod("getUrls"); if (method != null) { //noinspection unchecked urls.addAll((Collection<? extends URL>)method.invoke(baseLoader)); } UrlClassLoader loader = new UrlClassLoader(UrlClassLoader.build().urls(urls).parent(baseLoader.getParent())) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (name.equals(clazz.getName())) { return super.loadClass(name, resolve); } else { try { return baseLoader.loadClass(name); } catch (ClassNotFoundException e) { return super.loadClass(name, resolve); } } } }; //noinspection unchecked return (T)loader.loadClass(clazz.getName()).newInstance(); }
Example 15
Source File: ExternalSystemApiUtil.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nonnull public static <T> Collection<DataNode<T>> findAll(@Nonnull DataNode<?> parent, @Nonnull Key<T> key) { Collection<DataNode<T>> result = null; for (DataNode<?> child : parent.getChildren()) { if (!key.equals(child.getKey())) { continue; } if (result == null) { result = ContainerUtilRt.newArrayList(); } result.add((DataNode<T>)child); } return result == null ? Collections.<DataNode<T>>emptyList() : result; }
Example 16
Source File: ExternalSystemApiUtil.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nonnull public static <T> Collection<DataNode<T>> getChildren(@Nonnull DataNode<?> node, @Nonnull Key<T> key) { Collection<DataNode<T>> result = null; for (DataNode<?> child : node.getChildren()) { if (!key.equals(child.getKey())) { continue; } if (result == null) { result = ContainerUtilRt.newArrayList(); } result.add((DataNode<T>)child); } return result == null ? Collections.<DataNode<T>>emptyList() : result; }
Example 17
Source File: ExternalSystemApiUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static <K, V> Map<K, List<V>> groupBy(@Nonnull Collection<V> nodes, @Nonnull NullableFunction<V, K> grouper) { Map<K, List<V>> result = ContainerUtilRt.newHashMap(); for (V data : nodes) { K key = grouper.fun(data); if (key == null) { LOG.warn(String.format( "Skipping entry '%s' during grouping. Reason: it's not possible to build a grouping key with grouping strategy '%s'. " + "Given entries: %s", data, grouper.getClass(), nodes)); continue; } List<V> grouped = result.get(key); if (grouped == null) { result.put(key, grouped = ContainerUtilRt.newArrayList()); } grouped.add(data); } if (!result.isEmpty() && result.keySet().iterator().next() instanceof Comparable) { List<K> ordered = ContainerUtilRt.newArrayList(result.keySet()); Collections.sort(ordered, COMPARABLE_GLUE); Map<K, List<V>> orderedResult = ContainerUtilRt.newLinkedHashMap(); for (K k : ordered) { orderedResult.put(k, result.get(k)); } return orderedResult; } return result; }
Example 18
Source File: ArrangementStandardSettingsManager.java From consulo with Apache License 2.0 | 4 votes |
public List<ArrangementSettingsToken> sort(@Nonnull Collection<ArrangementSettingsToken> tokens) { List<ArrangementSettingsToken> result = ContainerUtilRt.newArrayList(tokens); Collections.sort(result, myComparator); return result; }
Example 19
Source File: AbstractExternalSystemConfigurable.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void prepareProjectSettings(@Nonnull SystemSettings s) { myProjectsModel = new DefaultListModel(); myProjectsList = new JBList(myProjectsModel); myProjectsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); addTitle(ExternalSystemBundle.message("settings.title.linked.projects", myExternalSystemId.getReadableName())); myComponent.add(new JBScrollPane(myProjectsList), ExternalSystemUiUtil.getFillLineConstraints(1)); addTitle(ExternalSystemBundle.message("settings.title.project.settings")); List<ProjectSettings> settings = ContainerUtilRt.newArrayList(s.getLinkedProjectsSettings()); myProjectsList.setVisibleRowCount(Math.max(3, Math.min(5, settings.size()))); ContainerUtil.sort(settings, new Comparator<ProjectSettings>() { @Override public int compare(ProjectSettings s1, ProjectSettings s2) { return getProjectName(s1.getExternalProjectPath()).compareTo(getProjectName(s2.getExternalProjectPath())); } }); myProjectSettingsControls.clear(); for (ProjectSettings setting : settings) { ExternalSystemSettingsControl<ProjectSettings> control = createProjectSettingsControl(setting); control.fillUi(myComponent, 1); myProjectsModel.addElement(getProjectName(setting.getExternalProjectPath())); myProjectSettingsControls.add(control); control.showUi(false); } myProjectsList.addListSelectionListener(new ListSelectionListener() { @SuppressWarnings("unchecked") @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } int i = myProjectsList.getSelectedIndex(); if (i < 0) { return; } if (myActiveProjectSettingsControl != null) { myActiveProjectSettingsControl.showUi(false); } myActiveProjectSettingsControl = myProjectSettingsControls.get(i); myActiveProjectSettingsControl.showUi(true); } }); if (!myProjectsModel.isEmpty()) { addTitle(ExternalSystemBundle.message("settings.title.system.settings", myExternalSystemId.getReadableName())); myProjectsList.setSelectedIndex(0); } }
Example 20
Source File: DocPreviewUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * Allows to build a documentation preview from the given arguments. Basically, takes given 'header' text and tries to modify * it by using hyperlink information encapsulated at the given 'full text'. * * @param header target documentation header. Is expected to be a result of the * {@link DocumentationProvider#getQuickNavigateInfo(PsiElement, PsiElement)} call * @param qName there is a possible case that not all documentation text will be included to the preview * (according to the given 'desired rows and columns per-row' arguments). A link that points to the * element with the given qualified name is added to the preview's end if the qName is provided then * @param fullText full documentation text (if available) */ @Nonnull public static String buildPreview(@Nonnull final String header, @Nullable final String qName, @Nullable final String fullText) { if (fullText == null) { return header; } // Build links info. Map<String/*qName*/, String/*address*/> links = ContainerUtilRt.newHashMap(); process(fullText, new LinksCollector(links)); // Add derived names. Map<String, String> toAdd = ContainerUtilRt.newHashMap(); for (Map.Entry<String, String> entry : links.entrySet()) { String shortName = parseShortName(entry.getKey()); if (shortName != null) { toAdd.put(shortName, entry.getValue()); } String longName = parseLongName(entry.getKey(), entry.getValue()); if (longName != null) { toAdd.put(longName, entry.getValue()); } } links.putAll(toAdd); if (qName != null) { links.put(qName, DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL + qName); } // Apply links info to the header template. List<TextRange> modifiedRanges = ContainerUtilRt.newArrayList(); List<String> sortedReplacements = ContainerUtilRt.newArrayList(links.keySet()); Collections.sort(sortedReplacements, REPLACEMENTS_COMPARATOR); StringBuilder buffer = new StringBuilder(header); replace(buffer, "\n", "<br/>", modifiedRanges); for (String replaceFrom : sortedReplacements) { String visibleName = replaceFrom; int i = visibleName.lastIndexOf('.'); if (i > 0 && i < visibleName.length() - 1) { visibleName = visibleName.substring(i + 1); } replace(buffer, replaceFrom, String.format("<a href=\"%s\">%s</a>", links.get(replaceFrom), visibleName), modifiedRanges); } return buffer.toString(); }