コード例 #1
0
 /**
  * Returns a TraitDefinition 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? Makes no sense currently
  *
  * @return \AppserverIo\Doppelgaenger\Interfaces\StructureDefinitionInterface
  *
  * @throws \AppserverIo\Doppelgaenger\Exceptions\GeneratorException
  */
 protected function getDefinitionFromTokens($tokens, $getRecursive = false)
 {
     // First of all we need a new TraitDefinition to fill
     if (is_null($this->currentDefinition)) {
         $this->currentDefinition = new TraitDefinition();
     } elseif (!$this->currentDefinition instanceof TraitDefinition) {
         throw new GeneratorException(sprintf('The structure definition %s does not seem to be a trait 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, $this->getToken()));
     // Get start and end line
     $this->currentDefinition->setStartLine($this->getStartLine($tokens));
     $this->currentDefinition->setEndLine($this->getEndLine($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);
     $this->currentDefinition->setInvariantConditions($annotationParser->getConditions($this->currentDefinition->getDocBlock(), Invariant::ANNOTATION));
     // 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);
     $this->currentDefinition->setFunctionDefinitions($functionParser->getDefinitionListFromTokens($tokens, $getRecursive));
     // Lets get the attributes the class might have
     $this->currentDefinition->setAttributeDefinitions($this->getAttributes($tokens));
     // Before exiting we will add the entry to the current structure definition hierarchy
     $this->structureDefinitionHierarchy->insert($this->currentDefinition);
     return $this->currentDefinition;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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
  * @param boolean $getRecursive Do we have to load the inherited contracts as well?
  *
  * @return \AppserverIo\Doppelgaenger\Entities\Definitions\InterfaceDefinition
  *
  * @throws \AppserverIo\Doppelgaenger\Exceptions\GeneratorException
  */
 protected function getDefinitionFromTokens($tokens, $getRecursive = true)
 {
     // First of all we need a new InterfaceDefinition to fill
     if (is_null($this->currentDefinition)) {
         $this->currentDefinition = new InterfaceDefinition();
     } elseif (!$this->currentDefinition instanceof InterfaceDefinition) {
         throw new GeneratorException(sprintf('The structure definition %s does not seem to be a interface definition.', $this->currentDefinition->getQualifiedName()));
     }
     // Save the path of the original definition for later use
     $this->currentDefinition->setPath($this->file);
     // Get the interfaces own namespace and the namespace which are included via use
     $this->currentDefinition->setNamespace($this->getNamespace());
     $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));
     // Get the interface identity
     $this->currentDefinition->setName($this->getName($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->setInvariantConditions($annotationParser->getConditions($this->currentDefinition->getDocBlock(), Invariant::ANNOTATION));
     // Lets check if there is any inheritance, or if we implement any interfaces
     $parentNames = $this->getParents($tokens);
     if (count($this->currentDefinition->getUsedStructures()) === 0) {
         foreach ($parentNames as $parentName) {
             if (strpos($parentName, '\\') !== false) {
                 $this->currentDefinition->getExtends()[] = $parentName;
             } else {
                 $this->currentDefinition->getExtends()[] = '\\' . $this->currentDefinition->getNamespace() . '\\' . $parentName;
             }
         }
     } else {
         foreach ($this->currentDefinition->getUsedStructures() as $alias) {
             foreach ($parentNames as $parentName) {
                 if (strpos($alias, $parentName) !== false) {
                     $this->currentDefinition->setExtends('\\' . $alias);
                 }
             }
         }
     }
     // Clean possible double-\
     $this->currentDefinition->setExtends(str_replace('\\\\', '\\', $this->currentDefinition->getExtends()));
     $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);
     $this->currentDefinition->setFunctionDefinitions($functionParser->getDefinitionListFromTokens($tokens));
     return $this->currentDefinition;
 }