use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class FileIncludeManagerImpl method processIncludingFiles.
@Override
public void processIncludingFiles(PsiFile context, Processor<Pair<VirtualFile, FileIncludeInfo>> processor) {
context = context.getOriginalFile();
VirtualFile contextFile = context.getVirtualFile();
if (contextFile == null)
return;
MultiMap<VirtualFile, FileIncludeInfoImpl> infoList = FileIncludeIndex.getIncludingFileCandidates(context.getName(), GlobalSearchScope.allScope(myProject));
for (VirtualFile candidate : infoList.keySet()) {
PsiFile psiFile = myPsiManager.findFile(candidate);
if (psiFile == null || context.equals(psiFile))
continue;
for (FileIncludeInfo info : infoList.get(candidate)) {
PsiFileSystemItem item = resolveFileInclude(info, psiFile);
if (item != null && contextFile.equals(item.getVirtualFile())) {
if (!processor.process(Pair.create(candidate, info))) {
return;
}
}
}
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class GotoFileCellRenderer method getContainerText.
@Override
protected String getContainerText(PsiFileSystemItem element, String name) {
PsiFileSystemItem parent = element.getParent();
final PsiDirectory psiDirectory = parent instanceof PsiDirectory ? (PsiDirectory) parent : null;
if (psiDirectory == null)
return null;
final VirtualFile virtualFile = psiDirectory.getVirtualFile();
final String relativePath = getRelativePath(virtualFile, element.getProject());
if (relativePath == null)
return "( " + File.separator + " )";
String path = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR.getOptimalTextForComponent(name + " ", new File(relativePath), this, myMaxWidth);
return "(" + path + ")";
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class GotoFileModel method getFullName.
@Override
@Nullable
public String getFullName(final Object element) {
if (element instanceof PsiFileSystemItem) {
VirtualFile file = ((PsiFileSystemItem) element).getVirtualFile();
VirtualFile root = getTopLevelRoot(file);
return root != null ? GotoFileCellRenderer.getRelativePathFromRoot(file, root) : GotoFileCellRenderer.getRelativePath(file, myProject);
}
return getElementName(element);
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class ScopePaneSelectInTarget method isSubIdSelectable.
@Override
public boolean isSubIdSelectable(@NotNull String subId, @NotNull SelectInContext context) {
PsiFileSystemItem file = getContextPsiFile(context);
if (!(file instanceof PsiFile))
return false;
final NamedScope scope = NamedScopesHolder.getScope(myProject, subId);
PackageSet packageSet = scope != null ? scope.getValue() : null;
if (packageSet == null)
return false;
NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, subId, DependencyValidationManager.getInstance(myProject));
return packageSet.contains((PsiFile) file, holder);
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class FileReferenceCompletionImpl method getFileReferenceCompletionVariants.
@NotNull
@Override
public Object[] getFileReferenceCompletionVariants(final FileReference reference) {
final String s = reference.getText();
if (s != null && s.equals("/")) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem> collector = new CommonProcessors.CollectUniquesProcessor<>();
final PsiElementProcessor<PsiFileSystemItem> processor = new PsiElementProcessor<PsiFileSystemItem>() {
@Override
public boolean execute(@NotNull PsiFileSystemItem fileSystemItem) {
return new FilteringProcessor<>(reference.getFileReferenceSet().getReferenceCompletionFilter(), collector).process(FileReference.getOriginalFile(fileSystemItem));
}
};
List<Object> additionalItems = ContainerUtil.newArrayList();
for (PsiFileSystemItem context : reference.getContexts()) {
for (final PsiElement child : context.getChildren()) {
if (child instanceof PsiFileSystemItem) {
processor.execute((PsiFileSystemItem) child);
}
}
if (context instanceof FileReferenceResolver) {
additionalItems.addAll(((FileReferenceResolver) context).getVariants(reference));
}
}
final FileType[] types = reference.getFileReferenceSet().getSuitableFileTypes();
final THashSet<PsiElement> set = new THashSet<>(collector.getResults(), VARIANTS_HASHING_STRATEGY);
final PsiElement[] candidates = PsiUtilCore.toPsiElementArray(set);
final Object[] variants = new Object[candidates.length + additionalItems.size()];
for (int i = 0; i < candidates.length; i++) {
PsiElement candidate = candidates[i];
Object item = reference.createLookupItem(candidate);
if (item == null) {
item = FileInfoManager.getFileLookupItem(candidate);
}
if (candidate instanceof PsiFile && item instanceof LookupElement && types.length > 0 && ArrayUtil.contains(((PsiFile) candidate).getFileType(), types)) {
item = PrioritizedLookupElement.withPriority((LookupElement) item, Double.MAX_VALUE);
}
variants[i] = item;
}
for (int i = 0; i < additionalItems.size(); i++) {
variants[i + candidates.length] = additionalItems.get(i);
}
if (!reference.getFileReferenceSet().isUrlEncoded()) {
return variants;
}
List<Object> encodedVariants = new ArrayList<>(variants.length + additionalItems.size());
for (int i = 0; i < candidates.length; i++) {
final PsiElement element = candidates[i];
if (element instanceof PsiNamedElement) {
final PsiNamedElement psiElement = (PsiNamedElement) element;
String name = psiElement.getName();
final String encoded = reference.encode(name, psiElement);
if (encoded == null)
continue;
if (!encoded.equals(name)) {
final Icon icon = psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
LookupElementBuilder item = FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
encodedVariants.add(item.withTailText(" (" + name + ")"));
} else {
encodedVariants.add(variants[i]);
}
}
}
encodedVariants.addAll(additionalItems);
return ArrayUtil.toObjectArray(encodedVariants);
}
Aggregations