Commit 9d7b617f authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Implemented IHoverContent for providing hover info data


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ed840a52
......@@ -14,6 +14,7 @@ import org.antlr.v4.runtime.CommonTokenFactory;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.UnbufferedCharStream;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentLexer;
import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentParser;
......@@ -84,6 +85,17 @@ public class DocumentComment implements ILocateableNode {
}
}
public void addAuthorsContent(Ttcn3HoverContent content) {
if (getAuthors().size() > 0) {
content.addText("\n\n");
content.addStyledText("Authors:\n", Ttcn3HoverContent.boldRange());
for (String author : getAuthors()) {
content.addText("\n ");
content.addStyledText(author, Ttcn3HoverContent.italicRange());
}
}
}
public List<String> getAuthors() {
return authors;
}
......@@ -92,10 +104,25 @@ public class DocumentComment implements ILocateableNode {
return descs;
}
public void addDescsContent(Ttcn3HoverContent content) {
if (descs.size() > 0) {
content.addText("\n\n");
content.addStyledText("Description\n", Ttcn3HoverContent.boldRange());
for (String desc : descs) {
content.addText("\n" + desc);
}
}
}
public Map<String, String> getParams() {
return params;
}
public void addParamsContent(Ttcn3HoverContent content) {
content.addText("\n\n");
content.addStyledText("Parameters\n", Ttcn3HoverContent.boldRange());
}
public Map<String, String> getMembers() {
return members;
}
......
......@@ -12,15 +12,20 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType;
import org.eclipse.titan.designer.AST.INamedNode;
import org.eclipse.titan.designer.AST.IReferenceChain;
......@@ -29,6 +34,7 @@ import org.eclipse.titan.designer.AST.ISubReference.Subreference_type;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.TypeOwner_type;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.Module;
......@@ -60,6 +66,8 @@ import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.Stylers;
import org.eclipse.titan.designer.editors.T3Doc;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3CodeSkeletons;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer;
......@@ -68,6 +76,7 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.ui.IEditorPart;
/**
* The Def_Function class represents TTCN3 function definitions.
......@@ -75,7 +84,7 @@ import org.eclipse.titan.designer.preferences.PreferenceConstants;
* @author Kristof Szabados
* @author Miklos Magyari
* */
public final class Def_Function extends Definition implements IParameterisedAssignment {
public final class Def_Function extends Definition implements IParameterisedAssignment{
/**
* The encoding prototype. Used with the extension attributes. Also used
* by Def_ExtFunction
......@@ -1485,4 +1494,76 @@ public final class Def_Function extends Definition implements IParameterisedAssi
source.append(tempSource);
}
@Override
public Ttcn3HoverContent getHoverContent(IEditorPart editor, Assignment ass) {
super.getHoverContent(editor, ass);
final Def_Function func = (Def_Function)ass;
hoverContent.addText("function ");
hoverContent.addStyledText(getIdentifier().getDisplayName(), Ttcn3HoverContent.boldRange());
if (hasDocumentComment()) {
final DocumentComment dc = getDocumentComment();
dc.addDescsContent(hoverContent);
dc.addParamsContent(hoverContent);
final FormalParameterList fpl = func.getFormalParameterList();
final Map<String,String> params = dc.getParams();
String paramType = null;
for (Map.Entry<String, String> param : params.entrySet()) {
final FormalParameter fp = fpl.getParameterById(new Identifier(Identifier_type.ID_TTCN, param.getKey()));
if (fp != null) {
paramType = getFormalParamType(fp);
} else {
// FIXME : report param mismatch
}
hoverContent.addText("\n ");
hoverContent.addStyledText(param.getKey(), Ttcn3HoverContent.boldItalicRange());
hoverContent.addStyledText(" (" + (paramType != null ? paramType : "<?>") + ")", Ttcn3HoverContent.boldRange());
hoverContent.addText(" " + param.getValue());
}
// addReturn(sb, styles, dc);
dc.addAuthorsContent(hoverContent);
} else {
final FormalParameterList fp = func.getFormalParameterList();
if (fp.getNofParameters() > 0) {
hoverContent.addText("\n\n");
hoverContent.addStyledText("Parameters\n", Ttcn3HoverContent.boldRange());
for (int i = 0; i < fp.getNofParameters(); i++) {
final FormalParameter param = fp.getParameterByIndex(i);
String paramType = getFormalParamType(param);
hoverContent.addText("\n ");
hoverContent.addStyledText(param.getIdentifier().getDisplayName(), Ttcn3HoverContent.boldItalicRange());
hoverContent.addStyledText(" (" + (paramType != null ? paramType : "<?>") + ")", Ttcn3HoverContent.boldRange());
}
}
}
hoverContent.addContent(ContentType.Info);
return hoverContent;
}
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 = "IN";
break;
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_INOUT:
paramType = "INOUT";
break;
case A_PAR_VAL_OUT:
case A_PAR_TEMP_OUT:
paramType = "OUT";
break;
default:
paramType = null;
}
return paramType;
}
}
......@@ -61,6 +61,8 @@ import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.graphics.ImageCache;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ParserMarkerSupport;
......@@ -75,6 +77,9 @@ import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.titan.designer.properties.data.MakefileCreationData;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.EditorPart;
/**
* The definition class represents general TTCN3 definitions.
......@@ -82,7 +87,7 @@ import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
* @author Kristof Szabados
* @author Arpad Lovassy
*/
public abstract class Definition extends Assignment implements IAppendableSyntax, IIncrementallyUpdateable {
public abstract class Definition extends Assignment implements IAppendableSyntax, IIncrementallyUpdateable, IHoverContent {
protected WithAttributesPath withAttributesPath = null;
protected ErroneousAttributes erroneousAttributes = null;
......@@ -120,6 +125,9 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
/** Optional documentation comment according to ETSI ES 201 873-10 */
private DocumentComment documentComment = null;
/** content of hover window for this defintion */
Ttcn3HoverContent hoverContent = new Ttcn3HoverContent();
static {
final IPreferencesService ps = Platform.getPreferencesService();
......@@ -188,12 +196,20 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
documentComment = docComment;
}
public DocumentComment getDocumentComment() {
public DocumentComment parseDocumentComment() {
if (documentComment != null) {
documentComment.parseComment();
}
return documentComment;
}
public boolean hasDocumentComment() {
return documentComment != null;
}
public DocumentComment getDocumentComment() {
return documentComment;
}
/**
* Sets the with attributes for this definition if it has any. Also
......@@ -806,4 +822,11 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
public boolean isInherited() {
return isInherited;
}
public Ttcn3HoverContent getHoverContent(IEditorPart editor, Assignment assignment) {
final IFile file = editor.getEditorInput().getAdapter(IFile.class);
PeekSource.addStyledSource(PeekSource.getPeekSource(editor, file, assignment.getDeclaration()), hoverContent);
return hoverContent;
}
}
package org.eclipse.titan.designer.AST.TTCN3.definitions;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.ui.IEditorPart;
public interface IHoverContent {
Ttcn3HoverContent getHoverContent(IEditorPart editor, Assignment assignment);
}
......@@ -7,11 +7,14 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
/**
* This class represents a collection of strings with style ranges
......@@ -28,10 +31,13 @@ public class Ttcn3HoverContent {
ContentEntry(String text, List<StyleRange> ranges) {
this.text = text;
this.ranges = ranges;
this.ranges = new ArrayList<StyleRange>(ranges);
}
}
private StringBuilder sb = new StringBuilder();
private List<StyleRange> styles = new ArrayList<StyleRange>();
private Map<ContentType, ContentEntry> map = new HashMap<ContentType, ContentEntry>();
public void addContent(ContentType type, String text, List<StyleRange> range) {
......@@ -39,6 +45,13 @@ public class Ttcn3HoverContent {
map.put(type, mapentry);
}
public void addContent(ContentType type) {
final ContentEntry mapentry = new ContentEntry(sb.toString(), styles);
map.put(type, mapentry);
styles.clear();
sb.setLength(0);
}
public boolean hasText(ContentType type) {
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
......@@ -65,4 +78,45 @@ public class Ttcn3HoverContent {
}
return mapentry.ranges;
}
public static StyleRange boldRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.BOLD;
return range;
}
public static StyleRange italicRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.ITALIC;
return range;
}
public static StyleRange colorRange(Color color) {
final StyleRange range = new StyleRange();
range.foreground = color;
return range;
}
public static StyleRange boldItalicRange() {
final StyleRange range = new StyleRange();
range.fontStyle = SWT.BOLD | SWT.ITALIC;
return range;
}
public void addText(String text) {
sb.append(text);
}
public void addStyledText(String text, StyleRange style) {
if (style != null) {
style.start = sb.length();
style.length = text.length();
styles.add(style);
}
sb.append(text);
}
}
......@@ -11,11 +11,14 @@ import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.editors.actions.SwitchHoverWindowContentAction;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.ui.PlatformUI;
......@@ -33,7 +36,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
private Ttcn3HoverContent content;
private Shell fShell;
private boolean isRich;
private ContentType actualType = ContentType.Info;
private ContentType actualType = ContentType.Source;
public Ttcn3HoverInfoControl(Shell parentShell, String string) {
super(parentShell, string);
......@@ -46,6 +49,14 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
this.isRich = isRich;
createContent(parentShell);
create();
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
// TODO Auto-generated method stub
}
});
}
@Override
......
......@@ -8,7 +8,6 @@
package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -42,6 +41,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
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.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.AST.TTCN3.types.Referenced_Type;
......@@ -57,7 +57,6 @@ 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.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
/**
......@@ -119,13 +118,18 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
}
if (ref != null) {
Assignment assignment = scope.getAssBySRef(timestamp, ref);
Ttcn3HoverContent info = null;
if (assignment instanceof Definition) {
DocumentComment dc = ((Definition) assignment).getDocumentComment();
DocumentComment dc = ((Definition) assignment).parseDocumentComment();
List<StyleRange> styles = new ArrayList<StyleRange>();
StringBuilder tooltip = new StringBuilder();
if (assignment instanceof Def_Function) {
functionHover(tooltip, styles, dc, assignment);
if (assignment instanceof IHoverContent) {
info = ((Definition)assignment).getHoverContent(editor, assignment);
}
// if (assignment instanceof Def_Function) {
//// functionHover(tooltip, styles, dc, assignment);
// Def_Function df = (Def_Function)assignment;
// }
if (assignment instanceof Def_Const) {
constantHover(tooltip, styles, dc, assignment, timestamp);
}
......@@ -143,12 +147,12 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
}
}
Map<Ttcn3HoverContent.ContentType, Ttcn3HoverContent> contents = new HashMap<Ttcn3HoverContent.ContentType, Ttcn3HoverContent>(2);
Ttcn3HoverContent info = new Ttcn3HoverContent();
info.addContent(ContentType.Info, tooltip.toString(), styles);
if (info == null) {
info = new Ttcn3HoverContent();
info.addContent(ContentType.Info, tooltip.toString(), styles);
}
PeekSource.addStyledSource(PeekSource.getPeekSource(editor, file, assignment.getDeclaration()), info);
//contents.put(ContentType.Source, source);
return info;
}
}
......@@ -290,7 +294,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
sb.append("\n\n");
final Class_Type ct = (Class_Type)refd.getTypeRefdLast(timestamp);
final Def_Type classType = (Def_Type)ct.getNameParent();
addClassMembers(sb, styles, classType.getDocumentComment(), timestamp, ct.getClassBody());
addClassMembers(sb, styles, classType.parseDocumentComment(), timestamp, ct.getClassBody());
}
}
if (dc != null) {
......
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