use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class DelimitedListConverter method createReferences.
@Override
@NotNull
public PsiReference[] createReferences(final GenericDomValue<List<T>> genericDomValue, final PsiElement element, final ConvertContext context) {
final String text = genericDomValue.getRawText();
if (text == null) {
return PsiReference.EMPTY_ARRAY;
}
final ArrayList<PsiReference> references = new ArrayList<>();
new DelimitedListProcessor(myDelimiters) {
@Override
protected void processToken(final int start, final int end, final boolean delimitersOnly) {
references.add(createPsiReference(element, start + 1, end + 1, context, genericDomValue, delimitersOnly));
}
}.processText(text);
return references.toArray(new PsiReference[references.size()]);
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class DomHardCoreTestCase method assertReference.
protected PsiReference assertReference(final GenericDomValue value, PsiElement resolveTo, int offset) {
final XmlTag tag = value.getXmlTag();
final PsiReference reference = tag.getContainingFile().findReferenceAt(offset);
assertNotNull(reference);
reference.getVariants();
assertEquals(resolveTo, reference.resolve());
return reference;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class DomHardCoreTestCase method getReference.
protected PsiReference getReference(final GenericAttributeValue value) {
final XmlAttributeValue attributeValue = value.getXmlAttributeValue();
assertNotNull(attributeValue);
final PsiReference reference = attributeValue.getContainingFile().findReferenceAt(attributeValue.getTextRange().getStartOffset() + 1);
assertNotNull(reference);
assertEquals(attributeValue, reference.resolve());
return reference;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class ImportOnDemandIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
if (!(element instanceof GrReferenceElement))
return;
final GrReferenceElement ref = (GrReferenceElement) element;
final PsiElement resolved = ref.resolve();
if (!(resolved instanceof PsiClass))
return;
final String qname = ((PsiClass) resolved).getQualifiedName();
final GrImportStatement importStatement = GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);
final PsiFile containingFile = element.getContainingFile();
if (!(containingFile instanceof GroovyFile))
return;
((GroovyFile) containingFile).addImport(importStatement);
for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
final PsiElement refElement = reference.getElement();
if (refElement == null)
continue;
final PsiElement parent = refElement.getParent();
if (parent instanceof GrQualifiedReference<?>) {
org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>) parent);
}
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class ImportReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (element instanceof XmlProcessingInstruction) {
final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
if (importNode != null) {
final PsiElement importInstr = importNode.getPsi();
final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction) element);
if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
final PsiReference[] references = FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
if (instructionTarget.endsWith(".*")) {
return ArrayUtil.remove(references, references.length - 1);
} else {
return references;
}
}
}
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations