use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class DocStringReferenceProvider method referencesFromFields.
@NotNull
private static List<PsiReference> referencesFromFields(@NotNull PyStringLiteralExpression element, int offset, @NotNull List<SectionBasedDocString.SectionField> fields, @Nullable ReferenceType nameRefType) {
final List<PsiReference> result = new ArrayList<>();
for (SectionBasedDocString.SectionField field : fields) {
for (Substring nameSub : field.getNamesAsSubstrings()) {
if (nameRefType != null && nameSub != null && !nameSub.isEmpty()) {
final TextRange range = nameSub.getTextRange().shiftRight(offset);
result.add(new DocStringParameterReference(element, range, nameRefType));
}
}
final Substring typeSub = field.getTypeAsSubstring();
if (typeSub != null && !typeSub.isEmpty()) {
result.addAll(parseTypeReferences(element, typeSub, offset));
}
}
return result;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class SchemaPrefixRenameHandler method getReference.
@Nullable
private static PossiblePrefixReference getReference(PsiFile file, Editor editor) {
if (file != null && editor != null) {
int offset = editor.getCaretModel().getOffset();
PsiReference reference = file.findReferenceAt(offset);
if (reference instanceof PossiblePrefixReference) {
return (PossiblePrefixReference) reference;
}
}
return null;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class XmlTagRenameDialog method completeVariable.
private void completeVariable(final Editor editor) {
String prefix = myNameSuggestionsField.getEnteredName();
final PsiReference reference = myTag.getReference();
if (reference instanceof TagNameReference) {
LookupElement[] lookupItems = TagNameReferenceCompletionProvider.getTagNameVariants(myTag, myTag.getNamespacePrefix());
editor.getCaretModel().moveToOffset(prefix.length());
editor.getSelectionModel().removeSelection();
LookupManager.getInstance(getProject()).showLookup(editor, lookupItems, prefix);
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class PrefixReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final XmlAttributeValue value = (XmlAttributeValue) element;
final String s = value.getValue();
final int i = s.indexOf(':');
if (i <= 0 || s.startsWith("xml:")) {
return PsiReference.EMPTY_ARRAY;
}
return new PsiReference[] { new PrefixReference(value, i) };
}
use of com.intellij.psi.PsiReference in project smali by JesusFreke.
the class FindUsagesTest method doTest.
protected void doTest() {
PsiReference reference = null;
PsiElement targetElement = null;
for (TestFile testFile : testFiles) {
int refIndex = testFile.getRefIndex();
if (refIndex != -1) {
PsiElement element = testFile.psiFile.findElementAt(refIndex);
UsageTarget[] targets = UsageTargetUtil.findUsageTargets(element);
if (targets != null) {
for (UsageTarget target : targets) {
if (target instanceof PsiElementUsageTarget) {
targetElement = ((PsiElementUsageTarget) target).getElement();
break;
}
}
}
if (targetElement == null) {
reference = testFile.psiFile.findReferenceAt(refIndex);
if (reference != null) {
targetElement = reference.resolve();
} else {
targetElement = TargetElementUtilBase.getInstance().getNamedElement(testFile.psiFile.findElementAt(refIndex), 0);
}
}
break;
}
}
Assert.assertNotNull(targetElement);
Collection<UsageInfo> usages = findUsages(targetElement);
for (TestFile testFile : testFiles) {
assertUsages(testFile, usages);
}
}
Aggregations