Commit 436d9f7d authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Converted rest of hover code to use IHoverContent


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 3fd8d5b6
......@@ -131,6 +131,11 @@ public class DocumentComment implements ILocateableNode {
return return_;
}
public void addReturnContent(Ttcn3HoverContent content) {
content.addText("\n\n");
content.addStyledText("Returns\n", Ttcn3HoverContent.boldRange());
}
public void addConfig(String text) {
if (text != null) {
configs.add(text.trim());
......@@ -202,10 +207,4 @@ public class DocumentComment implements ILocateableNode {
final Ttcn3DocCommentParser parser = new Ttcn3DocCommentParser(cts);
parser.pr_DocComment(this);
}
private boolean isIdentifier(String id) {
Pattern p = Pattern.compile(IDPATTERN);
Matcher m = p.matcher(id.trim());
return m.matches();
}
}
......@@ -44,8 +44,8 @@ import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.T3Doc;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ParserUtilities;
import org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser;
......@@ -572,7 +572,7 @@ public final class Def_Const extends Definition {
dc.addDescsContent(hoverContent);
dc.addAuthorsContent(hoverContent);
}
hoverContent.addContent(ContentType.Info);
hoverContent.addContent(HoverContentType.INFO);
return hoverContent;
}
}
......@@ -553,6 +553,7 @@ public final class Def_Type extends Definition {
final IType varType = assignment.getType(timestamp);
if (varType instanceof Class_Type) {
hoverContent.addStyledText("class " + ((Definition)assignment).getIdentifier().getName() + " ", Ttcn3HoverContent.boldRange());
hoverContent.addText("\n\n");
final Class_Type ct = (Class_Type)varType;
final ClassTypeBody body = ct.getClassBody();
......
......@@ -7,10 +7,6 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
......@@ -20,28 +16,15 @@ import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextHoverExtension2;
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;
import org.eclipse.titan.designer.AST.IType;
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_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.IHoverContent;
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.editors.Stylers;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
......@@ -113,26 +96,16 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
Assignment assignment = scope.getAssBySRef(timestamp, ref);
Ttcn3HoverContent info = null;
if (assignment instanceof Definition) {
DocumentComment dc = ((Definition) assignment).parseDocumentComment();
List<StyleRange> styles = new ArrayList<StyleRange>();
StringBuilder tooltip = new StringBuilder();
if (assignment instanceof Def_Type) {
final Def_Type deftype = (Def_Type)assignment;
final Type type = deftype.getType(timestamp);
switch (type.getTypetypeTtcn3()) {
case TYPE_CLASS:
info = ((IHoverContent)assignment).getHoverContent(editor, assignment);
break;
default:
}
} else if (assignment instanceof IHoverContent) {
((Definition) assignment).parseDocumentComment();
if (assignment instanceof IHoverContent) {
info = ((IHoverContent)assignment).getHoverContent(editor, assignment);
}
if (info == null) {
info = new Ttcn3HoverContent();
info.addContent(HoverContentType.INFO, tooltip.toString(), styles);
}
PeekSource.addStyledSource(PeekSource.getPeekSource(editor, file, assignment.getDeclaration()), info);
return info;
......@@ -146,12 +119,10 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
*
* getHoverInfo2 is used instead
*/
@Deprecated
@Override
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
final Ttcn3HoverContent content = (Ttcn3HoverContent)getHoverInfo2(textViewer, hoverRegion);
return null;
//return content != null ? content.getText() : "";
}
private String getIdentifier(IDocument doc, int pos) {
......@@ -181,134 +152,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
private boolean isIdChar(char c) {
return Character.isAlphabetic(c) || Character.isDigit(c) || c == '_';
}
private void addDescs(StringBuilder sb, List<StyleRange> styles, DocumentComment dc) {
final List<String> descs = dc.getDescs();
if (descs.size() > 0) {
sb.append("\n\n");
addStyledText(sb, styles, "Description\n", boldRange());
for (String desc : descs) {
sb.append("\n" + desc);
}
}
}
private void addReturn(StringBuilder sb, List<StyleRange> styles, DocumentComment dc) {
final String ret = dc.getReturn();
if (ret != null) {
sb.append("\n\n");
addStyledText(sb, styles, "Returns: ", boldRange());
sb.append(ret + "\n");
}
}
private void addAuthors(StringBuilder sb, List<StyleRange> styles, DocumentComment dc) {
if (dc.getAuthors().size() > 0) {
sb.append("\n\n");
addStyledText(sb, styles, "Authors:\n", boldRange());
for (String author : dc.getAuthors()) {
sb.append("\n ");
addStyledText(sb, styles, author, italicRange());
}
}
}
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 ");
addStyledText(sb, styles, body.getIdentifier().getDisplayName(), boldRange());
sb.append("\n\n");
addClassMembers(sb, styles, dc, timestamp, body);
if (dc != null) {
addAuthors(sb, styles, dc);
}
}
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) {
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(memberTypeName + " ");
addStyledText(sb, styles, def.getIdentifier().getDisplayName(), boldItalicRange());
sb.append(" " + (memberText != null ? memberText : ""));
sb.append("\n");
}
}
private void addStyledText(StringBuilder sb, List<StyleRange> ranges, String text, StyleRange style) {
if (style != null) {
style.start = sb.length();
style.length = text.length();
ranges.add(style);
}
sb.append(text);
}
private StyleRange boldRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.BOLD;
return range;
}
private StyleRange italicRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.ITALIC;
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;
return range;
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
......
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