void (@NotNull PsiField field, @NotNull PsiMethod method) { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(field.getProject()); CommentTracker tracker = new CommentTracker(); PsiDocComment methodJavaDoc = method.getDocComment(); if (methodJavaDoc != null) { tracker.text(methodJavaDoc); PsiDocComment fieldJavaDoc = field.getDocComment(); List<String> methodJavaDocTokens = Arrays.stream(methodJavaDoc.getChildren()) .filter(e -> e instanceof PsiDocToken) .map(PsiElement::getText) .filter(text -> !text.matches("\\s*\\*\\s*")) .toList(); methodJavaDocTokens = methodJavaDocTokens.subList(1, methodJavaDocTokens.size() - 1); String javaDocMethodText = String.join("\n* ", methodJavaDocTokens); PsiDocTag[] methodTags = methodJavaDoc.findTagsByName(getTagName()); if (fieldJavaDoc == null) { if (javaDocMethodText.isEmpty()) { fieldJavaDoc = factory.createDocCommentFromText("/**\n*/"); } else { fieldJavaDoc = factory.createDocCommentFromText("/**\n* -- " + getJavaDocMethodMarkup() + " --\n* " + javaDocMethodText + "\n*/"); } for (PsiDocTag methodTag : methodTags) { fieldJavaDoc.add(methodTag); } field.getParent().addBefore(fieldJavaDoc, field); } else { @NotNull PsiElement @NotNull [] fieldJavaDocChildren = Arrays.stream(fieldJavaDoc.getChildren()) .filter(e -> e instanceof PsiDocToken) .toArray(PsiElement[]::new); @NotNull PsiElement fieldJavaDocChild = fieldJavaDocChildren[fieldJavaDocChildren.length - 2]; PsiDocComment newMethodJavaDoc = factory.createDocCommentFromText("/**\n* -- " + getJavaDocMethodMarkup() + " --\n* " + javaDocMethodText + "\n*/"); PsiElement[] tokens = newMethodJavaDoc.getChildren(); for (int i = tokens.length - 2; 0 < i; i--) { fieldJavaDoc.addAfter(tokens[i], fieldJavaDocChild); } for (PsiDocTag methodTag : methodTags) { fieldJavaDoc.add(methodTag); } } methodJavaDoc.delete(); } tracker.delete(method); tracker.insertCommentsBefore(field); }