use of com.jetbrains.python.PythonLanguage in project intellij-community by JetBrains.
the class PyBreakContinueGotoProvider method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
if (source != null && source.getLanguage() instanceof PythonLanguage) {
final PyLoopStatement loop = PsiTreeUtil.getParentOfType(source, PyLoopStatement.class, false, PyFunction.class, PyClass.class);
if (loop != null) {
ASTNode node = source.getNode();
if (node != null) {
IElementType node_type = node.getElementType();
if (node_type == PyTokenTypes.CONTINUE_KEYWORD) {
return loop;
}
if (node_type == PyTokenTypes.BREAK_KEYWORD) {
PsiElement outer_element = loop;
PsiElement after_cycle;
while (true) {
after_cycle = outer_element.getNextSibling();
if (after_cycle != null) {
if (after_cycle instanceof PsiWhiteSpace) {
after_cycle = after_cycle.getNextSibling();
}
if (after_cycle instanceof PyStatement)
return after_cycle;
}
outer_element = outer_element.getParent();
if (PyUtil.instanceOf(outer_element, PsiFile.class, PyFunction.class, PyClass.class)) {
break;
}
}
// cycle is the last statement in the flow of execution. its last element is our best bet.
return PsiTreeUtil.getDeepestLast(loop);
}
}
}
}
return null;
}
Aggregations