forked from microsoft/tolerant-php-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintApiDocumentation.php
64 lines (52 loc) · 2.62 KB
/
PrintApiDocumentation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use Microsoft\PhpParser\Node\MethodDeclaration;
use Microsoft\PhpParser\Node\Statement\ClassDeclaration;
use Microsoft\PhpParser\Parser;
require_once __DIR__ . "/../src/bootstrap.php";
$files = [
__DIR__ . "/../src/Node.php",
__DIR__ . "/../src/Token.php",
__DIR__ . "/../src/Parser.php",
__DIR__ . "/../src/DiagnosticsProvider.php",
__DIR__ . "/../src/PositionUtilities.php",
__DIR__ . "/../src/LineCharacterPosition.php",
__DIR__ . "/../src/MissingToken.php",
__DIR__ . "/../src/SkippedToken.php"
];
$parser = new Parser();
echo "# API Documentation" . PHP_EOL;
echo "> Note: This documentation was auto-generated using this parser to help dogfood the API. It may be incomplete. Please contribute fixes to
`tools/PrintApiDocumentation.php` and suggest API improvements.\n<hr>\n\n";
foreach ($files as $file) {
$ast = $parser->parseSourceFile(file_get_contents($file));
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) {
// TODO: Maybe ask a class directly for all its method declarations
if ($member instanceof MethodDeclaration) {
if (!$member->isPublic()) {
continue;
}
$signature = $member->getSignatureFormatted();
$description = $member->getDescriptionFormatted();
if (strlen($description) <= 0) {
$description = "> TODO: add doc comment\n";
}
echo "### " . $className . "::" . $member->getName() . PHP_EOL;
echo $description . PHP_EOL;
echo "```php\n$signature\n```" . PHP_EOL;
}
}
}
}
}
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.";