Commit ebc5f9e1 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Initial doc comment support for functions


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 205a2613
......@@ -88,6 +88,14 @@ public class DocumentComment implements ILocateableNode {
return authors;
}
public Map<String, String> getParams() {
return params;
}
public String getReturn() {
return return_;
}
public void addConfig(String text) {
if (text != null) {
configs.add(text.trim());
......@@ -142,12 +150,16 @@ public class DocumentComment implements ILocateableNode {
}
}
public void parseComment() {
public void parseComment() {
authors.clear();
params.clear();
return_ = null;
final Reader reader = new StringReader(comment);
final CharStream charStream = new UnbufferedCharStream(reader);
final Ttcn3DocCommentLexer lexer = new Ttcn3DocCommentLexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
// List<? extends Token> tokens = lexer.getAllTokens();
//List<? extends Token> tokens = lexer.getAllTokens();
final CommonTokenStream cts = new CommonTokenStream(lexer);
final Ttcn3DocCommentParser parser = new Ttcn3DocCommentParser(cts);
......
......@@ -7,6 +7,8 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
......@@ -17,6 +19,7 @@ import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
......@@ -55,14 +58,14 @@ public final class TextHover extends BaseTextHover {
}
/**
* Inactive preliminary code for ttcn3 editor hover support
* Preliminary code for ttcn3 editor hover support
*
* @param textViewer
* @param hoverRegion
* @return
*/
// @Override
public String ___getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
IDocument doc = textViewer.getDocument();
final IFile file = editor.getEditorInput().getAdapter(IFile.class);
......@@ -76,6 +79,9 @@ public final class TextHover extends BaseTextHover {
if (tempModule != null) {
scope = tempModule.getSmallestEnclosingScope(hoverRegion.getOffset());
if (scope == null) {
scope = tempModule;
}
}
if (ref != null) {
Assignment assignment = scope.getAssBySRef(timestamp, ref);
......@@ -85,11 +91,12 @@ public final class TextHover extends BaseTextHover {
return "";
}
StringBuilder tooltip = new StringBuilder();
tooltip.append("<b>Authors:</b><br>");
for (String author : dc.getAuthors()) {
tooltip.append(author + "<br>");
tooltip.append("<html>");
if (assignment instanceof Def_Function) {
functionHover(tooltip, dc, assignment);
}
tooltip.append("</html>");
return tooltip.toString();
}
}
......@@ -123,4 +130,38 @@ public final class TextHover extends BaseTextHover {
private boolean isIdChar(char c) {
return Character.isAlphabetic(c) || Character.isDigit(c) || c == '_';
}
private void addParams(StringBuilder sb, DocumentComment dc) {
final Map<String,String> params = dc.getParams();
if (params.size() > 0) {
sb.append("<b>Parameters:</b>");
for (Map.Entry<String, String> param : params.entrySet()) {
sb.append(" <div><i>" + param.getKey() + "</i> " + param.getValue() + "</div>");
}
}
}
private void addReturn(StringBuilder sb, DocumentComment dc) {
final String ret = dc.getReturn();
if (ret != null) {
sb.append("<br><br><b>Returns:</b><br>");
sb.append("<pre>" + ret + "</pre>");
}
}
private void addAuthors(StringBuilder sb, DocumentComment dc) {
if (dc.getAuthors().size() > 0) {
sb.append("<br><br><b>Authors:</b><br>");
for (String author : dc.getAuthors()) {
sb.append(" " + author + "<br>");
}
}
}
private void functionHover(StringBuilder sb, DocumentComment dc, Assignment ass) {
sb.append("function <b>" + ((Definition)ass).getIdentifier().getName() + "()</b><br><br>");
addParams(sb, dc);
addReturn(sb, dc);
addAuthors(sb, dc);
}
}
......@@ -16,7 +16,7 @@ lexer grammar Ttcn3DocCommentLexer;
* author Miklos Magyari
*/
BLOCK_BEGIN: '/**' ;
BLOCK_BEGIN: '/**' STAR*;
BLOCK_END: '*/' ;
WS: [ \t]+ ;
......@@ -39,7 +39,7 @@ PRIORITY: '@priority' WS;
REQUIREMENT: '@requirement' WS;
REFERENCE: '@reference' WS;
STAR: '*' ;
NEWLINE: (WS* STAR WS*)? '\r'? '\n' (WS? (STAR { _input.LA(1) != '/'}?)+)?;
NEWLINE: (WS* STAR* WS*)? '\r'? '\n' (WS? (STAR { _input.LA(1) != '/'}?)+)?;
IDENTIFIER: [A-Za-z][A-Za-z0-9_]* ;
......
......@@ -32,7 +32,7 @@ pr_DocComment[DocumentComment documentComment]:
);
pr_BlockComment[DocumentComment documentComment]:
BLOCK_BEGIN
BLOCK_BEGIN
( pr_Tag[documentComment]
| WS
| NEWLINE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment