Couple<PsiElement> (@NotNull PyFromImportStatement statement) { final PsiElement fromKeyword = statement.getFirstChild(); assert fromKeyword.getNode().getElementType() == PyTokenTypes.FROM_KEYWORD; final PsiElement elementAfterFrom = PsiTreeUtil.skipWhitespacesForward(fromKeyword); if (elementAfterFrom == null) { return null; } else if (elementAfterFrom instanceof PyReferenceExpression) { return Couple.of(elementAfterFrom, elementAfterFrom); } else if (elementAfterFrom.getNode().getElementType() == PyTokenTypes.DOT) { PsiElement lastDot; PsiElement next = elementAfterFrom; do { lastDot = next; next = PsiTreeUtil.skipWhitespacesForward(next); } while (next != null && next.getNode().getElementType() == PyTokenTypes.DOT); if (next instanceof PyReferenceExpression) { return Couple.of(elementAfterFrom, next); } else { return Couple.of(elementAfterFrom, lastDot); } } return null; }