[required-props] Refine Required Props checker to only check @Prop

Summary: Before, we were mistakenly checking any annotation that ends with Prop such as TreeProp. This was wrong. Instead, we should only check Prop as adviced by the Litho team.

Reviewed By: ngorogiannis

Differential Revision: D17527769

fbshipit-source-id: b753dd87a
master
Ezgi Çiçek 5 years ago committed by Facebook Github Bot
parent c5ca4db8d0
commit df712bc629

@ -94,8 +94,8 @@ module RequiredProps = struct
let get_required_props typename tenv =
let is_required annot_list =
List.exists
~f:(fun ({Annot.class_name; parameters}, _) ->
String.is_suffix class_name ~suffix:Annotations.prop
~f:(fun (({Annot.parameters} as annot), _) ->
Annotations.annot_ends_with annot Annotations.prop
&& (* Don't count as required if it's @Prop(optional = true) *)
not (List.exists ~f:(fun annot_string -> String.equal annot_string "true") parameters)
)

@ -27,6 +27,14 @@ enum ResType {
boolean optional() default false;
}
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.CLASS)
@interface TreeProp {
ResType resType() default ResType.NONE;
boolean optional() default false;
}
class MyComponent extends Component {
@Prop Object prop1; // implicitly non-optional
@ -66,6 +74,29 @@ class MyComponent extends Component {
}
}
class MyTreeComponent extends Component {
@TreeProp Object prop1; // implicitly non-optional
Object nonProp;
public Builder create() {
return new Builder();
}
static class Builder extends Component.Builder {
MyTreeComponent mMyTreeComponent;
public Builder prop1(Object o) {
this.mMyTreeComponent.prop1 = o;
return this;
}
public MyTreeComponent build() {
return mMyTreeComponent;
}
}
}
/**
* using @Prop(resType = ..) allows you to set the Prop with any of .propname, .propnameRes, or
* .propnameAttr
@ -216,4 +247,13 @@ public class RequiredProps {
public void buildPropResMissingBad() {
mResPropComponent.create().build();
}
public class NonRequiredTreeProps {
public MyTreeComponent mMyTreeComponent;
public MyTreeComponent buildWithoutOk() {
return mMyTreeComponent.create().build();
}
}
}

Loading…
Cancel
Save