PsiElement () { String label = myIdentifier.getText(); for (PsiElement context = myStatement; context != null; context = context.getContext()) { if (context instanceof PsiLabeledStatement && label.equals(((PsiLabeledStatement)context).getName())) { return context; } } return null; }