99 * statistical
1010 * non-attributable
1111 */
12+
1213import cpp
1314
1415/**
1516 * Gets a string describing the kind of a `Class`.
1617 */
17- string kindstr ( Class c )
18- {
18+ string kindstr ( Class c ) {
1919 exists ( int kind | usertypes ( unresolveElement ( c ) , _, kind ) |
20- ( kind = 1 and result = "Struct" ) or
21- ( kind = 2 and result = "Class" ) or
22- ( kind = 6 and result = "Template class" )
20+ kind = 1 and result = "Struct"
21+ or
22+ kind = 2 and result = "Class"
23+ or
24+ kind = 6 and result = "Template class"
2325 )
2426}
2527
2628/**
2729 * Holds if the arguments correspond to information about a `VariableDeclarationEntry`.
2830 */
29- predicate vdeInfo ( VariableDeclarationEntry vde , Class c , File f , int line )
30- {
31+ predicate vdeInfo ( VariableDeclarationEntry vde , Class c , File f , int line ) {
3132 c = vde .getVariable ( ) .getDeclaringType ( ) and
3233 f = vde .getLocation ( ) .getFile ( ) and
3334 line = vde .getLocation ( ) .getStartLine ( )
3435}
3536
3637newtype TVariableDeclarationInfo =
37- TVariableDeclarationLine ( Class c , File f , int line ) {
38- vdeInfo ( _, c , f , line )
39- }
38+ TVariableDeclarationLine ( Class c , File f , int line ) { vdeInfo ( _, c , f , line ) }
4039
4140/**
4241 * A line that contains one or more `VariableDeclarationEntry`s (in the same class).
4342 */
44- class VariableDeclarationLine extends TVariableDeclarationInfo
45- {
43+ class VariableDeclarationLine extends TVariableDeclarationInfo {
4644 Class c ;
45+
4746 File f ;
47+
4848 int line ;
4949
5050 VariableDeclarationLine ( ) {
@@ -55,48 +55,38 @@ class VariableDeclarationLine extends TVariableDeclarationInfo
5555 /**
5656 * Gets the class associated with this `VariableDeclarationLine`.
5757 */
58- Class getClass ( ) {
59- result = c
60- }
58+ Class getClass ( ) { result = c }
6159
6260 /**
6361 * Gets the line of this `VariableDeclarationLine`.
6462 */
65- int getLine ( ) {
66- result = line
67- }
63+ int getLine ( ) { result = line }
6864
6965 /**
7066 * Gets a `VariableDeclarationEntry` on this line.
7167 */
72- VariableDeclarationEntry getAVDE ( )
73- {
74- vdeInfo ( result , c , f , line )
75- }
68+ VariableDeclarationEntry getAVDE ( ) { vdeInfo ( result , c , f , line ) }
7669
7770 /**
7871 * Gets the start column of the first `VariableDeclarationEntry` on this line.
7972 */
80- int getStartColumn ( ) {
81- result = min ( getAVDE ( ) .getLocation ( ) .getStartColumn ( ) )
82- }
73+ int getStartColumn ( ) { result = min ( getAVDE ( ) .getLocation ( ) .getStartColumn ( ) ) }
8374
8475 /**
8576 * Gets the end column of the last `VariableDeclarationEntry` on this line.
8677 */
87- int getEndColumn ( ) {
88- result = max ( getAVDE ( ) .getLocation ( ) .getEndColumn ( ) )
89- }
78+ int getEndColumn ( ) { result = max ( getAVDE ( ) .getLocation ( ) .getEndColumn ( ) ) }
9079
9180 /**
9281 * Gets the rank of this `VariableDeclarationLine` in its file and class
9382 * (that is, the first is 0, the second is 1 and so on).
9483 */
9584 private int getRank ( ) {
9685 line = rank [ result ] ( VariableDeclarationLine vdl , int l |
97- vdl = TVariableDeclarationLine ( c , f , l ) |
98- l
99- )
86+ vdl = TVariableDeclarationLine ( c , f , l )
87+ |
88+ l
89+ )
10090 }
10191
10292 /**
@@ -115,23 +105,19 @@ class VariableDeclarationLine extends TVariableDeclarationInfo
115105 result .getLine ( ) <= this .getLine ( ) + 3
116106 }
117107
118- string toString ( ) {
119- result = "VariableDeclarationLine"
120- }
108+ string toString ( ) { result = "VariableDeclarationLine" }
121109}
122110
123111/**
124112 * A group of `VariableDeclarationEntry`s in the same class that are approximately
125113 * contiguous.
126114 */
127- class VariableDeclarationGroup extends VariableDeclarationLine
128- {
115+ class VariableDeclarationGroup extends VariableDeclarationLine {
129116 VariableDeclarationLine end ;
130117
131118 VariableDeclarationGroup ( ) {
132119 // there is no `VariableDeclarationLine` within three lines previously
133120 not any ( VariableDeclarationLine prev ) .getProximateNext ( ) = this and
134-
135121 // `end` is the last transitively proximate line
136122 end = getProximateNext * ( ) and
137123 not exists ( end .getProximateNext ( ) )
@@ -149,17 +135,19 @@ class VariableDeclarationGroup extends VariableDeclarationLine
149135 * Gets the number of uniquely named `VariableDeclarationEntry`s in this group.
150136 */
151137 int getCount ( ) {
152- result = count ( VariableDeclarationLine l | l = getProximateNext * ( ) | l .getAVDE ( ) .getVariable ( ) .getName ( ) )
138+ result = count ( VariableDeclarationLine l |
139+ l = getProximateNext * ( )
140+ |
141+ l .getAVDE ( ) .getVariable ( ) .getName ( )
142+ )
153143 }
154144
155145 override string toString ( ) {
156- (
157- getCount ( ) = 1 and
158- result = "declaration of " + getAVDE ( ) .getVariable ( ) .getName ( )
159- ) or (
160- getCount ( ) > 1 and
161- result = "group of " + getCount ( ) + " fields here"
162- )
146+ getCount ( ) = 1 and
147+ result = "declaration of " + getAVDE ( ) .getVariable ( ) .getName ( )
148+ or
149+ getCount ( ) > 1 and
150+ result = "group of " + getCount ( ) + " fields here"
163151 }
164152}
165153
@@ -169,26 +157,32 @@ class ExtClass extends Class {
169157 }
170158
171159 predicate hasLocationInfo ( string path , int startline , int startcol , int endline , int endcol ) {
172- if hasOneVariableGroup ( ) then
173- exists ( VariableDeclarationGroup vdg | vdg .getClass ( ) = this | vdg .hasLocationInfo ( path , startline , startcol , endline , endcol ) )
174- else
175- getLocation ( ) .hasLocationInfo ( path , startline , startcol , endline , endcol )
160+ if hasOneVariableGroup ( )
161+ then
162+ exists ( VariableDeclarationGroup vdg | vdg .getClass ( ) = this |
163+ vdg .hasLocationInfo ( path , startline , startcol , endline , endcol )
164+ )
165+ else getLocation ( ) .hasLocationInfo ( path , startline , startcol , endline , endcol )
176166 }
177167}
178168
179169from ExtClass c , int n , VariableDeclarationGroup vdg , string suffix
180- where n = strictcount ( string fieldName
181- | exists ( Field f
182- | f .getDeclaringType ( ) = c and
183- fieldName = f .getName ( ) and
184- // IBOutlet's are a way of building GUIs
185- // automatically out of ObjC properties.
186- // We don't want to count those for the
187- // purposes of this query.
188- not ( f .getType ( ) .getAnAttribute ( ) .hasName ( "iboutlet" ) ) ) ) and
189- n > 15 and
190- not c .isConstructedFrom ( _) and
191- c = vdg .getClass ( ) and
192- if c .hasOneVariableGroup ( ) then suffix = "" else suffix = " - see $@"
193- select c , kindstr ( c ) + " " + c .getName ( ) + " has " + n + " fields; we suggest refactoring to 15 fields or fewer" + suffix + "." ,
194- vdg , vdg .toString ( )
170+ where
171+ n = strictcount ( string fieldName |
172+ exists ( Field f |
173+ f .getDeclaringType ( ) = c and
174+ fieldName = f .getName ( ) and
175+ // IBOutlet's are a way of building GUIs
176+ // automatically out of ObjC properties.
177+ // We don't want to count those for the
178+ // purposes of this query.
179+ not f .getType ( ) .getAnAttribute ( ) .hasName ( "iboutlet" )
180+ )
181+ ) and
182+ n > 15 and
183+ not c .isConstructedFrom ( _) and
184+ c = vdg .getClass ( ) and
185+ if c .hasOneVariableGroup ( ) then suffix = "" else suffix = " - see $@"
186+ select c ,
187+ kindstr ( c ) + " " + c .getName ( ) + " has " + n +
188+ " fields; we suggest refactoring to 15 fields or fewer" + suffix + "." , vdg , vdg .toString ( )
0 commit comments