boolean (@NotNull final PsiJavaCodeReferenceElement element) { PsiElement parent = element.getParent(); if (myKind == CreateClassKind.ANNOTATION) { return parent instanceof PsiAnnotation; } if (parent instanceof PsiJavaCodeReferenceCodeFragment) return true; if (parent instanceof PsiTypeElement) { if (parent.getParent() instanceof PsiReferenceParameterList) return true; if (parent.getParent() instanceof PsiDeconstructionPattern) return true; while (parent.getParent() instanceof PsiTypeElement){ parent = parent.getParent(); if (parent.getParent() instanceof PsiReferenceParameterList) return true; } if (parent.getParent() instanceof PsiCodeFragment || parent.getParent() instanceof PsiVariable || parent.getParent() instanceof PsiMethod || parent.getParent() instanceof PsiClassObjectAccessExpression || parent.getParent() instanceof PsiTypeCastExpression) { return true; } PsiInstanceOfExpression instanceOfExpression = PsiTreeUtil.getParentOfType(parent, PsiInstanceOfExpression.class); if (instanceOfExpression != null && instanceOfExpression.getCheckType() == parent) { PsiType type = instanceOfExpression.getOperand().getType(); if (type instanceof PsiArrayType) { return false; } if (type != null && (myKind == CreateClassKind.ENUM || myKind == CreateClassKind.RECORD)) { return type.accept(new PsiTypeVisitor<>() { @Override public Boolean visitType(@NotNull PsiType type) { return false; } @Override public Boolean visitClassType(@NotNull PsiClassType classType) { PsiClass aClass = classType.resolve(); return aClass != null && aClass.isInterface(); } @Override public Boolean visitWildcardType(@NotNull PsiWildcardType wildcardType) { PsiType bound = wildcardType.getBound(); return bound == null || bound.accept(this); } }); } return true; } } else if (parent instanceof PsiReferenceList) { if (myKind == CreateClassKind.ENUM || myKind == CreateClassKind.RECORD) return false; if (parent.getParent() instanceof PsiClass psiClass) { if (psiClass.getPermitsList() == parent) { if (myKind == CreateClassKind.INTERFACE && !psiClass.isInterface()) return false; return true; } if (psiClass.getExtendsList() == parent) { if (myKind == CreateClassKind.CLASS && !psiClass.isInterface()) return true; if (myKind == CreateClassKind.INTERFACE && psiClass.isInterface()) return true; } if (psiClass.getImplementsList() == parent && myKind == CreateClassKind.INTERFACE) return true; } else if (parent.getParent() instanceof PsiMethod method) { if (method.getThrowsList() == parent && myKind == CreateClassKind.CLASS) return true; } } else if (parent instanceof PsiAnonymousClass && ((PsiAnonymousClass)parent).getBaseClassReference() == element) { return true; } if (element instanceof PsiReferenceExpression) { if (parent instanceof PsiMethodCallExpression) { return false; } return !(parent.getParent() instanceof PsiMethodCallExpression) || myKind == CreateClassKind.CLASS; } return false; }