Skip to content

Commit b13313f

Browse files
authored
KQL plugin - Code cleanup (#116180)
1 parent 8afe2f4 commit b13313f

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

x-pack/plugin/kql/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ base {
1717

1818
dependencies {
1919
compileOnly project(path: xpackModule('core'))
20-
compileOnly "org.antlr:antlr4-runtime:${versions.antlr4}"
20+
api "org.antlr:antlr4-runtime:${versions.antlr4}"
2121

2222
testImplementation "org.antlr:antlr4-runtime:${versions.antlr4}"
2323
testImplementation project(':test:framework')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[The "BSD license"]
2+
Copyright (c) 2015 Terence Parr, Sam Harwell
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
3. The name of the author may not be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

x-pack/plugin/kql/licenses/antlr4-runtime-NOTICE.txt

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
module org.elasticsearch.kql {
9+
requires org.elasticsearch.server;
10+
requires org.elasticsearch.xcontent;
11+
requires org.antlr.antlr4.runtime;
12+
requires org.elasticsearch.base;
13+
requires org.apache.lucene.queryparser;
14+
requires org.elasticsearch.logging;
15+
requires org.apache.lucene.core;
16+
17+
exports org.elasticsearch.xpack.kql;
18+
exports org.elasticsearch.xpack.kql.parser;
19+
}

x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import org.antlr.v4.runtime.tree.ParseTree;
1313
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
1414
import org.antlr.v4.runtime.tree.TerminalNode;
15-
import org.apache.logging.log4j.util.Strings;
1615
import org.apache.lucene.queryparser.classic.QueryParser;
1716

1817
import java.util.ArrayList;
1918
import java.util.List;
19+
import java.util.Locale;
2020

2121
/**
2222
* Utility class for parsing and processing KQL expressions.
@@ -211,15 +211,15 @@ private static boolean isEscapedKeywordSequence(String input, int startIndex) {
211211
if (startIndex + 1 >= input.length()) {
212212
return false;
213213
}
214-
String remaining = Strings.toRootLowerCase(input.substring(startIndex));
214+
String remaining = input.substring(startIndex).toLowerCase(Locale.ROOT);
215215
return remaining.startsWith("and") || remaining.startsWith("or") || remaining.startsWith("not");
216216
}
217217

218218
private static String handleKeywordSequence(String input, int startIndex) {
219219
String remaining = input.substring(startIndex);
220-
if (Strings.toRootLowerCase(remaining).startsWith("and")) return remaining.substring(0, 3);
221-
if (Strings.toRootLowerCase(remaining).startsWith("or")) return remaining.substring(0, 2);
222-
if (Strings.toRootLowerCase(remaining).startsWith("not")) return remaining.substring(0, 3);
220+
if (remaining.toLowerCase(Locale.ROOT).startsWith("and")) return remaining.substring(0, 3);
221+
if (remaining.toLowerCase(Locale.ROOT).startsWith("or")) return remaining.substring(0, 2);
222+
if (remaining.toLowerCase(Locale.ROOT).startsWith("not")) return remaining.substring(0, 3);
223223
return "";
224224
}
225225

0 commit comments

Comments
 (0)