本文整理汇总了Java中com.intellij.psi.util.PsiUtilCore.getVirtualFile方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtilCore.getVirtualFile方法的具体用法?Java PsiUtilCore.getVirtualFile怎么用?Java PsiUtilCore.getVirtualFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtilCore
的用法示例。
在下文中一共展示了PsiUtilCore.getVirtualFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIcon
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
@Override
public Icon getIcon(@NotNull final PsiElement psiElement, final int i) {
Icon icon = null;
// Only replace icons on elements representing a file
// Prevents file icons from being assigned to classes, methods, fields, etc.
if (psiElement instanceof PsiFile) {
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile != null) {
final FileInfo file = new VirtualFileInfo(psiElement, virtualFile);
icon = getIconForAssociation(file, associations.findAssociationForFile(file));
}
} else if (psiElement instanceof PsiDirectory) {
icon = getDirectoryIcon((PsiDirectory) psiElement);
}
return icon;
}
示例2: onMarkReferenced
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void onMarkReferenced(PsiElement what, PsiElement from, boolean referencedFromClassInitializer) {
if (what != null && from != null){
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(what);
final VirtualFile containingDir = virtualFile != null ? virtualFile.getParent() : null;
if (containingDir != null) {
final VirtualFile libraryClassRoot = myFileIndex.getClassRootForFile(containingDir);
if (libraryClassRoot != null) {
final Module fromModule = ModuleUtilCore.findModuleForPsiElement(from);
if (fromModule != null){
final RefModule refModule = myManager.getRefModule(fromModule);
if (refModule != null) {
Set<VirtualFile> modules = refModule.getUserData(USED_LIBRARY_ROOTS);
if (modules == null){
modules = new HashSet<VirtualFile>();
refModule.putUserData(USED_LIBRARY_ROOTS, modules);
}
modules.add(libraryClassRoot);
}
}
}
}
}
}
示例3: invoke
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext, @Nullable Editor editor) {
if (element != null && !canRename(project, editor, element)) {
return;
}
VirtualFile contextFile = PsiUtilCore.getVirtualFile(nameSuggestionContext);
if (nameSuggestionContext != null &&
nameSuggestionContext.isPhysical() &&
(contextFile == null || contextFile.getFileType() != ScratchFileType.INSTANCE) &&
!PsiManager.getInstance(project).isInProject(nameSuggestionContext)) {
final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
if (Messages.showYesNoDialog(project, message,
RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != Messages.YES) {
return;
}
}
FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");
rename(element, project, nameSuggestionContext, editor);
}
示例4: getDescriptor
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
PsiElement original = getNavigatableOriginalElement(element);
if (original != null) {
element = original;
}
else if (!canNavigate(element)) {
return null;
}
if (element instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement)element).getTarget();
}
final PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement)navigationElement).getTarget();
}
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
if (virtualFile == null || !virtualFile.isValid()) {
return null;
}
OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
return desc;
}
示例5: commitToOriginal
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
private void commitToOriginal(final DocumentEvent e) {
VirtualFile origVirtualFile = PsiUtilCore.getVirtualFile(myNewFile.getContext());
myCommittingToOriginal = true;
try {
if (origVirtualFile == null || !ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(origVirtualFile).hasReadonlyFiles()) {
PostprocessReformattingAspect.getInstance(myProject).disablePostprocessFormattingInside(new Runnable() {
@Override
public void run() {
if (myAltFullRange != null) {
altCommitToOriginal(e);
return;
}
commitToOriginalInner();
}
});
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myOrigDocument);
}
}
finally {
myCommittingToOriginal = false;
}
}
示例6: decorate
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public void decorate(ProjectViewNode node, PresentationData data) {
final CoverageDataManager coverageDataManager = getCoverageDataManager();
final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
final Project project = node.getProject();
final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
// This decorator is applicable only to JavaCoverageAnnotator
if (javaCovAnnotator == null) {
return;
}
final Object value = node.getValue();
PsiElement element = null;
if (value instanceof PsiElement) {
element = (PsiElement)value;
}
else if (value instanceof SmartPsiElementPointer) {
element = ((SmartPsiElementPointer)value).getElement();
}
else if (value instanceof PackageElement) {
PackageElement packageElement = (PackageElement)value;
final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(),
packageElement.getModule(),
coverageDataManager);
data.setLocationString(coverageString);
}
if (element instanceof PsiClass) {
final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
if (vFile != null && searchScope.contains(vFile)) {
final String qName = ((PsiClass)element).getQualifiedName();
if (qName != null) {
data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
}
}
}
}
示例7: setHighlightingEnabled
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void setHighlightingEnabled(@NotNull PsiFile file, boolean value) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
if (value) {
myDisabledHighlightingFiles.remove(virtualFile);
}
else {
myDisabledHighlightingFiles.add(virtualFile);
}
}
示例8: suggestMostAppropriateDirectories
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@NotNull
private static PsiDirectory[] suggestMostAppropriateDirectories(@NotNull PsiPackage psiPackage) {
final Project project = psiPackage.getProject();
PsiDirectory[] directories = null;
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor != null) {
final Document document = editor.getDocument();
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (psiFile != null) {
final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
if (module != null) {
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiFile);
final boolean isInTests =
virtualFile != null && ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile);
if (isInTests) {
directories = psiPackage.getDirectories(GlobalSearchScope.moduleTestsWithDependentsScope(module));
}
if (directories == null || directories.length == 0) {
directories = psiPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
}
}
else {
directories = psiPackage.getDirectories(GlobalSearchScope.notScope(GlobalSearchScope.projectScope(project)));
}
}
}
if (directories == null || directories.length == 0) {
directories = psiPackage.getDirectories();
}
return directories;
}
示例9: error
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
private void error(String descr) {
PsiFile file = myScope.getContainingFile();
String fileText = file != null ? file.getText() : null;
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
String path = virtualFile == null ? null : virtualFile.getPresentableUrl();
LOG.error(descr+ myScope.getText(), new Attachment(path+"", fileText+""));
}
示例10: getReferences
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static PsiReference[] getReferences(@NotNull PsiElement element, String value, final String acceptedExtension) {
final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent();
if (directory == null) return PsiReference.EMPTY_ARRAY;
final boolean startsWithSlash = value.startsWith("/");
final VirtualFileSystem fs = directory.getVirtualFile().getFileSystem();
final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, fs.isCaseSensitive()) {
@NotNull
@Override
public Collection<PsiFileSystemItem> getDefaultContexts() {
if (startsWithSlash || !directory.isValid()) {
return super.getDefaultContexts();
}
return Collections.<PsiFileSystemItem>singletonList(directory);
}
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return new Condition<PsiFileSystemItem>() {
@Override
public boolean value(PsiFileSystemItem item) {
if (item instanceof PsiDirectory) return true;
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item);
return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension());
}
};
}
};
if (startsWithSlash) {
fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return fileReferenceSet.getAllReferences();
}
示例11: isInScope
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static boolean isInScope(@NotNull Usage usage, @NotNull SearchScope searchScope) {
PsiElement element = null;
VirtualFile file = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() :
usage instanceof PsiElementUsage ? PsiUtilCore.getVirtualFile(element = ((PsiElementUsage)usage).getElement()) : null;
if (file != null) {
return isFileInScope(file, searchScope);
}
else if(element != null) {
return searchScope instanceof EverythingGlobalScope ||
searchScope instanceof ProjectScopeImpl ||
searchScope instanceof ProjectAndLibrariesScope;
}
return false;
}
示例12: isConfiguredByElement
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public boolean isConfiguredByElement(PsiElement element) {
final PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof XmlFile) {
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(containingFile);
return virtualFile != null && Comparing.strEqual(myConfig.getPersistantData().getSuiteName(), virtualFile.getPath());
}
return false;
}
示例13: navigate
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void navigate(boolean requestFocus) {
final int offset = getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(myElement);
if (virtualFile != null && virtualFile.isValid()) {
PsiNavigationSupport.getInstance().createNavigatable(myElement.getProject(), virtualFile, offset).navigate(requestFocus);
}
}
示例14: getFiles
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static VirtualFile[] getFiles(AbstractTreeNode kid, Function<AbstractTreeNode, VirtualFile[]> converterFunction) {
if (kid instanceof BasePsiNode) {
Object value = kid.getValue();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile((PsiElement)value);
return new VirtualFile[]{virtualFile};
}
if (converterFunction != null) {
final VirtualFile[] result = converterFunction.fun(kid);
if (result != null) {
return result;
}
}
return new VirtualFile[0];
}
示例15: shouldEnableDeleteAction
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public static boolean shouldEnableDeleteAction(PsiElement[] elements) {
if (elements == null || elements.length == 0) return false;
for (PsiElement element : elements) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (virtualFile == null) {
return false;
}
if (!WritingAccessProvider.isPotentiallyWritable(virtualFile, element.getProject())) {
return false;
}
}
return true;
}