use of com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet in project intellij-community by JetBrains.
the class MavenPathReferenceConverter method createReferences.
public static PsiReference[] createReferences(final DomElement genericDomValue, PsiElement element, @NotNull final Condition<PsiFileSystemItem> fileFilter, boolean isAbsolutePath) {
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange range = manipulator.getRangeInElement(element);
String text = range.substring(element.getText());
FileReferenceSet set = new FileReferenceSet(text, element, range.getStartOffset(), null, SystemInfo.isFileSystemCaseSensitive, false) {
private MavenDomProjectModel model;
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return fileFilter;
}
@Override
protected boolean isSoft() {
return true;
}
@Override
public FileReference createFileReference(TextRange range, int index, String text) {
return new FileReference(this, range, index, text) {
@Override
protected void innerResolveInContext(@NotNull String text, @NotNull PsiFileSystemItem context, Collection<ResolveResult> result, boolean caseSensitive) {
if (model == null) {
DomElement rootElement = DomUtil.getFileElement(genericDomValue).getRootElement();
if (rootElement instanceof MavenDomProjectModel) {
model = (MavenDomProjectModel) rootElement;
}
}
String resolvedText = model == null ? text : MavenPropertyResolver.resolve(text, model);
if (resolvedText.equals(text)) {
if (getIndex() == 0 && resolvedText.length() == 2 && resolvedText.charAt(1) == ':') {
// it's root on windows, e.g. "C:"
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(resolvedText + '/');
if (file != null) {
PsiDirectory psiDirectory = context.getManager().findDirectory(file);
if (psiDirectory != null) {
result.add(new PsiElementResolveResult(psiDirectory));
}
}
} else {
super.innerResolveInContext(resolvedText, context, result, caseSensitive);
}
} else {
VirtualFile contextFile = context.getVirtualFile();
if (contextFile == null)
return;
VirtualFile file = null;
if (getIndex() == 0) {
file = LocalFileSystem.getInstance().findFileByPath(resolvedText);
}
if (file == null) {
file = LocalFileSystem.getInstance().findFileByPath(contextFile.getPath() + '/' + resolvedText);
}
if (file != null) {
PsiFileSystemItem res = file.isDirectory() ? context.getManager().findDirectory(file) : context.getManager().findFile(file);
if (res != null) {
result.add(new PsiElementResolveResult(res));
}
}
}
}
};
}
};
if (isAbsolutePath) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, file -> {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return FileReferenceSet.ABSOLUTE_TOP_LEVEL.fun(file);
}
virtualFile = VfsUtil.getRootFile(virtualFile);
PsiDirectory root = file.getManager().findDirectory(virtualFile);
if (root == null) {
return FileReferenceSet.ABSOLUTE_TOP_LEVEL.fun(file);
}
return Collections.<PsiFileSystemItem>singletonList(root);
});
}
return set.getAllReferences();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet in project intellij-community by JetBrains.
the class RngHrefConverter method createReferences.
@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;
}
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet in project intellij-community by JetBrains.
the class RncFileReferenceImpl method getReferences.
@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()));
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet in project intellij-community by JetBrains.
the class JavaFxLocationReferenceProvider method collectRefs.
private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
final int atSignIndex = value.indexOf('@');
if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
value = value.substring(atSignIndex + 1);
startInElement += atSignIndex + 1;
}
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = item.getVirtualFile();
if (virtualFile == null)
return false;
final FileType fileType = virtualFile.getFileType();
return myAcceptedFileTypes.contains(fileType);
};
}
};
if (value.startsWith("/")) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return set.getAllReferences();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet in project intellij-community by JetBrains.
the class FileIncludeManagerImpl method doResolve.
@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();
}
Aggregations