@Override public void visitElement(@NotNull PsiElement o) { for (PsiReference reference : o.getReferences()) { reference.resolve(); } } });
@Nullable public PsiReference getReference(PsiElement element) { if (element != null && element.isValid()) { for (PsiReference reference : element.getReferences()) { if (isSupportedReference(reference)) { return reference; } } } return null; }
@Override public void visitElement(@NotNull PsiElement o) { for (PsiReference reference : o.getReferences()) { reference.resolve(); } super.visitElement(o); } });
@Override public boolean autoImportReferenceAtCursor(@NotNull Editor editor, @NotNull PsiFile file) { if (!file.getViewProvider().getLanguages().contains(GoLanguage.INSTANCE) || !DaemonListeners.canChangeFileSilently(file)) { return false; } int caretOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); int lineNumber = document.getLineNumber(caretOffset); int startOffset = document.getLineStartOffset(lineNumber); int endOffset = document.getLineEndOffset(lineNumber); List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffset); for (PsiElement element : elements) { if (element instanceof GoCompositeElement) { for (PsiReference reference : element.getReferences()) { GoImportPackageQuickFix fix = new GoImportPackageQuickFix(reference); if (fix.doAutoImportOrShowHint(editor, false)) { return true; } } } } return false; }
private void assertReferences(@NotNull ElementPattern<?> pattern, PsiElement psiElement) { for (PsiReference reference : psiElement.getReferences()) { // single resolve; should also match first multi by design PsiElement element = reference.resolve(); if (pattern.accepts(element)) { return; } // multiResolve support if(reference instanceof PsiPolyVariantReference) { for (ResolveResult resolveResult : ((PsiPolyVariantReference) reference).multiResolve(true)) { if (pattern.accepts(resolveResult.getElement())) { return; } } } } fail(String.format("Fail that '%s' match given pattern", psiElement.toString())); }
@NotNull @Override public PsiReference[] getReferences() { return getDelegate().getReferences(); }
private void doTest(final String fileName, final String referencedValue) { myFixture.configureByFile("reference/" + fileName); PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); final PsiElement target = element.getReferences()[0].resolve(); Assert.assertNotNull(target); Assert.assertEquals(referencedValue, target.getText()); }
/** * Processing all targets of all references of all elements * * @param processor processor * @param elements references sources * @return processor result */ @SuppressWarnings("UnusedReturnValue") public static boolean processElementReferencesResolveResults(@NotNull Processor<Pair<PsiElement, PsiReference>> processor, PsiElement... elements) { if (elements == null || elements.length == 0) { return true; } for (PsiElement element : elements) { if (!processResolveElements(processor, element.getReferences())) { return false; } } return true; }
@Nullable private static BnfRule resolveRule(@Nullable PsiElement o) { if (!(o instanceof BnfReferenceOrToken || o instanceof BnfStringLiteralExpression)) return null; PsiReference reference = ContainerUtil.findInstance(o.getReferences(), BnfReferenceImpl.class); PsiElement target = reference != null ? reference.resolve() : null; return target instanceof BnfRule ? (BnfRule)target : null; } }
@Override public void visitElement(PsiElement element) { Collections.addAll(references, element.getReferences()); element.acceptChildren(this); } });
@Override public void visitTargetableSection(PodTitledSection o) { PsiElement titleBlock = o.getTitleBlock(); if (titleBlock != null) { PsiElement firstChild = titleBlock.getFirstChild(); if (firstChild != null) { for (PsiReference reference : firstChild.getReferences()) { if (reference instanceof PodSubReference) { for (ResolveResult resolveResult : ((PodSubReference)reference).multiResolve(false)) { PsiElement targetElement = resolveResult.getElement(); if (targetElement instanceof PerlSubElement) { possibleTargets.remove(targetElement); } } } } } } super.visitTargetableSection(o); } });
ContainerUtil.addAll(stack, child.getChildren()); for (final PsiReference reference : child.getReferences()) { if (!(reference instanceof PsiJavaReference)) continue; final PsiJavaReference javaReference = (PsiJavaReference) reference;
for (PsiReference reference : sourceElement.getReferences()) { if (reference.getRangeInElement().contains(offsetInElement)) { if (reference instanceof PsiPolyVariantReference) {
PsiReference[] references = parent.getReferences(); for (PsiReference reference : references) { TextRange refRange = reference.getRangeInElement();
private void checkReferenceToField(String typeReference, String fieldName, String... file) { myFixture.configureByFiles(file); ProtoPsiFileRoot proto = (ProtoPsiFileRoot) myFixture.getFile(); PsiElement elementAtCaret = proto .findElementAt(myFixture.getCaretOffset()); while (elementAtCaret != null && elementAtCaret.getReferences().length == 0) { elementAtCaret = elementAtCaret.getParent(); } assertNotNull(elementAtCaret); PsiElement target = elementAtCaret.getReferences()[0].resolve(); Assert.assertTrue(String.valueOf(target), target instanceof FieldNode); FieldNode field = (FieldNode) target; Assert.assertEquals(fieldName, field.getFieldName()); Assert.assertEquals(typeReference, ((DataType) field.getParent()).getQualifiedName()); } }
KnownAttribute attribute = KnownAttribute.getCompatibleAttribute(attrName); if (attribute != null) { BnfReferenceImpl reference = ContainerUtil.findInstance(psiElement.getReferences(), BnfReferenceImpl.class); PsiElement resolve = reference == null ? null : reference.resolve(); if (resolve instanceof BnfRule) {