Commit 21d763c2 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Function hover tooltip is now combined from AST and doc comment info


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ebc5f9e1
......@@ -88,6 +88,10 @@ public class DocumentComment implements ILocateableNode {
return authors;
}
public List<String> getDescs() {
return descs;
}
public Map<String, String> getParams() {
return params;
}
......@@ -152,6 +156,7 @@ public class DocumentComment implements ILocateableNode {
public void parseComment() {
authors.clear();
descs.clear();
params.clear();
return_ = null;
......
......@@ -7,20 +7,30 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
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.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -28,12 +38,13 @@ import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReferenceAnalyzer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.EditorsUI;
/**
* @author Kristof Szabados
* @author Miklos Magyari
* */
public final class TextHover extends BaseTextHover {
public final class TextHover extends BaseTextHover implements ITextHoverExtension {
private final ISourceViewer sourceViewer;
private final IEditorPart editor;
......@@ -87,9 +98,6 @@ public final class TextHover extends BaseTextHover {
Assignment assignment = scope.getAssBySRef(timestamp, ref);
if (assignment instanceof Definition) {
DocumentComment dc = ((Definition) assignment).getDocumentComment();
if (dc == null) {
return "";
}
StringBuilder tooltip = new StringBuilder();
tooltip.append("<html>");
if (assignment instanceof Def_Function) {
......@@ -131,12 +139,31 @@ public final class TextHover extends BaseTextHover {
return Character.isAlphabetic(c) || Character.isDigit(c) || c == '_';
}
private void addParams(StringBuilder sb, DocumentComment dc) {
private void addDescs(StringBuilder sb, DocumentComment dc) {
final List<String> descs = dc.getDescs();
if (descs.size() > 0) {
sb.append("<br><br><b>Description:</b>");
for (String desc : descs) {
sb.append("<br>" + desc);
}
}
}
private void addParams(StringBuilder sb, DocumentComment dc, Assignment ass) {
final Map<String,String> params = dc.getParams();
if (params.size() > 0) {
sb.append("<b>Parameters:</b>");
String paramType = null;
final Def_Function func = (Def_Function)ass;
final FormalParameterList fpl = func.getFormalParameterList();
sb.append("<br><br><b>Parameters:</b>");
for (Map.Entry<String, String> param : params.entrySet()) {
sb.append(" <div><i>" + param.getKey() + "</i> " + param.getValue() + "</div>");
final FormalParameter fp = fpl.getParameterById(new Identifier(Identifier_type.ID_TTCN, param.getKey()));
if (fp != null) {
paramType = getFormalParamType(fp);
} else {
// FIXME : report param mismatch
}
sb.append(" <div><i><b>" + param.getKey() + "</i> (" + (paramType != null ? paramType : "<?>") + ")</b> " + param.getValue() + "</div>");
}
}
}
......@@ -159,9 +186,56 @@ public final class TextHover extends BaseTextHover {
}
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);
sb.append("function <b>" + ((Definition)ass).getIdentifier().getName() + "()</b>");
if (dc != null) {
addDescs(sb, dc);
addParams(sb, dc, ass);
addReturn(sb, dc);
addAuthors(sb, dc);
} else {
final Def_Function func = (Def_Function)ass;
final FormalParameterList fp = func.getFormalParameterList();
if (fp.getNofParameters() > 0) {
sb.append("<br><br><b>Parameters:</b>");
for (int i = 0; i < fp.getNofParameters(); i++) {
final FormalParameter param = fp.getParameterByIndex(i);
String paramType = getFormalParamType(param);
sb.append("<div><i>" + param.getIdentifier().getName() + " </i>" + paramType + "</div>");
}
}
}
}
private String getFormalParamType(FormalParameter fp) {
String paramType;
switch (fp.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_TEMP_IN:
paramType = "<i>IN</i>";
break;
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_INOUT:
paramType = "<i>INOUT</i>";
break;
case A_PAR_VAL_OUT:
case A_PAR_TEMP_OUT:
paramType = "<i>OUT</i>";
break;
default:
paramType = null;
}
return paramType;
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString());
}
};
}
}
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