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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
36a061c
Removed parsing of annotation text (params) from ut_annotations as an…
jgebal Oct 6, 2017
a29cabe
Removed duplicate `old_tests` for ut_annotations - the functionality …
jgebal Oct 6, 2017
58c6293
Renamed `ut_annotations` to `ut_annotation_parser` and moved to annot…
jgebal Oct 7, 2017
375a7ff
Removed ``ut_annotations` from uninstall script.
jgebal Oct 7, 2017
13703fa
Fixed failing old tests after refactoring.
jgebal Oct 7, 2017
ac23f15
Refactored ut_annotation_parser API to use `ut_annotations` collectio…
jgebal Oct 7, 2017
df2c763
Added cache mechanism to `ut_annotation_parser`.
jgebal Oct 8, 2017
6088c81
Added ability to get annotations for single object.
jgebal Oct 9, 2017
4ec9eb5
Reworking annotation cache - not to use cast(Collect()) on dba_source.
jgebal Oct 13, 2017
dbf2538
Fixed failing test and test for Wrapped package.
jgebal Oct 14, 2017
ca31e98
Added missing annotation manager.
jgebal Oct 14, 2017
289f006
Removed dbms_output from code.
jgebal Oct 14, 2017
8e26ed0
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 14, 2017
239abde
Add grant ut_annotation_manager to public
pesse Oct 16, 2017
6acd2ad
Add grant ut_annotation_manager to ut3_user
pesse Oct 16, 2017
e114aae
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 17, 2017
b83e142
Fixed hardcoded schema-name
jgebal Oct 18, 2017
6dcaae9
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 18, 2017
aafca84
Refactored annotation cache.
jgebal Oct 22, 2017
cd394c7
Fixed test execution on 12.1.
jgebal Oct 23, 2017
73c15a2
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 23, 2017
5967a3a
Fixed test execution on 12.1.
jgebal Oct 23, 2017
1438753
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 24, 2017
4f5d870
Merge conflicts cleanup
jgebal Oct 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed parsing of annotation text (params) from ut_annotations as an…
…notation text can be different depending on use case and it's not parsers responsibility to support all use-cases for annotation text.

Added standalone/separated function `parse_annotation_params` that takes care of annotation text parsing.
  • Loading branch information
jgebal committed Oct 6, 2017
commit 36a061c687c0a00038e274365888b063e1cbe3d1
191 changes: 97 additions & 94 deletions source/core/ut_annotations.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ create or replace package body ut_annotations as
gc_annotation_qualifier constant varchar2(1) := '%';
c_multiline_comment_pattern constant varchar2(50) := '/\*.*?\*/';
c_annot_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*-- *('||gc_annotation_qualifier||'.*?)$'; -- chr(09) is a tab character
--c_nonannotat_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*--+ *[^'||gc_annotation_qualifier||']*?$';
c_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
c_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
c_regexp_identifier constant varchar2(50) := '[a-z][a-z0-9#_$]*';
Expand All @@ -45,9 +44,8 @@ create or replace package body ut_annotations as
l_comment_index pls_integer;
l_comment varchar2(32767);
l_annotation_str varchar2(32767);
l_annotation_params_str varchar2(32767);
l_annotation_text varchar2(32767);
l_annotation_name varchar2(1000);
l_annotation_params tt_annotation_params;
l_annotation t_annotation;
l_annotations_list tt_annotations;
begin
Expand All @@ -71,40 +69,14 @@ create or replace package body ut_annotations as
l_annotation_str := regexp_substr(l_comment, c_annotation_pattern, 1, 1, modifier => 'i');
if l_annotation_str is not null then

l_annotation_params.delete;

-- get the annotation name and it's parameters if present
l_annotation_name := lower(regexp_substr(l_annotation_str
,'%(' || c_regexp_identifier || ')'
,modifier => 'i'
,subexpression => 1));
l_annotation_params_str := trim(regexp_substr(l_annotation_str, '\((.*?)\)\s*$', subexpression => 1));

if l_annotation_params_str is not null then

-- parse the annotation parameters and store them as key-value pair array
for param_ind in 1 .. regexp_count(l_annotation_params_str, '(.+?)(,|$)') loop
declare
l_param_str varchar2(32767);
l_param_item typ_annotation_param;
begin
l_param_str := regexp_substr(srcstr => l_annotation_params_str
,pattern => '(.+?)(,|$)'
,occurrence => param_ind
,subexpression => 1);

l_param_item.key := regexp_substr(srcstr => l_param_str
,pattern => '(' || c_regexp_identifier || ')\s*='
,modifier => 'i'
,subexpression => 1);
l_param_item.val := trim(regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2));

l_annotation_params(l_annotation_params.count + 1) := l_param_item;
end;
end loop;
end if;
l_annotation.text := l_annotation_params_str;
l_annotation.params := l_annotation_params;
l_annotation_name := lower(regexp_substr(l_annotation_str
,'%(' || c_regexp_identifier || ')'
,modifier => 'i'
,subexpression => 1));
l_annotation_text := trim(regexp_substr(l_annotation_str, '\((.*?)\)\s*$', subexpression => 1));

l_annotation.text := l_annotation_text;
l_annotations_list(l_annotation_name) := l_annotation;
end if;
l_loop_index := l_loop_index + 1;
Expand Down Expand Up @@ -185,6 +157,7 @@ create or replace package body ut_annotations as
l_comments tt_comment_list;
l_comment_pos pls_integer;
l_comment_replacer varchar2(50);
l_source clob := a_source;
begin
l_comment_pos := 1;
loop
Expand All @@ -209,72 +182,74 @@ create or replace package body ut_annotations as

l_comment_replacer := replace(c_comment_replacer_patter, '%N%', l_comments.count);

a_source := regexp_replace(srcstr => a_source
l_source := regexp_replace(srcstr => a_source
,pattern => c_annot_comment_pattern
,replacestr => l_comment_replacer
,position => l_comment_pos
,occurrence => 1
,modifier => 'm');
dbms_lob.freetemporary(a_source);
a_source := l_source;
dbms_lob.freetemporary(l_source);
l_comment_pos := l_comment_pos + length(l_comment_replacer);

end loop;

ut_utils.debug_log(a_source);

return l_comments;
end extract_and_replace_comments;

$if $$ut_trace $then
procedure print_parse_results(a_annotated_pkg typ_annotated_package) is
l_name t_annotation_name := a_annotated_pkg.package_annotations.first;
l_proc_name t_annotation_name;
begin
dbms_output.put_line('Annotations count: ' || a_annotated_pkg.package_annotations.count);

while l_name is not null loop
dbms_output.put_line(' @' || l_name);
if a_annotated_pkg.package_annotations(l_name).count > 0 then
dbms_output.put_line(' Parameters:');

for j in 1 .. a_annotated_pkg.package_annotations(l_name).count loop
dbms_output.put_line(' ' || nvl(a_annotated_pkg.package_annotations(l_name)(j).key, '<Anonymous>') || ' = ' ||
nvl(a_annotated_pkg.package_annotations(l_name)(j).val, 'NULL'));
end loop;
else
dbms_output.put_line(' No parameters.');
end if;

l_name := a_annotated_pkg.package_annotations.next(l_name);

end loop;

dbms_output.put_line('Procedures count: ' || a_annotated_pkg.procedure_annotations.count);

for i in 1 .. a_annotated_pkg.procedure_annotations.count loop
l_proc_name := a_annotated_pkg.procedure_annotations(i).name;
dbms_output.put_line(rpad('-', 80, '-'));
dbms_output.put_line(' Procedure: ' || l_proc_name);
dbms_output.put_line(' Annotations count: ' || a_annotated_pkg.procedure_annotations(i).annotations.count);
l_name := a_annotated_pkg.procedure_annotations(i).annotations.first;
while l_name is not null loop
dbms_output.put_line(' @' || l_name);
if a_annotated_pkg.procedure_annotations(i).annotations(l_name).count > 0 then
dbms_output.put_line(' Parameters:');
for j in 1 .. a_annotated_pkg.procedure_annotations(i).annotations(l_name).count loop
dbms_output.put_line(' ' ||
nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).key, '<Anonymous>') ||
' = ' || nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).val, 'NULL'));
end loop;
else
dbms_output.put_line(' No parameters.');
end if;

l_name := a_annotated_pkg.procedure_annotations(i).annotations.next(l_name);
end loop;
end loop;

end print_parse_results;
$end
-- $if $$ut_trace $then
-- procedure print_parse_results(a_annotated_pkg typ_annotated_package) is
-- l_name t_annotation_name := a_annotated_pkg.package_annotations.first;
-- l_proc_name t_annotation_name;
-- begin
-- dbms_output.put_line('Annotations count: ' || a_annotated_pkg.package_annotations.count);
--
-- while l_name is not null loop
-- dbms_output.put_line(' @' || l_name);
-- if a_annotated_pkg.package_annotations(l_name).count > 0 then
-- dbms_output.put_line(' Parameters:');
--
-- for j in 1 .. a_annotated_pkg.package_annotations(l_name).count loop
-- dbms_output.put_line(' ' || nvl(a_annotated_pkg.package_annotations(l_name)(j).key, '<Anonymous>') || ' = ' ||
-- nvl(a_annotated_pkg.package_annotations(l_name)(j).val, 'NULL'));
-- end loop;
-- else
-- dbms_output.put_line(' No parameters.');
-- end if;
--
-- l_name := a_annotated_pkg.package_annotations.next(l_name);
--
-- end loop;
--
-- dbms_output.put_line('Procedures count: ' || a_annotated_pkg.procedure_annotations.count);
--
-- for i in 1 .. a_annotated_pkg.procedure_annotations.count loop
-- l_proc_name := a_annotated_pkg.procedure_annotations(i).name;
-- dbms_output.put_line(rpad('-', 80, '-'));
-- dbms_output.put_line(' Procedure: ' || l_proc_name);
-- dbms_output.put_line(' Annotations count: ' || a_annotated_pkg.procedure_annotations(i).annotations.count);
-- l_name := a_annotated_pkg.procedure_annotations(i).annotations.first;
-- while l_name is not null loop
-- dbms_output.put_line(' @' || l_name);
-- if a_annotated_pkg.procedure_annotations(i).annotations(l_name).count > 0 then
-- dbms_output.put_line(' Parameters:');
-- for j in 1 .. a_annotated_pkg.procedure_annotations(i).annotations(l_name).count loop
-- dbms_output.put_line(' ' ||
-- nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).key, '<Anonymous>') ||
-- ' = ' || nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).val, 'NULL'));
-- end loop;
-- else
-- dbms_output.put_line(' No parameters.');
-- end if;
--
-- l_name := a_annotated_pkg.procedure_annotations(i).annotations.next(l_name);
-- end loop;
-- end loop;
--
-- end print_parse_results;
-- $end

function parse_package_annotations(a_source clob) return typ_annotated_package is
l_source clob := a_source;
Expand All @@ -285,18 +260,19 @@ create or replace package body ut_annotations as
l_source := delete_multiline_comments(l_source);

-- replace all single line comments with {COMMENT#12} element and store it's content for easier processing
-- this call modifies a_source
-- this call modifies l_source
l_comments := extract_and_replace_comments(l_source);

l_annotated_pkg.package_annotations := get_package_annotations(l_source, l_comments);

l_annotated_pkg.procedure_annotations := get_procedure_list(l_source, l_comments);

-- printing out parsed structure for debugging
$if $$ut_trace $then
print_parse_results(l_annotated_pkg);
$end
-- -- printing out parsed structure for debugging
-- $if $$ut_trace $then
-- print_parse_results(l_annotated_pkg);
-- $end

dbms_lob.freetemporary(l_source);
return l_annotated_pkg;
end parse_package_annotations;

Expand Down Expand Up @@ -335,5 +311,32 @@ create or replace package body ut_annotations as
-- return l_result;
-- end get_annotation_param;

-- parse the annotation parameters and return as key-value pair array
function parse_annotation_params(a_annotation_text varchar2) return tt_annotation_params is
l_annotation_params tt_annotation_params;
l_param_str varchar2(32767);
l_param_item typ_annotation_param;
l_param_item_empty typ_annotation_param;
c_annot_param_pattern constant varchar2(50) := '(.+?)(,|$)';
begin
if a_annotation_text is not null then
for param_ind in 1 .. regexp_count(a_annotation_text, c_annot_param_pattern) loop
l_param_str := regexp_substr(srcstr => a_annotation_text
,pattern => c_annot_param_pattern
,occurrence => param_ind
,subexpression => 1);
l_param_item := l_param_item_empty;
l_param_item.key := regexp_substr(srcstr => l_param_str
,pattern => '(' || c_regexp_identifier || ')\s*='
,modifier => 'i'
,subexpression => 1);
l_param_item.val := trim(regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2));

l_annotation_params(l_annotation_params.count + 1) := l_param_item;
end loop;
end if;
return l_annotation_params;
end;

end ut_annotations;
/
10 changes: 8 additions & 2 deletions source/core/ut_annotations.pks
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ create or replace package ut_annotations authid current_user as
type tt_annotation_params is table of typ_annotation_param index by pls_integer;

type t_annotation is record(
text varchar2(4000),
params tt_annotation_params
text varchar2(4000)
);

/*
Expand Down Expand Up @@ -94,5 +93,12 @@ create or replace package ut_annotations authid current_user as
*/
-- function get_annotation_param(a_param_list tt_annotation_params, a_def_index pls_integer) return varchar2;

/*
function: parse_annotation_params

parses annotation parameters from annotation text string
*/
function parse_annotation_params(a_annotation_text varchar2) return tt_annotation_params;

end ut_annotations;
/
Loading