/** * Builds a new self reference instance. * * @param \PDepend\Source\AST\AbstractASTClassOrInterface $type * @return \PDepend\Source\AST\ASTSelfReference * @since 0.9.6 */ public function buildAstSelfReference(AbstractASTClassOrInterface $type) { Log::debug('Creating: \\PDepend\\Source\\AST\\ASTSelfReference(' . $type->getName() . ')'); return new \PDepend\Source\AST\ASTSelfReference($this->context, $type); }
/** * This method parses a {@link \PDepend\Source\AST\ASTParentReference} node. * * @param \PDepend\Source\Tokenizer\Token $token The "self" keyword token. * @return \PDepend\Source\AST\ASTNode * @throws \PDepend\Source\Parser\ParserException * @throws \PDepend\Source\Parser\InvalidStateException * @since 0.9.6 */ private function parseParentReference(Token $token) { if ($this->classOrInterface === null) { throw new InvalidStateException($token->startLine, (string) $this->compilationUnit, 'The keyword "parent" was used as type hint but the parameter ' . 'declaration is not in a class scope.'); } if ($this->classOrInterface instanceof ASTTrait) { $classReference = $this->builder->buildAstClassReference('__PDepend_TraitRuntimeReference'); } else { $classReference = $this->classOrInterface->getParentClassReference(); } if ($classReference === null) { throw new InvalidStateException($token->startLine, (string) $this->compilationUnit, sprintf('The keyword "parent" was used as type hint but the ' . 'class "%s" does not declare a parent.', $this->classOrInterface->getName())); } $ref = $this->builder->buildAstParentReference($classReference); $ref->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn); return $ref; }
/** * Generates the XML for a class or trait node. * * @param \PDepend\Source\AST\ASTClass $type * @param string $typeIdentifier * @return void */ private function generateTypeXml(AbstractASTClassOrInterface $type, $typeIdentifier) { if (!$type->isUserDefined()) { return; } $xml = end($this->xmlStack); $doc = $xml->ownerDocument; $typeXml = $doc->createElement($typeIdentifier); $typeXml->setAttribute('name', Utf8Util::ensureEncoding($type->getName())); $xml->appendChild($typeXml); array_push($this->xmlStack, $typeXml); $this->writeNodeDependencies($typeXml, $type); $this->writeFileReference($typeXml, $type->getCompilationUnit()); array_pop($this->xmlStack); }