Java Code Examples for com.intellij.util.PathUtil#getParentPath()
The following examples show how to use
com.intellij.util.PathUtil#getParentPath() .
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: FlutterTestUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static String findTestDataPath() { if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) { // started from IntelliJ IDEA Ultimate project return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/flutter-intellij/testData"); } final File f = new File("testData"); if (f.isDirectory()) { // started from flutter plugin project return FileUtil.toSystemIndependentName(f.getAbsolutePath()); } final String parentPath = PathUtil.getParentPath(PathManager.getHomePath()); if (new File(parentPath + "/intellij-plugins").isDirectory()) { // started from IntelliJ IDEA Community Edition + flutter plugin project return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData"); } if (new File(parentPath + "/contrib").isDirectory()) { // started from IntelliJ IDEA Community + flutter plugin project return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData"); } return ""; }
Example 2
Source File: DirectoryElementType.java From consulo with Apache License 2.0 | 6 votes |
@Override public CompositePackagingElement<?> createComposite(CompositePackagingElement<?> parent, String baseName, @Nonnull ArtifactEditorContext context) { final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, baseName != null ? baseName : "folder", ""); String path = Messages .showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, new FilePathValidator()); if (path == null) { return null; } path = FileUtil.toSystemIndependentName(path); final String parentPath = PathUtil.getParentPath(path); final String fileName = PathUtil.getFileName(path); final PackagingElement<?> element = new DirectoryPackagingElement(fileName); return (CompositePackagingElement<?>)PackagingElementFactoryImpl.getInstance(context.getProject()).createParentDirectories(parentPath, element); }
Example 3
Source File: ZipArchiveElementType.java From consulo with Apache License 2.0 | 6 votes |
@Override public CompositePackagingElement<?> createComposite(CompositePackagingElement<?> parent, @Nullable String baseName, @Nonnull ArtifactEditorContext context) { final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, baseName != null ? baseName : "archive", ".zip"); String path = Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, new FilePathValidator()); if (path == null) { return null; } path = FileUtil.toSystemIndependentName(path); final String parentPath = PathUtil.getParentPath(path); final String fileName = PathUtil.getFileName(path); final PackagingElement<?> element = new ZipArchivePackagingElement(fileName); return (CompositePackagingElement<?>)PackagingElementFactory.getInstance(context.getProject()).createParentDirectories(parentPath, element); }
Example 4
Source File: LightTempDirTestFixtureImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public VirtualFile createFile(String targetPath) { final String path = PathUtil.getParentPath(targetPath); final String name = PathUtil.getFileName(targetPath); return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Override public VirtualFile compute() { try { VirtualFile targetDir = findOrCreateDir(path); return targetDir.createChildData(this, name); } catch (IOException e) { throw new RuntimeException(e); } } }); }
Example 5
Source File: LightTempDirTestFixtureImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public VirtualFile copyFile(@Nonnull final VirtualFile file, final String targetPath) { final String path = PathUtil.getParentPath(targetPath); return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Override public VirtualFile compute() { try { VirtualFile targetDir = findOrCreateDir(path); final String newName = PathUtil.getFileName(targetPath); final VirtualFile existing = targetDir.findChild(newName); if (existing != null) { existing.setBinaryContent(file.contentsToByteArray()); return existing; } return VfsUtilCore.copyFile(this, file, targetDir, newName); } catch (IOException e) { throw new RuntimeException(e); } } }); }
Example 6
Source File: HaxeCommonCompilerUtil.java From intellij-haxe with Apache License 2.0 | 6 votes |
@NotNull private static String calculateWorkingPath(CompilationContext context) { HaxeModuleSettingsBase settings = context.getModuleSettings(); // TODO: Add a setting for the working directory to the project/module settings dialog. Then use that here. String workingPath = null; if (settings.isUseOpenFLToBuild()) { // Use the module directory... workingPath = context.getModuleDirPath(); } else if (settings.isUseNmmlToBuild()) { String nmmlPath = settings.getNmmlPath(); workingPath = PathUtil.getParentPath(nmmlPath); } else if (settings.isUseHxmlToBuild()) { String hxmlPath = settings.getHxmlPath(); workingPath = PathUtil.getParentPath(hxmlPath); } else if (settings.isUseUserPropertiesToBuild()) { workingPath = findCwdInCommandLineArguments(settings); } if (null == workingPath || workingPath.isEmpty()) { workingPath = context.getModuleDirPath(); // Last ditch effort. Location of the .iml } return null == workingPath ? "" : workingPath; }
Example 7
Source File: FileLookupData.java From intellij with Apache License 2.0 | 6 votes |
private String getItemText(String relativePath) { if (pathFormat == PathFormat.PackageLocal) { if (containingPackage.length() > relativePath.length()) { return ""; } return StringUtil.trimStart(relativePath.substring(containingPackage.length()), "/"); } String parentPath = PathUtil.getParentPath(relativePath); while (!parentPath.isEmpty()) { if (filePathFragment.startsWith(parentPath + "/")) { return StringUtil.trimStart(relativePath, parentPath + "/"); } else if (filePathFragment.startsWith(parentPath)) { return StringUtil.trimStart(relativePath, parentPath); } parentPath = PathUtil.getParentPath(parentPath); } return relativePath; }
Example 8
Source File: FlutterTestUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static String findTestDataPath() { if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) { // started from IntelliJ IDEA Ultimate project return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/flutter-intellij/testData"); } final File f = new File("testData"); if (f.isDirectory()) { // started from flutter plugin project return FileUtil.toSystemIndependentName(f.getAbsolutePath()); } final String parentPath = PathUtil.getParentPath(PathManager.getHomePath()); if (new File(parentPath + "/intellij-plugins").isDirectory()) { // started from IntelliJ IDEA Community Edition + flutter plugin project return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData"); } if (new File(parentPath + "/contrib").isDirectory()) { // started from IntelliJ IDEA Community + flutter plugin project return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData"); } return ""; }
Example 9
Source File: BuildReferenceManager.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private File resolveParentDirectory(WorkspacePath packagePath, TargetName targetName) { File packageFile = resolvePackage(packagePath); if (packageFile == null) { return null; } String rulePathParent = PathUtil.getParentPath(targetName.toString()); return new File(packageFile, rulePathParent); }
Example 10
Source File: BlazePackage.java From intellij with Apache License 2.0 | 5 votes |
/** * The path from the blaze package directory to the child file, or null if the package directory * is not an ancestor of the provided file. */ @Nullable public String getRelativePathToChild(@Nullable VirtualFile child) { if (child == null) { return null; } String packagePath = PathUtil.getParentPath(buildFile.getFilePath()); return Paths.relativeIfUnder(child.getPath(), packagePath); }
Example 11
Source File: DartTestUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("Duplicates") private static String findTestDataPath() { if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) { // started from IntelliJ IDEA Ultimate project return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/Dart/testData"); } final File f = new File("testData"); if (f.isDirectory()) { // started from 'Dart-plugin' project return FileUtil.toSystemIndependentName(f.getAbsolutePath()); } final String parentPath = PathUtil.getParentPath(PathManager.getHomePath()); if (new File(parentPath + "/intellij-plugins").isDirectory()) { // started from IntelliJ IDEA Community Edition + Dart Plugin project return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/Dart/testData"); } if (new File(parentPath + "/contrib").isDirectory()) { // started from IntelliJ IDEA Community + Dart Plugin project return FileUtil.toSystemIndependentName(parentPath + "/contrib/Dart/testData"); } return ""; }
Example 12
Source File: DartTestUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("Duplicates") private static String findTestDataPath() { if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) { // started from IntelliJ IDEA Ultimate project return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/Dart/testData"); } final File f = new File("testData"); if (f.isDirectory()) { // started from 'Dart-plugin' project return FileUtil.toSystemIndependentName(f.getAbsolutePath()); } final String parentPath = PathUtil.getParentPath(PathManager.getHomePath()); if (new File(parentPath + "/intellij-plugins").isDirectory()) { // started from IntelliJ IDEA Community Edition + Dart Plugin project return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/Dart/testData"); } if (new File(parentPath + "/contrib").isDirectory()) { // started from IntelliJ IDEA Community + Dart Plugin project return FileUtil.toSystemIndependentName(parentPath + "/contrib/Dart/testData"); } return ""; }
Example 13
Source File: ExtractedDirectoryPresentation.java From consulo with Apache License 2.0 | 5 votes |
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { presentationData.setIcon(AllIcons.Nodes.ExtractedFolder); final String parentPath = PathUtil.getParentPath(myJarPath); if (myFile == null || !myFile.isDirectory()) { mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(parentPath); if (parentFile == null) { commentAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; } } presentationData.addText("Extracted '" + PathUtil.getFileName(myJarPath) + myPathInJar + "'", mainAttributes); presentationData.addText(" (" + parentPath + ")", commentAttributes); }
Example 14
Source File: VcsLogPathsIndex.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Collection<String> getParentPaths(@Nonnull Collection<String> paths) { Set<String> result = ContainerUtil.newHashSet(); for (String path : paths) { while (!path.isEmpty() && !result.contains(path)) { result.add(path); if (myRoots.contains(path)) break; path = PathUtil.getParentPath(path); } } return result; }
Example 15
Source File: LocalFilePath.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public Charset getCharset(@Nullable Project project) { VirtualFile file = getVirtualFile(); String path = myPath; while ((file == null || !file.isValid()) && !path.isEmpty()) { path = PathUtil.getParentPath(path); file = LocalFileSystem.getInstance().findFileByPath(path); } if (file != null) { return file.getCharset(); } EncodingManager e = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project); return e.getDefaultCharset(); }
Example 16
Source File: BuildReferenceManager.java From intellij with Apache License 2.0 | 4 votes |
/** * Finds all child directories. If exactly one is found, continue traversing (and appending to * LookupElement string) until there are multiple options. Stops traversing at BUILD packages. * * <p>Used for package path completion suggestions. */ public BuildLookupElement[] resolvePackageLookupElements(FileLookupData lookupData) { String relativePath = lookupData.filePathFragment; if (!relativePath.equals(FileUtil.toCanonicalUriPath(relativePath))) { // ignore invalid labels containing './', '../', etc. return BuildLookupElement.EMPTY_ARRAY; } File file = resolveWorkspaceRelativePath(relativePath); FileOperationProvider provider = FileOperationProvider.getInstance(); String pathFragment = ""; if (file == null || (!provider.isDirectory(file) && !relativePath.endsWith("/"))) { // we might be partway through a file name. Try the parent directory relativePath = PathUtil.getParentPath(relativePath); file = resolveWorkspaceRelativePath(relativePath); pathFragment = StringUtil.trimStart(lookupData.filePathFragment.substring(relativePath.length()), "/"); } if (file == null || !provider.isDirectory(file)) { return BuildLookupElement.EMPTY_ARRAY; } VirtualFile vf = VirtualFileSystemProvider.getInstance().getSystem().findFileByPath(file.getPath()); if (vf == null || !vf.isDirectory()) { return BuildLookupElement.EMPTY_ARRAY; } BuildLookupElement[] uniqueLookup = new BuildLookupElement[1]; while (true) { VirtualFile[] children = vf.getChildren(); if (children == null || children.length == 0) { return uniqueLookup[0] != null ? uniqueLookup : BuildLookupElement.EMPTY_ARRAY; } List<VirtualFile> validChildren = Lists.newArrayListWithCapacity(children.length); for (VirtualFile child : children) { ProgressManager.checkCanceled(); if (child.getName().startsWith(pathFragment) && lookupData.acceptFile(project, child)) { validChildren.add(child); } } if (validChildren.isEmpty()) { return uniqueLookup[0] != null ? uniqueLookup : BuildLookupElement.EMPTY_ARRAY; } if (validChildren.size() > 1) { return uniqueLookup[0] != null ? uniqueLookup : lookupsForFiles(validChildren, lookupData); } // if we've already traversed a directory and this is a BUILD package, stop here if (uniqueLookup[0] != null && hasBuildFile(children)) { return uniqueLookup; } // otherwise continue traversing while there's only one option uniqueLookup[0] = lookupForFile(validChildren.get(0), lookupData); pathFragment = ""; vf = validChildren.get(0); } }
Example 17
Source File: BlazePackage.java From intellij with Apache License 2.0 | 4 votes |
/** * Returns the file path relative to this blaze package, or null if it does lie inside this * package */ @Nullable public String getPackageRelativePath(String filePath) { String packageFilePath = PathUtil.getParentPath(buildFile.getFilePath()); return Paths.relativeIfUnder(filePath, packageFilePath); }
Example 18
Source File: LocalFilePath.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nullable public FilePath getParentPath() { String parent = PathUtil.getParentPath(myPath); return parent.isEmpty() ? null : new LocalFilePath(parent, true); }
Example 19
Source File: RemoteFilePath.java From consulo with Apache License 2.0 | 4 votes |
@Nullable @Override public FilePath getParentPath() { String parent = PathUtil.getParentPath(myPath); return parent.isEmpty() ? null : new RemoteFilePath(parent, true); }