@@ -32,8 +32,8 @@ final class CodegenClass
3232 private bool $isAbstract = false ;
3333 private ?CodegenConstructor $constructor = null ;
3434
35- public function setIsFinal (): this {
36- $this -> isFinal = true ;
35+ public function setIsFinal (bool $value = true ): this {
36+ $this -> isFinal = $value ;
3737 return $this ;
3838 }
3939
@@ -43,7 +43,6 @@ public function setIsAbstract(bool $value = true): this {
4343 }
4444
4545 public function setExtends (string $name ): this {
46- invariant ($this -> extendsClass === null , ' extends has already been set' );
4746 $this -> extendsClass = $name ;
4847 return $this ;
4948 }
@@ -52,48 +51,33 @@ public function getExtends(): ?string {
5251 return $this -> extendsClass ;
5352 }
5453
55- public function getInheritedMethods (): Set <string > {
56- $classname_to_methods = $classname ==> {
57- try {
58- return (new Vector ((new \ReflectionClass ($classname ))-> getMethods()))
59- -> filter($m ==> ! $m -> isPrivate())
60- -> map($m ==> $m -> getName());
61- } catch (\ ReflectionException $e ) {
62- // The class doesn't exist (often seen in unit tests).
63- // Well, I guess it doesn't have any methods then.
64- return Set {};
65- }
66- };
67-
68- $methods = Set {};
69-
70- $methods -> addAll($classname_to_methods ($this -> getExtends()));
71- foreach ($this -> getImplements() as $interface ) {
72- $methods -> addAll($classname_to_methods ($interface ));
73- }
74- foreach ($this -> getUses() as $trait ) {
75- $methods -> addAll($classname_to_methods ($trait ));
76- }
77-
78- $dynamic_yield_methods = $methods -> filter(
79- $method_name ==> Str :: startsWith($method_name , ' gen' )
80- )-> map($gen_method_name ==>
81- ' get' . Str :: substr($gen_method_name , 3 , Str :: len($gen_method_name )- 3 )
82- );
83-
84- return $methods -> addAll($dynamic_yield_methods );
85- }
86-
8754 public function setConstructor (CodegenConstructor $constructor ): this {
8855 $this -> constructor = $constructor ;
8956 return $this ;
9057 }
9158
59+ /**
60+ * Add a comment before the class. Notice that you need to pass the
61+ * comment characters. Use this just for HH_FIXME or other ad-hoc uses.
62+ * For commenting the class, use method setDocBlock.
63+ * Example (a fake space was included between / and * to avoid a hack error
64+ * in this comment, but normally you won't have it):
65+ *
66+ * $class->addDeclComment('/ * HH_FIXME[4040] * /');
67+ */
9268 final public function addDeclComment (string $comment ): this {
9369 $this -> declComment .= $comment . " \n " ;
9470 return $this ;
9571 }
9672
73+ /**
74+ * Add a function to wrap calls to the class. E.g., for MyClass accepting
75+ * a string parameter it would generate:
76+ *
77+ * function MyClass(string $s): MyClass {
78+ * return new MyClass($s);
79+ * }
80+ */
9781 public function addConstructorWrapperFunc (
9882 ?Vector <string > $params = null ,
9983 ): this {
0 commit comments