Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 372baea

Browse files
committed
Fixed annotation parameter pattern matching
1 parent a9ffefa commit 372baea

3 files changed

Lines changed: 38 additions & 45 deletions

File tree

source/core/ut_annotations.pkb

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,14 @@ create or replace package body ut_annotations as
3030
c_rgexp_identifier constant varchar2(50) := '[a-z][a-z0-9#_$]*';
3131
c_annotation_block_pattern constant varchar2(200) := '(({COMMENT#.+}'||chr(10)||')+)( |'||chr(09)||')*(procedure|function)\s+(' ||
3232
c_rgexp_identifier || ')';
33-
c_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || c_rgexp_identifier || '(\(.*?\))?';
33+
c_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || c_rgexp_identifier || '(\(.*?\)$)?';
3434

3535

3636
function delete_multiline_comments(a_source in clob) return clob is
3737
begin
38-
39-
/* l_tmp_clob := regexp_replace(srcstr => a_source
40-
,pattern => c_multiline_comment_pattern
41-
,modifier => 'n');
42-
l_tmp_clob := regexp_replace(srcstr => l_tmp_clob
43-
,pattern => c_nonannotat_comment_pattern
44-
,modifier => 'm');
45-
46-
-- performance is too low when deleting spaces as it leads to lots of writes
47-
-- l_tmp_clob := regexp_replace(srcstr => l_tmp_cl0ob
48-
-- ,pattern => '(( |'||chr(09)||')*'|| chr(10)||'){3,}'
49-
-- ,replacestr => chr(10)||chr(10));
50-
return l_tmp_clob;
51-
*/
5238
return regexp_replace(srcstr => a_source
5339
,pattern => c_multiline_comment_pattern
5440
,modifier => 'n');
55-
56-
--this is not fast enough as the regexp parten is more complicated
57-
/*
58-
return regexp_replace(srcstr => a_source
59-
,pattern => '('||c_multiline_comment_pattern
60-
||'|'||c_nonannotat_comment_pattern||')'
61-
,modifier => 'mn');
62-
*/
63-
64-
/*
65-
return regexp_replace(
66-
srcstr => regexp_replace(srcstr => regexp_replace(srcstr => a_source
67-
,pattern => c_multiline_comment_pattern
68-
,modifier => 'n')
69-
,pattern => c_nonannotat_comment_pattern, modifier => 'm')
70-
,pattern => '((procedure|function)\s+' || c_rgexp_identifier || ')[^;]*'
71-
,replacestr => '\1'
72-
,modifier => 'mn'
73-
);
74-
*/
7541
end;
7642

7743
function get_annotations(a_source varchar2, a_comments tt_comment_list) return tt_annotations is
@@ -111,7 +77,7 @@ create or replace package body ut_annotations as
11177
,'%(' || c_rgexp_identifier || ')'
11278
,modifier => 'i'
11379
,subexpression => 1));
114-
l_annotation_params_str := trim(regexp_substr(l_annotation_str, '\((.*?)\)', subexpression => 1));
80+
l_annotation_params_str := trim(regexp_substr(l_annotation_str, '\((.*?)\)$', subexpression => 1));
11581

11682
if l_annotation_params_str is not null then
11783

@@ -343,7 +309,7 @@ create or replace package body ut_annotations as
343309

344310
-- TODO: Add cache of annotations. Cache invalidation should be based on DDL timestamp.
345311
-- Cache garbage collection should be executed once in a while to remove annotations cache for packages that were dropped.
346-
312+
347313
begin
348314
l_source := ut_metadata.get_package_spec_source(a_owner_name, a_name);
349315
exception

tests/RunAll.sql

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ exec ut_coverage.coverage_start_develop();
3838
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.IgnoreWrappedPackageAndDoesNotRaiseException.sql
3939
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationMixedWithWrongBeforeProcedure.sql
4040
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationNotBeforeProcedure.sql
41-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseComplexPackage.sql
42-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageAndProcedureLevelAnnotations.sql
43-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotation.sql
44-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationAccessibleBy.sql
45-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationMultilineDeclare.sql
46-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
47-
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
48-
41+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationParamsWithBrackets.sql
4942
@@ut_expectations/ut.expect.not_to_be_null.sql
5043
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql
5144
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PROMPT Parse package level annotations with annotation params containing brackets
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param := null;
9+
l_results ut_expectation_results;
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(Name of suite (including some brackets) and some more text)
13+
END;';
14+
15+
--Act
16+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
17+
18+
--Assert
19+
l_ann_param.val := 'Name of suite (including some brackets) and some more text';
20+
l_expected.package_annotations('suite')(1) := l_ann_param;
21+
22+
check_annotation_parsing(l_expected, l_parsing_result);
23+
24+
if ut_expectation_processor.get_status = ut_utils.tr_success then
25+
:test_result := ut_utils.tr_success;
26+
else
27+
l_results := ut_expectation_processor.get_expectations_results();
28+
for i in 1 .. l_results.count loop
29+
dbms_output.put_line(l_results(i).message);
30+
end loop;
31+
end if;
32+
33+
end;
34+
/

0 commit comments

Comments
 (0)