@param AttributeDefinition $attributeDefinition

We store the definitions indexed both by name and by urn to ensure speedy lookups due to the amount of
definitions and the amount of usages of the lookups
438167
public function addAttributeDefinition(AttributeDefinition $attributeDefinition)
    {
        if (isset($this->attributeDefinitionsByName[$attributeDefinition->getName()])) {
            throw new LogicException(sprintf(
                'Cannot add attribute "%s" as it has already been added',
                $attributeDefinition->getName()
            ));
        }

        $this->attributeDefinitionsByName[$attributeDefinition->getName()] = $attributeDefinition;

        if ($attributeDefinition->hasUrnMace()) {
            $this->attributeDefinitionsByUrn[$attributeDefinition->getUrnMace()] = $attributeDefinition;
        }

        if ($attributeDefinition->hasUrnOid()) {
            $this->attributeDefinitionsByUrn[$attributeDefinition->getUrnOid()] = $attributeDefinition;
        }
    }
109513
private function addServiceInlinedDefinitions($id, Definition $definition, \SplObjectStorage $inlinedDefinitions, &$isSimpleInstance)
    {
        $code = '';

        foreach ($inlinedDefinitions as $def) {
            if ($definition === $def) {
                continue;
            }
            if ($inlinedDefinitions[$def] <= 1 && !$def->getMethodCalls() && !$def->getProperties() && !$def->getConfigurator() && false === strpos($this->dumpValue($def->getClass()), '$')) {
                continue;
            }
            if (isset($this->definitionVariables[$def])) {
                $name = $this->definitionVariables[$def];
            } else {
                $name = $this->getNextVariableName();
                $this->definitionVariables[$def] = new Variable($name);
            }

            // a construct like:
            // $a = new ServiceA(ServiceB $b); $b = new ServiceB(ServiceA $a);
            // this is an indication for a wrong implementation, you can circumvent this problem
            // by setting up your service structure like this:
            // $b = new ServiceB();
            // $a = new ServiceA(ServiceB $b);
            // $b->setServiceA(ServiceA $a);
            if (isset($inlinedDefinition[$definition]) && $this->hasReference($id, array($def->getArguments(), $def->getFactory()))) {
                throw new ServiceCircularReferenceException($id, array($id));
            }

            $code .= $this->addNewInstance($def, '$'.$name, ' = ', $id);

            if (!$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true)) {
                $code .= $this->addServiceProperties($def, $name);
                $code .= $this->addServiceMethodCalls($def, $name);
                $code .= $this->addServiceConfigurator($def, $name);
            } else {
                $isSimpleInstance = false;
            }

            $code .= "\n";
        }

        return $code;
    }
317437
public function mapEntities(array $entityDefinitions)
	{
		foreach($entityDefinitions as $entityIdentifier => $entityDefinition)
		{
			$this->validateAndCompleteEntity($entityIdentifier, $entityDefinition);
		}
	}
137473
private String getAttribute(BeanDefinition beanDefinition, String attributeName) {
        String value = null;
        
        while (beanDefinition != null) {
            value = (String) beanDefinition.getAttribute(attributeName);
            
            if (value != null) {
                break;
            }
            
            beanDefinition = beanDefinition.getOriginatingBeanDefinition();
        }
        
        return value;
    }
1367153
private static Set<AttributeDefinition> sortAttributes(AttributeDefinition[] attributes) {
        Set<AttributeDefinition> sortedAttrs = new LinkedHashSet<>(attributes.length);
        List<AttributeDefinition> elementAds = null;
        for (AttributeDefinition ad : attributes) {
            if (ad.getParser().isParseAsElement()) {
                if (elementAds == null) {
                    elementAds = new ArrayList<>();
                }
                elementAds.add(ad);
            } else {
                sortedAttrs.add(ad);
            }
        }
        if (elementAds != null) {
            sortedAttrs.addAll(elementAds);
        }
        return sortedAttrs;
    }
1296195
@Override
	public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
		// accepts the beans in the order of classpath, which allow me to override beans
		// easily
		if (containsBean(beanName)) {
			return;
		}
		// just continue normally
		super.registerBeanDefinition(beanName, beanDefinition);
	}
873550
public void write(XMLStreamWriter writer, AttributeDefinition<?> def) throws XMLStreamException {
      write(writer, def, def.xmlName());
   }
663572
@Override
    public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
        for (AttributeAccess attr : attributes.values()) {
            resourceRegistration.registerReadOnlyAttribute(attr.getAttributeDefinition(), null);
        }
    }
