JEE11_Data: Diagnostics for JDQL Function calls
Diagnostic messages:
- The abs() function requires a numeric argument. Non‑numeric arguments are invalid.
- The length() function requires a String argument and returns an Integer.
- The lower() function requires a String argument and returns a lowercase String.
- The upper() function requires a String argument and returns an uppercase String.
- The left() function requires a String as the first argument and an integral number as the second.
- The right() function requires a String as the first argument and an integral number as the second.
Description:
A function call is the name of a JDQL function, followed by a parenthesized list of argument expressions, with syntax given by function_expression.
The abs() function is assigned the type of its numeric argument, and evaluates to the absolute value of the numeric value to which its argument evaluates. Its argument must be of numeric type.
The length() function is assigned the type java.lang.Integer, and evaluates to the length of string to which its argument evaluates. Its argument must be of type java.lang.String.
The lower() function is assigned the type java.lang.String, and evaluates to the lowercase form of the string to which its argument evaluates. Its argument must be of type java.lang.String.
The upper() function is assigned the type java.lang.String, and evaluates to the uppercase form of the string to which its argument evaluates. Its argument must be of type java.lang.String.
The left() function is assigned the type java.lang.String, and evaluates to a prefix of the string to which its first argument evaluates. The length of the prefix is given by the integer value to which its second argument evaluates. The first argument must be of type java.lang.String, and the second argument must be of integral numeric type.
The right() function is assigned the type java.lang.String, and evaluates to a suffix of the string to which its first argument evaluates. The length of the suffix is given by the integer value to which its second argument evaluates. The first argument must be of type java.lang.String, and the second argument must be of integral numeric type.
Examples:
Invalid example
SELECT abs(p.name) FROM Product p
//Invalid: abs() argument must be numeric
SELECT length(p.price) FROM Product p
//Invalid: length() argument must be String
SELECT lower(p.price) FROM Product p
//Invalid: lower() argument must be String
SELECT left(p.price, 3) FROM Product p
//Invalid: first argument must be String
SELECT right(p.name, p.price) FROM Product p
//Invalid: second argument must be integral numeric type
Valid example
SELECT abs(p.price) FROM Product p
SELECT length(p.name) FROM Product p
SELECT lower(p.category) FROM Product p
SELECT upper(p.category) FROM Product p
SELECT left(p.name, 3) FROM Product p
SELECT right(p.name, 2) FROM Product p
Specification:
https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#:~:text=by%20function_expression.-,The%20abs()%20function%20is%20assigned%20the%20type%20of%20its%20numeric,%2C%20and%20the%20second%20argument%20must%20be%20of%20integral%20numeric%20type.,-When%20any%20argument
Type of language feature proposed:
Select all that apply
- [x] diagnostic
- [ ] quick-fix
- [ ] snippet
- [ ] other, please specify: