Android example: improve AddIntDef.php.
This commit is contained in:
parent
3ea8255b42
commit
bcd89728c3
@ -12,7 +12,7 @@
|
|||||||
'import androidx.annotation.Nullable;'.PHP_EOL.
|
'import androidx.annotation.Nullable;'.PHP_EOL.
|
||||||
PHP_EOL.
|
PHP_EOL.
|
||||||
'import java.lang.annotation.Retention;'.PHP_EOL.
|
'import java.lang.annotation.Retention;'.PHP_EOL.
|
||||||
'import java.lang.annotation.RetentionPolicy;', $file);
|
'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);
|
preg_match_all('/public static class ([A-Za-z0-9]+) extends ([A-Za-z0-9]+)/', $file, $matches, PREG_SET_ORDER);
|
||||||
$children = [];
|
$children = [];
|
||||||
@ -21,13 +21,20 @@
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$children[$val[2]][] = PHP_EOL.' '.$val[1].'.CONSTRUCTOR';
|
$children[$val[2]][] = ' '.$val[1].'.CONSTRUCTOR';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = preg_replace_callback('/public abstract static class ([A-Za-z0-9]+)(<R extends Object>)? extends Object [{]/',
|
$file = preg_replace_callback('/public abstract static class ([A-Za-z0-9]+)(<R extends Object>)? extends Object [{]/',
|
||||||
function ($val) use ($children) {
|
function ($val) use ($children) {
|
||||||
return $val[0].PHP_EOL.' @Retention(RetentionPolicy.SOURCE)'.PHP_EOL.' @IntDef({'.implode(',', $children[$val[1]]).<<<'EOL'
|
$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 {}
|
public @interface Constructors {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user