com.intellij.psi.PsiDirectory Java Examples
The following examples show how to use
com.intellij.psi.PsiDirectory.
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: DirectoryAsPackageRenameHandlerBase.java From consulo with Apache License 2.0 | 6 votes |
private void renameDirs(final Project project, final PsiElement nameSuggestionContext, final Editor editor, final PsiDirectory contextDirectory, final T aPackage, final PsiDirectory... dirsToRename) { final RenameDialog dialog = new RenameDialog(project, contextDirectory, nameSuggestionContext, editor) { @Override protected void doAction() { String newQName = StringUtil.getQualifiedName(StringUtil.getPackageName(getQualifiedName(aPackage)), getNewName()); BaseRefactoringProcessor moveProcessor = createProcessor(newQName, project, dirsToRename, isSearchInComments(), isSearchInNonJavaFiles()); invokeRefactoring(moveProcessor); } }; dialog.show(); }
Example #2
Source File: ExtraModulesUtil.java From weex-language-support with MIT License | 6 votes |
private static PsiFile getMain(PsiDirectory moduleRoot) { PsiFile pkg = moduleRoot.findFile("package.json"); if (pkg != null && pkg instanceof JsonFile) { if (((JsonFile) pkg).getTopLevelValue() instanceof JsonObject) { JsonObject object = (JsonObject) ((JsonFile) pkg).getTopLevelValue(); if (object != null) { JsonProperty property = object.findProperty("main"); if (property != null && property.getValue() != null && property.getValue() instanceof JsonStringLiteral) { JsonStringLiteral propValue = (JsonStringLiteral) property.getValue(); String value = propValue.getValue(); PsiFile psiFile = moduleRoot.findFile(value.replace("./", "")); return psiFile; } } } } return null; }
Example #3
Source File: TaskUtils.java From JHelper with GNU Lesser General Public License v3.0 | 6 votes |
private static PsiElement generateCPP(Project project, TaskData taskData) { VirtualFile parent = FileUtils.findOrCreateByRelativePath(project.getBaseDir(), FileUtils.getDirectory(taskData.getCppPath())); PsiDirectory psiParent = PsiManager.getInstance(project).findDirectory(parent); if (psiParent == null) { throw new NotificationException("Couldn't open parent directory as PSI"); } Language objC = Language.findLanguageByID("ObjectiveC"); if (objC == null) { throw new NotificationException("Language not found"); } PsiFile file = PsiFileFactory.getInstance(project).createFileFromText( FileUtils.getFilename(taskData.getCppPath()), objC, getTaskContent(project, taskData.getClassName()) ); if (file == null) { throw new NotificationException("Couldn't generate file"); } return ApplicationManager.getApplication().runWriteAction( (Computable<PsiElement>) () -> psiParent.add(file) ); }
Example #4
Source File: ContentFolderTypeProvider.java From consulo with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction public final Image getChildDirectoryIcon(@Nullable PsiDirectory psiDirectory, @Nullable PsiPackageManager oldPsiPackageManager) { Image packageIcon = getChildPackageIcon(); if (packageIcon == null) { return getChildDirectoryIcon(); } if (psiDirectory != null) { PsiPackageManager psiPackageManager = oldPsiPackageManager == null ? PsiPackageManager.getInstance(psiDirectory.getProject()) : oldPsiPackageManager; PsiPackage anyPackage = psiPackageManager.findAnyPackage(psiDirectory); if (anyPackage != null) { return packageIcon; } else { return getChildDirectoryIcon(); } } else { // return packageIcon; } }
Example #5
Source File: BundleClassGeneratorUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static PhpClass getBundleClassInDirectory(@NotNull PsiDirectory bundleDirContext) { for (PsiFile psiFile : bundleDirContext.getFiles()) { if(!(psiFile instanceof PhpFile)) { continue; } PhpClass aClass = PhpPsiUtil.findClass((PhpFile) psiFile, phpClass -> PhpElementsUtil.isInstanceOf(phpClass, "\\Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface") ); if(aClass != null) { return aClass; } } return null; }
Example #6
Source File: DirectoryUrl.java From consulo with Apache License 2.0 | 6 votes |
@Override public Object[] createPath(final Project project) { if (moduleName != null) { final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() { @Nullable @Override public Module compute() { return ModuleManager.getInstance(project).findModuleByName(moduleName); } }); if (module == null) return null; } final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance(); final VirtualFile file = virtualFileManager.findFileByUrl(url); if (file == null) return null; final PsiDirectory directory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() { @Nullable @Override public PsiDirectory compute() { return PsiManager.getInstance(project).findDirectory(file); } }); if (directory == null) return null; return new Object[]{directory}; }
Example #7
Source File: BlazeGoPackageImportReferencesTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testResolvableImportPrefix() { Label label = Label.create("//foo/bar:baz"); PsiDirectory externalGithubDirectory = mockPsiDirectory("github.com", null); PsiDirectory externalGithubUserDirectory = mockPsiDirectory("user", externalGithubDirectory); PsiDirectory fooDirectory = mockPsiDirectory("foo", externalGithubUserDirectory); PsiDirectory fooBarDirectory = mockPsiDirectory("bar", fooDirectory); BuildFile fooBarBuild = mockBuildFile(fooBarDirectory); FuncallExpression fooBarBazRule = mockRule("baz", fooBarBuild); PsiElement[] importReferences = BlazeGoPackage.getImportReferences(label, fooBarBazRule, "github.com/user/foo/bar/baz"); assertThat(importReferences) .isEqualTo( new PsiElement[] { externalGithubDirectory, // github.com externalGithubUserDirectory, // user fooDirectory, // foo fooBarDirectory, // bar fooBarBazRule, // baz }); }
Example #8
Source File: FileWriter.java From PackageTemplates with Apache License 2.0 | 6 votes |
public static PsiDirectory writeDirectory(PsiDirectory dir, DirectoryWrapper dirWrapper, Project project) { if (dir == null) { //todo print error return null; } RunnableFuture<PsiDirectory> runnableFuture = new FutureTask<>(() -> ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() { @Override public PsiDirectory compute() { return writeDirectoryAction(dir, dirWrapper, project); } })); ApplicationManager.getApplication().invokeLater(runnableFuture); try { return runnableFuture.get(); } catch (InterruptedException | ExecutionException e) { Logger.log("runnableFuture " + e.getMessage()); Logger.printStack(e); } return null; }
Example #9
Source File: TYPO3ExtensionUtil.java From idea-php-typo3-plugin with MIT License | 6 votes |
/** * Traverses the given directories and returns the first valid * extension definition that's applicable. * * @param directories List of directories to analyze */ public static TYPO3ExtensionDefinition findContainingExtension(PsiDirectory[] directories) { for (PsiDirectory directory : directories) { VirtualDirectoryImpl virtualFile = (VirtualDirectoryImpl) directory.getVirtualFile(); while (!isExtensionRootDirectory(virtualFile)) { if (virtualFile.getParent() == null) { return null; } virtualFile = virtualFile.getParent(); } TYPO3ExtensionDefinition extensionDefinition = ExtensionDefinitionFactory.fromDirectory(virtualFile); if (extensionDefinition != null) { return extensionDefinition; } } return null; }
Example #10
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 6 votes |
private static void collectFiles2Move(Map<PsiFile, TargetDirectoryWrapper> files2Move, PsiDirectory directory, PsiDirectory rootDirectory, @Nonnull TargetDirectoryWrapper targetDirectory) { final PsiElement[] children = directory.getChildren(); final String relativePath = VfsUtilCore.getRelativePath(directory.getVirtualFile(), rootDirectory.getVirtualFile(), '/'); final TargetDirectoryWrapper newTargetDirectory = relativePath.length() == 0 ? targetDirectory : targetDirectory.findOrCreateChild(relativePath); for (PsiElement child : children) { if (child instanceof PsiFile) { files2Move.put((PsiFile)child, newTargetDirectory); } else if (child instanceof PsiDirectory){ collectFiles2Move(files2Move, (PsiDirectory)child, directory, newTargetDirectory); } } }
Example #11
Source File: ModulesUtil.java From svgtoandroid with MIT License | 6 votes |
public Set<String> getModules() { Set<String> modules = new HashSet<String>(); PsiDirectory baseDir = PsiDirectoryFactory.getInstance(project).createDirectory(project.getBaseDir()); if (isAndroidProject(baseDir)) { Logger.debug(project.getName() + " is an Android project"); PsiDirectory[] dirs = baseDir.getSubdirectories(); for (PsiDirectory dir : dirs) { if (!dir.getName().equals("build") && !dir.getName().equals("gradle")) { if (isModule(dir)) { Logger.debug(dir.getName() + " is a Module"); modules.add(dir.getName()); } } } } Logger.debug(modules.toString()); return modules; }
Example #12
Source File: PackageTemplateWrapper.java From PackageTemplates with Apache License 2.0 | 6 votes |
public void collectSimpleActions(Project project, VirtualFile virtualFile, List<SimpleAction> listSimpleAction) { ApplicationManager.getApplication().runReadAction(() -> { PsiDirectory currentDir = FileWriter.findCurrentDirectory(project, virtualFile); if (currentDir == null) { return; } // Disabled if (!getRootElement().getDirectory().isEnabled()) { return; } SimpleAction rootAction = getRootAction(project, listSimpleAction, currentDir); CollectSimpleActionVisitor visitor = new CollectSimpleActionVisitor(rootAction, project); for (ElementWrapper elementWrapper : rootElement.getListElementWrapper()) { elementWrapper.accept(visitor); } }); }
Example #13
Source File: BaseController.java From CleanArchitecturePlugin with Apache License 2.0 | 6 votes |
public static void generateBaseArchitecture(PsiDirectory parent) { // Check if exists main package PsiDirectory packageResult = containsPackage(parent, MAIN.toLowerCase()); // Not exists if (packageResult == null) { // Create main package mainDirectory = createDirectory(parent, MAIN.toLowerCase()); } else { // Exists // Set user main package setMainDirectory(packageResult); } // Create data package BaseDataController.create(); // Create domain package BaseDomainController.create(); // Create view package BaseViewController.create(); }
Example #14
Source File: FileResourceUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Gives targets to files which relative to current file directory */ @NotNull public static Collection<PsiFile> getFileResourceTargetsInDirectoryScope(@NotNull PsiFile psiFile, @NotNull String content) { // bundle scope if(content.startsWith("@")) { return Collections.emptyList(); } PsiDirectory containingDirectory = psiFile.getContainingDirectory(); if(containingDirectory == null) { return Collections.emptyList(); } VirtualFile relativeFile = VfsUtil.findRelativeFile(content, containingDirectory.getVirtualFile()); if(relativeFile == null) { return Collections.emptyList(); } PsiFile targetFile = PsiElementUtils.virtualFileToPsiFile(psiFile.getProject(), relativeFile); if(targetFile == null) { return Collections.emptyList(); } return Collections.singletonList(targetFile); }
Example #15
Source File: FileMoveHandler.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Nullable @Override public List<UsageInfo> findUsages(final PsiFile psiFile, final PsiDirectory newParent, final boolean searchInComments, final boolean searchInNonJavaFiles) { Query<PsiReference> search = ReferencesSearch.search(psiFile); final List<PsiExtraFileReference> extraFileRefs = new ArrayList<PsiExtraFileReference>(); search.forEach(new Processor<PsiReference>() { @Override public boolean process(PsiReference psiReference) { if (psiReference instanceof PsiExtraFileReference) { extraFileRefs.add((PsiExtraFileReference) psiReference); } return true; } }); if (extraFileRefs.isEmpty()) { return null; } else { final List<UsageInfo> result = new ArrayList<UsageInfo>(extraFileRefs.size()); for (final PsiExtraFileReference e : extraFileRefs) { result.add(new FileUsageInfo(e)); } return result; } }
Example #16
Source File: LibraryGroupNode.java From consulo with Apache License 2.0 | 6 votes |
public static void addLibraryChildren(final OrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) { final PsiManager psiManager = PsiManager.getInstance(project); VirtualFile[] files = entry instanceof LibraryOrderEntry ? getLibraryRoots((LibraryOrderEntry)entry) : entry.getFiles(BinariesOrderRootType.getInstance()); for (final VirtualFile file : files) { if (!file.isValid()) continue; if (file.isDirectory()) { final PsiDirectory psiDir = psiManager.findDirectory(file); if (psiDir == null) { continue; } children.add(new PsiDirectoryNode(project, psiDir, node.getSettings())); } else { final PsiFile psiFile = psiManager.findFile(file); if (psiFile == null) continue; children.add(new PsiFileNode(project, psiFile, node.getSettings())); } } }
Example #17
Source File: DeleteDirectoryAction.java From PackageTemplates with Apache License 2.0 | 6 votes |
@Override public void doRun() { PsiDirectory psiDirectory = VFSHelper.findPsiDirByPath(project, fileDirToDelete.getPath()); if (psiDirectory == null) { ReportHelper.setState(ExecutionState.FAILED); return; } try { psiDirectory.delete(); } catch (IncorrectOperationException ex) { Logger.log("DeleteDirectoryAction " + ex.getMessage()); Logger.printStack(ex); ReportHelper.setState(ExecutionState.FAILED); return; } }
Example #18
Source File: FileTreeIterator.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static List<PsiDirectory> collectProjectDirectories(@Nonnull Project project) { List<PsiDirectory> directories = ContainerUtil.newArrayList(); Module[] modules = ModuleManager.getInstance(project).getModules(); for (Module module : modules) { directories.addAll(collectModuleDirectories(module)); } return directories; }
Example #19
Source File: BaseProjectTreeBuilder.java From consulo with Apache License 2.0 | 5 votes |
private static VirtualFile getFileToRefresh(Object element) { Object object = element; if (element instanceof AbstractTreeNode) { object = ((AbstractTreeNode)element).getValue(); } return object instanceof PsiDirectory ? ((PsiDirectory)object).getVirtualFile() : object instanceof PsiFile ? ((PsiFile)object).getVirtualFile() : null; }
Example #20
Source File: ProjectViewModuleGroupNode.java From consulo with Apache License 2.0 | 5 votes |
@Override protected AbstractTreeNode createModuleNode(Module module) { final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots(); if (roots.length == 1) { final PsiDirectory psi = PsiManager.getInstance(myProject).findDirectory(roots[0]); if (psi != null) { return new PsiDirectoryNode(myProject, psi, getSettings()); } } return new ProjectViewModuleNode(getProject(), module, getSettings()); }
Example #21
Source File: CreateDirectoryOrPackageHandler.java From consulo with Apache License 2.0 | 5 votes |
public CreateDirectoryOrPackageHandler(@Nullable Project project, @Nonnull PsiDirectory directory, boolean isDirectory, @Nonnull final String delimiters, @Nullable Component dialogParent) { myProject = project; myDirectory = directory; myIsDirectory = isDirectory; myDelimiters = delimiters; myDialogParent = dialogParent; }
Example #22
Source File: CSharpCreateFileAction.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess protected boolean isAvailable(DataContext dataContext) { Module module = findModule(dataContext); if(module != null) { DotNetModuleExtension extension = ModuleUtilCore.getExtension(module, DotNetModuleExtension.class); if(extension != null && extension.isAllowSourceRoots()) { final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW); if(view == null) { return false; } PsiDirectory orChooseDirectory = view.getOrChooseDirectory(); if(orChooseDirectory == null) { return false; } PsiPackage aPackage = PsiPackageManager.getInstance(module.getProject()).findPackage(orChooseDirectory, DotNetModuleExtension.class); if(aPackage == null) { return false; } } } return module != null && ModuleUtilCore.getExtension(module, CSharpSimpleModuleExtension.class) != null; }
Example #23
Source File: WebProjectViewImpl.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable private LibraryOrderEntry getSelectedLibrary() { final AbstractProjectViewPane viewPane = getCurrentProjectViewPane(); DefaultMutableTreeNode node = viewPane != null ? viewPane.getSelectedNode() : null; if (node == null) return null; DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); if (parent == null) return null; Object userObject = parent.getUserObject(); if (userObject instanceof LibraryGroupNode) { userObject = node.getUserObject(); if (userObject instanceof NamedLibraryElementNode) { NamedLibraryElement element = ((NamedLibraryElementNode)userObject).getValue(); OrderEntry orderEntry = element.getOrderEntry(); return orderEntry instanceof LibraryOrderEntry ? (LibraryOrderEntry)orderEntry : null; } PsiDirectory directory = ((PsiDirectoryNode)userObject).getValue(); VirtualFile virtualFile = directory.getVirtualFile(); Module module = (Module)((AbstractTreeNode)((DefaultMutableTreeNode)parent.getParent()).getUserObject()).getValue(); if (module == null) return null; ModuleFileIndex index = ModuleRootManager.getInstance(module).getFileIndex(); OrderEntry entry = index.getOrderEntryForFile(virtualFile); if (entry instanceof LibraryOrderEntry) { return (LibraryOrderEntry)entry; } } return null; }
Example #24
Source File: GotoFileItemProvider.java From consulo with Apache License 2.0 | 5 votes |
private static JBIterable<FoundItemDescriptor<PsiFileSystemItem>> moveDirectoriesToEnd(Iterable<FoundItemDescriptor<PsiFileSystemItem>> iterable) { List<FoundItemDescriptor<PsiFileSystemItem>> dirs = new ArrayList<>(); return JBIterable.from(iterable).filter(res -> { if (res.getItem() instanceof PsiDirectory) { dirs.add(new FoundItemDescriptor<>(res.getItem(), DIRECTORY_MATCH_DEGREE)); return false; } return true; }).append(dirs); }
Example #25
Source File: NewVueActionBase.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) { final MyInputValidator validator = new MyInputValidator(project, directory); Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator); final PsiElement[] elements = validator.getCreatedElements(); return elements; }
Example #26
Source File: AddToFavoritesAction.java From consulo with Apache License 2.0 | 5 votes |
private static Class<? extends AbstractTreeNode> getPsiElementNodeClass(PsiElement psiElement) { Class<? extends AbstractTreeNode> klass = null; if (psiElement instanceof PsiFile) { klass = PsiFileNode.class; } else if (psiElement instanceof PsiDirectory) { klass = PsiDirectoryNode.class; } return klass; }
Example #27
Source File: CreateFileAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public boolean canClose(final String inputString) { if (inputString.length() == 0) { return super.canClose(inputString); } final PsiDirectory psiDirectory = getDirectory(); final Project project = psiDirectory.getProject(); final boolean[] result = {false}; FileTypeChooser.getKnownFileTypeOrAssociate(psiDirectory.getVirtualFile(), getFileName(inputString), project); result[0] = super.canClose(getFileName(inputString)); return result[0]; }
Example #28
Source File: FavoritesTreeNodeDescriptor.java From consulo with Apache License 2.0 | 5 votes |
public static String getLocation(final AbstractTreeNode element, final Project project) { Object nodeElement = element.getValue(); if (nodeElement instanceof SmartPsiElementPointer) { nodeElement = ((SmartPsiElementPointer)nodeElement).getElement(); } if (nodeElement instanceof PsiElement) { if (nodeElement instanceof PsiDirectory) { return ((PsiDirectory)nodeElement).getVirtualFile().getPresentableUrl(); } if (nodeElement instanceof PsiFile) { final PsiFile containingFile = (PsiFile)nodeElement; final VirtualFile virtualFile = containingFile.getVirtualFile(); return virtualFile != null ? virtualFile.getPresentableUrl() : ""; } } if (nodeElement instanceof LibraryGroupElement) { return ((LibraryGroupElement)nodeElement).getModule().getName(); } if (nodeElement instanceof NamedLibraryElement) { final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement)nodeElement); final Module module = namedLibraryElement.getModule(); return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName(); } final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project); for (FavoriteNodeProvider provider : nodeProviders) { String location = provider.getElementLocation(nodeElement); if (location != null) return location; } return null; }
Example #29
Source File: DirectoryChooser.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isParent(PsiDirectory directory, PsiDirectory parentCandidate) { while (directory != null) { if (directory.equals(parentCandidate)) return true; directory = directory.getParentDirectory(); } return false; }
Example #30
Source File: SpecsExecutionProducer.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
@Override public boolean isConfigurationFromContext(RunConfiguration config, ConfigurationContext context) { if (!(config.getType() instanceof GaugeRunTaskConfigurationType)) return false; if (!(context.getPsiLocation() instanceof PsiDirectory) && !(context.getPsiLocation() instanceof PsiFile)) return false; VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context.getDataContext()); if (selectedFiles == null) return false; String specs = ((GaugeRunConfiguration) config).getSpecsToExecute(); return StringUtil.join(getSpecs(selectedFiles), Constants.SPEC_FILE_DELIMITER).equals(specs); }