下面列出了怎么用com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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;
}
@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;
}
@Nullable
private PsiFileSystemItem doResolve(@Nonnull final FileIncludeInfo info, @Nonnull 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", PlainTextFileType.INSTANCE, info.path);
psiFile.setOriginalFile(context);
return new FileReferenceSet(psiFile) {
@Override
protected boolean useIncludingFileAsContext() {
return false;
}
}.resolve();
}
@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
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
String text,
int offset) {
return new FileReferenceSet(text, element, offset, this, true, myEndingSlashNotAllowed).getAllReferences();
}
/**
* Builds an instance of {@link IgnoreReferenceSet.IgnoreReference}.
*/
public IgnoreReference(@NotNull FileReferenceSet fileReferenceSet, TextRange range, int index, String text) {
super(fileReferenceSet, range, index, text);
cacheMap = ContainerUtil.newConcurrentMap();
}