2017-01-16 22:44:39 +03:00
|
|
|
<?php
|
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2017-01-30 02:06:13 +03:00
|
|
|
use Microsoft\PhpParser\Node\MethodDeclaration;
|
|
|
|
use Microsoft\PhpParser\Node\Statement\ClassDeclaration;
|
|
|
|
use Microsoft\PhpParser\Parser;
|
2017-01-16 22:44:39 +03:00
|
|
|
|
|
|
|
require_once __DIR__ . "/../src/bootstrap.php";
|
|
|
|
|
|
|
|
$files = [
|
|
|
|
__DIR__ . "/../src/Node.php",
|
|
|
|
__DIR__ . "/../src/Token.php",
|
2017-01-18 22:32:56 +03:00
|
|
|
__DIR__ . "/../src/Parser.php",
|
2017-02-02 04:41:56 +03:00
|
|
|
__DIR__ . "/../src/DiagnosticsProvider.php",
|
2017-02-02 00:20:04 +03:00
|
|
|
__DIR__ . "/../src/PositionUtilities.php",
|
2017-02-02 04:26:45 +03:00
|
|
|
__DIR__ . "/../src/LineCharacterPosition.php",
|
2017-01-18 22:32:56 +03:00
|
|
|
__DIR__ . "/../src/MissingToken.php",
|
|
|
|
__DIR__ . "/../src/SkippedToken.php"
|
2017-01-16 22:44:39 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$parser = new Parser();
|
|
|
|
|
|
|
|
echo "# API Documentation" . PHP_EOL;
|
2017-01-18 22:32:56 +03:00
|
|
|
echo "> Note: This documentation was auto-generated using this parser to help dogfood the API. It may be incomplete. Please contribute fixes to
|
2017-01-16 22:44:39 +03:00
|
|
|
`tools/PrintApiDocumentation.php` and suggest API improvements.\n<hr>\n\n";
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$ast = $parser->parseSourceFile(file_get_contents($file));
|
2020-08-10 17:20:57 +03:00
|
|
|
|
2017-01-16 22:44:39 +03:00
|
|
|
foreach ($ast->getDescendantNodes() as $descendant) {
|
|
|
|
if ($descendant instanceof ClassDeclaration) {
|
|
|
|
$className = $descendant->name->getText($descendant->getFileContents());
|
|
|
|
echo "## " . $className . PHP_EOL;
|
|
|
|
|
|
|
|
// TODO consider not having a separate classMemberDeclarations node
|
|
|
|
foreach ($descendant->classMembers->classMemberDeclarations as $member) {
|
2020-08-10 17:20:57 +03:00
|
|
|
// TODO: Maybe ask a class directly for all its method declarations
|
2017-01-16 22:44:39 +03:00
|
|
|
if ($member instanceof MethodDeclaration) {
|
2020-08-10 17:20:57 +03:00
|
|
|
if (!$member->isPublic()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-16 22:44:39 +03:00
|
|
|
|
2020-08-10 17:20:57 +03:00
|
|
|
$signature = $member->getSignatureFormatted();
|
|
|
|
|
|
|
|
$description = $member->getDescriptionFormatted();
|
|
|
|
if (strlen($description) <= 0) {
|
|
|
|
$description = "> TODO: add doc comment\n";
|
2017-01-16 22:44:39 +03:00
|
|
|
}
|
2020-08-10 17:20:57 +03:00
|
|
|
|
|
|
|
echo "### " . $className . "::" . $member->getName() . PHP_EOL;
|
|
|
|
echo $description . PHP_EOL;
|
|
|
|
echo "```php\n$signature\n```" . PHP_EOL;
|
2017-01-16 22:44:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:32:56 +03:00
|
|
|
echo "## Node types
|
|
|
|
> TODO: complete documentation - in addition to the helper methods on the Node base class,
|
|
|
|
every Node object has properties specific to the Node type. Browse `src/Node/` to explore these properties.";
|