本文整理汇总了Java中com.intellij.psi.PsiJavaFile.getVirtualFile方法的典型用法代码示例。如果您正苦于以下问题:Java PsiJavaFile.getVirtualFile方法的具体用法?Java PsiJavaFile.getVirtualFile怎么用?Java PsiJavaFile.getVirtualFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiJavaFile
的用法示例。
在下文中一共展示了PsiJavaFile.getVirtualFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGotoClass
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
public void testGotoClass() throws Exception {
PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("Foo.java", "public class Foo {\n" +
"}\n" +
"\n" +
"class Bar {}\n");
VirtualFile virtualFile = file.getVirtualFile();
assertNotNull(virtualFile);
myManager.openFile(virtualFile, true);
assertEquals(0, getOffset(virtualFile));
myManager.closeAllFiles();
PsiClass psiClass = file.getClasses()[1];
int identifierOffset = psiClass.getNameIdentifier().getTextOffset();
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset, getOffset(virtualFile));
getEditor(virtualFile).getCaretModel().moveToOffset(identifierOffset + 3); // it's still inside the class, so keep it
myManager.closeAllFiles();
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset + 3, getOffset(virtualFile));
getEditor(virtualFile).getCaretModel().moveToOffset(0);
NavigationUtil.activateFileWithPsiElement(psiClass);
assertEquals(identifierOffset, getOffset(virtualFile));
myManager.closeAllFiles();
NavigationUtil.activateFileWithPsiElement(file); // GoTo file should keep offset
assertEquals(identifierOffset, getOffset(virtualFile));
}
示例2: showCoverageForFile
import com.intellij.psi.PsiJavaFile; //导入方法依赖的package包/类
private void showCoverageForFile(PsiJavaFile javaFile, AnActionEvent e, Project project) {
VirtualFile virtualFile = javaFile.getVirtualFile();
if (virtualFile == null) {
Notifications.Bus.notify(getMissingFileNotification(virtualFile), project);
return;
}
Module module = ModuleUtil.findModuleForFile(virtualFile, project);
if(module == null){
return;
}
File coverageRootPath = CoverageUtils.getCoverageReportRoot(module, project);
if (coverageRootPath.exists()) {
String packageName = javaFile.getPackageName();
File url = new File(coverageRootPath, packageName);
boolean wasFound = false;
url = new File(url, virtualFile.getName() + ".html");
if (url.exists()) {
BrowserUtil.launchBrowser(url.toURI().getPath());
wasFound = true;
}
if (!wasFound) {
Notifications.Bus.notify(getMissingFileNotification(virtualFile), project);
}
} else {
Notifications.Bus.notify(getMissingReportNotification(e), project);
}
}