Commit 80e7de16 authored by Arpad Lovassy's avatar Arpad Lovassy
Browse files

Content assist doc comment tag parameter: deprecated after status (issue #477)


Signed-off-by: Arpad Lovassy's avatarzlovarp <arpad.lovassy@semcon.com>
parent 662e6e7d
......@@ -7,6 +7,8 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor.contentassist;
import java.util.Arrays;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.titan.designer.AST.TTCN3.definitions.ICommentable;
import org.eclipse.titan.designer.editors.CompletionProposal;
......@@ -18,14 +20,14 @@ import org.eclipse.titan.designer.graphics.ImageCache;
* Collects proposals for documentation comment context
*
* @author Adam Knapp
*
* @author Arpad Lovassy
*/
public class DocumentCommentContext extends ProposalContext {
private static final String[] HTML_TAGS = { "<b>", "<code>", "<em>", "<li>", "<ol>", "<p>", "<pre>",
"<strong>", "<ul>" };
private static final String LINE_BREAK = "<br>";
public DocumentCommentContext(final ProposalContextInfo proposalContextInfo) {
super(proposalContextInfo);
doFallback = false;
......@@ -37,14 +39,85 @@ public class DocumentCommentContext extends ProposalContext {
if (!prefix.isEmpty()) {
if (prefix.startsWith("<")) {
addHtmlTagProposals(propCollector, prefix);
return;
} else if (!prefix.startsWith(ICommentable.AT)) {
prefix = ICommentable.AT + prefix;
} else if (prefix.startsWith(ICommentable.AT)) {
addDocCommentTagProposals(propCollector, prefix);
} else {
String tag = getTagBeforePrefix();
if (Arrays.asList(ICommentable.DOC_COMMENT_TAGS).contains(tag)) {
addDocCommentTagParamProposals(propCollector, tag, prefix);
}
}
} else {
String tag = getTagBeforeSpace();
if (Arrays.asList(ICommentable.DOC_COMMENT_TAGS).contains(tag)) {
addDocCommentTagParamProposals(propCollector, tag, "");
}
}
addDocCommentTagProposals(propCollector, prefix);
}
/**
* Returns the tag before the prefix based on the context information. Never returns {@code null}.
*
* @return the tag before the prefix based on the context information
*/
private String getTagBeforeSpace() {
if (proposalContextInfo.context != null && !proposalContextInfo.context.isEmpty()) {
int i = proposalContextInfo.context.length()-1;
for (; i >= 0; i--) {
final char c = proposalContextInfo.context.charAt(i);
if (c != ' ') {
break;
}
}
final StringBuilder sb = new StringBuilder(proposalContextInfo.context.length());
for (; i >= 0; i--) {
final char c = proposalContextInfo.context.charAt(i);
if (!isPrefixChar(c)) {
break;
}
sb.insert(0, c);
}
return sb.toString();
} else {
return "";
}
}
/**
* Returns the tag before the spaces based on the context information. Never returns {@code null}.
*
* @return the tag before the spaces based on the context information
*/
private String getTagBeforePrefix() {
if (proposalContextInfo.context != null && !proposalContextInfo.context.isEmpty()) {
int i = proposalContextInfo.context.length()-1;
for (; i >= 0; i--) {
final char c = proposalContextInfo.context.charAt(i);
if (!isPrefixChar(c)) {
break;
}
}
for (; i >= 0; i--) {
final char c = proposalContextInfo.context.charAt(i);
if (c != ' ') {
break;
}
}
final StringBuilder sb = new StringBuilder(proposalContextInfo.context.length());
for (; i >= 0; i--) {
final char c = proposalContextInfo.context.charAt(i);
if (!isPrefixChar(c)) {
break;
}
sb.insert(0, c);
}
return sb.toString();
} else {
return "";
}
}
@Override
protected boolean isPrefixChar(final char c) {
return Character.isAlphabetic(c) || Character.isDigit(c) || c == '_' || c == '@' || c == '<';
......@@ -64,6 +137,26 @@ public class DocumentCommentContext extends ProposalContext {
propCollector.sortAll();
}
/**
* Adds proposals for doc comment tag parameter
* @param propCollector list of proposals
* @param tag doc comment tag
* @param prefix complete comment tag
*/
private void addDocCommentTagParamProposals(ProposalCollector propCollector, String tag, String prefix) {
final int replacementOffset = proposalContextInfo.offset - prefix.length();
final int replacementLength = prefix.length();
switch (tag) {
case ICommentable.STATUS_TAG:
final String deprecatedStr = "deprecated";
final CompletionProposal proposal = new CompletionProposal(deprecatedStr, replacementOffset, replacementLength,
deprecatedStr.length(), ImageCache.getImage(proposalContextInfo.module.getOutlineIcon()),
new StyledString(deprecatedStr), null, new Ttcn3HoverContent(tag + " " + deprecatedStr), deprecatedStr.startsWith(prefix) ? PREFIX_MATCHES : OTHER);
propCollector.addProposal(proposal);
}
propCollector.sortAll();
}
private void addHtmlTagProposals(ProposalCollector propCollector, String prefix) {
final int replacementOffset = proposalContextInfo.offset - prefix.length();
final int replacementLength = prefix.length();
......
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