Extract content below doc comment annotation

@param string $docComment
@param string $annotationClass

@return string
327822
private function extractContent($docComment, $annotationClass)
    {
        $isRecording = false;
        $content     = '';

        // remove doc comment stars at line start
        $docComment = preg_replace('/^[ \t]*(\*\/? ?|\/\*\*)/m', '', $docComment);

        $search = '(' .
            preg_quote($annotationClass, '/')
            . '|'
            . substr($annotationClass, strrpos($annotationClass, '\\') + 1)
            . ')';

        $lines = preg_split('/\n|\r\n/', $docComment);
        foreach ($lines as $line) {
            if ($isRecording === false && preg_match('/^@' . $search . '(\s|\(|$)/', $line)) {
                $isRecording = true;
            } elseif ($isRecording) {
                if (preg_match('/^@/', $line)) {
                    break;
                }
                $content .= $line . PHP_EOL;
            }
        }

        return trim($content);
    }
48088
private static function getDocLinesFromComment($docComment) {
		if (strpos($docComment, "/**") === 0) {
			$docComment = substr($docComment, 3);
		}
		
		// Let's remove all the \r...
		$docComment = str_replace("\r", "", $docComment);
			
		$commentLines = explode("\n", $docComment);
		$commentLinesWithoutStars = array();
		
		// For each line, let's remove the first spaces, and the first *
		foreach ($commentLines as $commentLine) {
			$length = strlen($commentLine);
			for ($i=0; $i<$length; $i++) {
				if ($commentLine{$i} != ' ' && $commentLine{$i} != '*' && $commentLine{$i} != "\t") {
					break;
				}
			}
			$commentLinesWithoutStars[] = substr($commentLine, $i);
		}
		
		// Let's remove the trailing /:
		$lastComment = $commentLinesWithoutStars[count($commentLinesWithoutStars)-1];
		$commentLinesWithoutStars[count($commentLinesWithoutStars)-1] = substr($lastComment, 0, strlen($lastComment)-1);
		
		if ($commentLinesWithoutStars[count($commentLinesWithoutStars)-1] == "")
			array_pop($commentLinesWithoutStars);
			
		if (isset($commentLinesWithoutStars[0]) && $commentLinesWithoutStars[0] == "") {
			$commentLinesWithoutStars = array_slice($commentLinesWithoutStars, 1);
		}
		
		return $commentLinesWithoutStars;
	}
963096
def cli(ctx, feature_id, organism="", sequence=""):
    
    return ctx.gi.annotations.get_comments(feature_id, organism=organism, sequence=sequence)
263121
private function getCommentDescriptionEndPointer(): int
    {
        $descriptionStartPtr = $this->getCommentDescriptionStartPointer();

        $commentStartToken = $this->docHelper->getBlockStartToken();
        $commentEndPtr = $this->docHelper->getBlockEndPosition();

        //If no tags found, possible end of search is the starting tag of the doc comment.
        if (count($commentStartToken['comment_tags']) === 0) {
            return $this->file->findPrevious(
                [T_DOC_COMMENT_STRING],
                $commentEndPtr - 1,
                $descriptionStartPtr
            );
        }

        //else its the pointer of the first comment tag found.
        $firstTagPtr = array_shift($commentStartToken['comment_tags']);

        return $this->file->findPrevious(
            [T_DOC_COMMENT_STRING],
            $firstTagPtr - 1,
            $descriptionStartPtr
        );
    }
704565
public static Comment toComment(Document doc, Object o) throws PageException {
	if (o instanceof Comment) return (Comment) o;
	else if (o instanceof CharacterData) return doc.createComment(((CharacterData) o).getData());
	return doc.createComment(Caster.toString(o));
    }
506723
private static String docComment(String doc, Object deprecation /* nullable */) {
    StringBuilder docStr = new StringBuilder();

    if (doc != null) {
      docStr.append(doc.trim());
    }

    if (deprecation != null) {
      docStr.append("\n\n").append("@deprecated");
      if (deprecation instanceof String) {
        docStr.append("  ").append(((String)deprecation).trim());
      }
    }
    return DocEscaping.stringToDocComment(docStr.toString(), DocCommentStyle.ASTRISK_MARGIN);
  }
