@@ -25,27 +25,9 @@ class GuidelineRecategorization extends XmlElement {
2525 /** Get a query for which a recategorization is specified. */
2626 Query getQuery ( ) { result .getRuleId ( ) = getRuleId ( ) }
2727
28- private EffectiveCategory getValidEffectiveCategory ( ) {
29- exists ( string category , string recategorization |
30- category = getQuery ( ) .getCategory ( ) and
31- recategorization = getCategory ( )
32- |
33- result = TMandatory ( ) and
34- category = [ "disapplied" , "advisory" , "required" ] and
35- recategorization = "mandatory"
36- or
37- result = TRequired ( ) and
38- category = [ "disapplied" , "advisory" ] and
39- recategorization = "required"
40- or
41- result = TAdvisory ( ) and
42- category = "disapplied" and
43- recategorization = "advisory"
44- or
45- result = TDisapplied ( ) and
46- category = "advisory" and
47- recategorization = "disapplied"
48- )
28+ /** Gets a matching query whose default category permits this recategorization. */
29+ Query getApplicableQuery ( ) {
30+ result = getQuery ( ) and isValidRecategorization ( result .getCategory ( ) , getCategory ( ) )
4931 }
5032
5133 private predicate isValidRecategorization ( string category , string recategorization ) {
@@ -62,25 +44,31 @@ class GuidelineRecategorization extends XmlElement {
6244 recategorization = "disapplied"
6345 }
6446
47+ /** Gets the reason why this recategorization is invalid for all matching queries. */
6548 string getAnInvalidReason ( ) {
66- not isValidRecategorization ( this . getQuery ( ) . getCategory ( ) , this . getCategory ( ) ) and
49+ not exists ( getApplicableQuery ( ) ) and
6750 if exists ( this .getQuery ( ) )
6851 then
6952 result =
70- "Invalid recategorization from '" + this . getQuery ( ) .getCategory ( ) + "' to '" +
71- this .getCategory ( ) + "'."
53+ "Invalid recategorization from '" + strictconcat ( getQuery ( ) .getCategory ( ) , "' or '" ) +
54+ "' to '" + this .getCategory ( ) + "'."
7255 else result = "Unknown rule id '" + this .getRuleId ( ) + "'."
7356 }
7457
58+ /** Gets the original category (or categories) of queries matched by this recategorization. */
59+ string getMatchingOriginalCategory ( ) {
60+ if exists ( getApplicableQuery ( ) )
61+ then result = strictconcat ( getApplicableQuery ( ) .getCategory ( ) , "/" )
62+ else result = strictconcat ( getQuery ( ) .getCategory ( ) , "/" )
63+ }
64+
7565 predicate isValid ( ) { not isInvalid ( ) }
7666
7767 predicate isInvalid ( ) { getEffectiveCategory ( ) = TInvalid ( _) }
7868
7969 EffectiveCategory getEffectiveCategory ( ) {
80- (
81- if exists ( getValidEffectiveCategory ( ) )
82- then result = getValidEffectiveCategory ( )
83- else result = TInvalid ( getAnInvalidReason ( ) )
84- )
70+ if exists ( getApplicableQuery ( ) )
71+ then result .toString ( ) = getCategory ( )
72+ else result = TInvalid ( getAnInvalidReason ( ) )
8573 }
8674}
0 commit comments