Ejemplo n.º 1
0
 protected function getAtomName(DivinerAtom $atom)
 {
     if ($atom->getDocblockMetaValue('title')) {
         return $atom->getDocblockMetaValue('title');
     }
     return $atom->getName();
 }
Ejemplo n.º 2
0
 private function loadSymbolForAtom(DivinerAtom $atom)
 {
     $symbol = id(new DivinerAtomQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBookPHIDs(array($this->loadBook()->getPHID()))->withTypes(array($atom->getType()))->withNames(array($atom->getName()))->withContexts(array($atom->getContext()))->withIndexes(array($this->getAtomSimilarIndex($atom)))->withIncludeUndocumentable(true)->withIncludeGhosts(true)->executeOne();
     if ($symbol) {
         return $symbol;
     }
     return id(new DivinerLiveSymbol())->setBookPHID($this->loadBook()->getPHID())->setType($atom->getType())->setName($atom->getName())->setContext($atom->getContext())->setAtomIndex($this->getAtomSimilarIndex($atom));
 }
Ejemplo n.º 3
0
 private function parseReturnType(DivinerAtom $atom, XHPASTNode $decl)
 {
     $return_spec = array();
     $metadata = $atom->getDocblockMeta();
     $return = idx($metadata, 'return');
     $type = null;
     $docs = null;
     if (!$return) {
         $return = idx($metadata, 'returns');
         if ($return) {
             $atom->addWarning(pht('Documentation uses `%s`, but should use `%s`.', '@returns', '@return'));
         }
     }
     $return = (array) $return;
     if (count($return) > 1) {
         $atom->addWarning(pht('Documentation specifies `%s` multiple times.', '@return'));
     }
     $return = head($return);
     if ($atom->getName() == '__construct' && $atom->getType() == 'method') {
         $return_spec = array('doctype' => 'this', 'docs' => '//Implicit.//');
         if ($return) {
             $atom->addWarning(pht('Method `%s` has explicitly documented `%s`. The `%s` method ' . 'always returns `%s`. Diviner documents this implicitly.', '__construct()', '@return', '__construct()', '$this'));
         }
     } else {
         if ($return) {
             $split = preg_split('/(?<!,)\\s+/', trim($return), 2);
             if (!empty($split[0])) {
                 $type = $split[0];
             }
             if ($decl->getChildByIndex(1)->getTypeName() == 'n_REFERENCE') {
                 $type = $type . ' &';
             }
             if (!empty($split[1])) {
                 $docs = $split[1];
             }
             $return_spec = array('doctype' => $type, 'docs' => $docs);
         } else {
             $return_spec = array('type' => 'wild');
         }
     }
     $atom->setProperty('return', $return_spec);
 }
Ejemplo n.º 4
0
 private function parseReturnType(DivinerAtom $atom, XHPASTNode $decl)
 {
     $return_spec = array();
     $metadata = $atom->getDocblockMeta();
     $return = idx($metadata, 'return');
     if (!$return) {
         $return = idx($metadata, 'returns');
         if ($return) {
             $atom->addWarning(pht('Documentation uses `@returns`, but should use `@return`.'));
         }
     }
     if ($atom->getName() == '__construct' && $atom->getType() == 'method') {
         $return_spec = array('doctype' => 'this', 'docs' => '//Implicit.//');
         if ($return) {
             $atom->addWarning('Method __construct() has explicitly documented @return. The ' . '__construct() method always returns $this. Diviner documents ' . 'this implicitly.');
         }
     } else {
         if ($return) {
             $split = preg_split('/\\s+/', trim($return), $limit = 2);
             if (!empty($split[0])) {
                 $type = $split[0];
             }
             if ($decl->getChildByIndex(1)->getTypeName() == 'n_REFERENCE') {
                 $type = $type . ' &';
             }
             $docs = null;
             if (!empty($split[1])) {
                 $docs = $split[1];
             }
             $return_spec = array('doctype' => $type, 'docs' => $docs);
         } else {
             $return_spec = array('type' => 'wild');
         }
     }
     $atom->setProperty('return', $return_spec);
 }