Java Code Examples for com.intellij.psi.PsiDirectory#findSubdirectory()
The following examples show how to use
com.intellij.psi.PsiDirectory#findSubdirectory() .
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: AbstractFileProvider.java From CodeGen with MIT License | 6 votes |
/** * 根据选择的package目录,找到resources目录 * @param psiDirectory * @return */ private PsiDirectory findResourcesDirectory(PsiDirectory psiDirectory) { PsiDirectory parentDirectory = psiDirectory.getParentDirectory(); PsiDirectory iterator = psiDirectory.getParentDirectory(); while (iterator != null && !iterator.getName().equals("main")) { iterator = iterator.getParentDirectory(); } PsiDirectory resourcesDirectory = iterator == null ? null : iterator.findSubdirectory("resources"); if (resourcesDirectory == null) { resourcesDirectory = parentDirectory.findSubdirectory("resources"); if (resourcesDirectory == null) { resourcesDirectory = parentDirectory.createSubdirectory("resources"); } } return resourcesDirectory; }
Example 2
Source File: CreateSimpleDirectoryAction.java From PackageTemplates with Apache License 2.0 | 6 votes |
@Override public void doRun() { PsiDirectory psiParent = VFSHelper.findPsiDirByPath(project, directory.getParentFile().getPath()); if (psiParent == null) { ReportHelper.setState(ExecutionState.FAILED); return; } try { // check existence psiDirectoryCreated = psiParent.findSubdirectory(directory.getName()); if (psiDirectoryCreated == null) { // create new one psiDirectoryCreated = psiParent.createSubdirectory(directory.getName()); } } catch (IncorrectOperationException ex) { Logger.log("CreateSimpleDirectoryAction " + ex.getMessage()); Logger.printStack(ex); ReportHelper.setState(ExecutionState.FAILED); return; } }
Example 3
Source File: ModulesUtil.java From svgtoandroid with MIT License | 6 votes |
public PsiDirectory getResDir(String moduleName) { PsiDirectory baseDir = PsiDirectoryFactory.getInstance(project).createDirectory(project.getBaseDir()); PsiDirectory moduleDir = baseDir.findSubdirectory(moduleName); if (moduleDir != null && moduleDir.isDirectory()) { PsiDirectory srcDir = moduleDir.findSubdirectory("src"); if (srcDir != null && srcDir.isDirectory()) { PsiDirectory mainDir = srcDir.findSubdirectory("main"); if (mainDir != null && mainDir.isDirectory()) { PsiDirectory resDir = mainDir.findSubdirectory("res"); if (resDir != null && resDir.isDirectory()) { return resDir; } } } } return null; }
Example 4
Source File: SymfonyBundle.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public PsiDirectory getSubDirectory(@NotNull String... names) { PsiDirectory currentDir = this.getDirectory(); if(null == currentDir) { return null; } for(String name: names) { currentDir = currentDir.findSubdirectory(name); if(null == currentDir) { return null; } } return currentDir; }
Example 5
Source File: DirectoryUtil.java From consulo with Apache License 2.0 | 6 votes |
public static PsiDirectory createSubdirectories(final String subDirName, PsiDirectory baseDirectory, final String delim) throws IncorrectOperationException { StringTokenizer tokenizer = new StringTokenizer(subDirName, delim); PsiDirectory dir = baseDirectory; while (tokenizer.hasMoreTokens()) { String packName = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { PsiDirectory existingDir = dir.findSubdirectory(packName); if (existingDir != null) { dir = existingDir; continue; } } dir = dir.createSubdirectory(packName); } return dir; }
Example 6
Source File: TypeStateCheckingTest.java From IntelliJDeodorant with MIT License | 5 votes |
private void checkTest() { myFixture.copyDirectoryToProject("expected", "expected"); VirtualFile directoryFile = myFixture.findFileInTempDir(""); PsiDirectory mainDirectory = myFixture.getPsiManager().findDirectory(directoryFile); PsiDirectory expectedDirectory = mainDirectory.findSubdirectory("expected"); checkDirectoriesAreEqual(mainDirectory, expectedDirectory); }
Example 7
Source File: AbstractFileProvider.java From CodeGen with MIT License | 5 votes |
/** * 创建子目录 * @param psiDirectory * @param temp * @param level * @return */ private PsiDirectory createSubDirectory(PsiDirectory psiDirectory, String[] temp, int level) { PsiDirectory subdirectory = psiDirectory.findSubdirectory(temp[level]); if (subdirectory == null) { subdirectory = psiDirectory.createSubdirectory(temp[level]); } if (temp.length != level + 1) { return createSubDirectory(subdirectory, temp, level + 1); } return subdirectory; }
Example 8
Source File: ExtraModulesUtil.java From weex-language-support with MIT License | 5 votes |
private static PsiDirectory[] getNodeModules(PsiDirectory root) { PsiDirectory node_modules = root.findSubdirectory("node_modules"); if (node_modules != null) { return node_modules.getSubdirectories(); } return new PsiDirectory[0]; }
Example 9
Source File: ExtraModulesUtil.java From weex-language-support with MIT License | 5 votes |
private static List<PsiFile> getComponents(PsiDirectory root, PsiFile file) { List<PsiFile> results = new ArrayList<PsiFile>(); if (file != null && file instanceof JSFile) { for (PsiElement element : file.getChildren()) { if (element instanceof JSExpressionStatement) { JSExpression expression = ((JSExpressionStatement) element).getExpression(); if (expression instanceof JSCallExpression && ((JSCallExpression) expression).getArguments().length == 1 && ((JSCallExpression) expression).getArguments()[0] instanceof JSLiteralExpression) { JSLiteralExpression expression1 = (JSLiteralExpression) ((JSCallExpression) expression).getArguments()[0]; Object val = expression1.getValue(); if (val != null) { String[] temp = val.toString().replace("./", "").split("/"); if (temp != null && temp.length > 0) { String fileName = temp[temp.length - 1]; if (fileName.toLowerCase().endsWith(".we")) { PsiDirectory start = root; for (int i = 0; i < temp.length - 1; i++) { PsiDirectory dir = start.findSubdirectory(temp[i]); if (dir != null) { start = dir; } } PsiFile weexScript = start.findFile(temp[temp.length - 1]); if (weexScript != null) { results.add(weexScript); } } } } } } } } return results; }
Example 10
Source File: ModulesUtil.java From svgtoandroid with MIT License | 5 votes |
public PsiDirectory getOrCreateDrawableDir(String moduleName,String dirName) { PsiDirectory baseDir = PsiDirectoryFactory.getInstance(project).createDirectory(project.getBaseDir()); PsiDirectory moduleDir = baseDir.findSubdirectory(moduleName); if (moduleDir != null) { PsiDirectory srcDir = moduleDir.findSubdirectory("src"); if (srcDir == null) { srcDir = moduleDir.createSubdirectory("src"); Logger.debug("Creating dir :" + srcDir.getName()); } PsiDirectory mainDir = srcDir.findSubdirectory("main"); if (mainDir == null) { mainDir = srcDir.createSubdirectory("main"); Logger.debug("Creating dir :" + mainDir.getName()); } PsiDirectory resDir = mainDir.findSubdirectory("res"); if (resDir == null) { resDir = mainDir.createSubdirectory("res"); Logger.debug("Creating dir :" + resDir.getName()); } PsiDirectory drawableDir = resDir.findSubdirectory(dirName); if (drawableDir == null) { drawableDir = resDir.createSubdirectory(dirName); Logger.debug("Creating dir :" + drawableDir.getName()); } return drawableDir; } return null; }
Example 11
Source File: BashPsiFileUtils.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Takes an existing psi file and tries to find another file relative to the first. * The file path is given as a relative path. * * @param start The existing psi file * @param relativePath The relative path as a string * @return The psi file or null if nothing has been found */ @Nullable public static PsiFile findRelativeFile(PsiFile start, String relativePath) { PsiDirectory startDirectory = BashPsiUtils.findFileContext(start).getContainingDirectory(); if (startDirectory == null || StringUtil.isEmptyOrSpaces(relativePath)) { return null; } //fixme handle escaped / chars! PsiDirectory currentDir = startDirectory; List<String> parts = StringUtil.split(relativePath, "/"); String filePart = parts.size() > 0 ? parts.get(parts.size() - 1) : ""; for (int i = 0, partsLength = parts.size() - 1; (i < partsLength) && (currentDir != null); i++) { String part = parts.get(i); if (".".equals(part)) { //ignore this } else if ("..".equals(part)) { currentDir = currentDir.getParentDirectory(); } else { currentDir = currentDir.findSubdirectory(part); } } if (currentDir != null) { return currentDir.findFile(filePart); } return null; }
Example 12
Source File: HaxeSourceRootModel.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Nullable public PsiDirectory access(String packagePath) { if (this == DUMMY) return null; if ((packagePath == null) || packagePath.isEmpty()) return directory; PsiDirectory current = directory; for (String part : HaxeStringUtil.split(packagePath, '.')) { if (current == null) break; current = current.findSubdirectory(part); } return current; }
Example 13
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 5 votes |
public PsiDirectory findOrCreateTargetDirectory() throws IncorrectOperationException{ if (myTargetDirectory == null) { final PsiDirectory root = myParentDirectory.findOrCreateTargetDirectory(); myTargetDirectory = root.findSubdirectory(myRelativePath); if (myTargetDirectory == null) { myTargetDirectory = root.createSubdirectory(myRelativePath); } } return myTargetDirectory; }
Example 14
Source File: CreateFileAction.java From consulo with Apache License 2.0 | 4 votes |
public static PsiDirectory findOrCreateSubdirectory(@Nonnull PsiDirectory parent, @Nonnull String subdirName) { final PsiDirectory sub = parent.findSubdirectory(subdirName); return sub == null ? WriteAction.compute(() -> parent.createSubdirectory(subdirName)) : sub; }
Example 15
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 4 votes |
public TargetDirectoryWrapper(PsiDirectory parentDirectory, String relativePath) { myTargetDirectory = parentDirectory.findSubdirectory(relativePath); //in case it was null myParentDirectory = new TargetDirectoryWrapper(parentDirectory); myRelativePath = relativePath; }