@@ -60,6 +60,16 @@ public class JFlexXref implements Xrefer, SymbolMatchedListener,
60
60
private Scope scope ;
61
61
private int scopeLevel ;
62
62
63
+ /**
64
+ * The following field is set to {@code true} (via
65
+ * {@link #sourceCodeSeen(org.opensolaris.opengrok.analysis.SourceCodeSeenEvent)})
66
+ * when applicable during lexing before a call to {@link #startNewLine()}
67
+ * so that the lines-of-code count is also incremented.
68
+ */
69
+ private boolean didSeePhysicalLOC ;
70
+
71
+ private int loc ;
72
+
63
73
/**
64
74
* See {@link RuntimeEnvironment#getUserPage()}. Per default initialized in
65
75
* the constructor and here to be consistent and avoid lot of unnecessary
@@ -124,7 +134,9 @@ public void setReader(Reader input) {
124
134
@ Override
125
135
public void reset () {
126
136
annotation = null ;
137
+ didSeePhysicalLOC = false ;
127
138
disjointSpanClassName = null ;
139
+ loc = 0 ;
128
140
scopes = new Scopes ();
129
141
scope = null ;
130
142
scopeLevel = 0 ;
@@ -136,10 +148,20 @@ public void reset() {
136
148
* of the instance's {@link ScanningSymbolMatcher}.
137
149
* @return yyline
138
150
*/
151
+ @ Override
139
152
public int getLineNumber () {
140
153
return matcher .getLineNumber ();
141
154
}
142
155
156
+ /**
157
+ * Gets the determined count of physical lines-of-code.
158
+ * @return lines-of-code count
159
+ */
160
+ @ Override
161
+ public int getLOC () {
162
+ return loc ;
163
+ }
164
+
143
165
@ Override
144
166
public void setAnnotation (Annotation annotation ) {
145
167
this .annotation = annotation ;
@@ -187,6 +209,17 @@ public void symbolMatched(SymbolMatchedEvent evt) {
187
209
}
188
210
}
189
211
212
+ /**
213
+ * Sets a value indicating that source code was encountered such that
214
+ * {@link #getLOC()} will be incremented upon the next
215
+ * {@link #startNewLine()} or at end-of-file.
216
+ * @param evt ignored
217
+ */
218
+ @ Override
219
+ public void sourceCodeSeen (SourceCodeSeenEvent evt ) {
220
+ didSeePhysicalLOC = true ;
221
+ }
222
+
190
223
@ Override
191
224
public void nonSymbolMatched (TextMatchedEvent evt ) {
192
225
String str = evt .getStr ();
@@ -463,19 +496,33 @@ public void write(Writer out) throws IOException {
463
496
while (!matcher .emptyStack ()) {
464
497
matcher .yypop ();
465
498
}
499
+
500
+ // Account for dangling line of code. Unlike line number, LOC is
501
+ // incremented post- rather than pre-.
502
+ if (didSeePhysicalLOC ) {
503
+ ++loc ;
504
+ didSeePhysicalLOC = false ;
505
+ }
466
506
}
467
507
468
508
/**
469
509
* Terminate the current line and insert preamble for the next line. The
470
- * line count will be incremented.
471
- *
510
+ * line count is taken from {@link ScanningSymbolMatcher#getLineNumber()}.
511
+ * The lines-of-code count may be incremented if {@link #didSeePhysicalLOC}
512
+ * has been set to {@code true} (after which it will be reset to
513
+ * {@code false}).
472
514
* @throws IOException on error when writing the xref
473
515
*/
474
516
public void startNewLine () throws IOException {
475
517
String iconId = null ;
476
518
int line = matcher .getLineNumber ();
477
519
boolean skipNl = false ;
478
520
521
+ if (didSeePhysicalLOC ) {
522
+ ++loc ;
523
+ didSeePhysicalLOC = false ;
524
+ }
525
+
479
526
if (scopesEnabled ) {
480
527
startScope ();
481
528
0 commit comments