Skip to content

Commit 6dc1480

Browse files
authored
Merge pull request #2652 from idodeclare/feature/retire_lex_helpers
Feature/retire lex helpers
2 parents 8ee2396 + 3b46bc3 commit 6dc1480

29 files changed

+1189
-884
lines changed

dev/checkstyle/suppressions.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1919
CDDL HEADER END
2020
2121
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22-
Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
22+
Portions Copyright (c) 2018-2019, Chris Fraire <[email protected]>.
2323
2424
-->
25+
2526
<!DOCTYPE suppressions PUBLIC
2627
"-//Checkstyle//DTD SuppressionFilter Configuration 1.1//EN"
2728
"https://checkstyle.org/dtds/suppressions_1_1.dtd">
@@ -34,8 +35,8 @@ Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
3435
|BlockingObjectPool\.java|OGKTextVecField\.java|OGKTextField\.java|
3536
|LazilyInstantiate\.java" />
3637

37-
<suppress checks="ParameterNumber" files="CtagsReader\.java|Definitions\.java|PerlLexHelper\.java|
38-
|JFlexXrefUtils\.java|RubyLexHelper\.java|FileAnalyzerFactory\.java|SearchController\.java|
38+
<suppress checks="ParameterNumber" files="CtagsReader\.java|Definitions\.java|
39+
|JFlexXrefUtils\.java|FileAnalyzerFactory\.java|SearchController\.java|
3940
|Context\.java|HistoryContext\.java|Suggester\.java" />
4041

4142
<suppress checks="MethodLength" files="Indexer\.java" />

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.ada;
2525

