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);
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class PsiFileReferenceHelper method getContextsForModule.
static Collection<PsiFileSystemItem> getContextsForModule(@NotNull Module module, @NotNull String packageName, @Nullable GlobalSearchScope scope) {
List<PsiFileSystemItem> result = null;
Query<VirtualFile> query = DirectoryIndex.getInstance(module.getProject()).getDirectoriesByPackageName(packageName, false);
PsiManager manager = null;
for (VirtualFile file : query) {
if (scope != null && !scope.contains(file))
continue;
if (result == null) {
result = new ArrayList<>();
manager = PsiManager.getInstance(module.getProject());
}
PsiDirectory psiDirectory = manager.findDirectory(file);
if (psiDirectory != null)
result.add(psiDirectory);
}
return result != null ? result : Collections.<PsiFileSystemItem>emptyList();
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.
the class KarmaRunConfigurationProducer method setup.
@Nullable
private static Pair<KarmaRunSettings, PsiElement> setup(@Nullable PsiElement element, @NotNull KarmaRunSettings templateSettings) {
JSFile file = ObjectUtils.tryCast(element != null ? element.getContainingFile() : null, JSFile.class);
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
if (virtualFile == null) {
return null;
}
if (!(element instanceof PsiFileSystemItem)) {
Pair<KarmaRunSettings, PsiElement> suiteOrTestConfiguration = setupAsSuiteOrTest(file, virtualFile, element, templateSettings);
if (suiteOrTestConfiguration != null) {
return suiteOrTestConfiguration;
}
}
if (KarmaUtil.isKarmaConfigFile(virtualFile.getNameSequence(), false)) {
return Pair.create(templateSettings.toBuilder().setScopeKind(KarmaScopeKind.ALL).setConfigPath(virtualFile.getPath()).build(), file);
}
if (file.getTestFileType() != null) {
KarmaRunSettings settings = guessConfigFileIfNeeded(templateSettings, virtualFile, element.getProject());
return Pair.create(settings.toBuilder().setScopeKind(KarmaScopeKind.TEST_FILE).setTestFilePath(virtualFile.getPath()).build(), file);
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.
the class SendToMayaAction method getPythonFile.
@Nullable
private static PyFile getPythonFile(AnActionEvent e) {
VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project != null && vFile != null) {
final PsiManager psiManager = PsiManager.getInstance(project);
PsiFileSystemItem fsItem = vFile.isDirectory() ? psiManager.findDirectory(vFile) : psiManager.findFile(vFile);
if (fsItem instanceof PyFile) {
return (PyFile) fsItem;
}
}
return null;
}
use of com.intellij.psi.PsiFileSystemItem in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoModuleLibrariesInitializer method moduleAdded.
@Override
public void moduleAdded() {
if (!myModuleInitialized) {
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
@Override
public void rootsChanged(ModuleRootEvent event) {
scheduleUpdate();
}
});
myConnection.subscribe(GoLibrariesService.LIBRARIES_TOPIC, newRootUrls -> scheduleUpdate());
Project project = myModule.getProject();
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
if (!project.isDisposed() && !myModule.isDisposed()) {
for (PsiFileSystemItem vendor : FilenameIndex.getFilesByName(project, GoConstants.VENDOR, GoUtil.moduleScope(myModule), true)) {
if (vendor.isDirectory()) {
showVendoringNotification();
break;
}
}
}
});
VirtualFileManager.getInstance().addVirtualFileListener(myFilesListener);
}
scheduleUpdate(0);
myModuleInitialized = true;
}
Aggregations