Java Code Examples for com.intellij.psi.PsiFileSystemItem#getVirtualFile()

The following examples show how to use com.intellij.psi.PsiFileSystemItem#getVirtualFile() . 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: BlazeCoverageAnnotator.java    From intellij with Apache License 2.0 6 votes vote down vote up
private boolean showCoverage(PsiFileSystemItem psiFile) {
  if (coverageFilePaths.isEmpty()) {
    return false;
  }
  VirtualFile vf = psiFile.getVirtualFile();
  if (vf == null) {
    return false;
  }
  String filePath = normalizeFilePath(vf.getPath());
  for (String path : coverageFilePaths) {
    if (filePath.startsWith(path)) {
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: VirtualFileUtil.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param element element to process.
 * @return The containing virtual file of the element.
 * @since 0.1
 */
@Nullable
public static VirtualFile getVirtualFile( @NotNull PsiElement element )
{
    if( element instanceof PsiFileSystemItem )
    {
        PsiFileSystemItem fileSystemItem = (PsiFileSystemItem) element;
        return fileSystemItem.getVirtualFile();
    }

    // If it's not a file system, assume that this is an element within a file
    PsiFile containingFile = element.getContainingFile();
    if( containingFile == null )
    {
        return null;
    }

    VirtualFile virtualFile = containingFile.getVirtualFile();
    if( virtualFile != null )
    {
        return virtualFile;
    }

    PsiFile originalFile = containingFile.getOriginalFile();
    if( originalFile == null )
    {
        return null;
    }

    return originalFile.getVirtualFile();
}
 
Example 3
Source File: HaxeSourceRootModel.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public boolean contains(PsiFileSystemItem file) {
  if (this == DUMMY) return false;

  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    virtualFile = file.getOriginalElement().getContainingFile().getVirtualFile();
  }
  if (virtualFile == null) {
    virtualFile = file.getUserData(IndexingDataKeys.VIRTUAL_FILE);
  }

  return virtualFile != null && (virtualFile.getCanonicalPath() + '/').startsWith(root.getCanonicalPath() + '/');
}
 
Example 4
Source File: ImagePreviewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JComponent getPreviewComponent(@Nullable final PsiElement parent) {
  if (parent == null) {
    return null;
  }
  final PsiReference[] references = parent.getReferences();
  for (final PsiReference reference : references) {
    final PsiElement fileItem = reference.resolve();
    if (fileItem instanceof PsiFileSystemItem) {
      final PsiFileSystemItem item = (PsiFileSystemItem)fileItem;
      if (!item.isDirectory()) {
        final VirtualFile file = item.getVirtualFile();
        if (file != null && supportedExtensions.contains(file.getExtension())) {
          try {
            refresh(file);
            SoftReference<BufferedImage> imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY);
            final BufferedImage image = SoftReference.dereference(imageRef);
            if (image != null) {
              return new ImagePreviewComponent(image, file.getLength());
            }
          }
          catch (IOException ignored) {
            // nothing
          }
        }
      }
    }
  }

  return null;
}
 
Example 5
Source File: BaseIconProvider.java    From intellij-extra-icons-plugin with MIT License 4 votes vote down vote up
private Optional<String> getFullPath(@NotNull PsiFileSystemItem file) {
    if (file.getVirtualFile() != null) {
        return Optional.of(file.getVirtualFile().getPath().toLowerCase());
    }
    return Optional.empty();
}
 
Example 6
Source File: PantsProjectPaneSelectInTarget.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canSelect(PsiFileSystemItem file) {
  if (!super.canSelect(file)) return false;
  final VirtualFile vFile = file.getVirtualFile();
  return canSelect(vFile);
}
 
Example 7
Source File: ProjectPaneSelectInTarget.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean canSelect(PsiFileSystemItem file) {
  if (!super.canSelect(file)) return false;
  final VirtualFile vFile = file.getVirtualFile();
  return vFile != null && ProjectViewPane.canBeSelectedInProjectView(myProject, vFile);
}