Search in sources :

Example 11 with FileReferenceSet

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

the class VelocityStrutsResultContributor method createReferences.

public boolean createReferences(@NotNull final PsiElement psiElement, @NotNull final List<PsiReference> references, final boolean soft) {
    final String namespace = getNamespace(psiElement);
    if (namespace == null) {
        return false;
    }
    final WebFacet webFacet = WebUtil.getWebFacet(psiElement);
    if (webFacet == null) {
        // setup error, web-facet must be present in current or dependent module
        return false;
    }
    final FileReferenceSet set = FileReferenceSetHelper.createRestrictedByFileType(psiElement, VtlFileType.INSTANCE);
    FileReferenceSetHelper.addWebDirectoryAndCurrentNamespaceAsRoots(psiElement, namespace, webFacet, set);
    set.setEmptyPathAllowed(false);
    Collections.addAll(references, set.getAllReferences());
    return true;
}
Also used : FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) WebFacet(com.intellij.javaee.web.facet.WebFacet)

Example 12 with FileReferenceSet

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

the class GoImportReference method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes() {
    if (GoPackageUtil.isBuiltinPackage(resolve())) {
        return new LocalQuickFix[] { new GoDeleteImportQuickFix() };
    }
    List<LocalQuickFix> result = ContainerUtil.newArrayList();
    FileReferenceSet fileReferenceSet = getFileReferenceSet();
    if (fileReferenceSet instanceof GoImportReferenceSet && !((GoImportReferenceSet) fileReferenceSet).isRelativeImport() && !fileReferenceSet.isAbsolutePathReference()) {
        result.add(new GoGetPackageFix(fileReferenceSet.getPathString()));
    }
    String fileNameToCreate = getFileNameToCreate();
    for (PsiFileSystemItem context : getContexts()) {
        if (context instanceof PsiDirectory) {
            try {
                ((PsiDirectory) context).checkCreateSubdirectory(fileNameToCreate);
                String targetPath = context.getVirtualFile().getPath();
                result.add(new CreateFileFix(true, fileNameToCreate, (PsiDirectory) context) {

                    @NotNull
                    @Override
                    public String getText() {
                        return "Create Directory " + fileNameToCreate + " at " + targetPath;
                    }
                });
            } catch (IncorrectOperationException ignore) {
            }
        }
    }
    return result.toArray(new LocalQuickFix[result.size()]);
}
Also used : GoDeleteImportQuickFix(com.goide.quickfix.GoDeleteImportQuickFix) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) NotNull(org.jetbrains.annotations.NotNull) CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GoGetPackageFix(com.goide.codeInsight.imports.GoGetPackageFix)

Example 13 with FileReferenceSet

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

the class DartPackagePathReferenceProvider method getDartPackageReferences.

private static FileReference[] getDartPackageReferences(@NotNull final PsiElement psiElement, @NotNull final DartUrlResolver dartResolver) {
    final TextRange textRange = ElementManipulators.getValueTextRange(psiElement);
    final String referenceText = psiElement.getText().substring(textRange.getStartOffset(), textRange.getEndOffset());
    final FileReferenceSet referenceSet = new FileReferenceSet(referenceText, psiElement, textRange.getStartOffset(), null, true) {

        public FileReference createFileReference(final TextRange range, final int index, final String text) {
            return new DartPackageAwareFileReference(this, range, index, text, dartResolver);
        }
    };
    return referenceSet.getAllReferences();
}
Also used : FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) TextRange(com.intellij.openapi.util.TextRange)

Example 14 with FileReferenceSet

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

the class StaticPathReferenceProvider method createReferences.

@Override
public boolean createReferences(@NotNull final PsiElement psiElement, final int offset, final String text, @NotNull final List<PsiReference> references, final boolean soft) {
    FileReferenceSet set = new FileReferenceSet(text, psiElement, offset, null, true, myEndingSlashNotAllowed, mySuitableFileTypes) {

        @Override
        protected boolean isUrlEncoded() {
            return true;
        }

        @Override
        protected boolean isSoft() {
            return soft;
        }
    };
    if (!myRelativePathsAllowed) {
        set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
    }
    Collections.addAll(references, set.getAllReferences());
    return true;
}
Also used : FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)

Example 15 with FileReferenceSet

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

the class JavaFxFileReferenceProvider method getReferences.

public static PsiReference[] getReferences(@NotNull PsiElement element, String value, final String acceptedExtension) {
    final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent();
    if (directory == null)
        return PsiReference.EMPTY_ARRAY;
    final boolean startsWithSlash = value.startsWith("/");
    final VirtualFileSystem fs = directory.getVirtualFile().getFileSystem();
    final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, fs.isCaseSensitive()) {

        @NotNull
        @Override
        public Collection<PsiFileSystemItem> getDefaultContexts() {
            if (startsWithSlash || !directory.isValid()) {
                return super.getDefaultContexts();
            }
            return Collections.singletonList(directory);
        }

        @Override
        protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
            return item -> {
                if (item instanceof PsiDirectory)
                    return true;
                final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item);
                return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension());
            };
        }
    };
    if (startsWithSlash) {
        fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
    }
    return fileReferenceSet.getAllReferences();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Collection(java.util.Collection) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)

Aggregations

FileReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)16 NotNull (org.jetbrains.annotations.NotNull)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 WebFacet (com.intellij.javaee.web.facet.WebFacet)3 TextRange (com.intellij.openapi.util.TextRange)3 FileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 ProcessingContext (com.intellij.util.ProcessingContext)3 ArrayList (java.util.ArrayList)3 FileType (com.intellij.openapi.fileTypes.FileType)2 Module (com.intellij.openapi.module.Module)2 Condition (com.intellij.openapi.util.Condition)2 com.intellij.psi (com.intellij.psi)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 GoGetPackageFix (com.goide.codeInsight.imports.GoGetPackageFix)1 GoDeleteImportQuickFix (com.goide.quickfix.GoDeleteImportQuickFix)1 RenameFileFix (com.intellij.codeInsight.daemon.impl.quickfix.RenameFileFix)1 CreateFileFix (com.intellij.codeInsight.daemon.quickFix.CreateFileFix)1