Commit 05086f58 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Added inactive ttcn3 editor text hover code


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent f5957ab9
......@@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenFactory;
......@@ -24,6 +26,8 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3DocCommentParser;
*
*/
public class DocumentComment implements ILocateableNode {
private static final String IDPATTERN = "^[A-Za-z][A-Za-z0-9_]*$";
/* Raw text of the comment */
private String comment;
......@@ -37,7 +41,7 @@ public class DocumentComment implements ILocateableNode {
**/
private Location location;
private List<String> authors = new ArrayList<String>();
private List<String> authors;
private List<String> configs = new ArrayList<String>();
private List<String> descs = new ArrayList<String>();
private Map<String,String> exceptions = new HashMap<String, String>();
......@@ -52,6 +56,8 @@ public class DocumentComment implements ILocateableNode {
this.comment = comment;
this.first = first;
this.last = last;
authors = new ArrayList<String>();
}
public Token getFirstToken() {
......@@ -73,11 +79,19 @@ public class DocumentComment implements ILocateableNode {
}
public void addAuthor(String text) {
authors.add(text.trim());
if (text != null) {
authors.add(text.trim());
}
}
public List<String> getAuthors() {
return authors;
}
public void addConfig(String text) {
configs.add(text.trim());
if (text != null) {
configs.add(text.trim());
}
}
public void addParam(String id, String text) {
......@@ -87,7 +101,9 @@ public class DocumentComment implements ILocateableNode {
}
public void addDesc(String text) {
descs.add(text.trim());
if (text != null) {
descs.add(text.trim());
}
}
public void addSince(String text) {
......@@ -115,7 +131,9 @@ public class DocumentComment implements ILocateableNode {
}
public void addRemark(String text) {
remarks.add(text.trim());
if (text != null) {
remarks.add(text.trim());
}
}
public void addReturn(String text) {
......@@ -132,7 +150,13 @@ public class DocumentComment implements ILocateableNode {
// List<? extends Token> tokens = lexer.getAllTokens();
final CommonTokenStream cts = new CommonTokenStream(lexer);
final Ttcn3DocCommentParser parser = new Ttcn3DocCommentParser(cts);
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();
}
}
......@@ -183,7 +183,11 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
*/
public void setDocumentComment(DocumentComment docComment) {
documentComment = docComment;
//documentComment.parseComment();
}
public DocumentComment getDocumentComment() {
documentComment.parseComment();
return documentComment;
}
/**
......
......@@ -7,13 +7,28 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
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.Definition;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
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;
/**
* @author Kristof Szabados
* @author Miklos Magyari
* */
public final class TextHover extends BaseTextHover {
private final ISourceViewer sourceViewer;
......@@ -38,4 +53,74 @@ public final class TextHover extends BaseTextHover {
protected IReferenceParser getReferenceParser() {
return new TTCN3ReferenceParser(false);
}
/**
* Inactive preliminary code for ttcn3 editor hover support
*
* @param textViewer
* @param hoverRegion
* @return
*/
// @Override
public String ___getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
IDocument doc = textViewer.getDocument();
final IFile file = editor.getEditorInput().getAdapter(IFile.class);
final String id = getIdentifier(doc, hoverRegion.getOffset());
Reference ref = TTCN3ReferenceAnalyzer.parseForCompletion(file, id);
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
final CompilationTimeStamp timestamp = tempModule.getLastCompilationTimeStamp();
Scope scope = null;
if (tempModule != null) {
scope = tempModule.getSmallestEnclosingScope(hoverRegion.getOffset());
}
if (ref != null) {
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("<b>Authors:</b><br>");
for (String author : dc.getAuthors()) {
tooltip.append(author + "<br>");
}
return tooltip.toString();
}
}
return "";
}
private String getIdentifier(IDocument doc, int pos) {
try {
char c = doc.getChar(pos);
if (isIdChar(c) == false) {
return "";
}
int start = 0;
for (int pt = pos; pt >= 0 && isIdChar(doc.getChar(pt)) ; pt--) {
start = pt;
}
int end = 0;
for (int pt = pos; pt < doc.getLength() && isIdChar(doc.getChar(pt)) ; pt++) {
end = pt;
}
String s = doc.get(start, end - start + 1);
return s;
} catch (Exception e) {
}
return null;
}
private boolean isIdChar(char c) {
return Character.isAlphabetic(c) || Character.isDigit(c) || c == '_';
}
}
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