use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class BaseClassesAnalysisAction method getScopeModules.
/**
* @param scope the scope of which to return the modules
* @return the modules contained by the scope and/or the module containing the scope.
*/
@NotNull
public static Set<Module> getScopeModules(@NotNull AnalysisScope scope) {
final int scopeType = scope.getScopeType();
final Set<Module> result = new HashSet<>();
final Project project = scope.getProject();
if (scopeType == AnalysisScope.MODULE) {
final Module module = scope.getModule();
if (module != null) {
result.add(module);
}
} else if (scopeType == AnalysisScope.MODULES) {
result.addAll(scope.getModules());
} else if (scopeType == AnalysisScope.FILE) {
final PsiElement element = scope.getElement();
if (element != null) {
final VirtualFile vFile = ((PsiFileSystemItem) element).getVirtualFile();
getContainingModule(vFile, project, result);
}
} else if (scopeType == AnalysisScope.DIRECTORY) {
final PsiElement element = scope.getElement();
if (element != null) {
final VirtualFile vFile = ((PsiFileSystemItem) element).getVirtualFile();
final Module[] modules = ModuleManager.getInstance(project).getModules();
getModulesContainedInDirectory(modules, vFile, result);
getContainingModule(vFile, project, result);
}
} else if (scopeType == AnalysisScope.VIRTUAL_FILES) {
final Set<VirtualFile> files = scope.getFiles();
final Module[] modules = ModuleManager.getInstance(project).getModules();
for (VirtualFile vFile : files) {
getModulesContainedInDirectory(modules, vFile, result);
getContainingModule(vFile, project, result);
}
} else {
result.addAll(Arrays.asList(ModuleManager.getInstance(project).getModules()));
}
return result;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class PsiFileReferenceHelper method getContexts.
@Override
@NotNull
public Collection<PsiFileSystemItem> getContexts(final Project project, @NotNull final VirtualFile file) {
final PsiFileSystemItem item = getPsiFileSystemItem(project, file);
if (item != null) {
final PsiFileSystemItem parent = item.getParent();
if (parent != null) {
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile parentFile = parent.getVirtualFile();
assert parentFile != null;
VirtualFile root = index.getSourceRootForFile(parentFile);
if (root != null) {
String path = VfsUtilCore.getRelativePath(parentFile, root, '.');
if (path != null) {
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module != null) {
OrderEntry orderEntry = ModuleRootManager.getInstance(module).getFileIndex().getOrderEntryForFile(file);
if (orderEntry instanceof ModuleSourceOrderEntry) {
for (ContentEntry e : ((ModuleSourceOrderEntry) orderEntry).getRootModel().getContentEntries()) {
for (SourceFolder sf : e.getSourceFolders(JavaModuleSourceRootTypes.SOURCES)) {
if (root.equals(sf.getFile())) {
String s = sf.getPackagePrefix();
if (!s.isEmpty()) {
path = s + "." + path;
break;
}
}
}
}
}
return getContextsForModule(module, path, module.getModuleWithDependenciesScope());
}
}
// TODO: content root
}
return Collections.singleton(parent);
}
}
return Collections.emptyList();
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class AntMissingPropertiesFileInspection method checkDomElement.
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
if (element instanceof AntDomProperty) {
final AntDomProperty property = (AntDomProperty) element;
final GenericAttributeValue<PsiFileSystemItem> fileValue = property.getFile();
final String fileName = fileValue.getStringValue();
if (fileName != null) {
final PropertiesFile propertiesFile = property.getPropertiesFile();
if (propertiesFile == null) {
final PsiFileSystemItem file = fileValue.getValue();
if (file instanceof XmlFile) {
holder.createProblem(fileValue, AntBundle.message("file.type.xml.not.supported", fileName));
} else if (file instanceof PsiFile) {
holder.createProblem(fileValue, AntBundle.message("file.type.not.supported", fileName));
} else {
holder.createProblem(fileValue, AntBundle.message("file.doesnt.exist", fileName));
}
}
}
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class NavBarPanel method getData.
@Override
@Nullable
public Object getData(String dataId) {
if (CommonDataKeys.PROJECT.is(dataId)) {
return !myProject.isDisposed() ? myProject : null;
}
if (LangDataKeys.MODULE.is(dataId)) {
final Module module = getSelectedElement(Module.class);
if (module != null && !module.isDisposed())
return module;
final PsiElement element = getSelectedElement(PsiElement.class);
if (element != null) {
return ModuleUtilCore.findModuleForPsiElement(element);
}
return null;
}
if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
final PsiDirectory directory = getSelectedElement(PsiDirectory.class);
if (directory != null) {
final VirtualFile dir = directory.getVirtualFile();
if (ProjectRootsUtil.isModuleContentRoot(dir, myProject)) {
return ModuleUtilCore.findModuleForPsiElement(directory);
}
}
return null;
}
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
final PsiElement element = getSelectedElement(PsiElement.class);
return element != null && element.isValid() ? element : null;
}
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
final List<PsiElement> elements = getSelectedElements(PsiElement.class);
if (elements == null || elements.isEmpty())
return null;
List<PsiElement> result = new ArrayList<>();
for (PsiElement element : elements) {
if (element != null && element.isValid()) {
result.add(element);
}
}
return result.isEmpty() ? null : result.toArray(new PsiElement[result.size()]);
}
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
PsiElement[] psiElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
if (psiElements == null)
return null;
Set<VirtualFile> files = new LinkedHashSet<>();
for (PsiElement element : psiElements) {
PsiFile file = element.getContainingFile();
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
files.add(virtualFile);
}
} else if (element instanceof PsiFileSystemItem) {
files.add(((PsiFileSystemItem) element).getVirtualFile());
}
}
return !files.isEmpty() ? VfsUtilCore.toVirtualFileArray(files) : null;
}
if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
final List<Navigatable> elements = getSelectedElements(Navigatable.class);
return elements == null || elements.isEmpty() ? null : elements.toArray(new Navigatable[elements.size()]);
}
if (PlatformDataKeys.CONTEXT_COMPONENT.is(dataId)) {
return this;
}
if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getCutProvider();
}
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getCopyProvider();
}
if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
return myCopyPasteDelegator.getPasteProvider();
}
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
return getSelectedElement(Module.class) != null ? myDeleteModuleProvider : new DeleteHandler.DefaultDeleteProvider();
}
if (LangDataKeys.IDE_VIEW.is(dataId)) {
return myIdeView;
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class ImagePreviewComponent method getPreviewComponent.
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;
}
Aggregations