Added script to update registry/enum docblocks

This commit is contained in:
Dylan K. Taylor 2021-03-22 16:00:09 +00:00
parent a515b5e1b8
commit 90161f24e3
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
14 changed files with 168 additions and 92 deletions

View File

@ -0,0 +1,76 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\build\update_registry_annotations;
use pocketmine\utils\RegistryUtils;
use function basename;
use function class_exists;
use function dirname;
use function file_get_contents;
use function file_put_contents;
use function preg_match;
use function str_replace;
use function substr;
if(count($argv) !== 2){
die("Provide a path to process");
}
require dirname(__DIR__) . '/vendor/autoload.php';
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($argv[1], \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME)) as $file){
if(substr($file, -4) !== ".php"){
continue;
}
$contents = file_get_contents($file);
if($contents === false){
throw new \RuntimeException("Failed to get contents of $file");
}
if(preg_match("/^namespace (.+);$/m", $contents, $matches) !== 1){
continue;
}
$shortClassName = basename($file, ".php");
$className = $matches[1] . "\\" . $shortClassName;
if(!class_exists($className)){
continue;
}
$reflect = new \ReflectionClass($className);
$docComment = $reflect->getDocComment();
if($docComment === false || (preg_match("/^\s*\*\s*\@see .+::_generateMethodAnnotations\(\)$/m", $docComment) !== 1 && preg_match("/^\s*\*\s*@generate-registry-docblock$/m", $docComment) !== 1)){
continue;
}
echo "Found registry in $file\n";
$replacement = RegistryUtils::_generateMethodAnnotations($matches[1], $className::getAll());
$newContents = str_replace($docComment, $replacement, $contents);
if($newContents !== $contents){
echo "Writing changed file $file\n";
file_put_contents($file, $newContents);
}else{
echo "No changes made to file $file\n";
}
}

View File

