void (@NotNull PsiClass clazz) { if (LOG.isDebugEnabled()) LOG.debug("checkClass: clazz=" + clazz); // must be a class final PsiIdentifier nameIdentifier = clazz.getNameIdentifier(); if (nameIdentifier == null || clazz.getName() == null) { return; } if (excludeException && InheritanceUtil.isInheritor(clazz, CommonClassNames.JAVA_LANG_THROWABLE)) { return; } if (excludeDeprecated && clazz.isDeprecated()) { return; } if (excludeEnum && clazz.isEnum()) { return; } if (excludeRecords && clazz.isRecord()) { return; } if (excludeAbstract && clazz.hasModifierProperty(PsiModifier.ABSTRACT)) { return; } if (excludeTestCode && TestFrameworks.getInstance().isTestClass(clazz)) { return; } if (excludeInnerClasses && clazz.getContainingClass() != null) { return; } // if it is an excluded class - then skip if (excludeClassNamesPattern != null) { try { String name = clazz.getName(); if (name != null && excludeClassNamesPattern.matcher(name).matches()) { return; } } catch (PatternSyntaxException ignore) {} } // must have fields PsiField[] fields = clazz.getFields(); if (fields.length == 0) { return; } // get list of fields and getter methods supposed to be dumped in the toString method fields = GenerateToStringUtils.filterAvailableFields(clazz, GenerateToStringContext.getConfig().getFilterPattern()); PsiMethod[] methods = null; if (GenerateToStringContext.getConfig().isEnableMethods()) { // okay 'getters in code generation' is enabled so check methods = GenerateToStringUtils.filterAvailableMethods(clazz, GenerateToStringContext.getConfig().getFilterPattern()); } // there should be any fields if (Math.max(fields.length, methods == null ? 0 : methods.length) == 0) { return; } // okay some fields/getter methods are supposed to dumped, does a toString method exist final PsiMethod[] toStringMethods = clazz.findMethodsByName("toString", false); for (PsiMethod method : toStringMethods) { final PsiParameterList parameterList = method.getParameterList(); if (parameterList.isEmpty()) { // toString() method found return; } } final PsiMethod[] superMethods = clazz.findMethodsByName("toString", true); for (PsiMethod method : superMethods) { final PsiParameterList parameterList = method.getParameterList(); if (!parameterList.isEmpty()) { continue; } if (method.hasModifierProperty(PsiModifier.FINAL)) { // final toString() in super class found return; } } holder.registerProblem(nameIdentifier, JavaAnalysisBundle.message("inspection.class.has.no.to.string.method.description", clazz.getName()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createFixes()); }