Skip to content

Commit d650e82

Browse files
ahornaceVladimir Kotal
authored andcommitted
Enable checkstyle in suggester module
1 parent 8a883da commit d650e82

File tree

8 files changed

+65
-24
lines changed

8 files changed

+65
-24
lines changed

checkstyle/style.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<!DOCTYPE module PUBLIC
3-
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
4-
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
55
<module name="Checker">
66
<module name="NewlineAtEndOfFile"/>
77
<module name="Header">
@@ -11,11 +11,10 @@
1111
<module name="FileTabCharacter"/>
1212
<module name="TreeWalker">
1313
<module name="AvoidStarImport">
14-
<property name="allowStaticMemberImports" value="true"/>
14+
<property name="allowStaticMemberImports" value="true"/>
1515
</module>
1616
<module name="RedundantImport"/>
1717
<module name="UnusedImports"/>
18-
<module name="ImportOrder"/>
1918
<module name="MethodLength">
2019
<property name="max" value="200"/>
2120
</module>
@@ -27,11 +26,12 @@
2726
<module name="GenericWhitespace"/>
2827
<module name="MethodParamPad"/>
2928
<module name="NoWhitespaceAfter"/>
30-
<module name="FileContentsHolder"/>
29+
<module name="SuppressionCommentFilter">
30+
<property name="offCommentFormat" value="&lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;Generated Code&quot;&gt;"/>
31+
<property name="onCommentFormat" value="&lt;/editor-fold&gt;"/>
32+
</module>
33+
</module>
34+
<module name="SuppressionFilter">
35+
<property name="file" value="checkstyle/suppressions.xml" />
3136
</module>
32-
<module name="SuppressionCommentFilter">
33-
<property name="offCommentFormat" value="&lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;Generated Code&quot;&gt;"/>
34-
<property name="onCommentFormat" value="&lt;/editor-fold&gt;"/>
35-
</module>
3637
</module>
37-

checkstyle/suppressions.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.1//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_1.dtd">
6+
7+
<suppressions>
8+
<suppress checks="Header" files="CustomSloppyPhraseScorer\.java|CustomPhraseQuery\.java|
9+
|CustomExactPhraseScorer\.java|PhrasePositions\.java|PhraseQueue\.java" />
10+
</suppressions>

pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,6 @@ Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
309309
<aggregate>true</aggregate>
310310
</configuration>
311311
</plugin>
312-
<plugin>
313-
<groupId>org.apache.maven.plugins</groupId>
314-
<artifactId>maven-checkstyle-plugin</artifactId>
315-
<version>2.17</version>
316-
<configuration>
317-
<configLocation>checkstyle/style.xml</configLocation>
318-
</configuration>
319-
</plugin>
320312
</plugins>
321313
</reporting>
322314

suggester/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,38 @@
6666
</dependency>
6767
</dependencies>
6868

69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-checkstyle-plugin</artifactId>
74+
<version>3.0.0</version>
75+
<dependencies>
76+
<dependency>
77+
<groupId>com.puppycrawl.tools</groupId>
78+
<artifactId>checkstyle</artifactId>
79+
<version>8.11</version>
80+
</dependency>
81+
</dependencies>
82+
<executions>
83+
<execution>
84+
<id>checkstyle</id>
85+
<phase>validate</phase>
86+
<configuration>
87+
<configLocation>../checkstyle/style.xml</configLocation>
88+
<encoding>UTF-8</encoding>
89+
<consoleOutput>true</consoleOutput>
90+
<failsOnError>true</failsOnError>
91+
</configuration>
92+
<goals>
93+
<goal>check</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
69101
<profiles>
70102
<profile>
71103
<id>java9plus</id>

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomPhraseQuery.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ public int compareTo(PostingsAndFreq other) {
347347
}
348348
for (int i=0; i<terms.length; i++) {
349349
int res = terms[i].compareTo(other.terms[i]);
350-
if (res!=0) return res;
350+
if (res!=0) {
351+
return res;
352+
}
351353
}
352354
return 0;
353355
}

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomSloppyPhraseScorer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ private ArrayList<ArrayList<PhrasePositions>> gatherRptGroups(LinkedHashMap<Term
440440
// simpler - no multi-terms - can base on positions in first doc
441441
for (int i=0; i<rpp.length; i++) {
442442
PhrasePositions pp = rpp[i];
443-
if (pp.rptGroup >=0) continue; // already marked as a repetition
443+
if (pp.rptGroup >=0) {
444+
continue; // already marked as a repetition
445+
}
444446
int tpPos = tpPos(pp);
445447
for (int j=i+1; j<rpp.length; j++) {
446448
PhrasePositions pp2 = rpp[j];

suggester/src/main/java/org/opengrok/suggest/query/customized/PhrasePositions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
*/
1717
package org.opengrok.suggest.query.customized;
1818

19+
import org.apache.lucene.index.PostingsEnum;
20+
import org.apache.lucene.index.Term;
21+
1922
import java.io.IOException;
20-
import org.apache.lucene.index.*;
2123

2224
/**
2325
* Copy of the Lucene's {@link org.apache.lucene.search.PhrasePositions}. It is needed by
@@ -58,8 +60,9 @@ final boolean nextPosition() throws IOException {
5860
if (count-- > 0) { // read subsequent pos's
5961
position = postings.nextPosition() - offset;
6062
return true;
61-
} else
63+
} else {
6264
return false;
65+
}
6366
}
6467

6568
/** for debug purposes */

suggester/src/main/java/org/opengrok/suggest/query/customized/PhraseQueue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ final class PhraseQueue extends PriorityQueue<PhrasePositions> {
3030

3131
@Override
3232
protected final boolean lessThan(PhrasePositions pp1, PhrasePositions pp2) {
33-
if (pp1.position == pp2.position)
33+
if (pp1.position == pp2.position) {
3434
// same doc and pp.position, so decide by actual term positions.
3535
// rely on: pp.position == tp.position - offset.
3636
if (pp1.offset == pp2.offset) {
3737
return pp1.ord < pp2.ord;
3838
} else {
3939
return pp1.offset < pp2.offset;
4040
}
41-
else {
41+
} else {
4242
return pp1.position < pp2.position;
4343
}
4444
}

0 commit comments

Comments
 (0)