PsiFile (@NotNull PsiMember member, @NotNull TextRange memberRange) { PsiFile file = member.getContainingFile(); CharSequence contents = file.getViewProvider().getContents(); if (memberRange.getEndOffset() > contents.length()) { StubTextInconsistencyException.checkStubTextConsistency(file); throw new RuntimeExceptionWithAttachments( "Range from the index " + memberRange + " exceeds the actual file length " + contents.length() + ", file will be reindexed", new Attachment(file.getVirtualFile().getPath(), contents.toString())); } String contextText = memberRange.subSequence(contents).toString(); Project project = file.getProject(); return member instanceof PsiEnumConstant ? PsiElementFactory.getInstance(project).createEnumConstantFromText(contextText, member).getContainingFile() : JavaCodeFragmentFactory.getInstance(project).createMemberCodeFragment(contextText, member, false); }