From 5253c0cb7479e8682c19d05898cac14a67c4280a Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Fri, 31 Jan 2020 17:04:10 -0500 Subject: [PATCH] LUCENE-9134 Port ant-regenerate tasks to Gradle build (#1226) LUCENE-9134: Port ant-regenerate tasks to Gradle build Javacc sub-task. Closes #1226 --- gradle/defaults-java.gradle | 6 +- gradle/generation/javacc.gradle | 244 +++++++++++++++++- .../queryparser/classic/CharStream.java | 2 +- .../queryparser/classic/QueryParser.java | 7 +- .../classic/QueryParserTokenManager.java | 8 +- .../flexible/standard/parser/CharStream.java | 2 +- .../standard/parser/StandardSyntaxParser.java | 7 +- .../StandardSyntaxParserTokenManager.java | 7 +- .../surround/parser/CharStream.java | 2 +- .../surround/parser/QueryParser.java | 8 +- .../parser/QueryParserTokenManager.java | 6 +- 11 files changed, 257 insertions(+), 42 deletions(-) diff --git a/gradle/defaults-java.gradle b/gradle/defaults-java.gradle index e9462250a9d..584054ccba1 100644 --- a/gradle/defaults-java.gradle +++ b/gradle/defaults-java.gradle @@ -25,13 +25,13 @@ allprojects { tasks.withType(JavaCompile) { options.encoding = "UTF-8" options.compilerArgs += [ - "-Xlint", + "-Xlint", "-Xlint:-deprecation", "-Xlint:-serial", "-Xdoclint:all/protected", - "-Xdoclint:-missing", - "-Xdoclint:-accessibility", + "-Xdoclint:-missing", + "-Xdoclint:-accessibility", "-proc:none", // proc:none was added because of LOG4J2-1925 / JDK-8186647 ] } diff --git a/gradle/generation/javacc.gradle b/gradle/generation/javacc.gradle index 85f06099356..9a21b556cfe 100644 --- a/gradle/generation/javacc.gradle +++ b/gradle/generation/javacc.gradle @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // This adds javacc generation support. @@ -66,6 +82,46 @@ class JavaCCTask extends DefaultTask { if (result.exitValue != 0) { throw new GradleException("JavaCC failed to compile ${javaccFile}, here is the compilation output:\n${output}") } + + // Cleanup common to more than one javacc invocation. + // + // This is a minor typo in a comment that nontheless people have hand-corrected in the past. + ant.replace(file: "${parentDir}/CharStream.java", + token: "implemetation", + value: "implementation", + encoding: "UTF-8") + + // StringBuffer -> StringBuilder + ant.replace(token: "StringBuffer", + value: "StringBuilder", + encoding: "UTF-8") { + ant.fileset(dir: parentDir, includes: '*.java') { + ant.containsregexp(expression: "Generated By:JavaCC:") + } + } + + // Eliminates redundant cast message + ant.replace(token: "int hiByte = (int)(curChar >> 8);", + value: "int hiByte = curChar >> 8;", + encoding: "UTF-8") { + ant.fileset(dir: parentDir, includes: "*TokenManager.java") + } + + // So precommit passes + ant.replaceregexp(match: "/\\*\\* Debug output.*?Set debug output.*?ds; }", + replace: '', + flags: 's', + encoding: 'UTF-8') { + ant.fileset(dir: parentDir, includes: "*TokenManager.java") + } + + // Correct line endings for Windows. + project.ant.fixcrlf(srcDir: parentDir, + includes: "*.java", + encoding: "UTF-8", + eol: "lf") { + ant.containsregexp(expression: "Generated By:JavaCC:") + } } } @@ -76,12 +132,53 @@ configure(project(":lucene:queryparser")) { group "generation" javaccFile = file('src/java/org/apache/lucene/queryparser/classic/QueryParser.jj') - def parent = javaccFile.parentFile.toString() // I'll need this later. + def parentDir = javaccFile.parentFile // I'll need this later. doLast { - // There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't - // run the javacc task in master and check the regenerated files in, we'll be OK. - // As soon as we merge this into master I can fill this in. + // control visibility issues + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "public QueryParser(CharStream ", + value: "protected QueryParser(CharStream ", + encoding: 'UTF-8') + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "public QueryParser(QueryParserTokenManager ", + value: "protected QueryParser(QueryParserTokenManager ", + encoding: 'UTF-8') + + // Some redundant casts etc. in queryparser.java + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "new java.util.ArrayList", + value: "new java.util.ArrayList<>", + encoding: 'UTF-8') + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "new java.util.ArrayList", + value: "new java.util.ArrayList<>", + encoding: 'UTF-8') + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "(int)(curChar >> 8);", + value: "curChar >> 8;", + encoding: 'UTF-8') + // Remove unnecessary imports + def separator = System.getProperty('line.separator') + [/import java\.io\.StringReader;/, + /import java\.util\.ArrayList;/, + /import java\.util\.Arrays;/, + /import java\.util\.HashSet;/, + /import java\.util\.List;/, + /import java\.util\.Locale;/, + /import java\.util\.Set;/, + /import org\.apache\.lucene\.analysis\.Analyzer;/, + /import org\.apache\.lucene\.document\.DateTools;/, + /import org\.apache\.lucene\.search\.BooleanClause;/, + /import org\.apache\.lucene\.search\.Query;/, + /import org\.apache\.lucene\.search\.TermRangeQuery/, + /import org\.apache\.lucene\.search\.TermRangeQuery;/ + ].each { + ant.replaceregexp(file: file("${parentDir}/QueryParserTokenManager.java"), + match: "${it}\\s*${separator}", + replace: "", + encoding: "UTF-8") + } } } } @@ -92,26 +189,151 @@ configure(project(":lucene:queryparser")) { group "generation" javaccFile = file('src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj') + def parentDir = javaccFile.parentFile doLast { - // There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't - // run the javacc task in master and check the regenerated files in, we'll be OK. - // As soon as we merge this into master I can fill this in. + def separator = System.getProperty('line.separator') + + // Remove unneeded import + ant.replaceregexp(match: /import org\.apache\.lucene\.analysis\.TokenStream;\s*${separator}${separator}/, + replace: "", + encoding: "UTF-8") { + ant.fileset(dir: parentDir, includes: "QueryParser.java") + } + + // Eliminate compiler warning + ant.replace(file: file("${parentDir}/QueryParser.java"), + token: "new java.util.ArrayList", + value: "new java.util.ArrayList<>", + encoding: 'UTF-8') + + // There are a bunch of unused imports we need to remove to pass precommit + [ + /import java\.util\.ArrayList;/, + /import java\.util\.List;/, + /import java\.io\.StringReader;/, + /import org\.apache\.lucene\.analysis\.TokenStream;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.SrndQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.FieldsQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.OrQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.AndQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.NotQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.DistanceQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.SrndTermQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.SrndPrefixQuery;/, + /import org\.apache\.lucene\.queryparser\.surround\.query\.SrndTruncQuery;/ + ].each { + ant.replaceregexp(file: file("${parentDir}/QueryParserTokenManager.java"), + match: "${it}\\s*${separator}", + replace: "", + encoding: "UTF-8") + } + } } } - configure(project(":lucene:queryparser")) { task javaccParserFlexible(type: JavaCCTask) { description "Regenerate Flexible query parser from java CC.java" group "generation" javaccFile = file('src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj') + def parentDir = javaccFile.parentFile doLast { - // There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't - // run the javacc task in master and check the regenerated files in, we'll be OK. - // As soon as we merge this into master I can fill this in. + def lineSeparator = System.lineSeparator() + + // extend the proper class + ant.replaceregexp(file: "${parentDir}/ParseException.java", + match: "public class ParseException extends Exception", + replace: "public class ParseException extends QueryNodeParseException", + flags: "g", + byline: "false", + encoding: 'UTF-8') + + // Import correct classes. + ant.replaceregexp(file: "${parentDir}/ParseException.java", + match: "package org.apache.lucene.queryparser.flexible.standard.parser;", + replace: "package org.apache.lucene.queryparser.flexible.standard.parser;${lineSeparator} ${lineSeparator}" + + " import org.apache.lucene.queryparser.flexible.messages.Message;${lineSeparator}" + + " import org.apache.lucene.queryparser.flexible.messages.MessageImpl;${lineSeparator}" + + " import org.apache.lucene.queryparser.flexible.core.*;${lineSeparator}" + + " import org.apache.lucene.queryparser.flexible.core.messages.*;", + flags: "g", + byline: "false", + encoding: 'UTF-8') + + // Fill in c'tor code + ant.replaceregexp(file: "${parentDir}/ParseException.java", + match: "^ public ParseException\\(Token currentTokenVal.*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException(Token currentTokenVal,${lineSeparator}" + + " int[][] expectedTokenSequencesVal, String[] tokenImageVal) {${lineSeparator}" + + " super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, initialise(${lineSeparator}" + + " currentTokenVal, expectedTokenSequencesVal, tokenImageVal)));${lineSeparator}" + + " this.currentToken = currentTokenVal;${lineSeparator}" + + " this.expectedTokenSequences = expectedTokenSequencesVal;${lineSeparator}" + + " this.tokenImage = tokenImageVal;${lineSeparator}" + + " }", + flags: "gm", + byline: "false", + encoding: 'UTF-8') + + // Invoke super, use proper c'tor + ant.replaceregexp(file: "${parentDir}/ParseException.java", + match: "^ public ParseException\\(String message.*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException(Message message) {${lineSeparator}" + + " super(message);${lineSeparator}" + + " }", + flags: "gm", + byline: "false", + encoding: 'UTF-8') + + // Invoke super properly + ant.replaceregexp(file: "${parentDir}/ParseException.java", + match: "^ public ParseException\\(\\).*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException() {${lineSeparator}" + + " super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, \"Error\"));${lineSeparator}" + + " }", + flags: "gm", + byline: "false", + encoding: 'UTF-8') + + // Redundant cast warning + ant.replace(file: file("${parentDir}/StandardSyntaxParser.java"), + token: "new java.util.ArrayList", + value: "new java.util.ArrayList<>", + encoding: 'UTF-8') + + // Remove unused imports. + def separator = System.getProperty('line.separator') + [ + /import java.io.StringReader;/, + /import java.util.Vector;/, + /import java.util.Arrays;/, + /import org.apache.lucene.queryparser.flexible.messages.Message;/, + /import org.apache.lucene.queryparser.flexible.messages.MessageImpl;/, + /import org.apache.lucene.queryparser.flexible.core.QueryNodeParseException;/, + /import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode;/, + /import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode;/, + /import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser;/, + /import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode;/ + ].each { + ant.replaceregexp(file: file("${parentDir}/StandardSyntaxParserTokenManager.java"), + match: "${it}\\s*${separator}", + replace: "", + encoding: "UTF-8") + } } } } \ No newline at end of file diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/CharStream.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/CharStream.java index 0fe9ab80af8..443117f0a36 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/CharStream.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/CharStream.java @@ -112,4 +112,4 @@ interface CharStream { void Done(); } -/* JavaCC - OriginalChecksum=6a5b704d1e6e4e036de8c95b24d47787 (do not edit this line) */ +/* JavaCC - OriginalChecksum=30b94cad7b10d0d81e3a59a1083939d0 (do not edit this line) */ diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.java index 01abb788bbf..877f1415865 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.java @@ -78,7 +78,6 @@ import org.apache.lucene.search.TermRangeQuery; * the same syntax as this class, but is more modular, * enabling substantial customization to how a query is created. */ -@SuppressWarnings("unchecked") public class QueryParser extends QueryParserBase implements QueryParserConstants { /** The default operator for parsing queries. * Use {@link QueryParserBase#setDefaultOperator} to change it. @@ -864,7 +863,7 @@ public class QueryParser extends QueryParserBase implements QueryParserConstants return (jj_ntk = jj_nt.kind); } - private java.util.List jj_expentries = new java.util.ArrayList(); + private java.util.List jj_expentries = new java.util.ArrayList<>(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -879,7 +878,7 @@ public class QueryParser extends QueryParserBase implements QueryParserConstants for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { int[] oldentry = (int[])(it.next()); if (oldentry.length == jj_expentry.length) { for (int i = 0; i < jj_expentry.length; i++) { @@ -927,7 +926,7 @@ public class QueryParser extends QueryParserBase implements QueryParserConstants jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.get(i); + exptokseq[i] = jj_expentries.get(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java index 065ff8b4411..39cac0232f2 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java @@ -1,8 +1,6 @@ /* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */ package org.apache.lucene.queryparser.classic; - /** Token Manager. */ -@SuppressWarnings("cast") public class QueryParserTokenManager implements QueryParserConstants { @@ -481,7 +479,7 @@ private int jjMoveNfa_2(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -675,7 +673,7 @@ private int jjMoveNfa_0(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -848,7 +846,7 @@ private int jjMoveNfa_1(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/CharStream.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/CharStream.java index 71c968d6eba..2dee00bc396 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/CharStream.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/CharStream.java @@ -112,4 +112,4 @@ interface CharStream { void Done(); } -/* JavaCC - OriginalChecksum=ad6e2aadb6864b25f5ca6701803e4f89 (do not edit this line) */ +/* JavaCC - OriginalChecksum=53b2ec7502d50e2290e86187a6c01270 (do not edit this line) */ diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java index 8f1160ef3f6..e034607e23e 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java @@ -44,7 +44,6 @@ import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode; /** * Parser for the standard Lucene syntax */ -@SuppressWarnings("unchecked") public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserConstants { @@ -962,7 +961,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC return (jj_ntk = jj_nt.kind); } - private java.util.List jj_expentries = new java.util.ArrayList(); + private java.util.List jj_expentries = new java.util.ArrayList<>(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -977,7 +976,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { int[] oldentry = (int[])(it.next()); if (oldentry.length == jj_expentry.length) { for (int i = 0; i < jj_expentry.length; i++) { @@ -1025,7 +1024,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.get(i); + exptokseq[i] = jj_expentries.get(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java index 2758bed1a63..1fdaa480af0 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java @@ -18,7 +18,6 @@ package org.apache.lucene.queryparser.flexible.standard.parser; */ /** Token Manager. */ -@SuppressWarnings("cast") public class StandardSyntaxParserTokenManager implements StandardSyntaxParserConstants { @@ -351,7 +350,7 @@ private int jjMoveNfa_2(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -471,7 +470,7 @@ private int jjMoveNfa_0(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -644,7 +643,7 @@ private int jjMoveNfa_1(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/CharStream.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/CharStream.java index 469b46e1abb..ba060f8203a 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/CharStream.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/CharStream.java @@ -112,4 +112,4 @@ interface CharStream { void Done(); } -/* JavaCC - OriginalChecksum=a2f9487333c63c295c1dfad0d1fc9019 (do not edit this line) */ +/* JavaCC - OriginalChecksum=242ae59b965491e225a44534cbc73b42 (do not edit this line) */ diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.java index 7af57f5fb93..584a82d4221 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.java @@ -40,7 +40,7 @@ import org.apache.lucene.queryparser.surround.query.SrndTruncQuery; * must appear within three positions of each other, or in other words, up * to two terms may appear between a and b.

*/ -@SuppressWarnings("unchecked") + public class QueryParser implements QueryParserConstants { static final int MINIMUM_PREFIX_LENGTH = 3; static final int MINIMUM_CHARS_IN_TRUNC = 3; @@ -639,7 +639,7 @@ public class QueryParser implements QueryParserConstants { return (jj_ntk = jj_nt.kind); } - private java.util.List jj_expentries = new java.util.ArrayList(); + private java.util.List jj_expentries = new java.util.ArrayList<>(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -654,7 +654,7 @@ public class QueryParser implements QueryParserConstants { for (int i = 0; i < jj_endpos; i++) { jj_expentry[i] = jj_lasttokens[i]; } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { int[] oldentry = (int[])(it.next()); if (oldentry.length == jj_expentry.length) { for (int i = 0; i < jj_expentry.length; i++) { @@ -699,7 +699,7 @@ public class QueryParser implements QueryParserConstants { jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.get(i); + exptokseq[i] = jj_expentries.get(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java index 60501c7931b..f51a03ef950 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java @@ -1,8 +1,6 @@ /* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */ package org.apache.lucene.queryparser.surround.parser; - /** Token Manager. */ -@SuppressWarnings("cast") public class QueryParserTokenManager implements QueryParserConstants { @@ -333,7 +331,7 @@ private int jjMoveNfa_1(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -453,7 +451,7 @@ private int jjMoveNfa_0(int startState, int curPos) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = curChar >> 8; int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6;