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

Applied tcn3 editor hover styles


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ad22fc82
......@@ -22,6 +22,7 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
......@@ -45,8 +46,11 @@ import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.StyledCompletionProposal;
import org.eclipse.titan.designer.editors.Stylers;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
import org.eclipse.titan.designer.graphics.ImageCache;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser;
......@@ -121,17 +125,17 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
functionHover(tooltip, styles, dc, assignment);
}
if (assignment instanceof Def_Const) {
constantHover(tooltip, dc, assignment, timestamp);
constantHover(tooltip, styles, dc, assignment, timestamp);
}
if (assignment instanceof Def_Var) {
varHover(tooltip, dc, assignment, timestamp);
varHover(tooltip, styles, 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);
classHover(tooltip, styles, dc, assignment, timestamp);
break;
default:
}
......@@ -266,56 +270,72 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
}
}
private void varHover(StringBuilder sb, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
private void varHover(StringBuilder sb, List<StyleRange> styles, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
final IType varType = ass.getType(timestamp);
String typeName = null;
if (varType != null) {
typeName = "<i>" + varType.getTypename() + " </i>";
typeName = varType.getTypename();
}
sb.append("var <b>" + typeName + ((Definition)ass).getIdentifier().getName() + "</b>");
sb.append("var ");
addStyledText(sb, styles, typeName + ((Definition)ass).getIdentifier().getName() + " ", boldRange());
if (varType instanceof Referenced_Type) {
final Referenced_Type refd = (Referenced_Type)varType;
if (refd.getTypeRefdLast(timestamp) instanceof Class_Type) {
sb.append("<br><br>");
sb.append("\n\n");
final Class_Type ct = (Class_Type)refd.getTypeRefdLast(timestamp);
final Def_Type classType = (Def_Type)ct.getNameParent();
addClassMembers(sb, classType.getDocumentComment(), timestamp, ct.getClassBody());
addClassMembers(sb, styles, classType.getDocumentComment(), timestamp, ct.getClassBody());
}
}
if (dc != null) {
// addDescs(sb, dc);
// addAuthors(sb, dc);
addDescs(sb, styles, dc);
addAuthors(sb, styles, dc);
}
}
private void constantHover(StringBuilder sb, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
private void constantHover(StringBuilder sb, List<StyleRange> styles, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
final IType constType = ass.getType(timestamp);
String typeName = null;
if (constType != null) {
typeName = "<i>" + constType.getTypename() + " </i>";
typeName = constType.getTypename();
}
sb.append("constant <b>" + typeName + ((Definition)ass).getIdentifier().getName() + "</b>");
sb.append("<br>Value: " + ((Def_Const)ass).getValue().createStringRepresentation());
sb.append("constant ");
addStyledText(sb, styles, typeName + ((Definition)ass).getIdentifier().getName(), boldRange());
sb.append("\nValue: " + ((Def_Const)ass).getValue().createStringRepresentation());
if (dc != null) {
// addDescs(sb, dc);
//addAuthors(sb, dc);
addDescs(sb, styles, dc);
addAuthors(sb, styles, dc);
}
}
private void classHover(StringBuilder sb, DocumentComment dc, Assignment ass, CompilationTimeStamp timestamp) {
private void classHover(StringBuilder sb, List<StyleRange> styles, 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>");
addClassMembers(sb, dc, timestamp, body);
sb.append("class ");
addStyledText(sb, styles, body.getIdentifier().getDisplayName(), boldRange());
sb.append("\n\n");
addClassMembers(sb, styles, dc, timestamp, body);
}
private void addClassMembers(StringBuilder sb, DocumentComment dc, CompilationTimeStamp timestamp, ClassTypeBody body) {
sb.append("<b>Members:</b><br>");
private void addClassMembers(StringBuilder sb, List<StyleRange> styles, DocumentComment dc, CompilationTimeStamp timestamp, ClassTypeBody body) {
addStyledText(sb, styles, "Members:\n\n", boldRange());
Map<String,String> members = null;
if (dc != null) {
members = dc.getMembers();
}
for (Definition def : body.getDefinitions()) {
Color color;
switch (def.getVisibilityModifier()) {
case Private:
color = Stylers.PrivateColor;
break;
case Public:
color= Stylers.PublicColor;
break;
default:
color = Stylers.ProtectedColor;
}
addStyledText(sb, styles, " \u25fc", colorRange(color));
String id = def.getIdentifier().getDisplayName();
String memberText = null;
if (members != null) {
......@@ -337,8 +357,10 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
memberTypeName = memberType.getTypename();
}
}
sb.append("<div>" + memberTypeName + " <b><i>" + def.getIdentifier().getDisplayName() + "</i></b> " +
(memberText != null ? memberText : "") + "</div>");
sb.append(memberTypeName + " ");
addStyledText(sb, styles, def.getIdentifier().getDisplayName(), boldItalicRange());
sb.append(memberText != null ? memberText : "");
sb.append("\n");
}
}
......@@ -388,6 +410,13 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
return range;
}
private StyleRange colorRange(Color color) {
final StyleRange range = new StyleRange();
range.foreground = color;
return range;
}
private StyleRange boldItalicRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.BOLD | SWT.ITALIC;
......
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