[plsql] Fix ScalarDataTypeName parsing

Fixes #5133
This commit is contained in:
Andreas Dangel
2024-07-25 11:17:49 +02:00
parent 5d39923c2f
commit 87b0c4f851
5 changed files with 29 additions and 6 deletions

View File

@ -50,6 +50,7 @@ This is a {{ site.pmd.release_type }} release.
* [#5086](https://github.com/pmd/pmd/pull/5086): \[plsql] Fixed issue with missing optional table alias in MERGE usage
* [#5087](https://github.com/pmd/pmd/pull/5087): \[plsql] Add support for SQL_MACRO
* [#5088](https://github.com/pmd/pmd/pull/5088): \[plsql] Add support for 'DEFAULT' clause on the arguments of some oracle functions
* [#5133](https://github.com/pmd/pmd/issues/5133): \[plsql] AssertionError: Root of the tree should implement RootNode for a PL/SQL type declaration
* cli
* [#5120](https://github.com/pmd/pmd/issues/5120): \[cli] Can't start designer under Windows
* core

View File

@ -993,12 +993,8 @@ ASTScalarDataTypeName ScalarDataTypeName() :
LOOKAHEAD(4) (<WITH><LOCAL><TIME><ZONE> {name.append(" WITH LOCAL TIME ZONE");}) |
LOOKAHEAD(3) (<WITH><TIME><ZONE> {name.append( " WITH TIME ZONE");}) |
LOOKAHEAD(2) (<TO><MONTH> {name.append( " TO MONTH");}) |
LOOKAHEAD(2) (<TO><SECOND> {name.append( " TO SECOND");}
(
LOOKAHEAD(2) "(" precision=NumericLiteral() {name.append( "(" + precision) ;}
")" {name.append( ")");}
)?
)
LOOKAHEAD(2) <TO><SECOND> { name.append(" TO SECOND"); }
[ LOOKAHEAD(2) "(" precision = NumericLiteral() { name.append("(").append(precision.getImage()).append(")"); } ")" ]
]
{ jjtThis.setImage(name.toString()) ; return jjtThis; }

View File

@ -71,4 +71,9 @@ class PlsqlTreeDumpTest extends BaseTreeDumpTest {
void parseSelectExpression() {
doTest("SelectExpressions");
}
@Test
void issue5133SubTypeDefinition() {
doTest("Issue5133SubTypeDefinition");
}
}

View File

@ -0,0 +1,8 @@
--
-- from https://github.com/pmd/pmd/issues/5133
--
CREATE or REPLACE PACKAGE x as
type last_run_duration is interval day(9) to second(6);
end x;
/

View File

@ -0,0 +1,13 @@
+- Input[@CanonicalImage = null, @ExcludedLinesCount = 0, @ExcludedRangesCount = 0]
+- PackageSpecification[@CanonicalImage = "X", @Image = "x", @ObjectName = "x"]
+- ObjectNameDeclaration[@CanonicalImage = "X", @Image = "x"]
| +- ID[@CanonicalImage = "X", @Image = "x"]
+- DeclarativeSection[@CanonicalImage = null]
| +- DeclarativeUnit[@CanonicalImage = null]
| +- SubTypeDefinition[@CanonicalImage = "LAST_RUN_DURATION", @Image = "last_run_duration"]
| +- QualifiedID[@CanonicalImage = "LAST_RUN_DURATION", @Image = "last_run_duration"]
| +- Datatype[@CanonicalImage = "INTERVAL DAY(9) TO SECOND(6)", @Image = "INTERVAL DAY(9) TO SECOND(6)", @TypeImage = "INTERVAL DAY(9) TO SECOND(6)"]
| +- ScalarDataTypeName[@CanonicalImage = "INTERVAL DAY(9) TO SECOND(6)", @Image = "INTERVAL DAY(9) TO SECOND(6)"]
| +- NumericLiteral[@CanonicalImage = "9", @Image = "9"]
| +- NumericLiteral[@CanonicalImage = "6", @Image = "6"]
+- ID[@CanonicalImage = "X", @Image = "x"]