use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class InjectedReferenceSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, final int cursorOffset, Editor editor) {
PsiReference ref = e.findReferenceAt(cursorOffset - e.getTextRange().getStartOffset());
if (ref == null)
return Collections.emptyList();
JBIterable<PsiReference> it = ref instanceof PsiMultiReference ? JBIterable.of(((PsiMultiReference) ref).getReferences()) : JBIterable.of(ref);
return it.transform(ref1 -> {
TextRange base = ref1.getElement().getTextRange();
TextRange r = ref1.getRangeInElement().shiftRight(base.getStartOffset());
return r.containsOffset(cursorOffset) ? r : null;
}).filter(Conditions.notNull()).toList();
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-plugins by JetBrains.
the class FlexCssNavigationTest method findTargetElements.
@NotNull
private PsiElement[] findTargetElements(@NotNull String... filenames) throws Exception {
String[] fileNamesWithBasePath = new String[filenames.length];
for (int i = 0, filenamesLength = filenames.length; i < filenamesLength; i++) {
fileNamesWithBasePath[i] = BASE_PATH + filenames[i];
}
configureByFiles(null, fileNamesWithBasePath);
Collection<PsiElement> targets;
PsiReference reference = TargetElementUtil.findReference(myEditor);
if (reference == null) {
reference = JSTestUtils.findReferenceFromInjected(myEditor, myFile);
}
assertNotNull(reference);
if (reference instanceof PsiMultiReference) {
targets = new ArrayList<>();
for (PsiReference ref : ((PsiMultiReference) reference).getReferences()) {
targets.addAll(TargetElementUtil.getInstance().getTargetCandidates(ref));
}
} else {
targets = TargetElementUtil.getInstance().getTargetCandidates(reference);
}
assertTrue("Target elements not found", targets.size() > 0);
return PsiUtilCore.toPsiElementArray(targets);
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-plugins by JetBrains.
the class DartServerCompletionContributor method beforeCompletion.
@Override
public void beforeCompletion(@NotNull final CompletionInitializationContext context) {
final PsiElement psiElement = context.getFile().findElementAt(context.getStartOffset());
final PsiElement parent = psiElement != null ? psiElement.getParent() : null;
if (parent instanceof DartStringLiteralExpression) {
final PsiElement parentParent = parent.getParent();
if (parentParent instanceof DartUriElement) {
final Pair<String, TextRange> uriAndRange = ((DartUriElement) parentParent).getUriStringAndItsRange();
context.setReplacementOffset(parentParent.getTextRange().getStartOffset() + uriAndRange.second.getEndOffset());
} else {
// If replacement context is not set explicitly then com.intellij.codeInsight.completion.CompletionProgressIndicator#duringCompletion
// implementation looks for the reference at caret and on Tab replaces the whole reference.
// angular_analyzer_plugin provides angular-specific completion inside Dart string literals. Without the following hack Tab replaces
// too much useful text. This hack is not ideal though as it may leave a piece of tail not replaced.
// TODO: use replacementLength received from the server
context.setReplacementOffset(context.getReplacementOffset());
}
} else {
PsiReference reference = context.getFile().findReferenceAt(context.getStartOffset());
if (reference instanceof PsiMultiReference && ((PsiMultiReference) reference).getReferences().length > 0) {
// to ensure that references are sorted by range
reference.getRangeInElement();
reference = ((PsiMultiReference) reference).getReferences()[0];
}
if (reference instanceof DartNewExpression) {
// historically DartNewExpression is a reference; it can appear here only in situation like new Foo(o.<caret>);
// without the following hack closing paren is replaced on Tab. We won't get here if at least one symbol after dot typed.
context.setReplacementOffset(context.getStartOffset());
}
}
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project WebStormRequireJsPlugin by Fedott.
the class RequirejsTestCase method assertReference.
protected void assertReference(PsiReference reference, String expectedText, String expectedFileName) {
assertNotNull("wrong cursor position", reference);
if (reference instanceof PsiMultiReference) {
for (PsiReference ref : ((PsiMultiReference) reference).getReferences()) {
if (ref instanceof RequirejsReference) {
reference = ref;
break;
}
}
}
if (!expectedText.startsWith("'")) {
expectedText = "'".concat(expectedText).concat("'");
}
assertInstanceOf(reference, RequirejsReference.class);
assertEquals(expectedText, reference.getCanonicalText());
PsiElement referenceElement = reference.resolve();
if (null == expectedFileName) {
assertNull(referenceElement);
} else {
assertNotNull("Not resolved", referenceElement);
assertInstanceOf(referenceElement, PsiFile.class);
assertEquals(expectedFileName, ((PsiFile) referenceElement).getName());
}
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class JavaFxEventHandlerReferenceProvider method getReferencesByElement.
@Override
protected PsiReference[] getReferencesByElement(@NotNull PsiClass controllerClass, XmlAttributeValue xmlAttributeValue, ProcessingContext context) {
final String attValueString = xmlAttributeValue.getValue();
LOG.assertTrue(attValueString.startsWith("#"));
final XmlAttribute attribute = (XmlAttribute) xmlAttributeValue.getParent();
if (attribute == null || !JavaFxPsiUtil.isEventHandlerProperty(attribute))
return PsiReference.EMPTY_ARRAY;
final String eventHandlerName = attValueString.substring(1);
final PsiMethod[] methods = controllerClass.findMethodsByName(eventHandlerName, true);
final PsiReference[] references = Arrays.stream(methods).filter(psiMethod -> JavaFxEventHandlerReference.isHandlerMethodSignature(psiMethod, controllerClass)).map(psiMethod -> new JavaFxEventHandlerReference(xmlAttributeValue, psiMethod, controllerClass)).toArray(PsiReference.ARRAY_FACTORY::create);
if (references.length == 1) {
return references;
}
if (references.length > 1) {
return new PsiReference[] { new PsiMultiReference(references, xmlAttributeValue) };
}
if (references.length == 0) {
final XmlTag rootTag = ((XmlFile) xmlAttributeValue.getContainingFile()).getRootTag();
if (rootTag == null || FxmlConstants.FX_ROOT.equals(rootTag.getName())) {
return PsiReference.EMPTY_ARRAY;
}
}
return new PsiReference[] { new JavaFxEventHandlerReference(xmlAttributeValue, null, controllerClass) };
}
Aggregations