Esempio n. 1
0
 /**
  * Display information
  *
  * @param  io.StringWriter $out
  * @return void
  */
 public function display($out)
 {
     $out->write(self::declarationOf($this->mirror));
     $parent = $this->mirror->parent();
     if ('lang.Enum' !== $parent->name()) {
         $this->displayExtensions([$parent], $out, 'extends');
     }
     $this->displayExtensions($this->mirror->interfaces()->declared(), $out, 'implements');
     $separator = false;
     $out->writeLine(' {');
     $this->displayMembers($this->mirror->constants(), $out, $separator);
     foreach (Enum::valuesOf($this->mirror->type()) as $member) {
         $out->write('  ', $member->name(), '(', $member->ordinal(), ')');
         $mirror = new TypeMirror(typeof($member));
         if ($mirror->isSubtypeOf($this->mirror)) {
             $out->writeLine(' {');
             foreach ($mirror->methods()->declared() as $method) {
                 $out->writeLine('    ', (string) $method);
             }
             $separator = true;
             $out->writeLine('  }');
         } else {
             $out->writeLine();
             $separator = true;
         }
     }
     $constructor = $this->mirror->constructor();
     if ($constructor->present()) {
         $this->displayMembers([$constructor], $out, $separator);
     }
     $this->displayMembers($this->mirror->methods()->all(Methods::ofClass()), $out, $separator);
     $this->displayMembers($this->mirror->methods()->all(Methods::ofInstance()), $out, $separator);
     $out->writeLine('}');
 }
 /**
  * Display information about a collection
  *
  * @param  lang.mirrors.Package $package
  * @param  lang.ClassLoader $loader
  * @param  io.StringWriter $out
  * @return void
  */
 protected function displayCollection($package, $loader, $out)
 {
     $ext = strlen(\xp::CLASS_FILE_EXT);
     $order = ['interface' => [], 'trait' => [], 'enum' => [], 'class' => []];
     // Child packages
     foreach ($loader->packageContents($package->name()) as $entry) {
         $base = $package->isGlobal() ? '' : $package->name() . '.';
         if ('/' === $entry[strlen($entry) - 1]) {
             $out->writeLine('  package ', $base . substr($entry, 0, -1));
         } else {
             if (0 === substr_compare($entry, \xp::CLASS_FILE_EXT, -$ext)) {
                 $mirror = new TypeMirror($loader->loadClass($base . substr($entry, 0, -$ext)));
                 $order[$mirror->kind()->name()][] = self::declarationOf($mirror);
             }
         }
     }
     // Types
     foreach ($order as $type => $types) {
         if (empty($types)) {
             continue;
         }
         $out->writeLine();
         sort($types);
         foreach ($types as $name) {
             $out->writeLine('  ', $name);
         }
     }
 }
Esempio n. 3
0
 public function this_class_constructors_declaring_type()
 {
     $type = new TypeMirror(self::class);
     $this->assertEquals($type->parent(), (new Constructor($type))->declaredIn());
 }
Esempio n. 4
0
 public function type_annotation_by_name()
 {
     $mirror = new TypeMirror(typeof($this));
     $this->assertEquals($mirror->annotations()->named('fixture'), $mirror->annotation('fixture'));
 }
 /** @return var[][] */
 private function targets()
 {
     $mirror = new TypeMirror(FixtureHackAnnotations::class, $this->source());
     return [[$mirror], [$mirror->constructor()], [$mirror->fields()->named('field')], [$mirror->methods()->named('method')], [$mirror->methods()->named('method')->parameters()->named('param')]];
 }
Esempio n. 6
0
 /** @return var[][] */
 private function targets($name)
 {
     $mirror = new TypeMirror(FixtureHackTypedClass::class, $this->source());
     return [[$mirror->fields()->named($name)->type(), 'field'], [$mirror->methods()->named($name)->returns(), 'method'], [$mirror->methods()->named('parameters')->parameters()->named($name)->type(), 'param']];
 }