use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class MavenDomTestCase method assertNoReferences.
protected void assertNoReferences(VirtualFile file, Class refClass) throws IOException {
PsiReference ref = getReferenceAtCaret(file);
if (ref == null)
return;
PsiReference[] refs = ref instanceof PsiMultiReference ? ((PsiMultiReference) ref).getReferences() : new PsiReference[] { ref };
for (PsiReference each : refs) {
assertFalse(each.toString(), refClass.isInstance(each));
}
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class PyBaseElementImpl method findReferenceAt.
/**
* Overrides the findReferenceAt() logic in order to provide a resolve context with origin file for returned references.
* The findReferenceAt() is usually invoked from UI operations, and it helps to be able to do deeper analysis in the
* current file for such operations.
*
* @param offset the offset to find the reference at
* @return the reference or null.
*/
@Override
public PsiReference findReferenceAt(int offset) {
// copy/paste from SharedPsiElementImplUtil
PsiElement element = findElementAt(offset);
if (element == null || element instanceof OuterLanguageElement)
return null;
offset = getTextRange().getStartOffset() + offset - element.getTextRange().getStartOffset();
List<PsiReference> referencesList = new ArrayList<>();
final PsiFile file = element.getContainingFile();
final PyResolveContext resolveContext = file != null ? PyResolveContext.defaultContext().withTypeEvalContext(TypeEvalContext.codeAnalysis(file.getProject(), file)) : PyResolveContext.defaultContext();
while (element != null) {
addReferences(offset, element, referencesList, resolveContext);
offset = element.getStartOffsetInParent() + offset;
if (element instanceof PsiFile)
break;
element = element.getParent();
}
if (referencesList.isEmpty())
return null;
if (referencesList.size() == 1)
return referencesList.get(0);
return new PsiMultiReference(referencesList.toArray(new PsiReference[referencesList.size()]), referencesList.get(referencesList.size() - 1).getElement());
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class JavaFxPropertyRenameHandler method getReferences.
@NotNull
private static PsiReference[] getReferences(DataContext dataContext) {
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (file == null && editor != null && ApplicationManager.getApplication().isUnitTestMode()) {
final Project project = editor.getProject();
if (project != null) {
file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
}
}
if (editor != null && file instanceof XmlFile && JavaFxFileTypeFactory.isFxml(file)) {
final int offset = editor.getCaretModel().getOffset();
final PsiReference reference = file.findReferenceAt(offset);
if (reference instanceof PsiMultiReference) {
return ((PsiMultiReference) reference).getReferences();
}
if (isKnown(reference))
return new PsiReference[] { reference };
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project intellij-community by JetBrains.
the class XmlLocationCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiReference reference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
if (reference instanceof URLReference) {
if (((URLReference) reference).isSchemaLocation()) {
Object[] objects = completeSchemaLocation(reference.getElement());
result.addAllElements(ContainerUtil.map(objects, MAPPING));
return;
}
Object[] objects = completeNamespace(reference.getElement());
result.addAllElements(ContainerUtil.map(objects, MAPPING));
return;
}
if (reference instanceof PsiMultiReference)
reference = ((PsiMultiReference) reference).getReferences()[0];
if (reference instanceof DependentNSReference) {
MultiMap<String, String> map = ExternalResourceManagerEx.getInstanceEx().getUrlsByNamespace(parameters.getOriginalFile().getProject());
String namespace = ((DependentNSReference) reference).getNamespaceReference().getCanonicalText();
Collection<String> strings = map.get(namespace);
for (String string : strings) {
if (!namespace.equals(string)) {
// exclude namespaces from location urls
result.consume(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(string), 100));
}
}
if (!strings.isEmpty())
result.stopHere();
}
}
use of com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference in project WebStormRequireJsPlugin by Fedott.
the class ReferenceTest method testReference.
public void testReference() {
PsiReference reference;
PsiElement referenceElement;
// referenceNotFound
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'app/as'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// referenceTrue
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 40));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// referenceNotFound2
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 40));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof PsiMultiReference);
reference = ((PsiMultiReference) reference).getReferences()[1];
assertEquals("'bl'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// referenceDirectory
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 40));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'blocks/childBlocks'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertNull(referenceElement);
// referenceWithTwoDot
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 46));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'../blocks/block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// referenceWithTwoDotTwoDir
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 49));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'../blocks/childBlocks/childBlock'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
// referenceWithOneDot
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 44));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'./block'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("block.js", ((JSFile) referenceElement).getName());
// referenceWithOneDotTwoDir
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(8, 50));
reference = myFixture.getReferenceAtCaretPosition();
assertTrue(reference instanceof RequirejsReference);
assertEquals("'./childBlocks/childBlock'", reference.getCanonicalText());
referenceElement = reference.resolve();
assertTrue(referenceElement instanceof JSFile);
assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
}
Aggregations