private static void logStats(Collection<PsiFile> otherFiles, long start) { long time = System.currentTimeMillis() - start; final Multiset<String> stats = HashMultiset.create(); for (PsiFile file : otherFiles) { stats.add( StringUtil.notNullize(file.getViewProvider().getVirtualFile().getExtension()) .toLowerCase()); } List<String> extensions = ContainerUtil.newArrayList(stats.elementSet()); Collections.sort( extensions, new Comparator<String>() { @Override public int compare(String o1, String o2) { return stats.count(o2) - stats.count(o1); } }); String message = "Search in " + otherFiles.size() + " files with unknown types took " + time + "ms.\n" + "Mapping their extensions to an existing file type (e.g. Plain Text) might speed up the search.\n" + "Most frequent non-indexed file extensions: "; for (int i = 0; i < Math.min(10, extensions.size()); i++) { String extension = extensions.get(i); message += extension + "(" + stats.count(extension) + ") "; } LOG.info(message); }
private <T> boolean findListToRemoveFrom( @NotNull String name, @NotNull final List<T> elements, final Convertor<T, AbstractUrl> convertor) { Collection<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); if (elements.size() > 1) { final List<T> sublist = elements.subList(0, elements.size() - 1); for (T obj : sublist) { AbstractUrl objUrl = convertor.convert(obj); final TreeItem<Pair<AbstractUrl, String>> item = findNextItem(objUrl, list); if (item == null || item.getChildren() == null) return false; list = item.getChildren(); } } TreeItem<Pair<AbstractUrl, String>> found = null; AbstractUrl url = convertor.convert(elements.get(elements.size() - 1)); if (url == null) return false; for (TreeItem<Pair<AbstractUrl, String>> pair : list) { if (url.equals(pair.getData().getFirst())) { found = pair; break; } } if (found != null) { list.remove(found); fireListeners.rootsChanged(name); return true; } return false; }
public void removeRootByIndexes(String name, List<Integer> elementsIndexes) { List<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); assert list != null; for (Integer index : elementsIndexes.subList(0, elementsIndexes.size() - 1)) { assert index >= 0 && index < list.size(); final TreeItem<Pair<AbstractUrl, String>> item = list.get(index); list = item.getChildren(); } assert list != null && !list.isEmpty(); list.remove(elementsIndexes.get(elementsIndexes.size() - 1).intValue()); fireListeners.rootsChanged(name); }
public synchronized boolean editRoot( @NotNull String name, @NotNull List<Integer> elementsIndexes, final AbstractTreeNode newElement) { List<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); assert list != null; for (Integer index : elementsIndexes.subList(0, elementsIndexes.size() - 1)) { assert index >= 0 && index < list.size(); final TreeItem<Pair<AbstractUrl, String>> item = list.get(index); list = item.getChildren(); } assert list != null && !list.isEmpty(); final Object value = newElement.getValue(); final AbstractUrl urlByElement = createUrlByElement(value, myProject); if (urlByElement == null) return false; list.set( elementsIndexes.get(elementsIndexes.size() - 1).intValue(), new TreeItem<Pair<AbstractUrl, String>>( Pair.create(urlByElement, newElement.getClass().getName()))); return true; }
private void runTransformingCompilers(final ModuleChunk chunk) { final JavaSourceTransformingCompiler[] transformers = CompilerManager.getInstance(myProject).getCompilers(JavaSourceTransformingCompiler.class); if (transformers.length == 0) { return; } if (LOG.isDebugEnabled()) { LOG.debug("Running transforming compilers..."); } final Module[] modules = chunk.getModules(); for (final JavaSourceTransformingCompiler transformer : transformers) { final Map<VirtualFile, VirtualFile> originalToCopyFileMap = new HashMap<VirtualFile, VirtualFile>(); final Application application = ApplicationManager.getApplication(); application.invokeAndWait( new Runnable() { public void run() { for (final Module module : modules) { for (final VirtualFile file : chunk.getFilesToCompile(module)) { final VirtualFile untransformed = chunk.getOriginalFile(file); if (transformer.isTransformable(untransformed)) { application.runWriteAction( new Runnable() { public void run() { try { // if untransformed != file, the file is already a (possibly // transformed) copy of the original 'untransformed' file. // If this is the case, just use already created copy and do not copy // file content once again final VirtualFile fileCopy = untransformed.equals(file) ? createFileCopy(getTempDir(module), file) : file; originalToCopyFileMap.put(file, fileCopy); } catch (IOException e) { // skip it } } }); } } } } }, myCompileContext.getProgressIndicator().getModalityState()); // do actual transform for (final Module module : modules) { final List<VirtualFile> filesToCompile = chunk.getFilesToCompile(module); for (int j = 0; j < filesToCompile.size(); j++) { final VirtualFile file = filesToCompile.get(j); final VirtualFile fileCopy = originalToCopyFileMap.get(file); if (fileCopy != null) { final boolean ok = transformer.transform(myCompileContext, fileCopy, chunk.getOriginalFile(file)); if (ok) { chunk.substituteWithTransformedVersion(module, j, fileCopy); } } } } } }