@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final int offset = editor.getCaretModel().getOffset(); final PsiElement element = file.findElementAt(offset); if (element == null || element instanceof PsiWhiteSpace) { return false; } final PsiReference reference = file.findReferenceAt(offset); final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference); if (fileReference != null) { final FileReferenceSet set = fileReference.getFileReferenceSet(); final FileReference lastReference = set.getLastReference(); return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null; } return false; }
@Override public boolean createReferences(@NotNull final PsiElement psiElement, final int offset, final String text, final @NotNull 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; }
@Nullable private PsiFileSystemItem doResolve(@NotNull final FileIncludeInfo info, @NotNull final PsiFile context) { if (info instanceof FileIncludeInfoImpl) { String id = ((FileIncludeInfoImpl)info).providerId; FileIncludeProvider provider = id == null ? null : myProviderMap.get(id); final PsiFileSystemItem resolvedByProvider = provider == null ? null : provider.resolveIncludedFile(info, context); if (resolvedByProvider != null) { return resolvedByProvider; } } PsiFileImpl psiFile = (PsiFileImpl)myPsiFileFactory.createFileFromText("dummy.txt", FileTypes.PLAIN_TEXT, info.path); psiFile.setOriginalFile(context); return new FileReferenceSet(psiFile) { @Override protected boolean useIncludingFileAsContext() { return false; } }.resolve(); }
private static PsiReference[] collectRefs(@NotNull PsiElement element, String value, final int startInElement, final FileType... acceptedFileTypes) { final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true){ @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem item) { if (item instanceof PsiDirectory) return true; final VirtualFile virtualFile = item.getVirtualFile(); if (virtualFile == null) return false; final FileType fileType = virtualFile.getFileType(); return ArrayUtilRt.find(acceptedFileTypes, fileType) >= 0; } }; } }; if (value.startsWith("/")) { set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); } return set.getAllReferences(); }
/** * Returns references for given @{link PsiElement}. * * @param psiElement current element * @param processingContext context * @return {@link PsiReference} list */ @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { if (psiElement instanceof LatexInstruction) { LatexInstructionExtImpl instruction = (LatexInstructionExtImpl) psiElement; String identifier = instruction.getIdentifier().getText(); if (Arrays.asList(IDENTIFIERS).contains(identifier)) { LatexArgument arg = instruction.getArgument(); if (arg != null && arg.getValue() != null) { return new FileReferenceSet(arg.getValue(), instruction, arg.getStartOffsetInParent() + 1, this, true).getAllReferences(); } } } return PsiReference.EMPTY_ARRAY; }
private static PsiReference[] collectRefs(PsiElement element, String value, final int startInElement, final FileType... acceptedFileTypes) { final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true){ @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem item) { if (item instanceof PsiDirectory) return true; final VirtualFile virtualFile = item.getVirtualFile(); if (virtualFile == null) return false; final FileType fileType = virtualFile.getFileType(); return ArrayUtilRt.find(acceptedFileTypes, fileType) >= 0; } }; } }; if (value.startsWith("/")) { set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); } return set.getAllReferences(); }
@Override public boolean createReferences(@Nonnull final PsiElement psiElement, final int offset, final String text, final @Nonnull 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; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { XmlAttributeValue xmlAttributeValue = (XmlAttributeValue) psiElement; ASTNode value = xmlAttributeValue.getNode().findChildByType(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN); if(value == null) { return PsiReference.EMPTY_ARRAY; } FileReferenceSet fileReferenceSet = new FileReferenceSet(value.getPsi()) { @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return item -> item instanceof XStyleSheetFile || item instanceof PsiDirectory; } }; fileReferenceSet.setEmptyPathAllowed(false); return fileReferenceSet.getAllReferences(); }
@Nullable public static XmlFile resolveXIncludeFile(XmlTag xincludeTag) { final XmlAttribute hrefAttribute = xincludeTag.getAttribute("href", null); if (hrefAttribute == null) return null; final XmlAttributeValue xmlAttributeValue = hrefAttribute.getValueElement(); if (xmlAttributeValue == null) return null; final FileReferenceSet referenceSet = FileReferenceSet.createSet(xmlAttributeValue, false, true, false); final PsiReference reference = referenceSet.getLastReference(); if (reference == null) return null; final PsiElement target = reference.resolve(); if (!(target instanceof XmlFile)) return null; return (XmlFile)target; }
@Override public PsiFile resolveFile() { final String includeText = getIncludeText(); if(includeText == null) { return null; } final FileReference[] references = new FileReferenceSet(includeText, this, 0, null, SystemInfo.isFileSystemCaseSensitive).getAllReferences(); if(references != null && references.length > 0) { final PsiElement element = references[references.length - 1].resolve(); if(element instanceof PsiFile) { return (PsiFile) element; } } return null; }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final int offset = editor.getCaretModel().getOffset(); final PsiElement element = file.findElementAt(offset); if(element == null || element instanceof PsiWhiteSpace) { return false; } final PsiReference reference = file.findReferenceAt(offset); final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference); if(fileReference != null) { final FileReferenceSet set = fileReference.getFileReferenceSet(); final FileReference lastReference = set.getLastReference(); return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null; } return false; }
@NotNull @Override @SuppressWarnings({ "SSBasedInspection" }) public PsiReference[] getReferences() { final ASTNode literal = getNode().findChildByType(RncTokenTypes.LITERAL); if (literal == null) return PsiReference.EMPTY_ARRAY; final String s = literal.getText(); final FileReferenceSet set = new FileReferenceSet(s.substring(1, s.length() - 1), this, getReferenceRange().getStartOffset(), null, true, false); return FileReferenceUtil.restrict(set, FileReferenceUtil.byType(RncFileType.getInstance())); }
@Override @NotNull public PsiReference[] createReferences(GenericDomValue<XmlFile> genericDomValue, PsiElement element, ConvertContext context) { final String s = genericDomValue.getStringValue(); if (s == null || element == null) { return PsiReference.EMPTY_ARRAY; } final FileReferenceSet set = FileReferenceSet.createSet(element, false, false, false); if (set != null) { return FileReferenceUtil.restrict(set, FileReferenceUtil.byNamespace(ApplicationLoader.RNG_NAMESPACE), true); } else { return PsiReference.EMPTY_ARRAY; } }
public static PsiReference[] restrict(FileReferenceSet set, final Condition<PsiFile> cond, final Boolean soft) { final FileReference[] references = set.getAllReferences(); return ContainerUtil.map2Array(references, PsiReference.class, new NotNullFunction<FileReference, PsiReference>() { @Override @NotNull public PsiReference fun(FileReference fileReference) { return new MyFileReference(fileReference, cond, soft); } }); }
@NotNull @Override public PsiReference[] getReferences(@NotNull PsiElement element, @NotNull ProcessingContext context, @NotNull TextRange range) { String text = range.substring(element.getText()); return new FileReferenceSet(text, element, range.getStartOffset(), null, true) { @Override protected boolean isSoft() { return true; } }.getAllReferences(); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { final TestDataReferenceSet referenceSet = new TestDataReferenceSet(element); referenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); return referenceSet.getAllReferences(); }
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.<PsiFileSystemItem>singletonList(directory); } @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem 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(); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull ProcessingContext context) { final FileReferenceSet set = new FileReferenceSet(((XmlAttributeValue)element).getValue(), element, 1, null, true); return set.getAllReferences(); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull ProcessingContext context) { final String value = ((XmlAttributeValue)element).getValue(); if (value.startsWith("@")) { return new FileReferenceSet(value.substring(1), element, 2, null, true).getAllReferences(); } else { if (mySupportCommaInValue && value.contains(",")) { int startIdx = 0; int endIdx = 0; List<PsiReference> refs = new ArrayList<PsiReference>(); while (true) { endIdx = value.indexOf(",", startIdx); Collections.addAll(refs, collectRefs(element, endIdx >= 0 ? value.substring(startIdx, endIdx) : value.substring(startIdx), startIdx + 1, myAcceptedFileTypes)); startIdx = endIdx + 1; if (endIdx < 0) { break; } } return refs.toArray(new PsiReference[refs.size()]); } else { return collectRefs(element, value, 1, myAcceptedFileTypes); } } }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset()); final FileReference fileReference = reference == null ? null : findFileReference(reference); if (fileReference != null) { final FileReferenceSet set = fileReference.getFileReferenceSet(); final FileReference lastReference = set.getLastReference(); return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null; } return false; }
@Nullable private PsiFileSystemItem doResolve(FileIncludeInfo info, PsiFile context) { PsiFileImpl psiFile = (PsiFileImpl)myPsiFileFactory.createFileFromText("dummy.txt", StdFileTypes.PLAIN_TEXT, info.path); psiFile.setOriginalFile(context); return new FileReferenceSet(psiFile) { @Override protected boolean useIncludingFileAsContext() { return false; } }.resolve(); }
@NotNull public PsiReference[] createReferences(GenericDomValue<XmlFile> genericDomValue, PsiElement element, ConvertContext context) { final String s = genericDomValue.getStringValue(); if (s == null || element == null) { return PsiReference.EMPTY_ARRAY; } final FileReferenceSet set = FileReferenceSet.createSet(element, false, false, false); if (set != null) { return FileReferenceUtil.restrict(set, FileReferenceUtil.byNamespace(ApplicationLoader.RNG_NAMESPACE), true); } else { return PsiReference.EMPTY_ARRAY; } }
public static PsiReference[] restrict(FileReferenceSet set, final Condition<PsiFile> cond, final Boolean soft) { final FileReference[] references = set.getAllReferences(); return ContainerUtil.map2Array(references, PsiReference.class, new NotNullFunction<FileReference, PsiReference>() { @NotNull public PsiReference fun(FileReference fileReference) { return new MyFileReference(fileReference, cond, soft); } }); }
public static PsiReference[] getReferences(final 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.<PsiFileSystemItem>singletonList(directory); } @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem 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(); }
@NotNull public PsiReference[] createReferences(GenericDomValue genericDomValue, PsiElement element, ConvertContext context) { final String text = genericDomValue.getStringValue(); if (text == null) { return PsiReference.EMPTY_ARRAY; } Project project = element.getProject(); final int offset = ElementManipulators.getOffsetInElement(element); final FileReferenceSet referenceSet = createReferenceSet(project, text, element, offset); return referenceSet.getAllReferences(); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { final FileReferenceSet fileReferenceSet = new FileReferenceSet(element) { @Override protected boolean isSoft() { return true; } }; return ArrayUtil.mergeArrays(fileReferenceSet.getAllReferences(), new PsiReference[] {new EmberJSTemplateCacheReference((JSLiteralExpression)element)}); }
@NotNull private static FileReferenceSet getReferenceSet(@NotNull ThriftInclude include) { final PsiElement element = include.getLastChild(); final String path = getPath(include); return new FileReferenceSet( path, include, element.getStartOffsetInParent() + 1, null, true, true, new FileType[]{ThriftFileType.INSTANCE} ); }
@NotNull @Override public PsiReference[] getReferences() { if (getMacroName().equals("image")) { ASTNode bodyNode = getNode().findChildByType(AsciiDocTokenTypes.BLOCK_MACRO_BODY); if (bodyNode != null) { return new FileReferenceSet(bodyNode.getText(), this, bodyNode.getStartOffset() - getTextRange().getStartOffset(), null, false).getAllReferences(); } } return super.getReferences(); }
@Nullable private PsiFileSystemItem doResolve(FileIncludeInfo info, PsiFile context) { PsiFileImpl psiFile = (PsiFileImpl)myPsiFileFactory.createFileFromText("dummy.txt", PlainTextFileType.INSTANCE, info.path); psiFile.setOriginalFile(context); return new FileReferenceSet(psiFile) { @Override protected boolean useIncludingFileAsContext() { return false; } }.resolve(); }