PsiClass (final Location<?> location) { for (Iterator<Location<PsiClass>> iterator = location.getAncestors(PsiClass.class, false); iterator.hasNext();) { final Location<PsiClass> classLocation = iterator.next(); if (isTestClass(classLocation.getPsiElement(), false, true)) return classLocation.getPsiElement(); } PsiElement element = location.getPsiElement(); if (element instanceof PsiClassOwner) { PsiClass[] classes = ((PsiClassOwner)element).getClasses(); if (classes.length == 1 && isTestClass(classes[0], false, true)) return classes[0]; } return null; }