diff options
author | George Hazan <george.hazan@gmail.com> | 2023-06-04 19:24:05 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-06-04 19:24:05 +0300 |
commit | efc336e60cf1331bf5f3213d296981b87b8b2a6c (patch) | |
tree | ea59ea1a324f45f6e8a06cc0887b376bfba90ca9 /protocols/Telegram/tdlib/td/example/android/AddIntDef.php | |
parent | 6e83622d2af1cec3c759f4cff6efe4df2fe3328c (diff) |
fixes #3537 (Telegram: 32-разрядная версия падает в 64-разрядной Windows) + update to the fresh TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/android/AddIntDef.php')
-rw-r--r-- | protocols/Telegram/tdlib/td/example/android/AddIntDef.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/example/android/AddIntDef.php b/protocols/Telegram/tdlib/td/example/android/AddIntDef.php new file mode 100644 index 0000000000..d4ae4a65bd --- /dev/null +++ b/protocols/Telegram/tdlib/td/example/android/AddIntDef.php @@ -0,0 +1,51 @@ +<?php + if ($argc !== 2) { + exit(); + } + $file = file_get_contents($argv[1]); + + if (strpos($file, 'androidx.annotation.IntDef') !== false) { + exit(); + } + + $file = str_replace('import androidx.annotation.Nullable;', 'import androidx.annotation.IntDef;'.PHP_EOL. + 'import androidx.annotation.Nullable;'.PHP_EOL. + PHP_EOL. + 'import java.lang.annotation.Retention;'.PHP_EOL. + 'import java.lang.annotation.RetentionPolicy;'.PHP_EOL, $file); + + preg_match_all('/public static class ([A-Za-z0-9]+) extends ([A-Za-z0-9]+)/', $file, $matches, PREG_SET_ORDER); + $children = []; + foreach ($matches as $val) { + if ($val[2] === 'Object') { + continue; + } + + $children[$val[2]][] = ' '.$val[1].'.CONSTRUCTOR'; + } + + $file = preg_replace_callback('/public abstract static class ([A-Za-z0-9]+)(<R extends Object>)? extends Object [{]/', + function ($val) use ($children) { + $values = implode(','.PHP_EOL, $children[$val[1]]); + return $val[0].<<<EOL + + /** + * Describes possible values returned by getConstructor(). + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ +$values + }) + public @interface Constructors {} + + /** + * @return identifier uniquely determining type of the object. + */ + @Constructors + @Override + public abstract int getConstructor(); +EOL; + }, + $file); + + file_put_contents($argv[1], $file); |