void (@NotNull PsiMethod method, @NotNull Consumer<? super HighlightInfo.Builder> errorSink) { if (!method.isConstructor()) return; PsiClass aClass = method.getContainingClass(); if (aClass == null) return; PsiIdentifier identifier = method.getNameIdentifier(); if (identifier == null) return; if (!aClass.isRecord()) { if (JavaPsiRecordUtil.isCompactConstructor(method)) { HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range( identifier).descriptionAndTooltip(JavaErrorBundle.message("compact.constructor.in.regular.class")); IntentionAction action = QuickFixFactory.getInstance().createAddParameterListFix(method); info.registerFix(action, null, null, null, null); errorSink.accept(info); } return; } if (JavaPsiRecordUtil.isExplicitCanonicalConstructor(method)) { PsiParameter[] parameters = method.getParameterList().getParameters(); PsiRecordComponent[] components = aClass.getRecordComponents(); assert parameters.length == components.length; for (int i = 0; i < parameters.length; i++) { PsiType componentType = components[i].getType(); PsiType parameterType = parameters[i].getType(); String componentName = components[i].getName(); String parameterName = parameters[i].getName(); if (!parameterType.equals(componentType)) { String message = JavaErrorBundle.message("record.canonical.constructor.wrong.parameter.type", componentName, componentType.getPresentableText(), parameterType.getPresentableText()); HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range( Objects.requireNonNull(parameters[i].getTypeElement())).descriptionAndTooltip(message); IntentionAction action = QuickFixFactory.getInstance().createMethodParameterTypeFix(method, i, componentType, false); info.registerFix(action, null, null, null, null); errorSink.accept(info); } if (!parameterName.equals(componentName)) { String message = JavaErrorBundle.message("record.canonical.constructor.wrong.parameter.name", componentName, parameterName); HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range( Objects.requireNonNull(parameters[i].getNameIdentifier())).descriptionAndTooltip(message); if (!ContainerUtil.exists(parameters, parameter -> parameter.getName().equals(componentName))) { IntentionAction action = QuickFixFactory.getInstance().createRenameElementFix(parameters[i], componentName); info.registerFix(action, null, null, null, null); } errorSink.accept(info); } } HighlightInfo.Builder builder = checkRecordSpecialMethodDeclaration(method, JavaErrorBundle.message("record.canonical.constructor")); errorSink.accept(builder); return; } if (JavaPsiRecordUtil.isCompactConstructor(method)) { HighlightInfo.Builder info = checkRecordSpecialMethodDeclaration(method, JavaErrorBundle.message("record.compact.constructor")); errorSink.accept(info); return; } // Non-canonical constructor PsiMethodCallExpression call = JavaPsiConstructorUtil.findThisOrSuperCallInConstructor(method); if (call == null || JavaPsiConstructorUtil.isSuperConstructorCall(call)) { String message = JavaErrorBundle.message("record.no.constructor.call.in.non.canonical"); HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(identifier).descriptionAndTooltip(message); errorSink.accept(info); } }