/**
  * Returns a ClassDefinition from a token array.
  *
  * This method will use a set of other methods to parse a token array and retrieve any
  * possible information from it. This information will be entered into a ClassDefinition object.
  *
  * @param array   $tokens       The token array containing structure tokens
  * @param boolean $getRecursive Do we have to get the ancestral conditions as well?
  *
  * @return \AppserverIo\Doppelgaenger\Interfaces\StructureDefinitionInterface
  *
  * @throws \AppserverIo\Doppelgaenger\Exceptions\GeneratorException
  */
 protected function getDefinitionFromTokens($tokens, $getRecursive = true)
 {
     // First of all we need a new ClassDefinition to fill
     if (is_null($this->currentDefinition)) {
         $this->currentDefinition = new ClassDefinition();
     } elseif (!$this->currentDefinition instanceof ClassDefinition) {
         throw new GeneratorException(sprintf('The structure definition %s does not seem to be a class definition.', $this->currentDefinition->getQualifiedName()));
     }
     // Save the path of the original definition for later use
     $this->currentDefinition->setPath($this->file);
     // File based namespaces do not make much sense, so hand it over here.
     $this->currentDefinition->setNamespace($this->getNamespace());
     $this->currentDefinition->setName($this->getName($tokens));
     $this->currentDefinition->setUsedStructures($this->getUsedStructures());
     // For our next step we would like to get the doc comment (if any)
     $this->currentDefinition->setDocBlock($this->getDocBlock($tokens, self::TOKEN));
     // Get start and end line
     $this->currentDefinition->setStartLine($this->getStartLine($tokens));
     $this->currentDefinition->setEndLine($this->getEndLine($tokens));
     // Lets get the attributes the class might have
     $this->currentDefinition->setAttributeDefinitions($this->getAttributes($tokens));
     // So we got our docBlock, now we can parse the invariant annotations from it
     $annotationParser = new AnnotationParser($this->file, $this->config, $this->tokens, $this->currentDefinition);
     $invariantConditions = $annotationParser->getConditions($this->currentDefinition->getDocBlock(), Invariant::ANNOTATION);
     if (!is_bool($invariantConditions)) {
         $this->currentDefinition->setInvariantConditions($invariantConditions);
     }
     // we would be also interested in introductions
     $introductions = new IntroductionList();
     $introductionAnnotations = $annotationParser->getAnnotationsByType($this->currentDefinition->getDocBlock(), Introduce::ANNOTATION);
     foreach ($introductionAnnotations as $introductionAnnotation) {
         $introduction = new Introduction();
         $introduction->setTarget($this->currentDefinition->getQualifiedName());
         $introduction->setImplementation($introductionAnnotation->values['implementation']);
         $introduction->setInterface($introductionAnnotation->values['interface']);
         $introductions->add($introduction);
     }
     $this->currentDefinition->setIntroductions($introductions);
     // Get the class identity
     $this->currentDefinition->setIsFinal($this->hasSignatureToken($this->tokens, T_FINAL, self::TOKEN));
     $this->currentDefinition->setIsAbstract($this->hasSignatureToken($this->tokens, T_ABSTRACT, self::TOKEN));
     // Lets check if there is any inheritance, or if we implement any interfaces
     $this->currentDefinition->setExtends(trim($this->resolveUsedNamespace($this->currentDefinition, $this->getParent($tokens)), '\\'));
     // Get all the interfaces we have
     $this->currentDefinition->setImplements($this->getInterfaces($this->currentDefinition));
     // Get all class constants
     $this->currentDefinition->setConstants($this->getConstants($tokens));
     // Only thing still missing are the methods, so ramp up our FunctionParser
     $functionParser = new FunctionParser($this->file, $this->config, $this->structureDefinitionHierarchy, $this->structureMap, $this->currentDefinition, $this->tokens);
     $functionDefinitions = $functionParser->getDefinitionListFromTokens($tokens, $getRecursive);
     if ($functionDefinitions !== false) {
         $this->currentDefinition->setFunctionDefinitions($functionDefinitions);
     }
     // If we have to parse the definition in a recursive manner, we have to get the parent invariants
     if ($getRecursive === true) {
         // Add all the assertions we might get from ancestral dependencies
         $this->addAncestralAssertions($this->currentDefinition);
     }
     // Lets get the attributes the class might have
     $this->currentDefinition->setAttributeDefinitions($this->getAttributes($tokens, $this->currentDefinition->getInvariants()));
     // Before exiting we will add the entry to the current structure definition hierarchy
     $this->structureDefinitionHierarchy->insert($this->currentDefinition);
     return $this->currentDefinition;
 }