void (UsageInfo @NotNull [] usageInfos) { XmlTag tag; if (myTemplate != null) { tag = myTemplate.getTag(); } else if ((tag = XsltCodeInsightUtil.getTemplateTag(myExpression, true, false)) == null) { final XmlDocument document = PsiTreeUtil.getContextOfType(myExpression, XmlDocument.class, true); assert document != null; tag = document.getRootTag(); } assert tag != null; final XmlTag param = tag.createChildTag("param", XsltSupport.XSLT_NS, null, false); try { param.setAttribute("name", mySettings.getName()); if (mySettings.isCreateDefault()) { param.setAttribute("select", myExpression.getText()); } XmlTag anchorParam = null; for (UsageInfo info : usageInfos) { if (info instanceof XPathUsageInfo x) { final XPathVariableReference variableReference = XPathChangeUtil.createVariableReference(x.getExpression(), mySettings.getName()); final XmlAttribute attribute = x.getAttribute(); assert attribute != null; x.getExpression().replace(variableReference); if (XsltSupport.isParam(attribute.getParent())) { if (anchorParam == null) { anchorParam = attribute.getParent(); } else if (attribute.getParent().getTextOffset() < anchorParam.getTextOffset()) { anchorParam = attribute.getParent(); } } } else { final XmlTag t = (XmlTag)info.getElement(); if (t != null) { final XmlTag p = t.createChildTag("with-param", t.getNamespace(), null, false); p.setAttribute("name", mySettings.getName()); p.setAttribute("select", myExpression.getText()); t.add(p); } } } if (anchorParam != null) { RefactoringUtil.addParameter(tag, param, PsiTreeUtil.getPrevSiblingOfType(anchorParam, XmlTag.class)); } else { RefactoringUtil.addParameter(tag, param); } } catch (IncorrectOperationException e) { Logger.getInstance(getClass().getName()).error(e); } }