本文整理汇总了Java中com.intellij.openapi.vfs.VirtualFile类的典型用法代码示例。如果您正苦于以下问题:Java VirtualFile类的具体用法?Java VirtualFile怎么用?Java VirtualFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VirtualFile类属于com.intellij.openapi.vfs包,在下文中一共展示了VirtualFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findProject
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Nullable
private Project findProject(String file) {
LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
ProjectLocator projectLocator = ProjectLocator.getInstance();
AtomicReference<Project> ret = new AtomicReference<>();
FileUtil.processFilesRecursively(
new File(file),
(f) -> {
VirtualFile vf = localFileSystem.findFileByIoFile(f);
if (vf != null) {
ret.set(projectLocator.guessProjectForFile(vf));
return false;
}
return true;
});
return ret.get();
}
示例2: modifyChildNode
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
Object value = childNode.getValue();
if (value instanceof PsiDirectory && !((PsiDirectory)value).getName().equals(EduNames.SRC)) {
return createChildDirectoryNode(null, (PsiDirectory)value);
}
if (value instanceof PsiElement) {
PsiFile psiFile = ((PsiElement) value).getContainingFile();
if (psiFile == null) return null;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) {
return null;
}
return StudyUtils.getTaskFile(myProject, virtualFile) != null ? childNode : null;
}
return null;
}
示例3: findProperties
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
public static List<CrystalProperty> findProperties(Project project) {
List<CrystalProperty> result = new ArrayList<CrystalProperty>();
Collection<VirtualFile> virtualFiles =
FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, CrystalFileType.INSTANCE,
GlobalSearchScope.allScope(project));
for (VirtualFile virtualFile : virtualFiles) {
CrystalFile simpleFile = (CrystalFile) PsiManager.getInstance(project).findFile(virtualFile);
if (simpleFile != null) {
CrystalProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, CrystalProperty.class);
if (properties != null) {
Collections.addAll(result, properties);
}
}
}
return result;
}
示例4: determineBranchName
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
private String determineBranchName(VirtualFile headFile) {
if (headFile != null) {
try {
String headLinkAsString = new String(headFile.contentsToByteArray());
Matcher matcher = FIRST_LINE_PATTERN.matcher(headLinkAsString);
if (matcher.find() && matcher.groupCount() >= 2) {
String branchName = matcher.group(2).trim();
branchName = removePrefix("refs/", branchName);
branchName = removePrefix("heads/", branchName);
return branchName;
}
} catch (Exception e) {
// ignore
}
}
// could not determine branch name, returning null
return null;
}
示例5: processFile
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Override
public boolean processFile(final VirtualFile file) {
final String fileName = file.getName();
final String filePath = file.getPath();
boolean isTarget = false;
if(fileContent.isPython()){
isTarget = !file.isDirectory() && !fileContent.contains(filePath);
}else{
isTarget = !file.isDirectory() && fileContent.contains(filePath);
}
if (isTarget && !this.fileContent.hasFile(fileName)) {
fileContent.get().put(fileName, filePath);
//System.out.println("include: " + fileName);
}
return true;
}
示例6: actionFileReadFailDoesNotBubbleExcepted
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Test
public void actionFileReadFailDoesNotBubbleExcepted() throws IOException {
AnActionEvent action = mock(AnActionEvent.class);
ISpecflowAnalyzer lexer = mock(ISpecflowAnalyzer.class);
FileFactory fileFactory = mock(FileFactory.class);
DirectoryFactory directoryFactory = mock(DirectoryFactory.class);
VirtualFile file = mock(VirtualFile.class);
when(action.getData(PlatformDataKeys.VIRTUAL_FILE)).thenReturn(file);
when(file.contentsToByteArray()).thenThrow(new IOException());
SpecflowGenerateCode generator = new SpecflowGenerateCode(lexer, fileFactory, directoryFactory);
generator.actionPerformed(action);
verify(lexer, never()).analyze(anyString(), anyString());
}
示例7: getComponentDeclarations
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
private static List<XmlTag> getComponentDeclarations(String componentValue, String componentType, ID<String, Void> id, Project project, ComponentMatcher componentMatcher) {
List<XmlTag> results = new ArrayList<XmlTag>();
Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
.getContainingFiles(
id,
componentValue,
GlobalSearchScope.allScope(project)
);
PsiManager psiManager = PsiManager.getInstance(project);
for (VirtualFile virtualFile: containingFiles) {
XmlFile xmlFile = (XmlFile)psiManager.findFile(virtualFile);
if (xmlFile == null) {
continue;
}
XmlTag rootTag = xmlFile.getRootTag();
if (rootTag == null) {
continue;
}
collectComponentDeclarations(rootTag, results, componentValue, componentType, componentMatcher);
}
return results;
}
示例8: getLineNumber
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
private static int getLineNumber(VirtualFile virtualFile, TextRange textRange) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(virtualFile.getInputStream()));
String line;
int pos = 0;
int lineNumber = 0;
while ((line = br.readLine()) != null) {
pos += line.length() + 1; //+1 for new line
lineNumber++;
if (pos >= textRange.getStartOffset()) {
return lineNumber;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
示例9: getLayoutFiles
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
public static List<XmlFile> getLayoutFiles(Project project, @Nullable String fileName) {
List<XmlFile> results = new ArrayList<XmlFile>();
Collection<VirtualFile> xmlFiles = FilenameIndex.getAllFilesByExt(project, "xml");
PsiManager psiManager = PsiManager.getInstance(project);
for (VirtualFile xmlFile: xmlFiles) {
if (isLayoutFile(xmlFile)) {
if (fileName != null && !xmlFile.getNameWithoutExtension().equals(fileName)) {
continue;
}
PsiFile file = psiManager.findFile(xmlFile);
if (file != null) {
results.add((XmlFile)file);
}
}
}
return results;
}
示例10: EmojiCheckinHandler
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
public EmojiCheckinHandler(CheckinProjectPanel checkinProjectPanel) {
JPanel emojiPanel = new JPanel();
emojiPanel.setLayout(new VerticalFlowLayout());
VirtualFile emojirc = checkinProjectPanel.getProject().getBaseDir().findChild(".emojirc");
if (emojirc == null) return;
PsiFile psiFile = PsiManager.getInstance(checkinProjectPanel.getProject()).findFile(emojirc);
if (psiFile == null) return;
for (PsiElement psiElement : psiFile.getChildren()) {
if (!(psiElement instanceof EmojiResourceProperty)) continue;
emojiPanel.add(createEmojiButton(psiElement.getFirstChild().getText(), psiElement.getLastChild().getText(), false, buttonGroup));
}
emojiPanel.add(createEmojiButton(null, NO_EMOJI, true, buttonGroup));
Splitter splitter = (Splitter) checkinProjectPanel.getComponent();
CommitMessage commitMessage = (CommitMessage) splitter.getSecondComponent();
JComponent component = (JComponent) commitMessage.getComponent(1);
JBScrollPane scrollPane = new JBScrollPane(emojiPanel);
scrollPane.setBorder(null);
Splitter commitSplitter = new Splitter();
commitSplitter.setFirstComponent(scrollPane);
commitSplitter.setSecondComponent((JComponent) commitMessage.getComponent(0));
commitMessage.add(commitSplitter, 0);
for (EmojiPanelFactory factory : factories) {
factory.createPanel(commitMessage);
}
this.checkinProjectPanel = checkinProjectPanel;
}
示例11: createTestsForNewSubtask
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Override
public void createTestsForNewSubtask(@NotNull Project project, @NotNull TaskWithSubtasks task) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
int nextSubtaskIndex = task.getLastSubtaskIndex() + 1;
String nextSubtaskTestsFileName = getSubtaskTestsFileName(nextSubtaskIndex);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
PsiDirectory taskPsiDir = PsiManager.getInstance(project).findDirectory(taskDir);
FileTemplate testsTemplate = FileTemplateManager.getInstance(project).getInternalTemplate(TESTS_PY);
if (taskPsiDir == null || testsTemplate == null) {
return;
}
FileTemplateUtil.createFromTemplate(testsTemplate, nextSubtaskTestsFileName, null, taskPsiDir);
}
catch (Exception e) {
LOG.error(e);
}
});
}
示例12: modifyChildNode
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
final AbstractTreeNode node = super.modifyChildNode(childNode);
if (node != null) return node;
Object value = childNode.getValue();
if (value instanceof PsiElement) {
PsiFile psiFile = ((PsiElement) value).getContainingFile();
VirtualFile virtualFile = psiFile.getVirtualFile();
Course course = StudyTaskManager.getInstance(myProject).getCourse();
if (course == null) {
return null;
}
EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById());
if (configurator == null) {
return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
}
if (!CCUtils.isTestsFile(myProject, virtualFile)) {
return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
}
}
return null;
}
示例13: createDictionaryFromInfo
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
@Nullable
private ApplicationDictionary createDictionaryFromInfo(final @NotNull DictionaryInfo dInfo) {
if (!dInfo.isInitialized()) {
//dictionary terms must be ridden from the dictionary file before creating a PSI for it
LOG.error("Attempt to create dictionary for not initialized Dictionary Info for application" + dInfo.getApplicationName());
return null;
}
String applicationName = dInfo.getApplicationName();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(dInfo.getDictionaryFile());
if (vFile != null && vFile.isValid()) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
XmlFile xmlFile = (XmlFile) psiFile;
if (xmlFile != null) {
ApplicationDictionary dictionary = new ApplicationDictionaryImpl(project, xmlFile, applicationName, dInfo.getApplicationFile());
dictionaryMap.put(applicationName, dictionary);
return dictionary;
}
}
LOG.warn("Failed to create dictionary from info for application: " + applicationName + ". Reason: file is null");
return null;
}
示例14: packCourse
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
private static void packCourse(@NotNull final VirtualFile baseDir, String locationDir, String zipName, boolean showMessage) {
try {
final File zipFile = new File(locationDir, zipName + ".zip");
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
VirtualFile[] courseFiles = baseDir.getChildren();
for (VirtualFile file : courseFiles) {
ZipUtil.addFileOrDirRecursively(zos, null, new File(file.getPath()), file.getName(), null, null);
}
zos.close();
if (showMessage) {
ApplicationManager.getApplication().invokeLater(
() -> Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(),
"Course Archive Was Created Successfully"));
}
}
catch (IOException e1) {
LOG.error(e1);
}
}
示例15: createChildFile
import com.intellij.openapi.vfs.VirtualFile; //导入依赖的package包/类
public static void createChildFile(@NotNull VirtualFile taskDir, @NotNull String name, @NotNull String text) throws IOException {
String newDirectories = null;
String fileName = name;
VirtualFile dir = taskDir;
if (name.contains("/")) {
int pos = name.lastIndexOf("/");
fileName = name.substring(pos + 1);
newDirectories = name.substring(0, pos);
}
if (newDirectories != null) {
dir = VfsUtil.createDirectoryIfMissing(taskDir, newDirectories);
}
if (dir != null) {
VirtualFile virtualTaskFile = dir.findChild(fileName);
if (virtualTaskFile == null) {
virtualTaskFile = dir.createChildData(taskDir, fileName);
}
if (EduUtils.isImage(name)) {
virtualTaskFile.setBinaryContent(Base64.decodeBase64(text));
}
else {
VfsUtil.saveText(virtualTaskFile, text);
}
}
}