@@ -30,8 +30,8 @@ final class CodegenClass
3030 private bool $isAbstract = false ;
3131 private ?CodegenConstructor $constructor = null ;
3232
33- public function setIsFinal (): this {
34- $this -> isFinal = true ;
33+ public function setIsFinal (bool $value = true ): this {
34+ $this -> isFinal = $value ;
3535 return $this ;
3636 }
3737
@@ -41,7 +41,6 @@ public function setIsAbstract(bool $value = true): this {
4141 }
4242
4343 public function setExtends (string $name ): this {
44- invariant ($this -> extendsClass === null , ' extends has already been set' );
4544 $this -> extendsClass = $name ;
4645 return $this ;
4746 }
@@ -50,48 +49,34 @@ public function getExtends(): ?string {
5049 return $this -> extendsClass ;
5150 }
5251
53- public function getInheritedMethods (): Set <string > {
54- $classname_to_methods = $classname ==> {
55- try {
56- return (new Vector ((new ReflectionClass ($classname ))-> getMethods()))
57- -> filter($m ==> ! $m -> isPrivate())
58- -> map($m ==> $m -> getName());
59- } catch (ReflectionException $e ) {
60- // The class doesn't exist (often seen in unit tests).
61- // Well, I guess it doesn't have any methods then.
62- return Set {};
63- }
64- };
65-
66- $methods = Set {};
67-
68- $methods -> addAll($classname_to_methods ($this -> getExtends()));
69- foreach ($this -> getImplements() as $interface ) {
70- $methods -> addAll($classname_to_methods ($interface ));
71- }
72- foreach ($this -> getUses() as $trait ) {
73- $methods -> addAll($classname_to_methods ($trait ));
74- }
75-
76- $dynamic_yield_methods = $methods -> filter(
77- $method_name ==> Str :: startsWith($method_name , ' gen' )
78- )-> map($gen_method_name ==>
79- ' get' . Str :: substr($gen_method_name , 3 , Str :: len($gen_method_name )- 3 )
80- );
81-
82- return $methods -> addAll($dynamic_yield_methods );
83- }
8452
8553 public function setConstructor (CodegenConstructor $constructor ): this {
8654 $this -> constructor = $constructor ;
8755 return $this ;
8856 }
8957
58+ /**
59+ * Add a comment before the class. Notice that you need to pass the
60+ * comment characters. Use this just for HH_FIXME or other ad-hoc uses.
61+ * For commenting the class, use method setDocBlock.
62+ * Example (a fake space was included between / and * to avoid a hack error
63+ * in this comment, but normally you won't have it):
64+ *
65+ * $class->addDeclComment('/ * HH_FIXME[4040] * /');
66+ */
9067 final public function addDeclComment (string $comment ): this {
9168 $this -> declComment .= $comment . " \n " ;
9269 return $this ;
9370 }
9471
72+ /**
73+ * Add a function to wrap calls to the class. E.g., for MyClass accepting
74+ * a string parameter it would generate:
75+ *
76+ * function MyClass(string $s): MyClass {
77+ * return new MyClass($s);
78+ * }
79+ */
9580 public function addConstructorWrapperFunc (
9681 ?Vector <string > $params = null ,
9782 ): this {
0 commit comments