/**
  * Initializes this descriptor.
  */
 public function __construct($name)
 {
     $this->setName($name);
     $this->setSettings(new Settings());
     $namespace = new NamespaceDescriptor();
     $namespace->setName('\\');
     $namespace->setFullyQualifiedStructuralElementName('\\');
     $this->setNamespace($namespace);
     $this->setFiles(new Collection());
     $this->setIndexes(new Collection());
 }
 /**
  * Creates a tree of NamespaceDescriptors based on the provided FQNN (namespace name).
  *
  * This method will examine the namespace name and create a namespace descriptor for each part of
  * the FQNN if it doesn't exist in the namespaces field of the current namespace (starting with the root
  * Namespace in the Project Descriptor),
  *
  * As an intended side effect this method also populates the *elements* index of the ProjectDescriptor with all
  * created NamespaceDescriptors. Each index key is prefixed with a tilde (~) so that it will not conflict with
  * other FQSEN's, such as classes or interfaces.
  *
  * @param ProjectDescriptor $project
  * @param string            $namespaceName A FQNN of the namespace (and parents) to create.
  *
  * @see ProjectDescriptor::getNamespace() for the root namespace.
  * @see NamespaceDescriptor::getNamespaces() for the child namespaces of a given namespace.
  *
  * @return void
  */
 protected function createNamespaceDescriptorTree(ProjectDescriptor $project, $namespaceName)
 {
     $parts = explode('\\', ltrim($namespaceName, '\\'));
     $fqnn = '';
     // this method does not use recursion to traverse the tree but uses a pointer that will be overridden with the
     // next item that is to be traversed (child namespace) at the end of the loop.
     $pointer = $project->getNamespace();
     foreach ($parts as $part) {
         $fqnn .= '\\' . $part;
         if ($pointer->getChildren()->get($part)) {
             $pointer = $pointer->getChildren()->get($part);
             continue;
         }
         // namespace does not exist, create it
         $interimNamespaceDescriptor = new NamespaceDescriptor();
         $interimNamespaceDescriptor->setParent($pointer);
         $interimNamespaceDescriptor->setName($part);
         $interimNamespaceDescriptor->setFullyQualifiedStructuralElementName($fqnn);
         // add to the pointer's list of children
         $pointer->getChildren()->set($part, $interimNamespaceDescriptor);
         // add to index
         $project->getIndexes()->elements['~' . $fqnn] = $interimNamespaceDescriptor;
         $project->getIndexes()->get('namespaces', new Collection())->add($interimNamespaceDescriptor);
         // move pointer forward
         $pointer = $interimNamespaceDescriptor;
     }
 }