Search in sources :

Example 1 with PsiFileReference

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPsiImplUtil method resolve.

@Nullable
public static PsiDirectory resolve(@NotNull GoImportString importString) {
    PsiReference[] references = importString.getReferences();
    for (PsiReference reference : references) {
        if (reference instanceof FileReferenceOwner) {
            PsiFileReference lastFileReference = ((FileReferenceOwner) reference).getLastFileReference();
            PsiElement result = lastFileReference != null ? lastFileReference.resolve() : null;
            return result instanceof PsiDirectory ? (PsiDirectory) result : null;
        }
    }
    return null;
}
Also used : FileReferenceOwner(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceOwner) PsiFileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiFileReference

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference in project intellij-community by JetBrains.

the class IconsReferencesContributor method execute.

@Override
public boolean execute(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement file = queryParameters.getElementToSearch();
    if (file instanceof PsiBinaryFile) {
        final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {

            @Override
            public Module compute() {
                return ModuleUtilCore.findModuleForPsiElement(file);
            }
        });
        final VirtualFile image = ((PsiBinaryFile) file).getVirtualFile();
        if (isImage(image) && isIconsModule(module)) {
            final Project project = file.getProject();
            final FindModel model = new FindModel();
            final String path = getPathToImage(image, module);
            if (path == null)
                return true;
            model.setStringToFind(path);
            model.setCaseSensitive(true);
            model.setFindAll(true);
            model.setWholeWordsOnly(true);
            FindInProjectUtil.findUsages(model, project, usage -> {
                ApplicationManager.getApplication().runReadAction(() -> {
                    final PsiElement element = usage.getElement();
                    final ProperTextRange textRange = usage.getRangeInElement();
                    if (element != null && textRange != null) {
                        final PsiElement start = element.findElementAt(textRange.getStartOffset());
                        final PsiElement end = element.findElementAt(textRange.getEndOffset());
                        if (start != null && end != null) {
                            PsiElement value = PsiTreeUtil.findCommonParent(start, end);
                            if (value instanceof PsiJavaToken) {
                                value = value.getParent();
                            }
                            if (value != null) {
                                final PsiFileReference reference = FileReferenceUtil.findFileReference(value);
                                if (reference != null) {
                                    consumer.process(reference);
                                }
                            }
                        }
                    }
                });
                return true;
            }, new FindUsagesProcessPresentation(new UsageViewPresentation()));
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) FindModel(com.intellij.find.FindModel) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) ProperTextRange(com.intellij.openapi.util.ProperTextRange) Project(com.intellij.openapi.project.Project) PsiFileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference) Module(com.intellij.openapi.module.Module)

Aggregations

PsiFileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference)2 FindModel (com.intellij.find.FindModel)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileReferenceOwner (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceOwner)1 FindUsagesProcessPresentation (com.intellij.usages.FindUsagesProcessPresentation)1 UsageViewPresentation (com.intellij.usages.UsageViewPresentation)1 Nullable (org.jetbrains.annotations.Nullable)1