122984
public function parse(string $docComment, string $target): array
    {
        $annotations = [$target => new Annotations($target)];
        $annotation  = new CurrentAnnotation($target);
        $expression  = Expression::$DOCBLOCK;
        // substract last two characters which close the doc comment, i.e. */
        $len  = strlen($docComment) - 2;
        $token = new Token();
        for ($i = 6; $i < $len; $i++) {
            $character = $docComment{$i};
            if (isset($expression->after[$character])) {
                if ($expression->evaluate($token, $character, $annotation)) {
                    $token->value = '';
                    $expression   = $expression->after[$character];
                    if ($expression instanceof Docblock) {
                        if (null !== $annotation->name) {
                            if (!isset($annotations[$annotation->target])) {
                                $annotations[$annotation->target] = new Annotations($annotation->target);
                            }

                            $annotations[$annotation->target]->add(
                                    new Annotation(
                                            $annotation->type,
                                            $annotation->target,
                                            $annotation->params,
                                            $annotation->name
                                    )
                            );
                        }

                        $annotation = new CurrentAnnotation($target);
                    }
                } elseif ($annotation->ignored) {
                    $token->value = '';
                    $expression = Expression::$DOCBLOCK;
                }
            } else {
                $token->value .= $character;
            }
        }

        if (!($expression instanceof Docblock)) {
            throw new \ReflectionException(
                    'Annotation parser finished in wrong state for annotation '
                    . $target . '@' . $annotation->name
                    . ', annotation probably closed incorrectly, last state was '
                    . get_class($expression));
        }

        return $annotations;
    }
164825
private function parsePhpDoc(string $phpDoc, string $class, string $name = null)
    {
        $phpDoc = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $phpDoc);
        $phpDoc = ltrim($phpDoc, "\r\n");

        $split = preg_split("/(\n@)/isU", $phpDoc, -1, PREG_SPLIT_DELIM_CAPTURE);

        if (!isset($split[0][0])) {
            throw new \Exception(sprintf("Empty PhpDoc for '%s::%s'", $class, $name));
        }

        if ($split[0][0] != '@') {
            $comments = explode("\n", array_shift($split));

            $this->add(new Comment(isset($comments[0]) ? array_shift($comments) : null), Definition::COMMENT);

            $commentLong = isset($comments[0]) ? trim(implode($comments, "\n"), "\n") : null;
            if ($commentLong) {
                $this->add(new CommentLong($commentLong), Definition::COMMENT_LONG);
            }
        } else {
            $split[0] = substr($split[0], 1);
        }

        foreach ($split as $content) {
            if ($content == '@') {
                continue;
            }

            // clean up variables
            $tempString = str_replace('  ', '-', $content);
            while ($content != $tempString) {
                $tempString = $content;
                $content = str_replace('  ', ' ', $content);
            }

            $explode = explode(' ', trim(str_replace("\t", '  ', $content)));

            $paramType = array_shift($explode);
            if ($paramType == '@') {
                continue;
            }

            switch ($paramType) {
                case Definition::PARAM:
                    $this->add(new Param($explode), $paramType, true);
                    break;

                case Definition::RETURNS:
                    $this->add(new ReturnType($explode), $paramType);
                    break;

                case Definition::THROWS:
                    $this->add(new Throws($explode), $paramType, true);
                    break;

                case Definition::RESPONSE:
                    $this->add(new Response($explode), $paramType, true);
                    break;

                case Definition::EXAMPLE:
                    $this->add(new Example($explode), $paramType, true);
                    break;

                case Definition::HEADER:
                    $this->add(new Header($explode), $paramType, true);
                    break;

                case Definition::AUTH:
                    $this->add(new Auth(implode(' ', $explode)), $paramType);
                    break;

                case Definition::HTTP_METHOD:
                    $this->add(new HttpMethod(implode(' ', $explode)), $paramType);
                    break;

                default:
                    throw new \InvalidArgumentException(
                        sprintf("Invalid param type '%s' on '%s::%s'", $paramType, $class, $name)
                    );
            }
        }

        if (is_null($this->getDefinition(Definition::RESPONSE)) &&
            !is_null($this->getDefinition(Definition::RETURNS))
        ) {
            $response = new Response();
            /* @noinspection PhpParamsInspection */
            $response->fromReturn($this->getDefinition(Definition::RETURNS));

            $this->add($response, Definition::RESPONSE, true);
        }
    }
1224112
Comment comment() {
        if (comment == null) {
            String d = documentation();
            if (env.javaScriptScanner != null) {
                env.javaScriptScanner.parse(d, new JavaScriptScanner.Reporter() {
                    @Override
                    public void report() {
                        env.error(DocImpl.this, "javadoc.JavaScript_in_comment");
                        throw new FatalError();
                    }
                });
            }
            if (env.doclint != null
                    && treePath != null
                    && env.shouldCheck(treePath.getCompilationUnit())
                    && d.equals(getCommentText(treePath))) {
                env.doclint.scan(treePath);
            }
            comment = new Comment(this, d);
        }
        return comment;
    }
