Java Code Examples for com.intellij.psi.PsiDirectory#createSubdirectory()
The following examples show how to use
com.intellij.psi.PsiDirectory#createSubdirectory() .
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: FileWriter.java From PackageTemplates with Apache License 2.0 | 6 votes |
@Nullable private static PsiDirectory writeDirectoryAction(PsiDirectory dir, DirectoryWrapper dirWrapper, Project project) { FutureTask<PsiDirectory> psiDirectoryFutureTask = new FutureTask<>(() -> { // Properties properties = new Properties(); // properties.putAll(dirWrapper.getPackageTemplateWrapper().getDefaultProperties()); // FileTemplate fileTemplate = AttributesHelper.getTemplate("Test"); // FileTemplateUtil.createFromTemplate(fileTemplate, "TestFile", properties, dir); return dir.createSubdirectory(dirWrapper.getDirectory().getName()); }); CommandProcessor.getInstance().executeCommand(project, psiDirectoryFutureTask, "Create '" + dirWrapper.getDirectory().getName() + "' Directory", "testGroupId"); try { return psiDirectoryFutureTask.get(); } catch (Exception ex) { Logger.log(ex.getMessage()); Logger.printStack(ex); return null; } }
Example 3
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 4
Source File: EntityBase.java From CleanArchitecturePlugin with Apache License 2.0 | 6 votes |
/** * Create package in the directory specific with a name * * @param parent package when create a subpackage * @param packageName package name * @return */ public static PsiDirectory createDirectory(PsiDirectory parent, String packageName) { directoryCreated = null; // Search subpackage with the same name for (PsiDirectory dir : parent.getSubdirectories()) { if (dir.getName().equalsIgnoreCase(packageName)) { directoryCreated = dir; break; } } // When the search not found a package with the same name, create a subdirectory if (directoryCreated == null) { runnable = () -> directoryCreated = parent.createSubdirectory(packageName); WriteCommandAction.runWriteCommandAction(project, runnable); } return directoryCreated; }
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: 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 7
Source File: FileWriter.java From PackageTemplates with Apache License 2.0 | 5 votes |
public static PsiDirectory createDirectory(Project project, File dir) { PsiDirectory psiParentDir = VFSHelper.findPsiDirByPath(project, dir.getParentFile().getPath()); if (psiParentDir == null) { return null; } return psiParentDir.createSubdirectory(dir.getName()); }
Example 8
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 9
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 10
Source File: DirectoryUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * Creates the directory with the given path via PSI, including any * necessary but nonexistent parent directories. Must be run in write action. * @param path directory path in the local file system; separators must be '/' * @return true if path exists or has been created as the result of this method call; false otherwise */ public static PsiDirectory mkdirs(PsiManager manager, String path) throws IncorrectOperationException{ if (File.separatorChar != '/') { if (path.indexOf(File.separatorChar) != -1) { throw new IllegalArgumentException("separators must be '/'; path is " + path); } } String existingPath = path; PsiDirectory directory = null; // find longest existing path while (existingPath.length() > 0) { VirtualFile file = LocalFileSystem.getInstance().findFileByPath(existingPath); if (file != null) { directory = manager.findDirectory(file); if (directory == null) { return null; } break; } if (StringUtil.endsWithChar(existingPath, '/')) { existingPath = existingPath.substring(0, existingPath.length() - 1); if (SystemInfo.isWindows && existingPath.length() == 2 && existingPath.charAt(1) == ':') { return null; } } int index = existingPath.lastIndexOf('/'); if (index == -1) { // nothing to do more return null; } existingPath = existingPath.substring(0, index); } if (directory == null) { return null; } if (existingPath.equals(path)) { return directory; } String postfix = path.substring(existingPath.length() + 1, path.length()); StringTokenizer tokenizer = new StringTokenizer(postfix, "/"); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); PsiDirectory subdirectory = directory.createSubdirectory(name); if (subdirectory == null) { return null; } directory = subdirectory; } return directory; }