boolean (@NotNull PsiModifierListOwner modifierListOwner, @NotNull String annotationFQN) { if (!modifierListOwner.isValid()) return false; if (!PsiUtil.isLanguageLevel5OrHigher(modifierListOwner)) return false; if (modifierListOwner instanceof PsiParameter && ((PsiParameter)modifierListOwner).getTypeElement() == null) { if (modifierListOwner.getParent() instanceof PsiParameterList && modifierListOwner.getParent().getParent() instanceof PsiLambdaExpression lambda) { // Lambda parameter without type cannot be annotated. Check if we can specify types if (PsiUtil.isLanguageLevel11OrHigher(modifierListOwner)) return true; return LambdaUtil.createLambdaParameterListWithFormalTypes(lambda.getFunctionalInterfaceType(), lambda, false) != null; } return false; } // e.g. PsiTypeParameterImpl doesn't have modifier list PsiModifierList modifierList = modifierListOwner.getModifierList(); return modifierList != null && !(modifierList instanceof LightElement) && !(modifierListOwner instanceof LightElement) && !AnnotationUtil.isAnnotated(modifierListOwner, annotationFQN, CHECK_EXTERNAL | CHECK_TYPE); }