Commit 21255669 authored by Arpad Lovassy's avatar Arpad Lovassy
Browse files

Code completion for setverdict


Signed-off-by: Arpad Lovassy's avatarzlovarp <arpad.lovassy@semcon.com>
parent 8e60d3ce
......@@ -28,7 +28,7 @@ import org.eclipse.ui.IEditorPart;
*
* @author Miklos Magyari
* @author Adam Knapp
*
* @author Arpad Lovassy
*/
public class CompletionFinder {
private static final String IDENTIFIER = "([A-Za-z][A-Za-z0-9_]*)";
......@@ -38,10 +38,12 @@ public class CompletionFinder {
private static final String FRIEND = "friend[\\s]+module[\\s]*(.*)";
private static final String IMPORT = "import[\\s]+from([\\s]*$|[\\s+]+(" + IDENTIFIER + "))";
private static final String COMPONENT = "(system|mtc|runs[\\s]+on)((\\s+" + IDENTIFIER + "$)|\\s*)";
private static final String PARAMETERIZED = IDENTIFIER + "\\s*\\(([^)]*$)";
private static final String PARAMETER = "\\s*\\(([^)]*$)";
private static final String SETVERDICT = "setverdict" + PARAMETER;
private static final String PARAMETERIZED = IDENTIFIER + PARAMETER;
private enum SpecialContext { None, SimpleComment, DocComment, StringLiteral }
private enum ContextType { Assignment, Component, Doccomment, Friend, Import, Parameterized }
private enum ContextType { Assignment, Component, Doccomment, Friend, Import, Setverdict, Parameterized }
private IEditorPart editor;
private Module module;
......@@ -63,6 +65,7 @@ public class CompletionFinder {
contextMap.put(Pattern.compile(ASSIGNMENT), ContextType.Assignment);
contextMap.put(Pattern.compile(IMPORT), ContextType.Import);
contextMap.put(Pattern.compile(FRIEND), ContextType.Friend);
contextMap.put(Pattern.compile(SETVERDICT), ContextType.Setverdict);
contextMap.put(Pattern.compile(PARAMETERIZED), ContextType.Parameterized);
}
......@@ -176,6 +179,8 @@ public class CompletionFinder {
return new FriendContext(info);
case Import:
return new ImportContext(info);
case Setverdict:
return new SetverdictContext(info);
case Parameterized:
return new ParameterizedContext(info);
default:
......
......@@ -39,6 +39,7 @@ import org.eclipse.titan.designer.parsers.ProjectSourceParser;
* Base class for different proposal contexts
*
* @author Miklos Magyari
* @author Arpad Lovassy
*
*/
public abstract class ProposalContext {
......@@ -259,38 +260,83 @@ public abstract class ProposalContext {
case TYPE_OCTETSTRING:
case TYPE_REAL:
case TYPE_UCHARSTRING:
List<Definition> defList = getAvailableDefsByType(ttype);
for (Definition a : defList) {
final String name = a.getIdentifier().getDisplayName();
if (! name.equals(excludeName)) {
final Ttcn3HoverContent doc = a.getHoverContent(null);
final CompletionProposal proposal = new CompletionProposal(name, replacementOffset, replacementLength,
name.length(), ImageCache.getImageByType(ttype), new StyledString(name),
null, doc, name.toLowerCase().startsWith(prefix.toLowerCase()) ? TYPE_MATCHES | PREFIX_MATCHES : TYPE_MATCHES);
propCollector.addProposal(proposal);
}
}
List<Assignment> aList = getAvailableAssignmentsByType(ttype);
for (Assignment a : aList) {
switch (a.getAssignmentType()) {
case A_TYPE:
break;
default:
Ttcn3HoverContent doc = null;
if (a instanceof ICommentable) {
final ICommentable d = (ICommentable)a;
doc = d.getHoverContent(null);
}
final String name = a.getIdentifier().getDisplayName();
final CompletionProposal proposal = new CompletionProposal(name, replacementOffset, replacementLength,
name.length(), ImageCache.getImageByType(ttype), new StyledString(name),
null, doc, name.toLowerCase().startsWith(prefix.toLowerCase()) ? TYPE_MATCHES | PREFIX_MATCHES : TYPE_MATCHES);
propCollector.addProposal(proposal);
}
}
addItems(ttype, propCollector, excludeName, replacementLength, replacementLength, prefix);
break;
case TYPE_VERDICT:
final String noneString = "none";
final CompletionProposal noneProposal = new CompletionProposal(noneString, replacementOffset, replacementLength,
noneString.length(), ImageCache.getImageByType(ttype), new StyledString(noneString, new Stylers.ItalicStyler()),
null, null, noneString.toLowerCase().startsWith(prefix.toLowerCase()) ? HIGHEST | PREFIX_MATCHES : TYPE_MATCHES);
final String passString = "pass";
final CompletionProposal passProposal = new CompletionProposal(passString, replacementOffset, replacementLength,
passString.length(), ImageCache.getImageByType(ttype), new StyledString(passString, new Stylers.ItalicStyler()),
null, null, passString.toLowerCase().startsWith(prefix.toLowerCase()) ? HIGHEST | PREFIX_MATCHES : TYPE_MATCHES);
final String inconcString = "inconc";
final CompletionProposal inconcProposal = new CompletionProposal(inconcString, replacementOffset, replacementLength,
inconcString.length(), ImageCache.getImageByType(ttype), new StyledString(inconcString, new Stylers.ItalicStyler()),
null, null, inconcString.toLowerCase().startsWith(prefix.toLowerCase()) ? HIGHEST | PREFIX_MATCHES : TYPE_MATCHES);
final String failString = "fail";
final CompletionProposal failProposal = new CompletionProposal(failString, replacementOffset, replacementLength,
failString.length(), ImageCache.getImageByType(ttype), new StyledString(failString, new Stylers.ItalicStyler()),
null, null, failString.toLowerCase().startsWith(prefix.toLowerCase()) ? HIGHEST | PREFIX_MATCHES : TYPE_MATCHES);
final String errorString = "error";
final CompletionProposal errorProposal = new CompletionProposal(errorString, replacementOffset, replacementLength,
errorString.length(), ImageCache.getImageByType(ttype), new StyledString(errorString, new Stylers.ItalicStyler()),
null, null, errorString.toLowerCase().startsWith(prefix.toLowerCase()) ? HIGHEST | PREFIX_MATCHES : TYPE_MATCHES);
propCollector.addProposal(noneProposal);
propCollector.addProposal(passProposal);
propCollector.addProposal(inconcProposal);
propCollector.addProposal(failProposal);
propCollector.addProposal(errorProposal);
addItems(ttype, propCollector, excludeName, replacementLength, replacementLength, prefix);
break;
default:
}
propCollector.sortAll();
}
/**
* Adds proposal to to the list.
* General version for basic TTCN-3 types
* @param ttype
* @param propCollector
* @param excludeName
* @param replacementOffset
* @param replacementLength
* @param prefix
*/
private void addItems(Type_type ttype, ProposalCollector propCollector, String excludeName,
int replacementOffset, int replacementLength, String prefix) {
List<Definition> defList = getAvailableDefsByType(ttype);
for (Definition a : defList) {
final String name = a.getIdentifier().getDisplayName();
if (! name.equals(excludeName)) {
final Ttcn3HoverContent doc = a.getHoverContent(null);
final CompletionProposal proposal = new CompletionProposal(name, replacementOffset, replacementLength,
name.length(), ImageCache.getImageByType(ttype), new StyledString(name),
null, doc, name.toLowerCase().startsWith(prefix.toLowerCase()) ? TYPE_MATCHES | PREFIX_MATCHES : TYPE_MATCHES);
propCollector.addProposal(proposal);
}
}
List<Assignment> aList = getAvailableAssignmentsByType(ttype);
for (Assignment a : aList) {
switch (a.getAssignmentType()) {
case A_TYPE:
break;
default:
Ttcn3HoverContent doc = null;
if (a instanceof ICommentable) {
final ICommentable d = (ICommentable)a;
doc = d.getHoverContent(null);
}
final String name = a.getIdentifier().getDisplayName();
final CompletionProposal proposal = new CompletionProposal(name, replacementOffset, replacementLength,
name.length(), ImageCache.getImageByType(ttype), new StyledString(name),
null, doc, name.toLowerCase().startsWith(prefix.toLowerCase()) ? TYPE_MATCHES | PREFIX_MATCHES : TYPE_MATCHES);
propCollector.addProposal(proposal);
}
}
}
}
/******************************************************************************
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor.contentassist;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.editors.ProposalCollector;
/**
* Collects proposals for setverdict parameter
*
* @author Arpad Lovassy
*
*/
public class SetverdictContext extends ProposalContext {
public SetverdictContext(ProposalContextInfo proposalContextInfo) {
super(proposalContextInfo);
doFallback = false;
}
@Override
public void getProposals(ProposalCollector propCollector) {
addItemsByType(null, Type_type.TYPE_VERDICT, propCollector, null, 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