import { xmlToFQN , xmlClosingTagToFQN , flattenProperties , flattenAggregations , isSameXMLNS , resolveXMLNS , splitQNameByNamespace , flattenEvents , flattenAssociations , } from "@ui5-language-assistant/logic-utils" ; import { XMLElement , XMLAttribute } from "@xml-tools/ast" ; import { UI5Class , UI5SemanticModel , UI5Prop , UI5Aggregation , BaseUI5Node , UI5Event , UI5Association , } from "@ui5-language-assistant/semantic-model-types" ; import { find } from "lodash" ; import { findSymbol } from "@ui5-language-assistant/semantic-model" ; export function getUI5ClassByXMLElement ( element , model ) { const elementTagFqn = xmlToFQN ( element ) ; const ui5Class = model . classes [ elementTagFqn ] ; if ( ui5Class === undefined || ui5Class . name !== element . name ) { return undefined ; } return ui5Class ; } export function getUI5ClassByXMLElementClosingTag ( element , model ) { if ( element . syntax . closeName === undefined ) { return undefined ; } const closingTagName = splitQNameByNamespace ( element . syntax . closeName . image ) . localName ; const elementTagFqn = xmlClosingTagToFQN ( element ) ; const ui5Class = model . classes [ elementTagFqn ] ; if ( ui5Class === undefined || ui5Class . name !== closingTagName ) { return undefined ; } return ui5Class ; } export function getUI5AggregationByXMLElement ( element , model ) { if ( element . parent . type === "XMLDocument" ) { return undefined ; } if ( ! isSameXMLNS ( element , element . parent ) ) { return undefined ; } const ui5Class = getUI5ClassByXMLElement ( element . parent , model ) ; if ( ui5Class === undefined ) { return undefined ; } const aggregations = flattenAggregations ( ui5Class ) ; const elementAggregation = find ( aggregations , [ "name" , element . name ] ) ; return elementAggregation ; } export function getUI5PropertyByXMLAttributeKey ( attribute , model ) { const xmlElement = attribute . parent ; const elementClass = getUI5ClassByXMLElement ( xmlElement , model ) ; if ( elementClass === undefined ) { return undefined ; } const properties = flattenProperties ( elementClass ) ; const ui5Property = find ( properties , [ "name" , attribute . key ] ) ; return ui5Property ; } export function getUI5NodeByXMLAttribute ( attribute , model ) { const parentElementClass = getUI5ClassByXMLElement ( attribute . parent , model ) ; if ( parentElementClass === undefined ) { return undefined ; } return findUI5ClassMemberByName ( parentElementClass , attribute . key ) ; } function findUI5ClassMemberByName ( ui5Class , targetName ) { const allProps = flattenProperties ( ui5Class ) ; const allEvents = flattenEvents ( ui5Class ) ; const allAssociations = flattenAssociations ( ui5Class ) ; const allAggregations = flattenAggregations ( ui5Class ) ; const allClassMembers = allProps . concat ( allEvents ) . concat ( allAssociations ) . concat ( allAggregations ) ; const found = find ( allClassMembers , ( _ ) => _ . name === targetName ) ; return found ; } export function getUI5NodeFromXMLElementNamespace ( xmlElement , model ) { const isDefault = xmlElement . ns === undefined ; const xmlNamespace = resolveXMLNS ( xmlElement ) ; if ( xmlNamespace === undefined ) { return { namespace : undefined , isDefault : isDefault , isXmlnsDefined : false , } ; } const ui5Namespace = findSymbol ( model , xmlNamespace ) ; return { namespace : ui5Namespace , isDefault : isDefault , isXmlnsDefined : true , } ; }