Context (@NotNull PsiJavaCodeReferenceElement element, boolean findFirstOnly) { if (!PsiUtil.isLanguageLevel5OrHigher(element)) return null; if (element.isQualified()) return null; PsiElement container = PsiTreeUtil.getParentOfType(element, PsiReferenceList.class, PsiClass.class, PsiMethod.class, PsiClassInitializer.class, PsiStatement.class); if (container == null || (container instanceof PsiClass aClass && !aClass.isRecord())) return null; PsiElement parent = element.getParent(); if (parent instanceof PsiMethodCallExpression || parent instanceof PsiJavaCodeReferenceElement || parent instanceof PsiReferenceList || parent instanceof PsiNewExpression || parent instanceof PsiAnnotation || (parent instanceof PsiTypeElement && typeParameterIsNotValidInTypeElementContext((PsiTypeElement)parent)) || element instanceof PsiReferenceExpression) { return null; } List<PsiNameIdentifierOwner> candidates = collectParentClassesAndMethodsUntilStatic(element, findFirstOnly); if (candidates.isEmpty()) return null; String name = element.getReferenceName(); if (name == null) return null; return new Context(candidates, name); }