Package: VdmContentAssistProcessor$1

VdmContentAssistProcessor$1

nameinstructionbranchcomplexitylinemethod
compare(Object, Object)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.ui.templates;
23:
24: import java.util.ArrayList;
25: import java.util.Arrays;
26: import java.util.Comparator;
27: import java.util.List;
28:
29: import org.eclipse.jface.text.ITextViewer;
30: import org.eclipse.jface.text.Region;
31: import org.eclipse.jface.text.contentassist.ICompletionProposal;
32: import org.eclipse.jface.text.contentassist.ICompletionProposalSorter;
33: import org.overture.ide.ui.completion.CompletionUtil;
34: import org.overture.ide.ui.editor.core.VdmDocument;
35:
36: public abstract class VdmContentAssistProcessor extends
37:                 VdmTemplateAssistProcessor
38: {
39:         private VdmCompleteProcessor processer = new VdmCompleteProcessor();
40:
41:         public boolean enableTemplate()
42:         {
43:                 return true;
44:         }
45:
46:         /**
47:          * @param offset an offset within the document for which completions should be computed
48:          */
49:         public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
50:                         int offset)
51:         {
52:                 List<ICompletionProposal> modList = new ArrayList<ICompletionProposal>();
53:                 ICompletionProposal[] completionProposals = null;
54:
55:                 // IEditorInput editorInput = editor.getEditorInput();
56:                 // String text = viewer.getTextWidget().getText();
57:
58:                 if (enableTemplate())
59:                 {
60:                         ICompletionProposal[] templates = super.computeCompletionProposals(viewer, offset);
61:                         if (templates != null)
62:                         {
63:                                 for (int i = 0; i < templates.length; i++)
64:                                 {
65:                                         modList.add(templates[i]);
66:                                 }
67:
68:                         }
69:                 }
70:
71:                 if (viewer.getDocument() instanceof VdmDocument)
72:                 {
73:                         VdmCompletionContext completionContext = CompletionUtil.computeVdmCompletionContext(viewer.getDocument(), offset);
74:                  Region region = new Region(offset - completionContext.getProposalPrefix().length(), completionContext.getProposalPrefix().length());
75:                 
76:                  processer.computeCompletionProposals(completionContext,
77:                                  (VdmDocument) viewer.getDocument(), modList, offset,
78:                                  viewer, createContext(viewer, region));
79:                 }
80:
81:                 if (modList.size() > 0)
82:                 {
83:                         completionProposals = (ICompletionProposal[]) modList.toArray(new ICompletionProposal[modList.size()]);
84:                 }
85:                 sortProposals(completionProposals);
86:                 return completionProposals;
87:         }
88:         
89:         @SuppressWarnings("unchecked")
90:         private void sortProposals(final ICompletionProposal[] proposals) {
91:                 if(proposals != null && proposals.length > 0){
92:                         final ICompletionProposalSorter fSorter = new VdmCompletionProposalSorter();
93:                         Arrays.sort(proposals, new Comparator() {
94:                                 public int compare(Object o1, Object o2) {
95:                                         return fSorter.compare((ICompletionProposal) o1,(ICompletionProposal) o2);
96:                                 }
97:                         });
98:                 }
99:         }
100:
101: }