XmlParser: cleanup XmlParser

GitOrigin-RevId: 838a3a8bfc2cde9b47c15838df703044e05da11f
This commit is contained in:
Max Medvedev
2025-05-16 21:45:56 +02:00
committed by intellij-monorepo-bot
parent 028e4623fb
commit 6881811753

View File

@@ -44,31 +44,37 @@ private fun reparseXmlTagByName(
newNode: LighterASTNode,
structure: FlyweightCapableTreeStructure<LighterASTNode>,
): ThreeState {
if (oldNode is PsiNamedElement
&& oldNode.elementType === XmlElementType.XML_TAG
&& newNode.tokenType === XmlElementType.XML_TAG
) {
val oldName = oldNode.name
val childrenRef = Ref.create<Array<LighterASTNode>>()
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<Array<LighterASTNode>>()
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
}