PsiElement (int startOffset, int endOffset, @NotNull PsiFile file) { for (PsiElement element = file.findElementAt(startOffset); element != null; element = element.getParent()) { TextRange range = element.getTextRange(); if (range.getStartOffset() < startOffset) { return null; } if (range.getStartOffset() == startOffset && range.getEndOffset() == endOffset) { return element; } } return null; }