@ -28,25 +28,25 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self WHITE()
* @method static self ORANGE()
* @method static self MAGENTA()
* @method static self LIGHT_BLUE()
* @method static self YELLOW()
* @method static self LIME()
* @method static self PINK()
* @method static self GRAY()
* @method static self LIGHT_GRAY()
* @method static self CYAN()
* @method static self PURPLE()
* @method static self BLUE()
* @method static self BROWN()
* @method static self GREEN()
* @method static self RED()
* @method static self BLACK()
* @method static DyeColor WHITE()
* @method static DyeColor ORANGE()
* @method static DyeColor MAGENTA()
* @method static DyeColor LIGHT_BLUE()
* @method static DyeColor YELLOW()
* @method static DyeColor LIME()
* @method static DyeColor PINK()
* @method static DyeColor GRAY()
* @method static DyeColor LIGHT_GRAY()
* @method static DyeColor CYAN()
* @method static DyeColor PURPLE()
* @method static DyeColor BLUE()
* @method static DyeColor BROWN()
* @method static DyeColor GREEN()
* @method static DyeColor RED()
* @method static DyeColor BLACK()
*/
final class DyeColor{
use EnumTrait {

View File

@ -29,20 +29,20 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self DISK_13()
* @method static self DISK_CAT()
* @method static self DISK_BLOCKS()
* @method static self DISK_CHIRP()
* @method static self DISK_FAR()
* @method static self DISK_MALL()
* @method static self DISK_MELLOHI()
* @method static self DISK_STAL()
* @method static self DISK_STRAD()
* @method static self DISK_WARD()
* @method static self DISK_11()
* @method static self DISK_WAIT()
* @method static RecordType DISK_13()
* @method static RecordType DISK_CAT()
* @method static RecordType DISK_BLOCKS()
* @method static RecordType DISK_CHIRP()
* @method static RecordType DISK_FAR()
* @method static RecordType DISK_MALL()
* @method static RecordType DISK_MELLOHI()
* @method static RecordType DISK_STAL()
* @method static RecordType DISK_STRAD()
* @method static RecordType DISK_WARD()
* @method static RecordType DISK_11()
* @method static RecordType DISK_WAIT()
*/
final class RecordType{
use EnumTrait {

View File

@ -27,15 +27,15 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self SKELETON()
* @method static self WITHER_SKELETON()
* @method static self ZOMBIE()
* @method static self PLAYER()
* @method static self CREEPER()
* @method static self DRAGON()
* @method static SkullType SKELETON()
* @method static SkullType WITHER_SKELETON()
* @method static SkullType ZOMBIE()
* @method static SkullType PLAYER()
* @method static SkullType CREEPER()
* @method static SkullType DRAGON()
*/
final class SkullType{
use EnumTrait {

View File

@ -27,12 +27,12 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self BOTTOM()
* @method static self TOP()
* @method static self DOUBLE()
* @method static SlabType BOTTOM()
* @method static SlabType TOP()
* @method static SlabType DOUBLE()
*/
final class SlabType{
use EnumTrait;

View File

@ -27,14 +27,14 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self STRAIGHT()
* @method static self INNER_LEFT()
* @method static self INNER_RIGHT()
* @method static self OUTER_LEFT()
* @method static self OUTER_RIGHT()
* @method static StairShape STRAIGHT()
* @method static StairShape INNER_LEFT()
* @method static StairShape INNER_RIGHT()
* @method static StairShape OUTER_LEFT()
* @method static StairShape OUTER_RIGHT()
*/
final class StairShape{
use EnumTrait;

View File

@ -27,15 +27,15 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self OAK()
* @method static self SPRUCE()
* @method static self BIRCH()
* @method static self JUNGLE()
* @method static self ACACIA()
* @method static self DARK_OAK()
* @method static TreeType OAK()
* @method static TreeType SPRUCE()
* @method static TreeType BIRCH()
* @method static TreeType JUNGLE()
* @method static TreeType ACACIA()
* @method static TreeType DARK_OAK()
*/
final class TreeType{
use EnumTrait {

View File

@ -30,7 +30,7 @@ use function assert;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static AbsorptionEffect ABSORPTION()
* @method static Effect BLINDNESS()

View File

@ -27,12 +27,12 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self NONE()
* @method static self FAIL()
* @method static self SUCCESS()
* @method static ItemUseResult NONE()
* @method static ItemUseResult FAIL()
* @method static ItemUseResult SUCCESS()
*/
final class ItemUseResult{
use EnumTrait;

View File

@ -28,13 +28,13 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self WOOD()
* @method static self GOLD()
* @method static self STONE()
* @method static self IRON()
* @method static self DIAMOND()
* @method static ToolTier WOOD()
* @method static ToolTier GOLD()
* @method static ToolTier STONE()
* @method static ToolTier IRON()
* @method static ToolTier DIAMOND()
*/
final class ToolTier{
use EnumTrait {

View File

@ -27,13 +27,13 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self SURVIVAL()
* @method static self CREATIVE()
* @method static self ADVENTURE()
* @method static self SPECTATOR()
* @method static GameMode SURVIVAL()
* @method static GameMode CREATIVE()
* @method static GameMode ADVENTURE()
* @method static GameMode SPECTATOR()
*/
final class GameMode{
use EnumTrait {

View File

@ -28,11 +28,11 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self NEEDED()
* @method static self REQUESTED()
* @method static self SENT()
* @method static UsedChunkStatus NEEDED()
* @method static UsedChunkStatus REQUESTED()
* @method static UsedChunkStatus SENT()
*/
final class UsedChunkStatus{
use EnumTrait;

View File

@ -27,11 +27,11 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self STARTUP()
* @method static self POSTWORLD()
* @method static PluginEnableOrder STARTUP()
* @method static PluginEnableOrder POSTWORLD()
*/
final class PluginEnableOrder{
use EnumTrait;

View File

@ -27,14 +27,14 @@ use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
* This must be regenerated whenever registry members are added, removed or changed.
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static self PIANO()
* @method static self BASS_DRUM()
* @method static self SNARE()
* @method static self CLICKS_AND_STICKS()
* @method static self DOUBLE_BASS()
* @method static NoteInstrument PIANO()
* @method static NoteInstrument BASS_DRUM()
* @method static NoteInstrument SNARE()
* @method static NoteInstrument CLICKS_AND_STICKS()
* @method static NoteInstrument DOUBLE_BASS()
*/
final class NoteInstrument{
use EnumTrait {