From 0978a49069716dccc2b7aefbe6330d07818c3997 Mon Sep 17 00:00:00 2001 From: Miklos Magyari Date: Tue, 21 Jun 2022 12:19:56 +0200 Subject: [PATCH] Better handling of standalone document comment tags Signed-off-by: Miklos Magyari --- .../titan/designer/AST/DocumentComment.java | 14 +- .../ttcn3parser/Ttcn3DocCommentLexer.g4 | 36 +-- .../ttcn3parser/Ttcn3DocCommentParser.g4 | 252 +++++++++++++----- 3 files changed, 212 insertions(+), 90 deletions(-) diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/DocumentComment.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/DocumentComment.java index 84f8db82e..fa48dcb8f 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/DocumentComment.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/DocumentComment.java @@ -172,7 +172,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addConfigContent(Ttcn3HoverContent content) { - if (config == null) { + if (config == null || config.length() == 0) { return; } content.addTag("Configuration:"); @@ -423,7 +423,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addPriorityContent(Ttcn3HoverContent content) { - if (priority == null) { + if (priority == null || priority.length() == 0) { return; } content.addTagWithText("Priority:", priority); @@ -465,7 +465,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addPurposeContent(Ttcn3HoverContent content) { - if (purpose == null) { + if (purpose == null || purpose.length() == 0) { return; } content.addTagWithText("Purpose:", purpose); @@ -507,7 +507,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addReferenceContent(Ttcn3HoverContent content) { - if (reference == null) { + if (reference == null || reference.length() == 0) { return; } content.addTagWithText("Reference:", reference); @@ -712,7 +712,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addSinceContent(Ttcn3HoverContent content) { - if (since == null) { + if (since == null || since.length() == 0) { return; } content.addTagWithText("Since:", since); @@ -755,7 +755,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addStatusContent(Ttcn3HoverContent content) { - if (status == null) { + if (status == null || status.length() == 0) { return; } content.addTagWithText("Status:", status); @@ -890,7 +890,7 @@ public class DocumentComment implements ILocateableNode { * @param content Content of hover info */ public void addVersionContent(Ttcn3HoverContent content) { - if (version == null) { + if (version == null || version.length() == 0) { return; } content.addTagWithText("Version:", version); diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentLexer.g4 b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentLexer.g4 index b1a051397..b7b92332a 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentLexer.g4 +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentLexer.g4 @@ -42,27 +42,27 @@ BLOCK_BEGIN: '/**' STAR*; BLOCK_END: '*/' ; WS: [ \t]+ ; -AUTHOR: '@author' WS; -CONFIG: '@config' WS; -DESC: '@desc' WS; -EXCEPTION: '@exception' WS; -MEMBER: '@member' WS; -PARAM: '@param' WS; -PRIORITY: '@priority' WS; -PURPOSE: '@purpose' WS; -REFERENCE: '@reference' WS; -REMARK: '@remark' WS; -REQUIREMENT: '@requirement' WS; +AUTHOR: '@author'; +CONFIG: '@config'; +DESC: '@desc'; +EXCEPTION: '@exception'; +MEMBER: '@member'; +PARAM: '@param'; +PRIORITY: '@priority'; +PURPOSE: '@purpose'; +REFERENCE: '@reference'; +REMARK: '@remark'; +REQUIREMENT: '@requirement'; RETURN: '@return'; -SEE: '@see' WS; -SINCE: '@since'WS; -STATUS: '@status' WS; -URL: '@url' WS; -VERDICT: '@verdict' WS; -VERSION: '@version' WS; +SEE: '@see'; +SINCE: '@since'; +STATUS: '@status'; +URL: '@url'; +VERDICT: '@verdict'; +VERSION: '@version'; // non-standard tags -CATEGORY: '@category' WS; +CATEGORY: '@category'; STAR: '*' ; NEWLINE: (WS* STAR* WS*)? '\r'? '\n' (WS? (STAR { _input.LA(1) != '/'}?)+)?; diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentParser.g4 b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentParser.g4 index ed78070d0..b1d30c179 100755 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentParser.g4 +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/parsers/ttcn3parser/Ttcn3DocCommentParser.g4 @@ -88,92 +88,166 @@ pr_LineComments[DocumentComment documentComment]: )+ ; -pr_AuthorTag[DocumentComment documentComment]: - AUTHOR - txt = pr_FreeText { documentComment.addAuthor( $txt.text, getLocation($AUTHOR, $txt.endcol) ); } +pr_AuthorTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + AUTHOR { endcol = $AUTHOR; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addAuthor( text, getLocation($AUTHOR, endcol) ); + } ; -pr_ConfigTag[DocumentComment documentComment]: - CONFIG - txt = pr_FreeText { documentComment.addConfig( $txt.text, getLocation($CONFIG, $txt.endcol) ); } +pr_ConfigTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + CONFIG { endcol = $CONFIG; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addConfig( text, getLocation($CONFIG, endcol) ); + } ; -pr_DescTag[DocumentComment documentComment]: - DESC - txt = pr_FreeText { documentComment.addDesc( $txt.text, getLocation($DESC, $txt.endcol) ); } +pr_DescTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + DESC { endcol = $DESC; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addDesc( text, getLocation($DESC, endcol) ); + } ; pr_ExceptionTag[DocumentComment documentComment] @init { + String idtext = null; String freetext = null; Token endcol = null; }: EXCEPTION - id = pr_Identifier { endcol = $id.stop; } - WS? - ( ft = pr_FreeText { - freetext = $ft.text; - endcol = $ft.endcol; - } )? + ( + WS+ + id = pr_Identifier { idtext = $id.text; endcol = $id.stop; } + )? + ( + WS+ + ft = pr_FreeText { + freetext = $ft.text; + endcol = $ft.endcol; + } + )? { - documentComment.addException( $id.text, freetext, getLocation($EXCEPTION, endcol) ); + documentComment.addException( idtext, freetext, getLocation($EXCEPTION, endcol) ); }; pr_MemberTag[DocumentComment documentComment] @init { + String idtext = null; String freetext = null; Token endcol = null; }: MEMBER - id = pr_Identifier { endcol = $id.stop; } - WS? - ( ft = pr_FreeText { - freetext = $ft.text; - endcol = $ft.endcol; - } )? + ( + WS+ + id = pr_Identifier { idtext = $id.text; endcol = $id.stop; } + )? + ( + WS+ + ft = pr_FreeText { + freetext = $ft.text; + endcol = $ft.endcol; + } + )? { - documentComment.addMember( $id.text, freetext, getLocation($MEMBER, endcol) ); + documentComment.addMember( idtext, freetext, getLocation($MEMBER, endcol) ); }; pr_ParamTag[DocumentComment documentComment] @init { + String idtext = null; String freetext = null; Token endcol = null; }: PARAM - id = pr_Identifier { endcol = $id.stop; } - WS? - ( ft = pr_FreeText { - freetext = $ft.text; - endcol = $ft.endcol; - } )? + ( + WS+ + id = pr_Identifier { idtext = $id.text; endcol = $id.stop; } + )? + ( + WS+ + ft = pr_FreeText { + freetext = $ft.text; + endcol = $ft.endcol; + } + )? { - documentComment.addParam( $id.text, freetext, getLocation($PARAM, endcol) ); + documentComment.addParam( idtext, freetext, getLocation($PARAM, endcol) ); }; -pr_PriorityTag[DocumentComment documentComment]: - PRIORITY - id = pr_Identifier { documentComment.addPriority( $id.text, getLocation($PRIORITY, $id.stop) ); } +pr_PriorityTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + PRIORITY { endcol = $PRIORITY; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addPriority( text, getLocation($PRIORITY, endcol) ); + } ; -pr_PurposeTag[DocumentComment documentComment]: - PURPOSE - txt = pr_FreeText { documentComment.addPurpose( $txt.text, getLocation($PURPOSE, $txt.endcol) ); } +pr_PurposeTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + PURPOSE { endcol = $PURPOSE; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addPurpose( text, getLocation($PURPOSE, endcol) ); + } ; -pr_ReferenceTag[DocumentComment documentComment]: - REFERENCE - txt = pr_FreeText { documentComment.addReference( $txt.text, getLocation($REFERENCE, $txt.endcol) ); } +pr_ReferenceTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + REFERENCE { endcol = $REFERENCE; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addReference( text, getLocation($REFERENCE, endcol) ); + } ; -pr_RemarkTag[DocumentComment documentComment]: - REMARK - txt = pr_FreeText { documentComment.addRemark( $txt.text, getLocation($REMARK, $txt.endcol) ); } +pr_RemarkTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + REMARK { endcol = $REMARK; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addRemark( text, getLocation($REMARK, endcol) ); + } ; -pr_RequirementTag[DocumentComment documentComment]: - REQUIREMENT - txt = pr_FreeText { documentComment.addRequirement( $txt.text, getLocation($REQUIREMENT, $txt.endcol) ); } +pr_RequirementTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + REQUIREMENT { endcol = $REQUIREMENT; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addRequirement( text, getLocation($REQUIREMENT, endcol) ); + } ; pr_ReturnTag[DocumentComment documentComment] @@ -188,53 +262,101 @@ pr_ReturnTag[DocumentComment documentComment] } ; -pr_SeeTag[DocumentComment documentComment]: +pr_SeeTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: SEE - id = pr_Identifier { documentComment.addSee( $id.text, getLocation($SEE, $id.stop) ); } + ( + WS+ + id = pr_Identifier { text = $id.text; endcol = $id.stop; } + ) + { + documentComment.addSee( text, getLocation($SEE, endcol) ); + } ; -pr_SinceTag[DocumentComment documentComment]: - SINCE - txt = pr_FreeText { documentComment.addSince( $txt.text, getLocation($SINCE, $txt.endcol) ); } +pr_SinceTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + SINCE { endcol = $SINCE; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addSince( text, getLocation($SINCE, endcol) ); + } ; -pr_StatusTag[DocumentComment documentComment]: - STATUS - txt = pr_FreeText { documentComment.addStatus( $txt.text, getLocation($STATUS, $txt.endcol) ); } +pr_StatusTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + STATUS { endcol = $STATUS; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addStatus( text, getLocation($STATUS, endcol) ); + } ; -pr_UrlTag[DocumentComment documentComment]: - URL - txt = pr_FreeText { documentComment.addUrl( $txt.text, getLocation($URL, $txt.endcol) ); } +pr_UrlTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + URL { endcol = $URL; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addUrl( text, getLocation($URL, endcol) ); + } ; pr_VerdictTag[DocumentComment documentComment] @init { + String idtext = null; String freetext = null; Token endcol = null; }: VERDICT - id = pr_Identifier { endcol = $id.stop; } - WS? + ( + WS+ + id = pr_Identifier { idtext = $id.text; endcol = $id.stop; } + ) ( ft = pr_FreeText { freetext = $ft.text; endcol = $ft.endcol; } )? { - documentComment.addVerdict( $id.text, freetext, getLocation($VERDICT, endcol) ); + documentComment.addVerdict( idtext, freetext, getLocation($VERDICT, endcol) ); }; -pr_VersionTag[DocumentComment documentComment]: - VERSION - txt = pr_FreeText { documentComment.addVersion( $txt.text, getLocation($VERSION, $txt.endcol) ); } +pr_VersionTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + VERSION { endcol = $VERSION; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addVersion( text, getLocation($VERSION, endcol) ); + } ; /* * Non-standard tags */ -pr_CategoryTag[DocumentComment documentComment]: - CATEGORY - txt = pr_FreeText { documentComment.addCategory( $txt.text, getLocation($CATEGORY, $txt.endcol) ); } +pr_CategoryTag[DocumentComment documentComment] +@init { + Token endcol = null; + String text = ""; +}: + CATEGORY { endcol = $CATEGORY; } + ( WS+ txt = pr_FreeText { text = $txt.text; endcol = $txt.stop; })? + { + documentComment.addCategory( text, getLocation($CATEGORY, endcol) ); + } ; pr_Tag[DocumentComment documentComment]: -- GitLab