diff --git a/xml/xml-parser/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.kt b/xml/xml-parser/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.kt index f270e4386b37..b190859a2fb5 100644 --- a/xml/xml-parser/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.kt +++ b/xml/xml-parser/src/com/intellij/psi/impl/source/parsing/xml/XmlParser.kt @@ -44,31 +44,37 @@ private fun reparseXmlTagByName( newNode: LighterASTNode, structure: FlyweightCapableTreeStructure, ): ThreeState { - if (oldNode is PsiNamedElement - && oldNode.elementType === XmlElementType.XML_TAG - && newNode.tokenType === XmlElementType.XML_TAG - ) { - val oldName = oldNode.name - val childrenRef = Ref.create>() - val count = structure.getChildren(newNode, childrenRef) - - if (count < 3) - return ThreeState.UNSURE - - val children = childrenRef.get()!! - if (children[0].tokenType !== XmlTokenType.XML_START_TAG_START) - return ThreeState.UNSURE - if (children[1].tokenType !== XmlTokenType.XML_NAME) - return ThreeState.UNSURE - if (children[2].tokenType !== XmlTokenType.XML_TAG_END) - return ThreeState.UNSURE - - val name = children[1] as LighterASTTokenNode - val newName = name.text - - if (!Comparing.equal(oldName, newName)) - return ThreeState.NO + if (oldNode !is PsiNamedElement || oldNode.elementType !== XmlElementType.XML_TAG || newNode.tokenType !== XmlElementType.XML_TAG) { + return ThreeState.UNSURE } - return ThreeState.UNSURE + val oldName = oldNode.name + val childrenRef = Ref.create>() + val count = structure.getChildren(newNode, childrenRef) + + if (count < 3) { + return ThreeState.UNSURE + } + + val children = childrenRef.get()!! + if (children[0].tokenType !== XmlTokenType.XML_START_TAG_START) { + return ThreeState.UNSURE + } + if (children[1].tokenType !== XmlTokenType.XML_NAME) { + return ThreeState.UNSURE + } + if (children[2].tokenType !== XmlTokenType.XML_TAG_END) { + return ThreeState.UNSURE + } + + val name = children[1] as LighterASTTokenNode + val newName = name.text + + // note: oldName is String, newName is CharSequence, so plain kotlin `==` can't be used! + if (Comparing.equal(oldName, newName)) { + return ThreeState.UNSURE + } + + // different names => oldNode and newNode are not equal + return ThreeState.NO }