42195
public static String stringToDocComment(String doc, DocCommentStyle style) {
    if (doc == null || doc.trim().isEmpty()) return "";

    String commentNewline = (style == DocCommentStyle.ASTRISK_MARGIN) ? "\n * " : "\n";
    String schemadoc = wrap(escape(doc)).replaceAll("\\n", commentNewline);
    StringBuilder builder = new StringBuilder();
    builder.append("/**\n");
    if (style == DocCommentStyle.ASTRISK_MARGIN) builder.append(" * ");
    builder.append(schemadoc).append("\n");
    if (style == DocCommentStyle.ASTRISK_MARGIN) builder.append(" ");
    builder.append("*/");
    return builder.toString();
  }
83417
private function __extractDocString($DocComment, $lines = null, $parse_tags = false)
    {
        $split = preg_split("/\r\n|\n|\r/", $DocComment);

        //clean up: removes useless chars like new-lines, tabs and *
        $_tmp = array();
        $_l=1;
        foreach ($split as $id => $row) {
            $_row = trim($row, "* /\n\t\r");
            if (!empty($_row) AND $_row[0]!='@') {
                $_tmp[$_l] = $_row;
                $_l++;
            }
        }           

        if (!empty($lines)) {
            if (is_numeric($lines)) {
                if (!isset($_tmp[ $lines ])) return '';
                $_tmp = array( $_tmp[ $lines ] );
            } elseif (is_array($lines)) {
                if (!empty($lines[1]))
                    $_tmp = array_slice($_tmp, array_search( $_tmp[ $lines[0] ], $_tmp)-1, $lines[1]);
                else
                    $_tmp = array_slice($_tmp, array_search( $_tmp[ $lines[0] ], $_tmp)-1 );
            }
        }

        return trim(implode("\n",$_tmp));
    }
317525
private function parseAnnotations($docBlock, $pattern, callable $callback)
    {
        $annotations = [];
        // Strip away the docblock header and footer to ease parsing of one line annotations
        $docBlock = substr($docBlock, 3, -2);

        if (preg_match_all($pattern, $docBlock, $matches) && is_callable($callback)) {
            return call_user_func($callback, $matches);
        }

        return $annotations;
    }
1131864
public function parseBlockComment($blockComment)
    {
        $blockCommentLines = $this->parseBlockCommentLines($blockComment);

        return new Element\DocumentationBlock(
            $this->parseBlockCommentTags($blockCommentLines),
            $this->parseBlockCommentSummary($blockCommentLines),
            $this->parseBlockCommentBody($blockCommentLines)
        );
    }
399961
protected function extractReturnType(array $tokens, $docBlockOpenTagIndex, $docBlockCloseTagIndex) {
		for ($i = $docBlockOpenTagIndex + 1; $i < $docBlockCloseTagIndex; $i++) {

			if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') {
				continue;
			}
			if ($tokens[$i]['content'] !== '@return') {
				continue;
			}

			$classNameIndex = $i + 2;

			if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') {
				continue;
			}

			$content = $tokens[$classNameIndex]['content'];

			//$appendix = '';
			$spaceIndex = strpos($content, ' ');
			if ($spaceIndex) {
				//$appendix = substr($content, $spaceIndex);
				$content = substr($content, 0, $spaceIndex);
			}

			return $content;
		}

		return 'mixed';
	}
387620
function removeExportAnnotationsFromComment(comment) {
  // Remove @export annotations.
  comment = comment.replace(EXPORT_REGEX, '')

  // Split into lines, remove empty comment lines, then recombine.
  comment = comment.split('\n')
      .filter(function(line) { return !/^ *\*? *$/.test(line); })
      .join('\n');

  return comment;
}
806987
private function parseComment(RefComment $comment = null)
    {
        if ($comment === null) {
            return [];
        }

        $annotations = $this->docParser->parse($comment->text);

        foreach ($annotations as $key => $annotation) {
            if (!$annotation instanceof Annotation) {
                unset($annotations[$key]);
                continue;
            }

            if ($annotation instanceof ContentInterface) {
                $content = $this->extractContent($comment->text, get_class($annotation));
                $annotation->setContent($content);
            }
        }

        return $annotations;
    }
114658
public function getDocComment ( $withCommentMark = false ) {
        $docComment = $this->_reflectionClass->getDocComment();
        if ( $withCommentMark === false ) {
            $docComment = PhpDocCommentObject::stripCommentMarks($docComment);
        }
        return $docComment;
    }