public static PsiElement getChild( final PsiElement parent, int position, boolean ignoreWhiteSpaces, boolean ignoreComments, boolean ignoreErrors) { PsiElement curChild = parent.getFirstChild(); int i = 0; while (i <= position && curChild != null) { if (WHITE_SPACES.contains(curChild.getNode().getElementType())) { if (!ignoreWhiteSpaces) i++; curChild = curChild.getNextSibling(); } else if (COMMENTS.contains(curChild.getNode().getElementType())) { if (!ignoreComments) i++; curChild = curChild.getNextSibling(); } else if (curChild instanceof PsiErrorElement) { if (!ignoreErrors) { return null; } i++; curChild = curChild.getNextSibling(); } else { if (i == position) return curChild; i++; curChild = curChild.getNextSibling(); } } return null; }