Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalmahajan15 committed Oct 30, 2023
1 parent e93118a commit 337055f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
8 changes: 4 additions & 4 deletions annotation/affiliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func FullTriggerForInterfaceParamFlow(affiliation AffiliationPair, paramNum int)
Annotation: &InterfaceParamReachesImplementation{
TriggerIfNilable: &TriggerIfNilable{
Ann: ParamKeyFromArgNum(affiliation.InterfaceMethod, paramNum)},
AffiliationPair: &affiliation,
AffiliationPair: affiliation,
},
Expr: affiliation.interfaceMethodAsExpr(),
},
Consumer: &ConsumeTrigger{
Annotation: &MethodParamFromInterface{
TriggerIfNonNil: &TriggerIfNonNil{
Ann: ParamKeyFromArgNum(affiliation.ImplementingMethod, paramNum)},
AffiliationPair: &affiliation,
AffiliationPair: affiliation,
},
Expr: affiliation.implementingMethodAsExpr(),
Guards: util.NoGuards(),
Expand All @@ -91,15 +91,15 @@ func FullTriggerForInterfaceResultFlow(affiliation AffiliationPair, retNum int)
Annotation: &MethodResultReachesInterface{
TriggerIfNilable: &TriggerIfNilable{
Ann: RetKeyFromRetNum(affiliation.ImplementingMethod, retNum)},
AffiliationPair: &affiliation,
AffiliationPair: affiliation,
},
Expr: affiliation.implementingMethodAsExpr(),
},
Consumer: &ConsumeTrigger{
Annotation: &InterfaceResultFromImplementation{
TriggerIfNonNil: &TriggerIfNonNil{
Ann: RetKeyFromRetNum(affiliation.InterfaceMethod, retNum)},
AffiliationPair: &affiliation,
AffiliationPair: affiliation,
},
Expr: affiliation.interfaceMethodAsExpr(),
Guards: util.NoGuards(),
Expand Down
6 changes: 3 additions & 3 deletions annotation/consume_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (a RecvPassPrestring) String() string {
// InterfaceResultFromImplementation is when a result is determined to flow from a concrete method to an interface method via implementation
type InterfaceResultFromImplementation struct {
*TriggerIfNonNil
*AffiliationPair
AffiliationPair
}

// equals returns true if the passed ConsumingAnnotationTrigger is equal to this one
Expand Down Expand Up @@ -612,7 +612,7 @@ func (i InterfaceResultFromImplementationPrestring) String() string {
// MethodParamFromInterface is when a param flows from an interface method to a concrete method via implementation
type MethodParamFromInterface struct {
*TriggerIfNonNil
*AffiliationPair
AffiliationPair
}

// equals returns true if the passed ConsumingAnnotationTrigger is equal to this one
Expand Down Expand Up @@ -1389,7 +1389,7 @@ type ConsumeTrigger struct {
GuardMatched bool
}

// Eq compares two ConsumeTrigger pointers for equality
// equals compares two ConsumeTrigger pointers for equality
func (c *ConsumeTrigger) equals(c2 *ConsumeTrigger) bool {
return c.Annotation.equals(c2.Annotation) &&
c.Expr == c2.Expr &&
Expand Down
5 changes: 3 additions & 2 deletions annotation/consume_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (s *ConsumingAnnotationTriggerTestSuite) SetupTest() {
&GlobalVarAssign{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&ArgPass{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&RecvPass{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&InterfaceResultFromImplementation{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}, AffiliationPair: &AffiliationPair{}},
&MethodParamFromInterface{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}, AffiliationPair: &AffiliationPair{}},
&InterfaceResultFromImplementation{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&MethodParamFromInterface{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&UseAsReturn{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&UseAsFldOfReturn{TriggerIfNonNil: &TriggerIfNonNil{Ann: mockedKey}},
&SliceAssign{TriggerIfDeepNonNil: &TriggerIfDeepNonNil{Ann: mockedKey}},
Expand All @@ -73,5 +73,6 @@ func (s *ConsumingAnnotationTriggerTestSuite) SetupTest() {
// TestConsumingAnnotationTriggerEqualsSuite runs the test suite for the `equals` method of all the structs that implement
// the `ConsumingAnnotationTrigger` interface.
func TestConsumingAnnotationTriggerEqualsSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(ConsumingAnnotationTriggerTestSuite))
}
1 change: 1 addition & 0 deletions annotation/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ func (s *KeyTestSuite) SetupTest() {
// TestKeyEqualsSuite runs the test suite for the `equals` method of all the structs that implement
// the `Key` interface.
func TestKeyEqualsSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(KeyTestSuite))
}
29 changes: 10 additions & 19 deletions annotation/produce_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,10 @@ func (t *TriggerIfNilable) CheckProduce(annMap Map) bool {
return ok && ann.IsNilable
}

// NeedsGuardMatch for a `TriggerIfNilable` is default false, as guarding
// applies mostly to deep reads, but this behavior is overriden
// for `VariadicFuncParamDeep`s, which have the semantics of
// deep reads despite consulting shallow annotations
// NeedsGuardMatch returns true if this trigger needs to be matched with a guarded consumer
func (t *TriggerIfNilable) NeedsGuardMatch() bool { return t.NeedsGuard }

// SetNeedsGuard for a `TriggerIfNilable` is, by default, a noop, as guarding
// applies mostly to deep reads, but this behavior is overriden
// for `VariadicFuncParamDeep`s, which have the semantics of
// deep reads despite consulting shallow annotations
// SetNeedsGuard sets the underlying Guard-Neediness of this ProduceTrigger, if present
func (t *TriggerIfNilable) SetNeedsGuard(b bool) { t.NeedsGuard = b }

// Kind returns Conditional.
Expand Down Expand Up @@ -141,13 +135,10 @@ func (t *TriggerIfDeepNilable) CheckProduce(annMap Map) bool {
return ok && ann.IsDeepNilable
}

// NeedsGuardMatch for a `TriggerIfDeepNilable` is default false,
// but overridden for most concrete triggers to read a boolean
// field
// NeedsGuardMatch returns true if this trigger needs to be matched with a guarded consumer
func (t *TriggerIfDeepNilable) NeedsGuardMatch() bool { return t.NeedsGuard }

// SetNeedsGuard for a `TriggerIfDeepNilable` is, by default, a noop,
// but overridden for most concrete triggers to set an underlying field
// SetNeedsGuard sets the underlying Guard-Neediness of this ProduceTrigger, if present
func (t *TriggerIfDeepNilable) SetNeedsGuard(b bool) { t.NeedsGuard = b }

// Kind returns DeepConditional.
Expand All @@ -174,12 +165,12 @@ func (*ProduceTriggerTautology) CheckProduce(Map) bool {
return true
}

// NeedsGuardMatch for a ProduceTriggerTautology is false - there is no wiggle room with these
// NeedsGuardMatch returns true if this trigger needs to be matched with a guarded consumer
func (p *ProduceTriggerTautology) NeedsGuardMatch() bool {
return p.NeedsGuard
}

// SetNeedsGuard for a ProduceTriggerTautology is a noop
// SetNeedsGuard sets the underlying Guard-Neediness of this ProduceTrigger, if present
func (p *ProduceTriggerTautology) SetNeedsGuard(b bool) { p.NeedsGuard = b }

// Prestring returns this Prestring as a Prestring
Expand Down Expand Up @@ -230,10 +221,10 @@ func (*ProduceTriggerNever) CheckProduce(Map) bool {
return false
}

// NeedsGuardMatch for a ProduceTriggerNever is false, like ProduceTriggerTautology
// NeedsGuardMatch returns true if this trigger needs to be matched with a guarded consumer
func (p *ProduceTriggerNever) NeedsGuardMatch() bool { return p.NeedsGuard }

// SetNeedsGuard for a ProduceTriggerNever is a noop, like ProduceTriggerTautology
// SetNeedsGuard sets the underlying Guard-Neediness of this ProduceTrigger, if present
func (p *ProduceTriggerNever) SetNeedsGuard(b bool) { p.NeedsGuard = b }

// Kind returns Never.
Expand Down Expand Up @@ -835,7 +826,7 @@ func (m MethodReturnPrestring) String() string {
// MethodResultReachesInterface is used when a result of a method is determined to flow into a result of an interface using inheritance
type MethodResultReachesInterface struct {
*TriggerIfNilable
*AffiliationPair
AffiliationPair
}

// equals returns true if the passed ProducingAnnotationTrigger is equal to this one
Expand Down Expand Up @@ -872,7 +863,7 @@ func (m MethodResultReachesInterfacePrestring) String() string {
// InterfaceParamReachesImplementation is used when a param of a method is determined to flow into the param of an implementing method
type InterfaceParamReachesImplementation struct {
*TriggerIfNilable
*AffiliationPair
AffiliationPair
}

// equals returns true if the passed ProducingAnnotationTrigger is equal to this one
Expand Down
5 changes: 3 additions & 2 deletions annotation/produce_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (s *ProducingAnnotationTriggerTestSuite) SetupTest() {
&FldReturn{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&FuncReturn{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&MethodReturn{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&MethodResultReachesInterface{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}, AffiliationPair: &AffiliationPair{}},
&InterfaceParamReachesImplementation{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}, AffiliationPair: &AffiliationPair{}},
&MethodResultReachesInterface{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&InterfaceParamReachesImplementation{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&GlobalVarRead{TriggerIfNilable: &TriggerIfNilable{Ann: mockedKey}},
&MapRead{TriggerIfDeepNilable: &TriggerIfDeepNilable{Ann: mockedKey}},
&ArrayRead{TriggerIfDeepNilable: &TriggerIfDeepNilable{Ann: mockedKey}},
Expand All @@ -82,5 +82,6 @@ func (s *ProducingAnnotationTriggerTestSuite) SetupTest() {
// TestProducingAnnotationTriggerEqualsSuite runs the test suite for the `equals` method of all the structs that implement
// the `ProducingAnnotationTrigger` interface.
func TestProducingAnnotationTriggerEqualsSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(ProducingAnnotationTriggerTestSuite))
}

0 comments on commit 337055f

Please sign in to comment.