<commit_before>package com.jetbrains.python.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.psi.PyBreakStatement;
import com.jetbrains.python.psi.PyElementVisitor;
import com.jetbrains.python.psi.PyLoopStatement;
import org.jetbrains.annotations.Nullable;

/**
 * @author yole
 */
public class PyBreakStatementImpl extends PyElementImpl implements PyBreakStatement {
  public PyBreakStatementImpl(ASTNode astNode) {
    super(astNode);
  }

  @Override
  protected void acceptPyVisitor(PyElementVisitor pyVisitor) {
    pyVisitor.visitPyBreakStatement(this);
  }

  @Nullable
  public PyLoopStatement getLoopStatement() {
    return PsiTreeUtil.getParentOfType(this, PyLoopStatement.class);
  }
}<commit_msg>Fixed false positive in unreachable code inspection for 'break' inside 'else' in nested for loop (PY-6062)<commit_after>package com.jetbrains.python.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author yole
 */
public class PyBreakStatementImpl extends PyElementImpl implements PyBreakStatement {
  public PyBreakStatementImpl(ASTNode astNode) {
    super(astNode);
  }

  @Override
  protected void acceptPyVisitor(PyElementVisitor pyVisitor) {
    pyVisitor.visitPyBreakStatement(this);
  }

  @Nullable
  public PyLoopStatement getLoopStatement() {
    return getLoopStatement(this);
  }

  @Nullable
  private static PyLoopStatement getLoopStatement(@NotNull PsiElement element) {
    final PyLoopStatement loop = PsiTreeUtil.getParentOfType(element, PyLoopStatement.class);
    if (loop instanceof PyForStatement) {
      final PyForStatement forLoop = (PyForStatement)loop;
      final PyElsePart elsePart = forLoop.getElsePart();
      if (PsiTreeUtil.isAncestor(elsePart, element, true)) {
        return getLoopStatement(loop);
      }
    }
    return loop;
  }
}
{'fraction_non_alphanumeric': 0.09055501460564752, 'fraction_numerical': 0.0019474196689386564, 'mean_word_length': 5.008771929824562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769455', 'n_tokens_mistral': 623, 'n_tokens_neox': 602, 'n_words': 126}