PsiClass (@NotNull PsiElement element) { // We use java.util.Objects for code generation, but it's absent before Java 7 if (!PsiUtil.isLanguageLevel7OrHigher(element)) return null; PsiJavaFile maybeRecord = (PsiJavaFile)PsiFileFactory.getInstance(element.getProject()) .createFileFromText("Dummy.java", JavaLanguage.INSTANCE, element.getText(), false, false); PsiUtil.FILE_LANGUAGE_LEVEL_KEY.set(maybeRecord, LanguageLevel.JDK_16); PsiClass[] classes = maybeRecord.getClasses(); if (classes.length == 1 && classes[0].isRecord()) { return classes[0]; } return null; }