Java Code Examples for com.intellij.psi.util.PsiUtilCore#toPsiFileArray()
The following examples show how to use
com.intellij.psi.util.PsiUtilCore#toPsiFileArray() .
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: CheckinHandlerUtil.java From consulo with Apache License 2.0 | 6 votes |
public static PsiFile[] getPsiFiles(final Project project, final Collection<VirtualFile> selectedFiles) { ArrayList<PsiFile> result = new ArrayList<PsiFile>(); PsiManager psiManager = PsiManager.getInstance(project); VirtualFile projectFileDir = null; VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { projectFileDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); } for (VirtualFile file : selectedFiles) { if (file.isValid()) { if (isUnderProjectFileDir(projectFileDir, file) || !isFileUnderSourceRoot(project, file)) { continue; } PsiFile psiFile = psiManager.findFile(file); if (psiFile != null) result.add(psiFile); } } return PsiUtilCore.toPsiFileArray(result); }
Example 2
Source File: IndexTodoCacheManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public PsiFile[] getFilesWithTodoItems() { if (myProject.isDefault()) { return PsiFile.EMPTY_ARRAY; } final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); final Set<PsiFile> allFiles = new HashSet<>(); final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) { final Collection<VirtualFile> files = fileBasedIndex.getContainingFiles( TodoIndex.NAME, new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), GlobalSearchScope.allScope(myProject)); ApplicationManager.getApplication().runReadAction(() -> { for (VirtualFile file : files) { if (projectFileIndex.isInContent(file)) { final PsiFile psiFile = myPsiManager.findFile(file); if (psiFile != null) { allFiles.add(psiFile); } } } }); } return allFiles.isEmpty() ? PsiFile.EMPTY_ARRAY : PsiUtilCore.toPsiFileArray(allFiles); }
Example 3
Source File: PsiDirectoryImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override @Nonnull public PsiFile[] getFiles() { LOG.assertTrue(myFile.isValid()); VirtualFile[] files = myFile.getChildren(); ArrayList<PsiFile> psiFiles = new ArrayList<PsiFile>(); for (VirtualFile file : files) { PsiFile psiFile = myManager.findFile(file); if (psiFile != null) { psiFiles.add(psiFile); } } return PsiUtilCore.toPsiFileArray(psiFiles); }
Example 4
Source File: ReformatCodeAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction public static PsiFile[] convertToPsiFiles(final VirtualFile[] files,Project project) { final PsiManager manager = PsiManager.getInstance(project); final ArrayList<PsiFile> result = new ArrayList<>(); for (VirtualFile virtualFile : files) { final PsiFile psiFile = manager.findFile(virtualFile); if (psiFile != null) result.add(psiFile); } return PsiUtilCore.toPsiFileArray(result); }
Example 5
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) { PsiElement[] elements = new PsiElement[myFilesToMove.size()]; final PsiFile[] classes = PsiUtilCore.toPsiFileArray(myFilesToMove.keySet()); System.arraycopy(classes, 0, elements, 0, classes.length); return new MoveMultipleElementsViewDescriptor(elements, getTargetName()); }
Example 6
Source File: ViewerTreeStructure.java From consulo with Apache License 2.0 | 4 votes |
@Override public Object[] getChildElements(final Object element) { if (myRootElement == element) { if (myRootPsiElement == null) { return ArrayUtil.EMPTY_OBJECT_ARRAY; } if (!(myRootPsiElement instanceof PsiFile)) { return new Object[]{myRootPsiElement}; } List<PsiFile> files = ((PsiFile)myRootPsiElement).getViewProvider().getAllFiles(); return PsiUtilCore.toPsiFileArray(files); } final Object[][] children = new Object[1][]; children[0] = ArrayUtil.EMPTY_OBJECT_ARRAY; ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { final Object[] result; if (myShowTreeNodes) { final ArrayList<Object> list = new ArrayList<Object>(); ASTNode root = element instanceof PsiElement? SourceTreeToPsiMap.psiElementToTree((PsiElement)element) : element instanceof ASTNode? (ASTNode)element : null; if (element instanceof Inject) { root = SourceTreeToPsiMap.psiElementToTree(((Inject)element).getPsi()); } if (root != null) { ASTNode child = root.getFirstChildNode(); while (child != null) { if (myShowWhiteSpaces || child.getElementType() != TokenType.WHITE_SPACE) { final PsiElement childElement = child.getPsi(); list.add(childElement == null ? child : childElement); } child = child.getTreeNext(); } final PsiElement psi = root.getPsi(); if (psi instanceof PsiLanguageInjectionHost) { InjectedLanguageUtil.enumerate(psi, new PsiLanguageInjectionHost.InjectedPsiVisitor() { @Override public void visit(@Nonnull PsiFile injectedPsi, @Nonnull List<PsiLanguageInjectionHost.Shred> places) { list.add(new Inject(psi, injectedPsi)); } }); } } result = ArrayUtil.toObjectArray(list); } else { final PsiElement[] elementChildren = ((PsiElement)element).getChildren(); if (!myShowWhiteSpaces) { final List<PsiElement> childrenList = new ArrayList<PsiElement>(elementChildren.length); for (PsiElement psiElement : elementChildren) { if (!myShowWhiteSpaces && psiElement instanceof PsiWhiteSpace) { continue; } childrenList.add(psiElement); } result = PsiUtilCore.toPsiElementArray(childrenList); } else { result = elementChildren; } } children[0] = result; } }); return children[0]; }