Commit 5796e44d authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Basic doc comment support for classes


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent c57d79e0
......@@ -96,6 +96,10 @@ public class DocumentComment implements ILocateableNode {
return params;
}
public Map<String, String> getMembers() {
return members;
}
public String getReturn() {
return return_;
}
......@@ -132,13 +136,13 @@ public class DocumentComment implements ILocateableNode {
public void addException(String id, String text) {
if (id != null) {
exceptions.put(id.trim(), text.trim());
exceptions.put(id.trim(), text != null ? text.trim() : null);
}
}
public void addMember(String id, String text) {
if (id != null) {
members.put(id.trim(), text.trim());
members.put(id.trim(), text != null ? text.trim() : null);
}
}
......@@ -157,6 +161,7 @@ public class DocumentComment implements ILocateableNode {
public void parseComment() {
authors.clear();
descs.clear();
members.clear();
params.clear();
return_ = null;
......
......@@ -28,11 +28,16 @@ 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.Type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type;
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.AST.TTCN3.types.ClassTypeBody;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -87,7 +92,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
Reference ref = TTCN3ReferenceAnalyzer.parseForCompletion(file, id);
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
final CompilationTimeStamp timestamp = tempModule.getLastCompilationTimeStamp();
CompilationTimeStamp timestamp = null;
Scope scope = null;
if (tempModule != null) {
......@@ -95,6 +100,9 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
if (scope == null) {
scope = tempModule;
}
timestamp = tempModule.getLastCompilationTimeStamp();
} else {
return "";
}
if (ref != null) {
Assignment assignment = scope.getAssBySRef(timestamp, ref);
......@@ -108,6 +116,16 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
if (assignment instanceof Def_Const) {
constantHover(tooltip, dc, assignment, timestamp);
}
if (assignment instanceof Def_Type) {
final Def_Type deftype = (Def_Type)assignment;
final Type type = deftype.getType(timestamp);
switch (type.getTypetypeTtcn3()) {
case TYPE_CLASS:
classHover(tooltip, dc, assignment, timestamp);
break;
default:
}
}
tooltip.append("</html>");
return tooltip.toString();
}
......@@ -190,7 +208,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
}
private void functionHover(StringBuilder sb, DocumentComment dc, Assignment ass) {
sb.append("function <b>" + ((Definition)ass).getIdentifier().getName() + "()</b>");
sb.append("function <b>" + ((Definition)ass).getIdentifier().getDisplayName() + "()</b>");
if (dc != null) {
addDescs(sb, dc);
addParams(sb, dc, ass);
......@@ -217,12 +235,49 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
typeName = "<i>" + constType.getTypename() + " </i>";
}
sb.append("constant <b>" + typeName + ((Definition)ass).getIdentifier().getName() + "</b>");
sb.append("<br>Value: " + ((Def_Const)ass).getValue().createStringRepresentation());
if (dc != null) {
addDescs(sb, dc);
addAuthors(sb, dc);
}
}
private void classHover(StringBuilder sb, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
final Class_Type ct = (Class_Type)ass.getType(timestamp);
final ClassTypeBody body = ct.getClassBody();
sb.append("class <b>" + body.getIdentifier().getDisplayName() + "</b><br><br>");
sb.append("<b>Members:</b><br>");
Map<String,String> members = null;
if (dc != null) {
members = dc.getMembers();
}
for (Definition def : body.getDefinitions()) {
String id = def.getIdentifier().getDisplayName();
String memberText = null;
if (members != null) {
memberText = members.get(id);
}
String memberTypeName = null;
if (def instanceof Def_Function) {
if (id.equals("create")) {
memberTypeName = "constructor";
} else {
memberTypeName = "function";
}
} else if (def instanceof Def_Timer) {
memberTypeName = "timer";
}
else {
final IType memberType = def.getType(timestamp);
if (memberType != null) {
memberTypeName = memberType.getTypename();
}
}
sb.append("<div>" + memberTypeName + " <b><i>" + def.getIdentifier().getDisplayName() + "</i></b> " +
(memberText != null ? memberText : "") + "</div>");
}
}
private String getFormalParamType(FormalParameter fp) {
String paramType;
......
......@@ -78,6 +78,7 @@ pr_MemberTag[DocumentComment documentComment]
}:
MEMBER
id = pr_Identifier
WS?
( ft = pr_FreeText { freetext = $ft.text; } )?
{
documentComment.addMember( $id.text, freetext );
......
......@@ -562,9 +562,9 @@ pr_TTCN3Module
act_ttcn3_module.addControlpart( controlpart );
controlpart.setAttributeParentPath( act_ttcn3_module.getAttributePath() );
}
// if (docComment != null) {
// // act_ttcn3_module.setDocumentatComment(docComment);
// }
if (docComment != null) {
//act_ttcn3_module.setDocumentComment(docComment);
}
};
pr_TTCN3ModuleKeyword returns[String stringValue]:
......@@ -766,6 +766,7 @@ pr_ModuleDef returns [List<Definition> definitions]
pr_TypeDef returns[Def_Type def_type]
@init {
$def_type = null;
DocumentComment docComment = getDocumentComment();
}:
( pr_TypeDefKeyword
( d1 = pr_StructuredTypeDef { $def_type = $d1.def_type; }
......@@ -774,6 +775,9 @@ pr_TypeDef returns[Def_Type def_type]
)
{ if ( $def_type != null ) {
$def_type.setLocation(getLocation( $start, getLastVisibleToken() ));
if (docComment != null) {
$def_type.setDocumentComment(docComment);
}
}
};
......
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