Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getName()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#getName() .
These examples are extracted from open source projects.
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 Project: AndroidPixelDimenGenerator File: MyDialog.java License: Apache License 2.0 | 6 votes |
private String getOutputPath(VirtualFile[] virtualFiles) { for (VirtualFile virtualFile : virtualFiles) { String name = virtualFile.getName(); VirtualFile[] childVirtualFile = virtualFile.getChildren(); if (name.equals("res")) { return virtualFile.getCanonicalPath(); } else if (childVirtualFile.length > 0) { String resPath = getOutputPath(childVirtualFile); if (resPath != null) { return resPath; } } } return null; }
Example 2
Source Project: CppTools File: BuildCppAction.java License: Apache License 2.0 | 6 votes |
public void update(AnActionEvent e) { super.update(e); final DataContext dataContext = e.getDataContext(); final Project project = (Project) dataContext.getData(DataConstants.PROJECT); final VirtualFile file = (VirtualFile) dataContext.getData(DataConstants.VIRTUAL_FILE); BaseBuildHandler buildHandler = null; if (project != null && file != null && !file.isDirectory() ) { buildHandler = BaseBuildHandler.getBuildHandler(project, file); } final boolean enabled = buildHandler != null; e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(enabled); final String s = "Do &build for " + (buildHandler != null ? file.getName():"makefile/dsp/dsw file"); e.getPresentation().setText(s); e.getPresentation().setDescription(s); }
Example 3
Source Project: consulo File: PersistentFSTest.java License: Apache License 2.0 | 6 votes |
public void testFindRootShouldNotBeFooledByRelativePath() throws IOException { File tmp = createTempDirectory(); File x = new File(tmp, "x.jar"); x.createNewFile(); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vx = lfs.refreshAndFindFileByIoFile(x); assertNotNull(vx); ArchiveFileSystem jfs = (ArchiveFileSystem)StandardFileSystems.jar(); VirtualFile root = ArchiveVfsUtil.getArchiveRootForLocalFile(vx); PersistentFS fs = PersistentFS.getInstance(); String path = vx.getPath() + "/../" + vx.getName() + ArchiveFileSystem.ARCHIVE_SEPARATOR; NewVirtualFile root1 = fs.findRoot(path, (NewVirtualFileSystem)jfs); assertSame(root1, root); }
Example 4
Source Project: consulo File: FileTypeDescriptor.java License: Apache License 2.0 | 6 votes |
@Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { if (!showHiddenFiles && FileElement.isFileHidden(file)) { return false; } if (file.isDirectory()) { return true; } String name = file.getName(); for (String extension : myExtensions) { if (name.endsWith(extension)) { return true; } } return false; }
Example 5
Source Project: consulo File: LocalFileSystemRefreshWorker.java License: Apache License 2.0 | 6 votes |
/** * @param fileOrDir * @param refreshContext * @param childrenToRefresh null means all * @param existingPersistentChildren */ RefreshingFileVisitor(@Nonnull NewVirtualFile fileOrDir, @Nonnull RefreshContext refreshContext, @Nullable Collection<String> childrenToRefresh, @Nonnull Collection<? extends VirtualFile> existingPersistentChildren) { myFileOrDir = fileOrDir; myRefreshContext = refreshContext; myPersistentChildren = new THashMap<>(existingPersistentChildren.size(), refreshContext.strategy); myChildrenWeAreInterested = childrenToRefresh == null ? null : new THashSet<>(childrenToRefresh, refreshContext.strategy); for (VirtualFile child : existingPersistentChildren) { String name = child.getName(); myPersistentChildren.put(name, child); if (myChildrenWeAreInterested != null) myChildrenWeAreInterested.add(name); } }
Example 6
Source Project: consulo File: ComputeVirtualFileNameStatAction.java License: Apache License 2.0 | 6 votes |
private void compute(VirtualFile root) { String name = root.getName(); if (!nameCount.increment(name)) nameCount.put(name, 1); for (int i=1; i<=name.length(); i++) { //String prefix = name.substring(0, i); //if (!prefixes.increment(prefix)) prefixes.put(prefix, 1); String suffix = name.substring(name.length()-i); if (!suffixes.increment(suffix)) suffixes.put(suffix, 1); } Collection<VirtualFile> cachedChildren = ((VirtualFileSystemEntry)root).getCachedChildren(); //VirtualFile[] cachedChildren = ((VirtualFileSystemEntry)root).getChildren(); for (VirtualFile cachedChild : cachedChildren) { compute(cachedChild); } }
Example 7
Source Project: idea-php-shopware-plugin File: TemplateUtil.java License: MIT License | 5 votes |
private static boolean isValidTemplateFile(VirtualFile virtualFile, List<String> extensions) { if(virtualFile.isDirectory()) { return false; } String filename = virtualFile.getName(); for(String ext: extensions) { if(filename.toLowerCase().endsWith(ext.toLowerCase())) { return true; } } return false; }
Example 8
Source Project: consulo File: VcsImplUtil.java License: Apache License 2.0 | 5 votes |
@Nonnull public static String getShortVcsRootName(@Nonnull Project project, @Nonnull VirtualFile root) { VirtualFile projectDir = project.getBaseDir(); String repositoryPath = root.getPresentableUrl(); if (projectDir != null) { String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar); if (relativePath != null) { repositoryPath = relativePath; } } return repositoryPath.isEmpty() ? root.getName() : repositoryPath; }
Example 9
Source Project: dsl-compiler-client File: DslSyntaxHighlighterFactory.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { MapKey key = new MapKey(project, virtualFile != null ? virtualFile.getPath() + "/" + virtualFile.getName() : ""); DslSyntaxHighlighter highlighter = highlighters.get(key); if (highlighter == null || highlighter.virtualFile == null || !highlighter.virtualFile.isValid() || virtualFile != null && !virtualFile.equals(highlighter.virtualFile) || highlighter.isDisposed()) { if (highlighter != null) highlighter.stop(); highlighter = new DslSyntaxHighlighter(project, virtualFile); highlighters.put(key, highlighter); } return highlighter; }
Example 10
Source Project: Android-Resource-Usage-Count File: FindUsageAction.java License: MIT License | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); if (vFile == null) { return; } String fileName = vFile.getName(); if (!fileName.endsWith(".xml")) { return; } PsiFile pFile = e.getData(PlatformDataKeys.PSI_FILE); if (pFile == null) { return; } // for (PsiElement psiElement : pFile.getChildren()) { // System.out.println(psiElement.getText() + " is: " + (psiElement instanceof XmlTag)); // if (psiElement instanceof XmlTag) { // System.out.println(FindUsagesCompat.findUsage((XmlTag) psiElement)); // } // } pFile.accept(new XmlRecursiveElementVisitor() { @Override public void visitElement(PsiElement element) { super.visitElement(element); if (element instanceof XmlTag) { System.out.println(element.getText()); if (ResourceUsageCountUtils.isTargetTagToCount(element)) { System.out.println(FindUsagesCompat.findUsage((XmlTag) element)); } } } }); }
Example 11
Source Project: idea-gitignore File: IgnoreBundle.java License: MIT License | 5 votes |
/** * Returns {@link IgnoreLanguage} matching to the given {@link VirtualFile}. * * @param file to obtain * @return matching language */ @Nullable public static IgnoreLanguage obtainLanguage(@NotNull VirtualFile file) { final String filename = file.getName(); for (IgnoreLanguage language : LANGUAGES) { if (language.getFilename().equals(filename)) { return language; } } return null; }
Example 12
Source Project: consulo-unity3d File: Unity3dMetaManager.java License: Apache License 2.0 | 5 votes |
@Nullable @RequiredReadAction public String getGUID(@Nonnull VirtualFile virtualFile) { String name = virtualFile.getName(); VirtualFile parent = virtualFile.getParent(); if(parent == null) { return null; } int targetId = FileBasedIndex.getFileId(virtualFile); Object o = myGUIDs.computeIfAbsent(targetId, integer -> { VirtualFile child = parent.findChild(name + "." + Unity3dMetaFileType.INSTANCE.getDefaultExtension()); if(child != null) { String guid = null; PsiFile file = PsiManager.getInstance(myProject).findFile(child); if(file instanceof YAMLFile) { guid = Unity3dMetaIndexExtension.findGUIDFromFile((YAMLFile) file); } return guid == null ? ObjectUtil.NULL : guid; } return ObjectUtil.NULL; }); return o instanceof String ? (String) o : null; }
Example 13
Source Project: js-graphql-intellij-plugin File: JSGraphQLEndpointImportUtil.java License: MIT License | 5 votes |
public static String getImportName(VirtualFile entryFileDir, VirtualFile virtualFile, String name) { if(entryFileDir != null) { VirtualFile parentDir = virtualFile.getParent(); while(parentDir != null && !parentDir.equals(entryFileDir)) { name = parentDir.getName() + '/' + name; parentDir = parentDir.getParent(); } } return name; }
Example 14
Source Project: flutter-intellij File: AndroidUtils.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void enableCoEditing(@NotNull Project project) { Module module = FlutterUtils.findFlutterGradleModule(project); if (module == null) return; VirtualFile root = FlutterUtils.locateModuleRoot(module); if (root == null) return; VirtualFile androidDir = root.getParent(); VirtualFile flutterModuleDir = androidDir.getParent(); String flutterModuleName = flutterModuleDir.getName(); if (!isVanillaAddToApp(project, androidDir, flutterModuleName)) return; new CoEditHelper(project, flutterModuleDir).enable(); }
Example 15
Source Project: consulo File: ExternalDiffToolUtil.java License: Apache License 2.0 | 5 votes |
@Nonnull private static String getFileName(@Nonnull DiffContent content, @javax.annotation.Nullable String title, @javax.annotation.Nullable String windowTitle) { if (content instanceof EmptyContent) { return "no_content.tmp"; } String fileName = content.getUserData(DiffUserDataKeysEx.FILE_NAME); if (fileName == null && content instanceof DocumentContent) { VirtualFile highlightFile = ((DocumentContent)content).getHighlightFile(); fileName = highlightFile != null ? highlightFile.getName() : null; } if (fileName == null && content instanceof FileContent) { fileName = ((FileContent)content).getFile().getName(); } if (!StringUtil.isEmptyOrSpaces(fileName)) { return fileName; } FileType fileType = content.getContentType(); String ext = fileType != null ? fileType.getDefaultExtension() : null; if (StringUtil.isEmptyOrSpaces(ext)) ext = "tmp"; String name = ""; if (title != null && windowTitle != null) { name = title + "_" + windowTitle; } else if (title != null || windowTitle != null) { name = title != null ? title : windowTitle; } if (name.length() > 50) name = name.substring(0, 50); return PathUtil.suggestFileName(name + "." + ext, true, false); }
Example 16
Source Project: BashSupport File: BashPsiFileUtils.java License: Apache License 2.0 | 5 votes |
@Nullable public static String findRelativeFilePath(PsiFile base, PsiFile targetFile) { PsiFile currentFile = BashPsiUtils.findFileContext(base); VirtualFile baseVirtualFile = currentFile.getVirtualFile(); if (!(baseVirtualFile.getFileSystem() instanceof LocalFileSystem)) { throw new IncorrectOperationException("Can not rename file refeferences in non-local files"); } VirtualFile targetVirtualFile = BashPsiUtils.findFileContext(targetFile).getVirtualFile(); if (!(targetVirtualFile.getFileSystem() instanceof LocalFileSystem)) { throw new IncorrectOperationException("Can not bind to non-local files"); } VirtualFile baseParent = baseVirtualFile.getParent(); VirtualFile targetParent = targetVirtualFile.getParent(); if (baseParent == null || targetParent == null) { throw new IllegalStateException("parent directories not found"); } char separator = '/'; String baseDirPath = ensureEnds(baseParent.getPath(), separator); String targetDirPath = ensureEnds(targetParent.getPath(), separator); String targetRelativePath = FileUtilRt.getRelativePath(baseDirPath, targetDirPath, separator, true); if (targetRelativePath == null) { return null; } if (".".equals(targetRelativePath)) { //same parent dir return targetVirtualFile.getName(); } return ensureEnds(targetRelativePath, separator) + targetVirtualFile.getName(); }
Example 17
Source Project: consulo File: EditorComponentImpl.java License: Apache License 2.0 | 5 votes |
@Nullable @Override public String getAccessibleName() { if (accessibleName != null) { return accessibleName; } VirtualFile file = myEditor.getVirtualFile(); if (file != null) { return "Editor for " + file.getName(); } return "Editor"; }
Example 18
Source Project: consulo File: FileTreeStructure.java License: Apache License 2.0 | 4 votes |
@Override public Object[] getChildElements(Object nodeElement) { if (!(nodeElement instanceof FileElement)) { return ArrayUtil.EMPTY_OBJECT_ARRAY; } FileElement element = (FileElement)nodeElement; VirtualFile file = element.getFile(); if (file == null || !file.isValid()) { if (element == myRootElement) { return myRootElement.getChildren(); } return ArrayUtil.EMPTY_OBJECT_ARRAY; } VirtualFile[] children = null; if (element.isArchive() && myChooserDescriptor.isChooseJarContents()) { String path = file.getPath(); if (!(file.getFileSystem() instanceof ArchiveFileSystem)) { file = ((ArchiveFileType)file.getFileType()).getFileSystem().findLocalVirtualFileByPath(path); } if (file != null) { children = file.getChildren(); } } else { children = file.getChildren(); } if (children == null) { return ArrayUtil.EMPTY_OBJECT_ARRAY; } Set<FileElement> childrenSet = new HashSet<FileElement>(); for (VirtualFile child : children) { if (myChooserDescriptor.isFileVisible(child, myShowHidden)) { final FileElement childElement = new FileElement(child, child.getName()); childElement.setParent(element); childrenSet.add(childElement); } } return ArrayUtil.toObjectArray(childrenSet); }
Example 19
Source Project: consulo File: StructureFilterPopupComponent.java License: Apache License 2.0 | 4 votes |
private SelectVisibleRootAction(@Nonnull VirtualFile root) { super(root.getName(), root.getPresentableUrl(), null); myRoot = root; myIcon = new CheckboxColorIcon(CHECKBOX_ICON_SIZE, VcsLogGraphTable.getRootBackgroundColor(myRoot, myColorManager)); getTemplatePresentation().setIcon(EmptyIcon.create(CHECKBOX_ICON_SIZE)); // see PopupFactoryImpl.calcMaxIconSize }
Example 20
Source Project: protobuf-jetbrains-plugin File: ProtoPsiFileRoot.java License: Apache License 2.0 | 4 votes |
@Override public String toString() { final VirtualFile virtualFile = getVirtualFile(); return "Protobuf File: " + (virtualFile != null ? virtualFile.getName() : "<unknown>"); }