PsiElement (PsiElement element) { PsiElement parent = element == null ? null : element.getParent(); if (!(parent instanceof PsiDocComment docComment)) return null; final PsiJavaDocumentedElement owner = docComment.getOwner(); if (!(owner instanceof PsiMethod)) return null; PsiParameter[] parameters = ((PsiMethod)owner).getParameterList().getParameters(); PsiParameter myParam = ContainerUtil.find(parameters, psiParameter -> myName.equals(psiParameter.getName())); if (myParam == null) return null; PsiDocTag[] tags = docComment.findTagsByName("param"); if (tags.length == 0) { //insert as first tag or append to description tags = docComment.getTags(); if (tags.length == 0) return null; return tags[0]; } PsiParameter nextParam = PsiTreeUtil.getNextSiblingOfType(myParam, PsiParameter.class); while (nextParam != null) { for (PsiDocTag tag : tags) { if (matches(nextParam, tag)) { return tag; } } nextParam = PsiTreeUtil.getNextSiblingOfType(nextParam, PsiParameter.class); } PsiParameter prevParam = PsiTreeUtil.getPrevSiblingOfType(myParam, PsiParameter.class); while (prevParam != null) { for (PsiDocTag tag : tags) { if (matches(prevParam, tag)) { return PsiTreeUtil.getNextSiblingOfType(tag, PsiDocTag.class); } } prevParam = PsiTreeUtil.getPrevSiblingOfType(prevParam, PsiParameter.class); } return null; }