PsiElement (String newText) { if (myPosition instanceof XmlTag) { return ((XmlTag)myPosition).setName(newText); } else { final XmlElementFactory xmlElementFactory = XmlElementFactory.getInstance(myPosition.getProject()); final XmlAttribute xmlAttribute = xmlElementFactory.createXmlAttribute("attributeName", newText); final XmlAttributeValue valueElement = xmlAttribute.getValueElement(); assert valueElement != null; return myPosition.replace(valueElement); } }