|
56 | 56 | use PDepend\Source\AST\ASTInterface;
|
57 | 57 | use PDepend\Source\AST\ASTMethod;
|
58 | 58 | use PDepend\Source\AST\ASTNamespace;
|
| 59 | +use PDepend\Source\AST\ASTTrait; |
59 | 60 | use PDepend\Source\ASTVisitor\AbstractASTVisitor;
|
60 | 61 |
|
61 | 62 | /**
|
@@ -256,27 +257,50 @@ private function getProjectMetrics()
|
256 | 257 | */
|
257 | 258 | public function visitClass(ASTClass $class)
|
258 | 259 | {
|
259 |
| - if (!$class->isUserDefined()) { |
| 260 | + $this->generateTypeXml($class, 'class'); |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * Visits a trait node. |
| 265 | + * |
| 266 | + * @param \PDepend\Source\AST\ASTTrait $trait |
| 267 | + * @return void |
| 268 | + */ |
| 269 | + public function visitTrait(ASTTrait $trait) |
| 270 | + { |
| 271 | + $this->generateTypeXml($trait, 'trait'); |
| 272 | + } |
| 273 | + |
| 274 | + /** |
| 275 | + * Generates the XML for a class or trait node. |
| 276 | + * |
| 277 | + * @param \PDepend\Source\AST\ASTClass $type |
| 278 | + * @param string $typeIdentifier |
| 279 | + * @return void |
| 280 | + */ |
| 281 | + private function generateTypeXml(ASTClass $type, $typeIdentifier) |
| 282 | + { |
| 283 | + if (!$type->isUserDefined()) { |
260 | 284 | return;
|
261 | 285 | }
|
262 | 286 |
|
263 | 287 | $xml = end($this->xmlStack);
|
264 | 288 | $doc = $xml->ownerDocument;
|
265 | 289 |
|
266 |
| - $classXml = $doc->createElement('class'); |
267 |
| - $classXml->setAttribute('name', $class->getName()); |
| 290 | + $typeXml = $doc->createElement($typeIdentifier); |
| 291 | + $typeXml->setAttribute('name', $type->getName()); |
268 | 292 |
|
269 |
| - $this->writeNodeMetrics($classXml, $class); |
270 |
| - $this->writeFileReference($classXml, $class->getCompilationUnit()); |
| 293 | + $this->writeNodeMetrics($typeXml, $type); |
| 294 | + $this->writeFileReference($typeXml, $type->getCompilationUnit()); |
271 | 295 |
|
272 |
| - $xml->appendChild($classXml); |
| 296 | + $xml->appendChild($typeXml); |
273 | 297 |
|
274 |
| - array_push($this->xmlStack, $classXml); |
| 298 | + array_push($this->xmlStack, $typeXml); |
275 | 299 |
|
276 |
| - foreach ($class->getMethods() as $method) { |
| 300 | + foreach ($type->getMethods() as $method) { |
277 | 301 | $method->accept($this);
|
278 | 302 | }
|
279 |
| - foreach ($class->getProperties() as $property) { |
| 303 | + foreach ($type->getProperties() as $property) { |
280 | 304 | $property->accept($this);
|
281 | 305 | }
|
282 | 306 |
|
|
0 commit comments