Package: VdmCompletionHelper

VdmCompletionHelper

nameinstructionbranchcomplexitylinemethod
VdmCompletionHelper()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
checkForDuplicates(String, ArrayList)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
createProposal(INode, String, String, String, VdmCompletionContext, List, int)
M: 46 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
dynamicTemplateCreator(String[], String, int, TemplateContext, List, VdmCompletionContext, ITextViewer, int)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
dynamicTemplateCreator(String[], String, int, TemplateContext, List, VdmCompletionContext, ITextViewer, int, String)
M: 80 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
findInString(String, String)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getTempleteContextType()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
nullOrEmptyCheck(String)
M: 9 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
parameterNameChecker(List)
M: 39 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
templatePatternGenerator(List, String[])
M: 91 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.ide.ui.templates;
2:
3: import java.util.ArrayList;
4: import java.util.Iterator;
5: import java.util.List;
6: import java.util.Objects;
7:
8: import org.eclipse.jface.text.IRegion;
9: import org.eclipse.jface.text.ITextSelection;
10: import org.eclipse.jface.text.ITextViewer;
11: import org.eclipse.jface.text.Region;
12: import org.eclipse.jface.text.contentassist.CompletionProposal;
13: import org.eclipse.jface.text.contentassist.ContextInformation;
14: import org.eclipse.jface.text.contentassist.ICompletionProposal;
15: import org.eclipse.jface.text.contentassist.IContextInformation;
16: import org.eclipse.jface.text.templates.Template;
17: import org.eclipse.jface.text.templates.TemplateContext;
18: import org.overture.ast.node.INode;
19: import org.overture.ide.ui.internal.viewsupport.VdmElementImageProvider;
20:
21: public class VdmCompletionHelper extends VdmTemplateAssistProcessor{
22:         
23:         static VdmElementImageProvider imgProvider = new VdmElementImageProvider();
24:         
25:         public boolean checkForDuplicates(String value, ArrayList<String> container){
26:                 
27:                 Iterator<String> iter = container.iterator();
28:
29:•                while(iter.hasNext()){
30:                         String item = iter.next();
31:•                        if(Objects.equals(value, item)){
32:                                 return true;
33:                         }
34:                 }
35:                 return false;
36:         }
37:         
38:         public boolean nullOrEmptyCheck(String str){
39:•                return str != null && !str.isEmpty();
40:         }
41:
42:         public boolean findInString(String text,String word)
43:         {
44:•         if(text == ""){
45:                 return true;
46:         }
47:         return word.toLowerCase().startsWith(text.toLowerCase());
48:         }
49:
50:         public void createProposal(INode node, String displayname, String replacmentString,String additionalProposalInfo,final VdmCompletionContext info,
51:                 final List<ICompletionProposal> proposals,final int offset)
52: {
53:•         if(nullOrEmptyCheck(replacmentString) && findInString(info.getProposalPrefix(),replacmentString))
54:                 {        
55:                         IContextInformation contextInfo = new ContextInformation(displayname, displayname); //$NON-NLS-1$
56:                         
57:                         int curOffset = offset + info.getReplacementOffset();// - info2.proposalPrefix.length();
58:                         int length = replacmentString.length();
59:                         int replacementLength = info.getProposalPrefix().length();
60:                         
61:                         proposals.add(new CompletionProposal(replacmentString, curOffset, replacementLength, length, imgProvider.getImageLabel(node, 0), displayname, contextInfo, additionalProposalInfo));
62:                 }
63: }
64:
65:         public String[] templatePatternGenerator(List<String> parameterNames,String[] functionName){
66:                 StringBuilder sbPattern = new StringBuilder();
67:                 StringBuilder sbDisplayName = new StringBuilder();
68:                 sbPattern.append(functionName[1]);
69:                 sbDisplayName.append(functionName[1]);
70:•                if((parameterNames != null && !parameterNames.isEmpty())){
71:                         List<String> checkedParamenterNames = parameterNameChecker(parameterNames);
72:•                        for (int i = 0; i < checkedParamenterNames.size(); i++) {
73:                                 String str = checkedParamenterNames.get(i);
74:
75:•                                if(str != checkedParamenterNames.get(0)){
76:                                         sbPattern.append(", ");
77:                                         sbDisplayName.append(", ");
78:                                 }
79:                                 sbPattern.append("${" + str + "}");
80:                                 sbDisplayName.append(str);
81:                         }
82:                         
83:                 }
84:                 sbPattern.append(")");
85:                 sbDisplayName.append(")");
86:                 
87:                 functionName[1] = sbPattern.toString();
88:                 functionName[0] = sbDisplayName.toString();
89:
90:         return functionName;
91:         }
92:         
93:         public void dynamicTemplateCreator(String[] extractedNames, String type, int offset,TemplateContext context,List<ICompletionProposal> proposals,VdmCompletionContext info,ITextViewer viewer,int nodeOffsetPosition) {
94:         
95:                 dynamicTemplateCreator( extractedNames, type, offset, context, proposals, info, viewer, nodeOffsetPosition, null);
96:         }
97:                 
98:         public void dynamicTemplateCreator(String[] extractedNames, String type, int offset,TemplateContext context,List<ICompletionProposal> proposals,VdmCompletionContext info,ITextViewer viewer,int nodeOffsetPosition, String prefix) {
99:                 
100:•                if (context == null)
101:                         return;
102:                 
103:•                if(nullOrEmptyCheck(extractedNames[0]) && findInString(info.getProposalPrefix(),extractedNames[1])){
104:
105:                         ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
106:                         // get caret pos = selection.getOffset()
107:                                 
108:•                        if (selection.getOffset() == offset){
109:                                 offset = selection.getOffset() + selection.getLength();
110:                         }
111:•                        if(prefix == null){
112:                                 prefix = extractPrefix(viewer, offset);
113:                         }
114:                         Region region = new Region(offset - prefix.length(), prefix.length());
115:                         context.setVariable("selection", selection.getText());
116:                         
117:                         Template template = new Template(extractedNames[0],type,"org.overture.ide.vdmsl.ui.contextType",extractedNames[1],true);
118:                         
119:                         proposals.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
120:                 }
121:         }
122:         
123:         @Override
124:         protected String getTempleteContextType() {
125:                 // TODO Auto-generated method stub
126:                 return null;
127:         }
128:         
129:         private List<String> parameterNameChecker(List<String> parameterNames){
130:                 //TODO Temp class which has to be removed and replaced with the NameGen from package org.overture.codegen.vdm2jml.util; since it duplicates functionality
131:                 NameGen nameGen = new NameGen();
132:                 List<String> checkedParameterNames = new ArrayList<String>();
133:•                for (String parm : parameterNames) {
134:                         String tempParm = parm;
135:                         tempParm = parm.replaceAll("[^a-zA-Z0-9_]", "");
136:                         
137:•                        if(tempParm.length() <= 0){
138:                                 tempParm = "parameter";
139:                         }
140:                         checkedParameterNames.add(nameGen.getName(tempParm));
141:                 }
142:                 return checkedParameterNames;
143:         }
144: }