Esempio n. 1
0
    public int hashCode() {
      int result = myInfo.hashCode();
      result = 31 * result + myStartOffset;
      result = 31 * result + myEndOffset;
      result = 31 * result + myVirtualFile.hashCode();

      return result;
    }
Esempio n. 2
0
    public boolean equals(Object o) {
      if (this == o) return true;
      if (!(o instanceof TreeRangeReference)) return false;

      final TreeRangeReference that = (TreeRangeReference) o;

      return myEndOffset == that.myEndOffset
          && myStartOffset == that.myStartOffset
          && myInfo.equals(that.myInfo)
          && myVirtualFile.equals(that.myVirtualFile);
    }
Esempio n. 3
0
  @NotNull
  private static PsiAnchor doCreateAnchor(@NotNull PsiElement element) {
    if (element instanceof PsiFile) {
      VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
      if (virtualFile != null) return new PsiFileReference(virtualFile, (PsiFile) element);
      return new HardReference(element);
    }
    if (element instanceof PsiDirectory) {
      VirtualFile virtualFile = ((PsiDirectory) element).getVirtualFile();
      return new PsiDirectoryReference(virtualFile, element.getProject());
    }

    PsiFile file = element.getContainingFile();
    if (file == null) {
      return new HardReference(element);
    }
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) return new HardReference(element);

    PsiAnchor stubRef = createStubReference(element, file);
    if (stubRef != null) return stubRef;

    if (!element.isPhysical()) {
      return wrapperOrHardReference(element);
    }

    TextRange textRange = element.getTextRange();
    if (textRange == null) {
      return wrapperOrHardReference(element);
    }

    Language lang = null;
    final FileViewProvider viewProvider = file.getViewProvider();
    for (Language l : viewProvider.getLanguages()) {
      if (viewProvider.getPsi(l) == file) {
        lang = l;
        break;
      }
    }

    if (lang == null) {
      return wrapperOrHardReference(element);
    }

    return new TreeRangeReference(
        file,
        textRange.getStartOffset(),
        textRange.getEndOffset(),
        AnchorTypeInfo.obtainInfo(element, lang),
        virtualFile);
  }
Esempio n. 4
0
 @Override
 @Nullable
 public PsiFile getFile() {
   return SelfElementInfo.restoreFileFromVirtual(
       myVirtualFile, myProject, myInfo.getFileLanguage());
 }