Java Code Examples for com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference

The following examples show how to use com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   Source File: FileReferenceContextUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static PsiElement bindElement(final PsiElement element, PsiFileSystemItem item) {
  if (item != null && item.isValid() && item.getVirtualFile() != null) {
    PsiReference[] refs = element.getReferences();
    for (PsiReference ref : refs) {
      if (ref instanceof FileReferenceOwner) {
        final PsiFileReference fileReference = ((FileReferenceOwner)refs[0]).getLastFileReference();
        if (fileReference != null) {
          try {
            PsiElement newElement = fileReference.bindToElement(item);
            if (newElement != null) {
              // assertion for troubles like IDEA-59540
              LOG.assertTrue(element.getClass() == newElement.getClass(), "Reference " + ref + " violated contract of bindToElement()");
            }
            return newElement;
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
        break;
      }
    }
  }
  return element;
}
 
Example 2
Source Project: consulo   Source File: PsiDynaReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PsiFileReference getLastFileReference() {
  for (PsiReference reference : myReferences) {
    if (reference instanceof FileReferenceOwner) {
      return ((FileReferenceOwner)reference).getLastFileReference();
    }
  }
  return null;
}
 
Example 3
@Nullable
@Override
public PsiFileReference getLastFileReference() {
	return this;
}