Skip to content

Commit

Permalink
Make our own Java identifier methods. ()
Browse files Browse the repository at this point in the history
Java has changed set of unicodes between Java 17 and Java 21 so relying on Java's method would lead to breaking changes when switching JDK.
  • Loading branch information
Lojjs authored Nov 11, 2023
1 parent fa9d53a commit 8dd199a
Show file tree
Hide file tree
Showing 5 changed files with 892 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import org.neo4j.cypher.internal.label_expressions.LabelExpression.Wildcard
import org.neo4j.cypher.internal.label_expressions.LabelExpressionPredicate
import org.neo4j.cypher.internal.logical.plans.CoerceToPredicate
import org.neo4j.cypher.internal.util.InputPosition
import org.neo4j.cypher.internal.util.UnicodeHelper

trait ExpressionStringifier {
def apply(ast: Expression): String
Expand Down Expand Up @@ -611,11 +612,9 @@ object ExpressionStringifier {
else {
val isJavaIdentifier =
txt.codePoints().limit(1).allMatch(p =>
(Character.isJavaIdentifierStart(p) && Character.getType(
p
) != Character.CURRENCY_SYMBOL) || orGlobbedCharacter(p)
UnicodeHelper.isIdentifierStart(p) || orGlobbedCharacter(p)
) &&
txt.codePoints().skip(1).allMatch(p => Character.isJavaIdentifierPart(p) || orGlobbedCharacter(p))
txt.codePoints().skip(1).allMatch(p => UnicodeHelper.isIdentifierPart(p) || orGlobbedCharacter(p))
if (!isJavaIdentifier)
s"`$escaped`"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class PrettifierPropertyTest extends CypherFunSuite
implicit val config: PropertyCheckConfiguration = PropertyCheckConfiguration(minSuccessful = 5000)

test("Prettifier output should parse to the same ast") {
assume(Runtime.version().feature() < 21)
// To reproduce test failures, enable the following line with the seed from the TC build
// setScalaCheckInitialSeed(seed)
forAll(astGenerator._statement) { statement =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ TOKEN :
{
< IDENTIFIER: <LETTER> (<PART_LETTER>)* >
| < #LETTER:
[ // all chars for which Character.isJavaIdentifierStart(c) && Character.getType(c) != Character.CURRENCY_SYMBOL is true
[ // all chars for which Character.isJavaIdentifierStart(c) && Character.getType(c) != Character.CURRENCY_SYMBOL is true (in Java 17)
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
Expand Down Expand Up @@ -1064,7 +1064,7 @@ TOKEN :
"\uffda"-"\uffdc"
] >
| < #PART_LETTER:
[ // all chars for which Character.isIdentifierPart is true
[ // all chars for which Character.isIdentifierPart is true (in Java 17)
"\u0000"-"\u0008",
"\u000e"-"\u001b",
"\u0024",
Expand Down
Loading

0 comments on commit 8dd199a

Please sign in to comment.