xsdata.analyzer module

xsdata.analyzer.simple_type(item)[source]
class xsdata.analyzer.ClassAnalyzer(processed=<factory>, class_index=<factory>, substitutions_index=<factory>)[source]

Bases: xsdata.utils.codegen.ClassUtils

Class analyzer is responsible to minize the final classes footprint by merging and flattening extensions and attributes.

Also promotes the classes necessary for generation and demotes the classes to be used as common types for future runs.

processed: List = None
class_index: Dict[QName, List[Class]] = None
substitutions_index: Dict[QName, List[Attr]] = None
process(classes)[source]

Process class list in steps.

Steps:
  • Merge redefined classes

  • Create a class index

  • Create a substitution index

  • Mark as abstract classes with the same qname

  • Flatten classes

  • Return a final class list for code generators.

Return type

List[Class]

fetch_classes_for_generation()[source]

Return the qualified classes to continue for code generation. Return all if there are not primary classes.

Qualifications:
  • not an abstract

  • type: element | complexType | simpleType with enumerations

Return type

List[Class]

create_class_index(classes)[source]

Group classes by their fully qualified name.

create_substitutions_index(classes)[source]

Create reference attributes for all the classes substitutions and group them by their fully qualified name.

find_class(qname, condition=<function simple_type>)[source]
Return type

Optional[Class]

merge_redefined_classes(classes)[source]

Merge original and redefined classes.

mark_abstract_duplicate_classes()[source]

Search for groups with more than one class and mark as abstract any complex type with the same name as an element.

flatten_classes()[source]
flatten_class(target)[source]

Simplify class footprint by flattening class extensions, attributes and inner classes.

Steps:
  • Merge enum unions

  • Expand attribute groups

  • Copy extensions attributes

  • Flatten attribute types

  • Merge duplicate attributes

  • Unset sequential attributes

  • Flatten inner classes

flatten_enumeration_unions(target)[source]
flatten_extension(target, extension)[source]

Remove if possible the given extension for the target class.

If extension type is xsd native and target is not enumeration create a default value attribute otherwise delegate the task to the responsible handler based on the extension source type complex or simple.

flatten_extension_simple(source, target, ext)[source]

Simple flatten extension handler for common classes eg SimpleType, Restriction.

Steps:
  1. If target is source: drop the extension.

  2. If source is enumeration and target isn’t create default value attribute.

  3. If both source and target are enumerations copy all attributes.

  4. If both source and target are not enumerations copy all attributes.

  5. If target is enumeration: drop the extension.

flatten_extension_complex(source, target, ext)[source]

Complex flatten extension handler for primary classes eg ComplexType, Element.

Steps:
  1. If source includes all target attributes: drop the extension

  2. If source includes some of the target attributes copy attributes

  3. If source depends on target class copy all attributes

  4. Otherwise maintain the extension.

expand_attribute_group(target, attr)[source]

Expand a group attribute with the source class attributes.

Clone the attributes and apply the group restrictions as well.

flatten_attribute_types(target, attr)[source]

Flatten attribute types by using the source attribute type.

Steps:
  • Skip xsd native types

  • Detect circular references if no source is found

  • Skip enumeration types

  • Overwrite attribute type from source

add_substitution_attrs(target, attr)[source]

Find all the substitution attributes for the given attribute and add them to the target class.

Exclude enumerations and wildcard attributes.

class_depends_on(source, target)[source]

Check if any source dependencies recursively match the target class.

Return type

bool

attr_depends_on(dependency, target)[source]

Check if dependency or any of its dependencies match the target class.

Return type

bool