Set<String> (Set<String> explicitModifiers) { Set<String> implicitModifiers = new HashSet<>(); PsiElement parent = getParent(); if (parent instanceof PsiClass) { PsiElement grandParent = parent.getContext(); if (grandParent instanceof PsiClass && ((PsiClass)grandParent).isInterface()) { Collections.addAll(implicitModifiers, PUBLIC, STATIC); } if (((PsiClass)parent).isInterface()) { implicitModifiers.add(ABSTRACT); // nested or local interface is implicitly static if (!(grandParent instanceof PsiFile)) { implicitModifiers.add(STATIC); } } if (((PsiClass)parent).isRecord()) { if (!(grandParent instanceof PsiFile)) { implicitModifiers.add(STATIC); } implicitModifiers.add(FINAL); } if (((PsiClass)parent).isEnum()) { if (!(grandParent instanceof PsiFile)) { implicitModifiers.add(STATIC); } List<PsiField> fields = parent instanceof PsiExtensibleClass ? ((PsiExtensibleClass)parent).getOwnFields() : Arrays.asList(((PsiClass)parent).getFields()); boolean hasSubClass = ContainerUtil.find(fields, field -> field instanceof PsiEnumConstant && ((PsiEnumConstant)field).getInitializingClass() != null) != null; if (hasSubClass) { implicitModifiers.add(SEALED); } else { implicitModifiers.add(FINAL); } List<PsiMethod> methods = parent instanceof PsiExtensibleClass ? ((PsiExtensibleClass)parent).getOwnMethods() : Arrays.asList(((PsiClass)parent).getMethods()); for (PsiMethod method : methods) { if (method.hasModifierProperty(ABSTRACT)) { implicitModifiers.add(ABSTRACT); break; } } } } else if (parent instanceof PsiMethod) { PsiClass aClass = ((PsiMethod)parent).getContainingClass(); if (aClass != null && aClass.isInterface()) { if (!explicitModifiers.contains(PRIVATE)) { implicitModifiers.add(PUBLIC); if (!explicitModifiers.contains(DEFAULT) && !explicitModifiers.contains(STATIC)) { implicitModifiers.add(ABSTRACT); } } } else if (aClass != null && aClass.isEnum() && ((PsiMethod)parent).isConstructor()) { implicitModifiers.add(PRIVATE); } } else if (parent instanceof PsiRecordComponent) { implicitModifiers.add(FINAL); } else if (parent instanceof PsiField) { if (parent instanceof PsiEnumConstant) { Collections.addAll(implicitModifiers, PUBLIC, STATIC, FINAL); } else { PsiClass aClass = ((PsiField)parent).getContainingClass(); if (aClass != null && aClass.isInterface()) { Collections.addAll(implicitModifiers, PUBLIC, STATIC, FINAL); } } } else if (parent instanceof PsiParameter && parent.getParent() instanceof PsiCatchSection && ((PsiParameter)parent).getType() instanceof PsiDisjunctionType) { Collections.addAll(implicitModifiers, FINAL); } else if (parent instanceof PsiResourceVariable) { Collections.addAll(implicitModifiers, FINAL); } return implicitModifiers; }