[required-props] Extend required prop setting with more custom suffixes

Summary: Our annotation parameter parsing is too primitive to identify `resType` and before we only assumed that all Prop's can be set by any of the two suffixes: `Attr` and `Res`. After talking to Litho team, there is 3 more additions to these suffixes: `Dip`, `Sip`, and `Px`.

Reviewed By: ngorogiannis

Differential Revision: D17528482

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

@ -140,13 +140,16 @@ module RequiredProps = struct
&& Procdesc.get_access proc_desc <> PredSymb.Private && Procdesc.get_access proc_desc <> PredSymb.Private
let suffixes = String.Set.of_list ["Attr"; "Dip"; "Px"; "Res"; "Sp"]
let has_prop prop_set prop = let has_prop prop_set prop =
String.Set.mem prop_set prop String.Set.mem prop_set prop
(* @Prop(resType = ...) myProp can also be set via myProp(), myPropAttr(), or myPropRes(). (* @Prop(resType = ...) myProp can also be set via myProp(), myPropAttr(), myPropDip(), myPropPx(), myPropRes() or myPropSp().
Our annotation parameter parsing is too primitive to identify resType, so just assume Our annotation parameter parsing is too primitive to identify resType, so just assume
that all @Prop's can be set any of these 3 ways. *) that all @Prop's can be set any of these 6 ways. *)
|| String.Set.mem prop_set (prop ^ "Attr") || String.Set.exists prop_set ~f:(fun el ->
|| String.Set.mem prop_set (prop ^ "Res") String.chop_prefix el ~prefix:prop
|> Option.exists ~f:(fun suffix -> String.Set.mem suffixes suffix) )
let report astate tenv summary = let report astate tenv summary =

@ -129,6 +129,21 @@ class ResPropComponent extends Component {
return this; return this;
} }
public Builder propDip(Object o) {
this.mResPropComponent.prop = o;
return this;
}
public Builder propPx(Object o) {
this.mResPropComponent.prop = o;
return this;
}
public Builder propSp(Object o) {
this.mResPropComponent.prop = o;
return this;
}
public ResPropComponent build() { public ResPropComponent build() {
return mResPropComponent; return mResPropComponent;
} }
@ -244,6 +259,18 @@ public class RequiredProps {
mResPropComponent.create().propAttr(new Object()).build(); mResPropComponent.create().propAttr(new Object()).build();
} }
public void buildPropResWithDipOk() {
mResPropComponent.create().propDip(new Object()).build();
}
public void buildPropResWithPxOk() {
mResPropComponent.create().propPx(new Object()).build();
}
public void buildPropResWithSpOk() {
mResPropComponent.create().propSp(new Object()).build();
}
public void buildPropResMissingBad() { public void buildPropResMissingBad() {
mResPropComponent.create().build(); mResPropComponent.create().build();
} }

Loading…
Cancel
Save