@@ -51,11 +51,11 @@ protected AdaAnalyzer(AnalyzerFactory factory) {
5151
* Gets a version number to be used to tag processed documents so that
5252
* re-analysis can be re-done later if a stored version number is different
5353
* from the current implementation.
54-
* @return 20180208_00
54+
* @return 20190118_01
5555
*/
5656
@Override
5757
protected int getSpecializedVersionNo() {
58-
return 20180208_00; // Edit comment above too!
58+
return 20190118_01; // Edit comment above too!
5959
}
6060

6161
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaLexHelper.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaLexer.java

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,32 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, Chris Fraire <[email protected]>.
21+
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2222
*/
2323

2424
package org.opengrok.indexer.analysis.ada;
2525

2626
import java.io.IOException;
27+
2728
import org.opengrok.indexer.analysis.JFlexJointLexer;
29+
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
2830
import org.opengrok.indexer.analysis.Resettable;
2931

3032
/**
31-
* Represents an API for object's using {@link AdaLexHelper}
32-
*/
33-
interface AdaLexer extends JFlexJointLexer {
34-
}
35-
36-
/**
37-
* Represents a helper for Ada lexers
33+
* Represents an abstract base class for Ada lexers.
3834
*/
39-
class AdaLexHelper implements Resettable {
40-
41-
private final AdaLexer lexer;
42-
43-
private final int SCOMMENT;
44-
45-
AdaLexHelper(int sCOMMENT, AdaLexer lexer) {
46-
if (lexer == null) {
47-
throw new IllegalArgumentException("`lexer' is null");
48-
}
49-
this.lexer = lexer;
50-
this.SCOMMENT = sCOMMENT;
51-
}
52-
53-
/**
54-
* Resets the instance to an initial state.
55-
*/
56-
@Override
57-
public void reset() {
58-
// noop
59-
}
35+
abstract class AdaLexer extends JFlexSymbolMatcher
36+
implements JFlexJointLexer, Resettable {
6037

6138
/**
62-
* Write {@code value} to output -- if it contains any EOLs then the
63-
* {@code startNewLine()} is called in lieu of outputting EOL.
39+
* Writes {@code value} to output -- if it contains any EOLs then the
40+
* {@link JFlexJointLexer#startNewLine()} is called in lieu of outputting
41+
* EOL.
6442
*/
6543
public void takeLiteral(String value, String className)
6644
throws IOException {
6745

68-
lexer.disjointSpan(className);
46+
disjointSpan(className);
6947

7048
int off = 0;
7149
do {
@@ -74,7 +52,7 @@ public void takeLiteral(String value, String className)
7452
ni = value.indexOf("\n", off);
7553
if (ri == -1 && ni == -1) {
7654
String sub = value.substring(off);
77-
lexer.offer(sub);
55+
offer(sub);
7856
break;
7957
}
8058
if (ri != -1 && ni != -1) {
@@ -93,22 +71,28 @@ public void takeLiteral(String value, String className)
9371
}
9472

9573
String sub = value.substring(off, i);
96-
lexer.offer(sub);
97-
lexer.disjointSpan(null);
98-
lexer.startNewLine();
99-
lexer.disjointSpan(className);
74+
offer(sub);
75+
disjointSpan(null);
76+
startNewLine();
77+
disjointSpan(className);
10078
off = i + w;
10179
} while (off < value.length());
10280

103-
lexer.disjointSpan(null);
81+
disjointSpan(null);
10482
}
10583

10684
/**
107-
* Calls {@link AdaLexer#phLOC()} if the yystate is not SCOMMENT.
85+
* Calls {@link #phLOC()} if the yystate is not SCOMMENT.
10886
*/
10987
public void chkLOC() {
110-
if (lexer.yystate() != SCOMMENT) {
111-
lexer.phLOC();
88+
if (yystate() != SCOMMENT()) {
89+
phLOC();
11290
}
11391
}
92+
93+
/**
94+
* Subclasses must override to get the constant value created by JFlex to
95+
* represent SCOMMENT.
96+
*/
97+
abstract int SCOMMENT();
11498
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
21+
* Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2222
*/
2323

2424
package org.opengrok.indexer.analysis.eiffel;
@@ -48,11 +48,11 @@ protected EiffelAnalyzer(AnalyzerFactory factory) {
4848
* Gets a version number to be used to tag processed documents so that
4949
* re-analysis can be re-done later if a stored version number is different
5050
* from the current implementation.
51-
* @return 20180208_00
51+
* @return 20190118_00
5252
*/
5353
@Override
5454
protected int getSpecializedVersionNo() {
55-
return 20180208_00; // Edit comment above too!
55+
return 20190118_00; // Edit comment above too!
5656
}
5757

5858
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelLexHelper.java renamed to opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/eiffel/EiffelLexer.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,35 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, Chris Fraire <[email protected]>.
21+
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2222
*/
2323

2424
package org.opengrok.indexer.analysis.eiffel;
2525

2626
import java.io.IOException;
27+
2728
import org.opengrok.indexer.analysis.JFlexJointLexer;
29+
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
2830
import org.opengrok.indexer.analysis.Resettable;
2931
import org.opengrok.indexer.web.HtmlConsts;
3032

3133
/**
32-
* Represents an API for object's using {@link EiffelLexHelper}.
33-
*/
34-
interface EiffelLexer extends JFlexJointLexer {
35-
}
36-
37-
/**
38-
* Represents a helper for Eiffel lexers.
34+
* Represents an abstract base class for Eiffel lexers.
3935
*/
40-
class EiffelLexHelper implements Resettable {
41-
42-
private final EiffelLexer lexer;
43-
44-
private final int VSTRING;
45-
private final int SCOMMENT;
36+
abstract class EiffelLexer extends JFlexSymbolMatcher
37+
implements JFlexJointLexer, Resettable {
4638

4739
/**
4840
* When matching a Verbatim_string, the expected closer is stored here.
4941
*/
5042
private String vstring_closer;
5143

52-
EiffelLexHelper(int vSTRING, int sCOMMENT, EiffelLexer lexer) {
53-
if (lexer == null) {
54-
throw new IllegalArgumentException("`lexer' is null");
55-
}
56-
this.lexer = lexer;
57-
this.VSTRING = vSTRING;
58-
this.SCOMMENT = sCOMMENT;
59-
}
60-
6144
/**
6245
* Resets the instance to an initial state.
6346
*/
6447
@Override
6548
public void reset() {
49+
super.reset();
6650
vstring_closer = null;
6751
}
6852

@@ -94,9 +78,9 @@ public void vop(String opener) throws IOException {
9478
}
9579
vstring_closer = close0 + alpha + "\"";
9680

97-
lexer.yypush(VSTRING);
98-
lexer.disjointSpan(HtmlConsts.STRING_CLASS);
99-
lexer.offer(opener);
81+
yypush(VSTRING());
82+
disjointSpan(HtmlConsts.STRING_CLASS);
83+
offer(opener);
10084
}
10185

10286
/**
@@ -112,26 +96,38 @@ public void maybeEndVerbatim(String capture) throws IOException {
11296
int npushback;
11397
if (!capture.startsWith(vstring_closer)) {
11498
// Nope--so just write the double quote, and push back the rest.
115-
lexer.offer(capture.substring(0, 1));
99+
offer(capture.substring(0, 1));
116100
npushback = capture.length() - 1;
117101
} else {
118-
lexer.offer(vstring_closer);
119-
lexer.disjointSpan(null);
120-
lexer.yypop();
102+
offer(vstring_closer);
103+
disjointSpan(null);
104+
yypop();
121105
npushback = capture.length() - vstring_closer.length();
122106
vstring_closer = null;
123107
}
124108
if (npushback > 0) {
125-
lexer.yypushback(npushback);
109+
yypushback(npushback);
126110
}
127111
}
128112

129113
/**
130-
* Calls {@link EiffelLexer#phLOC()} if the yystate is not SCOMMENT.
114+
* Calls {@link #phLOC()} if the yystate is not SCOMMENT.
131115
*/
132116
public void chkLOC() {
133-
if (lexer.yystate() != SCOMMENT) {
134-
lexer.phLOC();
117+
if (yystate() != SCOMMENT()) {
118+
phLOC();
135119
}
136120
}
121+
122+
/**
123+
* Subclasses must override to get the constant value created by JFlex to
124+
* represent SCOMMENT.
125+
*/
126+
abstract int SCOMMENT();
127+
128+
/**
129+
* Subclasses must override to get the constant value created by JFlex to
130+
* represent VSTRING.
131+
*/
132+
abstract int VSTRING();
137133
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/fortran/FortranAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.fortran;
2525

@@ -45,11 +45,11 @@ public class FortranAnalyzer extends AbstractSourceCodeAnalyzer {
4545
* Gets a version number to be used to tag processed documents so that
4646
* re-analysis can be re-done later if a stored version number is different
4747
* from the current implementation.
48-
* @return 20180208_00
48+
* @return 20190118_00
4949
*/
5050
@Override
5151
protected int getSpecializedVersionNo() {
52-
return 20180208_00; // Edit comment above too!
52+
return 20190118_00; // Edit comment above too!
5353
}
5454

5555
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/perl/PerlAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.perl;
2525

@@ -49,11 +49,11 @@ protected PerlAnalyzer(AnalyzerFactory factory) {
4949
* Gets a version number to be used to tag processed documents so that
5050
* re-analysis can be re-done later if a stored version number is different
5151
* from the current implementation.
52-
* @return 20180208_00
52+
* @return 20190118_01
5353
*/
5454
@Override
5555
protected int getSpecializedVersionNo() {
56-
return 20180208_00; // Edit comment above too!
56+
return 20190118_01; // Edit comment above too!
5757
}
5858

5959
/**

0 commit comments

Comments
 (0)