1303799
@Override
	public void cacheResult(List<CPDefinition> cpDefinitions) {
		for (CPDefinition cpDefinition : cpDefinitions) {
			if (entityCache.getResult(
						CPDefinitionModelImpl.ENTITY_CACHE_ENABLED,
						CPDefinitionImpl.class, cpDefinition.getPrimaryKey()) == null) {
				cacheResult(cpDefinition);
			}
			else {
				cpDefinition.resetOriginalValues();
			}
		}
	}
973403
private function resolveDefinition(ChildDefinition $definition)
    {
        try {
            return $this->doResolveDefinition($definition);
        } catch (ExceptionInterface $e) {
            $r = new \ReflectionProperty($e, 'message');
            $r->setAccessible(true);
            $r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));

            throw $e;
        }
    }
644049
private function hydrateDefinitionFactory(Definition $definition, array &$definitionArray)
    {
        if (null !== $definition->getFactory()) {
            foreach ($definition->getFactory() as $argument) {
                $definitionArray['factory'][] = $this->convertArgument($argument);
            }
        }
    }
118856
protected function resolveObjectRealInterfaceExtensions(ClassAwareDefinitionInterface $definition): void
    {
        $class = $definition->getClass();

        if (class_exists($class)) {
            $refClass = new \ReflectionClass($definition->getClass());
            if ($interfaces = $refClass->getInterfaceNames()) {
                foreach ($interfaces as $interface) {
                    $bundleNamespace = ClassUtils::relatedBundleNamespace($interface);
                    if (preg_match('/(\w+)Interface?$/', $interface, $matches)) {
                        $extensionClass = ClassUtils::applyNamingConvention($bundleNamespace, 'Extension', null, $matches[1].'Extension');
                        if (class_exists($extensionClass)) {
                            if ($definition instanceof HasExtensionsInterface) {
                                $definition->addExtension($extensionClass);
                            }
                        }
                    }
                }
            }
        }
    }
337621
protected static function parseDefinition($definition)
    {
        if (!is_array($definition)) {
            $definition = deserialize($definition, true);

            return $definition;
        }

        return $definition;
    }
384762
public function setDefinition(string $fqn, Definition $definition)
    {
        $parts = $this->splitFqn($fqn);
        $this->indexDefinition(0, $parts, $this->definitions, $definition);

        $this->emit('definition-added');
    }
967227
public function addContentItemDefinition(ContentItemDefinition $definition)
    {
        if (!is_string($definition->getMimeType())) {
            throw UnregisterableDefinitionException::notAStringMimeType($definition);
        }

        if (!in_array($definition->getMimeType(), ItemType::getList())) {
            throw UnregisterableDefinitionException::unsupportedMimeType($definition);
        }

        if ($this->has($definition->getMimeType())) {
            throw UnregisterableDefinitionException::duplicateMimeType($definition);
        }

        $this->definitions[$definition->getMimeType()] = $definition;
    }
1192034
@Override
    public AttributeDefinition[] getAttributeDefinitions(int filter) {
        List<AttributeDefinition> adList;
        if (filter == ObjectClassDefinition.ALL) {
            adList = new ArrayList<AttributeDefinition>(requiredAttributeDefinitions.size() + optionalAttributeDefinitions.size());
            adList.addAll(requiredAttributeDefinitions);
            adList.addAll(optionalAttributeDefinitions);
        } else if (filter == ObjectClassDefinition.OPTIONAL) {
            adList = optionalAttributeDefinitions;
        } else if (filter == ObjectClassDefinition.REQUIRED) {
            adList = requiredAttributeDefinitions;
        } else {
            throw new IllegalArgumentException("Unexpected filter value: " + filter);
        }
        AttributeDefinition[] ads = new AttributeDefinition[adList.size()];
        return adList.toArray(ads);
    }
247233
protected function configureDefinition(EntityDefinition $definition, array $crud)
    {
        $toConfigure = [
            'deleteCascade',
            'listFields',
            'filter',
            'childrenLabelFields',
            'pageSize',
            'initialSortField',
            'initialSortAscending',
            'navBarGroup',
            'optimisticLocking',
            'hardDeletion',
        ];
        foreach ($toConfigure as $field) {
            if (array_key_exists($field, $crud)) {
                $function = 'set'.ucfirst($field);
                $definition->$function($crud[$field]);
            }
        }
    }