private static boolean isInvalidCode(PsiElement element, boolean allowDanglingElse) {
    final PsiElement firstChild = element.getFirstChild();
    final PsiElement lastChild = element.getLastChild();
    final boolean strict = firstChild == lastChild && firstChild instanceof PsiExpressionStatement;
    if (firstChild instanceof PsiComment) {
      if (firstChild == lastChild) {
        return true;
      }
      final PsiElement sibling = firstChild.getNextSibling();
      if (sibling instanceof PsiWhiteSpace && sibling == lastChild) {
        return true;
      }
    }
    final CodeVisitor visitor = new CodeVisitor(strict, allowDanglingElse);
    element.accept(visitor);
    return visitor.isInvalidCode();
  }
private static boolean isInvalidCode(PsiElement element, boolean allowDanglingElse)