/** * Adds the given class to the 'Background' layer of the diagram * * @param &text.doclet.ClassDoc ClassDoc */ protected function _addClass($ClassDoc) { // check for DiaDiagram instance if (!isset($this->Dia)) { Console::writeLine('DiaDiagram object not defined!'); exit(-1); } // get background layer $Layer = $this->Dia->getLayer('Background'); // create new (empty) UMLClass and update it $Class = new DiaUMLClass(); $Class->setName($ClassDoc->qualifiedName()); $this->_updateClass($Class, $ClassDoc); // add the class to the background layer $Layer->addClass($Class); $this->added_classes[] = $ClassDoc->qualifiedName(); }
/** * Generates DiaUMLClass object for a single class - no recursion! * * @param text.doclet.ClassDoc classdoc The ClassDoc instance of the class to generate * @return org.dia.DiaUMLClass * @throws lang.IllegalArgumentException If argument is not usable */ protected function _genClass($classdoc) { // accept only ClassDoc if (!is('ClassDoc', $classdoc)) { throw new IllegalArgumentException('No ClassDoc given!'); } $ClassDoc = $classdoc; // get DiaUMLClass $UMLClass = new DiaUMLClass(); $DiaClass = $UMLClass->getClass(); $DiaMethods = $DiaClass->getMethods(); // loop over methods (annotations) for ($i = 0, $s = sizeof($DiaMethods); $i < $s; $i++) { $Method = $DiaMethods[$i]; // Console::writeLine('Method: '.$Method->getName().' Annotations: '.xp::stringOf($Method->getAnnotations())); // skip methods that don't have the appropriate annotation if (!$Method->hasAnnotation('fromClass')) { continue; } if (!$Method->hasAnnotation('fromClass', 'type')) { continue; } // determine action according to 'type' $ann_type = $Method->getAnnotation('fromClass', 'type'); // Console::writeLine('Method: '.$Method->getName()." Annotation-type: $ann_type"); switch ($ann_type) { case 'string': case 'integer': case 'bool': if ($Method->hasAnnotation('fromClass', 'eval')) { $ann_eval = $Method->getAnnotation('fromClass', 'eval'); // Console::write('Evaluating: ', $ann_eval); $value = eval("return {$ann_eval};"); // Console::writeLine('... Value: ', $value); try { $Method->invoke($UMLClass, array($value)); } catch (Exception $e) { Console::writeLine('Fatal: ', $e->toString()); exit(-1); } } else { Console::writeLine('Fatal ERROR: Annotation "fromClass" has no attribute "eval"!'); exit(-1); } break; case 'attribute': $fields = $ClassDoc->fields; foreach (array_keys($fields) as $name) { if (0 == strncmp('__', $name, 2)) { continue; } // skip magic fields // TODO: can we figure out in which class the attribute was defined? $Method->invoke($UMLClass, array(array($name => $fields[$name]))); } /** TODO: $Attrib= &new DiaUMLAttribute($name, $value, $type); parameters??? $Attrib->setName($name); if (isset($fields[$name])) { $Attrib->setValue($fields[$name]); $Attrib->setType(xp::typeOf($fields[$name])); } $Method->invoke($UMLClass, array($Attrib)); */ break; case 'method': $methods = $ClassDoc->methods; for ($i = 0, $s = sizeof($methods); $i < $s; $i++) { // skip magic methods?!? what about __construct() and __destruct()? if (0 == strncmp('__', $methods[$i]->name(), 2)) { continue; } // TODO: can we figure out in which class the method was defined? $Method->invoke($UMLClass, array($methods[$i])); } break; default: throw new IllegalArgumentException("Unknown annotation type: '{$type}'"); } } return $UMLClass; }