public static void processPrimaryMethod(JavaChangeInfo changeInfo, PsiMethod method,
                                          PsiMethod baseMethod,
                                          boolean isOriginal) throws IncorrectOperationException {
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(method.getProject());

    if (changeInfo.isVisibilityChanged()) {
      PsiModifierList modifierList = method.getModifierList();
      final String targetVisibility;
      if (isOriginal || changeInfo instanceof JavaChangeInfoImpl && ((JavaChangeInfoImpl)changeInfo).propagateVisibility) {
        targetVisibility = changeInfo.getNewVisibility();
      }
      else {
        targetVisibility =
          VisibilityUtil.getHighestVisibility(changeInfo.getNewVisibility(), VisibilityUtil.getVisibilityModifier(modifierList));
      }
      VisibilityUtil.setVisibility(modifierList, targetVisibility);
    }

    if (changeInfo.isNameChanged()) {
      String newName = baseMethod == null ? changeInfo.getNewName() :
                       RefactoringUtil.suggestNewOverriderName(method.getName(), baseMethod.getName(), changeInfo.getNewName());

      if (newName != null && !newName.equals(method.getName())) {
        final PsiIdentifier nameId = method.getNameIdentifier();
        assert nameId != null : method;
        nameId.replace(JavaPsiFacade.getElementFactory(method.getProject()).createIdentifier(newName));
      }
    }

    final PsiSubstitutor substitutor =
      baseMethod == null ? PsiSubstitutor.EMPTY : ChangeSignatureProcessor.calculateSubstitutor(method, baseMethod);

    final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(method.getProject());
    if (changeInfo.isReturnTypeChanged()) {
      PsiType newTypeElement = changeInfo.getNewReturnType().getType(changeInfo.getMethod().getParameterList(), method.getManager());
      final PsiType returnType = substitutor.substitute(newTypeElement);
      // don't modify return type for non-Java overriders (EJB)
      if (method.getName().equals(changeInfo.getNewName())) {
        final PsiTypeElement typeElement = method.getReturnTypeElement();
        if (typeElement != null) {
          ensureNullabilityAnnotationsDoNotRepeat(typeElement, returnType);
          PsiTypeElement replacementType = factory.createTypeElement(returnType);
          javaCodeStyleManager.shortenClassReferences(typeElement.replace(replacementType));
          if (replacementType.getText().startsWith("@")) {
            // Annotation could be moved to modifier list during the replacement
            javaCodeStyleManager.shortenClassReferences(method.getModifierList());
          }
        }
      }
    }

    PsiParameterList list = method.getParameterList();
    PsiClass aClass = method.getContainingClass();
    boolean isRecordCanonicalConstructor = aClass != null && JavaPsiRecordUtil.isCanonicalConstructor(method);
    boolean shouldChangeParameters = !isRecordCanonicalConstructor || JavaPsiRecordUtil.isExplicitCanonicalConstructor(method);
    int newParamsLength = MethodParamsProcessor.getNewParametersCount(changeInfo, baseMethod, list);

    if (shouldChangeParameters) {
      MethodParamsProcessor processor = new MethodParamsProcessor(changeInfo, baseMethod, factory, substitutor, list, method.getBody());
      processor.run();
    }
    if (isRecordCanonicalConstructor) {
      PsiRecordHeader header = aClass.getRecordHeader();
      if (header == null) {
        header = factory.createRecordHeaderFromText("", aClass);
        header = (PsiRecordHeader)aClass.addAfter(header, aClass.getTypeParameterList());
      }
      RecordHeaderProcessor processor = new RecordHeaderProcessor(changeInfo, factory, header);
      processor.run();
      if (method instanceof SyntheticElement) {
        method = Objects.requireNonNull(JavaPsiRecordUtil.findCanonicalConstructor(aClass));
      }
    }
    fixJavadocsForChangedMethod(method, changeInfo, newParamsLength);
    if (changeInfo.isExceptionSetOrOrderChanged()) {
      final PsiClassType[] newExceptions = getPrimaryChangedExceptionInfo(changeInfo);
      fixPrimaryThrowsLists(method, newExceptions);
    }

    tryUpdateContracts(method, changeInfo);

    if (baseMethod == null && method.findSuperMethods().length == 0) {
      final PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, true, Override.class.getName());
      if (annotation != null) {
        annotation.delete();
      }
    }
  }
public static void processPrimaryMethod(JavaChangeInfo changeInfo, PsiMethod method,
                                          PsiMethod baseMethod,
                                          boolean isOriginal)