Пример #1
0
 /**
  * Puts constants, fields and methods from the given statements into $class
  * 
  * @param PC_Obj_Class $class the class
  * @param array $stmts an array of PC_Obj_Constant, PC_Obj_Field and PC_Obj_Method
  */
 private function handle_class_stmts($class, $stmts)
 {
     foreach ($stmts as $stmt) {
         if ($stmt instanceof PC_Obj_Constant) {
             $class->add_constant($stmt);
         } else {
             if ($stmt instanceof PC_Obj_Field) {
                 $class->add_field($stmt);
             } else {
                 if ($stmt instanceof PC_Obj_Method) {
                     // methods in interfaces are implicitly abstract
                     if ($class->is_interface()) {
                         $stmt->set_abstract(true);
                     }
                     // convert old-style constructors to the new ones
                     if (strcasecmp($stmt->get_name(), $class->get_name()) == 0) {
                         $stmt->set_name('__construct');
                     }
                     // constructors return an object of the class
                     if ($stmt->is_constructor() && ($stmt->get_return_type() && !$stmt->get_return_type()->is_unknown())) {
                         $spec = $stmt->get_return_type();
                         $this->report_error('The constructor of class ' . $class->get_name() . ' specifies return type ' . $spec, PC_Obj_Error::E_T_RETURN_DIFFERS_FROM_DOC, $stmt->get_line());
                     }
                     $class->add_method($stmt);
                 } else {
                     FWS_Helper::error('Unknown statement: ' . $stmt);
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * Checks whether the method with given name may be a method of a subclass of $class
  *
  * @param PC_Obj_Class $class the class
  * @param string $name the method-name
  * @return bool true if so
  */
 private function is_method_of_sub($class, $name)
 {
     if ($class->is_final()) {
         return false;
     }
     $cname = $class->get_name();
     $isif = $class->is_interface();
     foreach ($this->env->get_types()->get_classes() as $sub) {
         if ($sub && (!$isif && strcasecmp($sub->get_super_class(), $cname) == 0 || $isif && $sub->is_implementing($cname))) {
             if ($sub->contains_method($name)) {
                 return true;
             }
             if ($this->is_method_of_sub($sub, $name)) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #3
0
 /**
  * @see FWS_Module::run()
  */
 public function run()
 {
     $tpl = FWS_Props::get()->tpl();
     if (!$this->class) {
         $this->report_error();
         return;
     }
     $curl = PC_URL::get_mod_url();
     $classname = $this->class->get_name();
     // build class-declaration
     $declaration = '';
     if (!$this->class->is_interface()) {
         if ($this->class->is_abstract()) {
             $declaration .= 'abstract ';
         } else {
             if ($this->class->is_final()) {
                 $declaration .= 'final ';
             }
         }
         $declaration .= 'class ';
     } else {
         $declaration .= 'interface ';
     }
     $declaration .= $classname . ' ';
     if (!$this->class->is_interface() && ($cn = $this->class->get_super_class())) {
         $declaration .= 'extends <a href="' . $curl->set('name', $cn)->to_url() . '">' . $cn . '</a> ';
     }
     if (count($this->class->get_interfaces()) > 0) {
         $declaration .= !$this->class->is_interface() ? 'implements ' : 'extends ';
         foreach ($this->class->get_interfaces() as $if) {
             $declaration .= '<a href="' . $curl->set('name', $if)->to_url() . '">' . $if . '</a>, ';
         }
         $declaration = FWS_String::substr($declaration, 0, -1);
     }
     $declaration = FWS_String::substr($declaration, 0, -1) . ';';
     $tpl->add_variables(array('classname' => $classname, 'declaration' => $declaration));
     $classfile = $this->class->get_file();
     // constants
     $consts = array();
     foreach ($this->class->get_constants() as $const) {
         $consts[] = array('name' => $const->get_name(), 'type' => $const->get_type(), 'line' => $const->get_line(), 'url' => $this->get_url($classfile, $const));
     }
     $tpl->add_variable_ref('consts', $consts);
     // fields
     $fields = array();
     $cfields = $this->class->get_fields();
     ksort($cfields);
     foreach ($cfields as $field) {
         $fields[] = array('name' => $field->get_name(), 'type' => (string) $field, 'line' => $field->get_line(), 'url' => $this->get_url($classfile, $field));
     }
     $tpl->add_variable_ref('fields', $fields);
     // methods
     $methods = array();
     $cmethods = $this->class->get_methods();
     ksort($cmethods);
     foreach ($cmethods as $method) {
         $methods[] = array('name' => $method->get_name(), 'type' => $method->__ToString(), 'line' => $method->get_line(), 'url' => $this->get_url($classfile, $method), 'since' => implode(', ', $method->get_version()->get_min()), 'till' => implode(', ', $method->get_version()->get_max()));
     }
     $tpl->add_variable_ref('methods', $methods);
     if ($this->class->get_file() && $this->class->get_line()) {
         $source = PC_Utils::highlight_file($this->class->get_file());
     } else {
         $source = '';
     }
     $tpl->add_variables(array('source' => $source, 'file' => $this->class->get_file(), 'line' => $this->class->get_line(), 'since' => implode(', ', $this->class->get_version()->get_min()), 'till' => implode(', ', $this->class->get_version()->get_max())));
 }