@@ -24,7 +24,6 @@ create or replace package body ut_annotations as
2424 gc_annotation_qualifier constant varchar2(1) := '%';
2525 c_multiline_comment_pattern constant varchar2(50) := '/\*.*?\*/';
2626 c_annot_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*-- *('||gc_annotation_qualifier||'.*?)$'; -- chr(09) is a tab character
27- --c_nonannotat_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*--+ *[^'||gc_annotation_qualifier||']*?$';
2827 c_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
2928 c_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
3029 c_regexp_identifier constant varchar2(50) := '[a-z][a-z0-9#_$]*';
@@ -45,9 +44,8 @@ create or replace package body ut_annotations as
4544 l_comment_index pls_integer;
4645 l_comment varchar2(32767);
4746 l_annotation_str varchar2(32767);
48- l_annotation_params_str varchar2(32767);
47+ l_annotation_text varchar2(32767);
4948 l_annotation_name varchar2(1000);
50- l_annotation_params tt_annotation_params;
5149 l_annotation t_annotation;
5250 l_annotations_list tt_annotations;
5351 begin
@@ -71,40 +69,14 @@ create or replace package body ut_annotations as
7169 l_annotation_str := regexp_substr(l_comment, c_annotation_pattern, 1, 1, modifier => 'i');
7270 if l_annotation_str is not null then
7371
74- l_annotation_params.delete;
75-
7672 -- get the annotation name and it's parameters if present
77- l_annotation_name := lower(regexp_substr(l_annotation_str
78- ,'%(' || c_regexp_identifier || ')'
79- ,modifier => 'i'
80- ,subexpression => 1));
81- l_annotation_params_str := trim(regexp_substr(l_annotation_str, '\((.*?)\)\s*$', subexpression => 1));
82-
83- if l_annotation_params_str is not null then
84-
85- -- parse the annotation parameters and store them as key-value pair array
86- for param_ind in 1 .. regexp_count(l_annotation_params_str, '(.+?)(,|$)') loop
87- declare
88- l_param_str varchar2(32767);
89- l_param_item typ_annotation_param;
90- begin
91- l_param_str := regexp_substr(srcstr => l_annotation_params_str
92- ,pattern => '(.+?)(,|$)'
93- ,occurrence => param_ind
94- ,subexpression => 1);
95-
96- l_param_item.key := regexp_substr(srcstr => l_param_str
97- ,pattern => '(' || c_regexp_identifier || ')\s*='
98- ,modifier => 'i'
99- ,subexpression => 1);
100- l_param_item.val := trim(regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2));
101-
102- l_annotation_params(l_annotation_params.count + 1) := l_param_item;
103- end;
104- end loop;
105- end if;
106- l_annotation.text := l_annotation_params_str;
107- l_annotation.params := l_annotation_params;
73+ l_annotation_name := lower(regexp_substr(l_annotation_str
74+ ,'%(' || c_regexp_identifier || ')'
75+ ,modifier => 'i'
76+ ,subexpression => 1));
77+ l_annotation_text := trim(regexp_substr(l_annotation_str, '\((.*?)\)\s*$', subexpression => 1));
78+
79+ l_annotation.text := l_annotation_text;
10880 l_annotations_list(l_annotation_name) := l_annotation;
10981 end if;
11082 l_loop_index := l_loop_index + 1;
@@ -185,6 +157,7 @@ create or replace package body ut_annotations as
185157 l_comments tt_comment_list;
186158 l_comment_pos pls_integer;
187159 l_comment_replacer varchar2(50);
160+ l_source clob := a_source;
188161 begin
189162 l_comment_pos := 1;
190163 loop
@@ -209,72 +182,74 @@ create or replace package body ut_annotations as
209182
210183 l_comment_replacer := replace(c_comment_replacer_patter, '%N%', l_comments.count);
211184
212- a_source := regexp_replace(srcstr => a_source
185+ l_source := regexp_replace(srcstr => a_source
213186 ,pattern => c_annot_comment_pattern
214187 ,replacestr => l_comment_replacer
215188 ,position => l_comment_pos
216189 ,occurrence => 1
217190 ,modifier => 'm');
191+ dbms_lob.freetemporary(a_source);
192+ a_source := l_source;
193+ dbms_lob.freetemporary(l_source);
218194 l_comment_pos := l_comment_pos + length(l_comment_replacer);
219195
220196 end loop;
221197
222198 ut_utils.debug_log(a_source);
223-
224199 return l_comments;
225200 end extract_and_replace_comments;
226201
227- $if $$ut_trace $then
228- procedure print_parse_results(a_annotated_pkg typ_annotated_package) is
229- l_name t_annotation_name := a_annotated_pkg.package_annotations.first;
230- l_proc_name t_annotation_name;
231- begin
232- dbms_output.put_line('Annotations count: ' || a_annotated_pkg.package_annotations.count);
233-
234- while l_name is not null loop
235- dbms_output.put_line(' @' || l_name);
236- if a_annotated_pkg.package_annotations(l_name).count > 0 then
237- dbms_output.put_line(' Parameters:');
238-
239- for j in 1 .. a_annotated_pkg.package_annotations(l_name).count loop
240- dbms_output.put_line(' ' || nvl(a_annotated_pkg.package_annotations(l_name)(j).key, '<Anonymous>') || ' = ' ||
241- nvl(a_annotated_pkg.package_annotations(l_name)(j).val, 'NULL'));
242- end loop;
243- else
244- dbms_output.put_line(' No parameters.');
245- end if;
246-
247- l_name := a_annotated_pkg.package_annotations.next(l_name);
248-
249- end loop;
250-
251- dbms_output.put_line('Procedures count: ' || a_annotated_pkg.procedure_annotations.count);
252-
253- for i in 1 .. a_annotated_pkg.procedure_annotations.count loop
254- l_proc_name := a_annotated_pkg.procedure_annotations(i).name;
255- dbms_output.put_line(rpad('-', 80, '-'));
256- dbms_output.put_line(' Procedure: ' || l_proc_name);
257- dbms_output.put_line(' Annotations count: ' || a_annotated_pkg.procedure_annotations(i).annotations.count);
258- l_name := a_annotated_pkg.procedure_annotations(i).annotations.first;
259- while l_name is not null loop
260- dbms_output.put_line(' @' || l_name);
261- if a_annotated_pkg.procedure_annotations(i).annotations(l_name).count > 0 then
262- dbms_output.put_line(' Parameters:');
263- for j in 1 .. a_annotated_pkg.procedure_annotations(i).annotations(l_name).count loop
264- dbms_output.put_line(' ' ||
265- nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).key, '<Anonymous>') ||
266- ' = ' || nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).val, 'NULL'));
267- end loop;
268- else
269- dbms_output.put_line(' No parameters.');
270- end if;
271-
272- l_name := a_annotated_pkg.procedure_annotations(i).annotations.next(l_name);
273- end loop;
274- end loop;
275-
276- end print_parse_results;
277- $end
202+ -- $if $$ut_trace $then
203+ -- procedure print_parse_results(a_annotated_pkg typ_annotated_package) is
204+ -- l_name t_annotation_name := a_annotated_pkg.package_annotations.first;
205+ -- l_proc_name t_annotation_name;
206+ -- begin
207+ -- dbms_output.put_line('Annotations count: ' || a_annotated_pkg.package_annotations.count);
208+ --
209+ -- while l_name is not null loop
210+ -- dbms_output.put_line(' @' || l_name);
211+ -- if a_annotated_pkg.package_annotations(l_name).count > 0 then
212+ -- dbms_output.put_line(' Parameters:');
213+ --
214+ -- for j in 1 .. a_annotated_pkg.package_annotations(l_name).count loop
215+ -- dbms_output.put_line(' ' || nvl(a_annotated_pkg.package_annotations(l_name)(j).key, '<Anonymous>') || ' = ' ||
216+ -- nvl(a_annotated_pkg.package_annotations(l_name)(j).val, 'NULL'));
217+ -- end loop;
218+ -- else
219+ -- dbms_output.put_line(' No parameters.');
220+ -- end if;
221+ --
222+ -- l_name := a_annotated_pkg.package_annotations.next(l_name);
223+ --
224+ -- end loop;
225+ --
226+ -- dbms_output.put_line('Procedures count: ' || a_annotated_pkg.procedure_annotations.count);
227+ --
228+ -- for i in 1 .. a_annotated_pkg.procedure_annotations.count loop
229+ -- l_proc_name := a_annotated_pkg.procedure_annotations(i).name;
230+ -- dbms_output.put_line(rpad('-', 80, '-'));
231+ -- dbms_output.put_line(' Procedure: ' || l_proc_name);
232+ -- dbms_output.put_line(' Annotations count: ' || a_annotated_pkg.procedure_annotations(i).annotations.count);
233+ -- l_name := a_annotated_pkg.procedure_annotations(i).annotations.first;
234+ -- while l_name is not null loop
235+ -- dbms_output.put_line(' @' || l_name);
236+ -- if a_annotated_pkg.procedure_annotations(i).annotations(l_name).count > 0 then
237+ -- dbms_output.put_line(' Parameters:');
238+ -- for j in 1 .. a_annotated_pkg.procedure_annotations(i).annotations(l_name).count loop
239+ -- dbms_output.put_line(' ' ||
240+ -- nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).key, '<Anonymous>') ||
241+ -- ' = ' || nvl(a_annotated_pkg.procedure_annotations(i).annotations(l_name)(j).val, 'NULL'));
242+ -- end loop;
243+ -- else
244+ -- dbms_output.put_line(' No parameters.');
245+ -- end if;
246+ --
247+ -- l_name := a_annotated_pkg.procedure_annotations(i).annotations.next(l_name);
248+ -- end loop;
249+ -- end loop;
250+ --
251+ -- end print_parse_results;
252+ -- $end
278253
279254 function parse_package_annotations(a_source clob) return typ_annotated_package is
280255 l_source clob := a_source;
@@ -285,18 +260,19 @@ create or replace package body ut_annotations as
285260 l_source := delete_multiline_comments(l_source);
286261
287262 -- replace all single line comments with {COMMENT#12} element and store it's content for easier processing
288- -- this call modifies a_source
263+ -- this call modifies l_source
289264 l_comments := extract_and_replace_comments(l_source);
290265
291266 l_annotated_pkg.package_annotations := get_package_annotations(l_source, l_comments);
292267
293268 l_annotated_pkg.procedure_annotations := get_procedure_list(l_source, l_comments);
294269
295- -- printing out parsed structure for debugging
296- $if $$ut_trace $then
297- print_parse_results(l_annotated_pkg);
298- $end
270+ -- -- printing out parsed structure for debugging
271+ -- $if $$ut_trace $then
272+ -- print_parse_results(l_annotated_pkg);
273+ -- $end
299274
275+ dbms_lob.freetemporary(l_source);
300276 return l_annotated_pkg;
301277 end parse_package_annotations;
302278
@@ -335,5 +311,32 @@ create or replace package body ut_annotations as
335311-- return l_result;
336312-- end get_annotation_param;
337313
314+ -- parse the annotation parameters and return as key-value pair array
315+ function parse_annotation_params(a_annotation_text varchar2) return tt_annotation_params is
316+ l_annotation_params tt_annotation_params;
317+ l_param_str varchar2(32767);
318+ l_param_item typ_annotation_param;
319+ l_param_item_empty typ_annotation_param;
320+ c_annot_param_pattern constant varchar2(50) := '(.+?)(,|$)';
321+ begin
322+ if a_annotation_text is not null then
323+ for param_ind in 1 .. regexp_count(a_annotation_text, c_annot_param_pattern) loop
324+ l_param_str := regexp_substr(srcstr => a_annotation_text
325+ ,pattern => c_annot_param_pattern
326+ ,occurrence => param_ind
327+ ,subexpression => 1);
328+ l_param_item := l_param_item_empty;
329+ l_param_item.key := regexp_substr(srcstr => l_param_str
330+ ,pattern => '(' || c_regexp_identifier || ')\s*='
331+ ,modifier => 'i'
332+ ,subexpression => 1);
333+ l_param_item.val := trim(regexp_substr(l_param_str, '(.+?=)?(.*$)', subexpression => 2));
334+
335+ l_annotation_params(l_annotation_params.count + 1) := l_param_item;
336+ end loop;
337+ end if;
338+ return l_annotation_params;
339+ end;
340+
338341end ut_annotations;
339342/
0 commit comments