本文整理汇总了Java中com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference类的典型用法代码示例。如果您正苦于以下问题:Java PsiMultiReference类的具体用法?Java PsiMultiReference怎么用?Java PsiMultiReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiMultiReference类属于com.intellij.psi.impl.source.resolve.reference.impl包,在下文中一共展示了PsiMultiReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findFileReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
public static FileReference findFileReference(@NotNull final PsiReference original) {
if (original instanceof PsiMultiReference) {
final PsiMultiReference multiReference = (PsiMultiReference)original;
for (PsiReference reference : multiReference.getReferences()) {
if (reference instanceof FileReference) {
return (FileReference)reference;
}
}
}
else if (original instanceof FileReferenceOwner) {
final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
if (fileReference instanceof FileReference) {
return (FileReference)fileReference;
}
}
return null;
}
示例2: findReferenceAt
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
public static PsiReference findReferenceAt(PsiElement thisElement, int offset, @Nullable Language lang) {
if (thisElement == null) return null;
PsiElement element = lang != null ? thisElement.getContainingFile().getViewProvider().findElementAt(offset, lang) :
thisElement.findElementAt(offset);
if (element == null || element instanceof OuterLanguageElement) return null;
offset = thisElement.getTextRange().getStartOffset() + offset - element.getTextRange().getStartOffset();
List<PsiReference> referencesList = new ArrayList<PsiReference>();
while (element != null) {
addReferences(offset, element, referencesList);
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());
}
示例3: getReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
private static Pair<FileReference, Boolean> getReference(final PsiReference original) {
if (original == null) {
return null;
}
if (original instanceof PsiMultiReference) {
final PsiMultiReference multiReference = (PsiMultiReference)original;
for (PsiReference reference : multiReference.getReferences()) {
if (reference instanceof FileReference) {
return Pair.create((FileReference) reference, false);
}
}
}
else if (original instanceof FileReferenceOwner) {
final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
if (fileReference instanceof FileReference) {
return Pair.create((FileReference) fileReference, true);
}
}
return null;
}
示例4: addReferenceAtCaret
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
protected void addReferenceAtCaret(Collection<PsiReference> refs) {
PsiFile myEditorFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
// Note, that myEditorFile can be different from myElement.getContainingFile() e.g. in injections: myElement declaration in one
// file / usage in another !
final PsiReference reference = (myEditorFile != null ?
myEditorFile : myElementToRename.getContainingFile())
.findReferenceAt(myEditor.getCaretModel().getOffset());
if (reference instanceof PsiMultiReference) {
final PsiReference[] references = ((PsiMultiReference)reference).getReferences();
for (PsiReference ref : references) {
addReferenceIfNeeded(refs, ref);
}
}
else {
addReferenceIfNeeded(refs, reference);
}
}
示例5: findReferenceAt
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
/**
* 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<PsiReference>();
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());
}
示例6: findFileReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
private static FileReference findFileReference(@NotNull final PsiReference original) {
if (original instanceof PsiMultiReference) {
final PsiMultiReference multiReference = (PsiMultiReference)original;
for (PsiReference reference : multiReference.getReferences()) {
if (reference instanceof FileReference) {
return (FileReference)reference;
}
}
}
else if (original instanceof FileReferenceOwner) {
final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
if (fileReference instanceof FileReference) {
return (FileReference)fileReference;
}
}
return null;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java
示例7: assertReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
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());
}
}
示例8: findFileReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
public static FileReference findFileReference(@Nonnull final PsiReference original) {
if (original instanceof PsiMultiReference) {
final PsiMultiReference multiReference = (PsiMultiReference)original;
for (PsiReference reference : multiReference.getReferences()) {
if (reference instanceof FileReference) {
return (FileReference)reference;
}
}
}
else if (original instanceof FileReferenceOwner) {
final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
if (fileReference instanceof FileReference) {
return (FileReference)fileReference;
}
}
return null;
}
示例9: findReferenceAt
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
@RequiredReadAction
public static PsiReference findReferenceAt(PsiElement thisElement, int offset, @Nullable Language lang) {
if (thisElement == null) return null;
PsiElement element = lang != null ? thisElement.getContainingFile().getViewProvider().findElementAt(offset, lang) :
thisElement.findElementAt(offset);
if (element == null || element instanceof OuterLanguageElement) return null;
offset = thisElement.getTextRange().getStartOffset() + offset - element.getTextRange().getStartOffset();
List<PsiReference> referencesList = new ArrayList<PsiReference>();
while (element != null) {
addReferences(offset, element, referencesList);
if (element instanceof PsiFile) break;
if (element instanceof HintedReferenceHost &&
!((HintedReferenceHost)element).shouldAskParentForReferences(new PsiReferenceService.Hints(null, offset))) {
break;
}
offset = element.getStartOffsetInParent() + offset;
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());
}
示例10: findJavaReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
private static PsiJavaReference findJavaReference(final PsiFile file, final int offset)
{
PsiReference reference = file.findReferenceAt(offset);
if(reference instanceof PsiMultiReference)
{
for(final PsiReference psiReference : ((PsiMultiReference) reference).getReferences())
{
if(psiReference instanceof PsiJavaReference)
{
return (PsiJavaReference) psiReference;
}
}
}
return reference instanceof PsiJavaReference ? (PsiJavaReference) reference : null;
}
示例11: findJavaReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
private static PsiJavaReference findJavaReference(final PsiFile file, final int offset) {
PsiReference reference = file.findReferenceAt(offset);
if (reference instanceof PsiMultiReference) {
for (final PsiReference psiReference : ((PsiMultiReference)reference).getReferences()) {
if (psiReference instanceof PsiJavaReference) {
return (PsiJavaReference)psiReference;
}
}
}
return reference instanceof PsiJavaReference ? (PsiJavaReference)reference : null;
}
示例12: findJavaClassReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
public static JavaClassReference findJavaClassReference(final PsiFile file, final int offset) {
PsiReference reference = file.findReferenceAt(offset);
if (reference instanceof PsiMultiReference) {
for (final PsiReference psiReference : ((PsiMultiReference)reference).getReferences()) {
if (psiReference instanceof JavaClassReference) {
return (JavaClassReference)psiReference;
}
}
}
return reference instanceof JavaClassReference ? (JavaClassReference)reference : null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:JavaClassReferenceCompletionContributor.java
示例13: getReferences
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
protected static PsiReference[] getReferences(final PsiMultiReference multiReference) {
final PsiReference[] references = multiReference.getReferences();
final List<PsiReference> hard = ContainerUtil.findAll(references, new Condition<PsiReference>() {
@Override
public boolean value(final PsiReference object) {
return !object.isSoft();
}
});
if (!hard.isEmpty()) {
return hard.toArray(new PsiReference[hard.size()]);
}
return references;
}
示例14: assertNoReferences
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
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));
}
}
示例15: getReference
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; //导入依赖的package包/类
@Nullable
@Override
public PsiReference getReference() {
final PsiReference[] references = getReferences();
if (references.length == 1) {
return references[0];
}
if (references.length > 1) {
return new PsiMultiReference(references, this);
}
return null;
}