Package: VdmSourceViewerConfiguration

VdmSourceViewerConfiguration

nameinstructionbranchcomplexitylinemethod
VdmSourceViewerConfiguration()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
VdmSourceViewerConfiguration(IPreferenceStore)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getAnnotationHover(ISourceViewer)
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%
getAutoEditStrategies(ISourceViewer, String)
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%
getConfiguredContentTypes(ISourceViewer)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getConfiguredDocumentPartitioning(ISourceViewer)
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%
getDefaultPrefixes(ISourceViewer, String)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getPresentationReconciler(ISourceViewer)
M: 79 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getQuickAssistAssistant(ISourceViewer)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getReconciler(ISourceViewer)
M: 28 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getTextHover(ISourceViewer, String)
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%
getVdmMultiLineCommentScanner()
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getVdmSingleLineCommentScanner()
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getVdmStringScanner()
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 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.editor.core;
23:
24: import org.eclipse.jface.preference.IPreferenceStore;
25: import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
26: import org.eclipse.jface.text.IAutoEditStrategy;
27: import org.eclipse.jface.text.IDocument;
28: import org.eclipse.jface.text.IRegion;
29: import org.eclipse.jface.text.ITextHover;
30: import org.eclipse.jface.text.ITextViewer;
31: import org.eclipse.jface.text.Region;
32: import org.eclipse.jface.text.contentassist.IContentAssistant;
33: import org.eclipse.jface.text.presentation.IPresentationReconciler;
34: import org.eclipse.jface.text.presentation.PresentationReconciler;
35: import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
36: import org.eclipse.jface.text.quickassist.QuickAssistAssistant;
37: import org.eclipse.jface.text.reconciler.IReconciler;
38: import org.eclipse.jface.text.reconciler.MonoReconciler;
39: import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
40: import org.eclipse.jface.text.rules.ITokenScanner;
41: import org.eclipse.jface.text.source.IAnnotationHover;
42: import org.eclipse.jface.text.source.ISourceViewer;
43: import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
44: import org.eclipse.ui.internal.editors.text.EditorsPlugin;
45: import org.overture.ide.ui.IVdmUiConstants;
46: import org.overture.ide.ui.VdmUIPlugin;
47: import org.overture.ide.ui.editor.partitioning.IVdmPartitions;
48: import org.overture.ide.ui.editor.partitioning.VdmPartitionScanner;
49: import org.overture.ide.ui.editor.syntax.VdmColorProvider;
50: import org.overture.ide.ui.editor.syntax.VdmMultiLineCommentScanner;
51: import org.overture.ide.ui.editor.syntax.VdmSingleLineCommentScanner;
52: import org.overture.ide.ui.editor.syntax.VdmStringScanner;
53: import org.overture.ide.ui.quickfix.VdmQuickAssistantProcessor;
54:
55: public abstract class VdmSourceViewerConfiguration extends
56:                 TextSourceViewerConfiguration
57: {
58:         private PresentationReconciler reconciler = null;
59:         protected String[] commentingPrefix = new String[] { "--" };
60:         protected ITokenScanner vdmSingleLineCommentScanner;
61:         private ITokenScanner vdmMultiLineCommentScanner;
62:         private ITokenScanner vdmStringScanner;
63:         
64:         public VdmSourceViewerConfiguration()
65:         {
66:                 super();
67:         }
68:         
69:         /**
70:          * Creates a text source viewer configuration and
71:          * initializes it with the given preference store.
72:          *
73:          * @param preferenceStore        the preference store used to initialize this configuration
74:          */
75:         public VdmSourceViewerConfiguration(IPreferenceStore preferenceStore) {
76:                 super(preferenceStore);
77:         }
78:         
79:         
80:
81:         // private Object fScanner;
82:
83:         @Override
84:         public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer)
85:         {
86:                 return IVdmPartitions.VDM_PARTITIONING;
87:         }
88:
89:         @Override
90:         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer)
91:         {
92:
93:                 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
94:                                 VdmPartitionScanner.SINGLELINE_COMMENT,
95:                                 VdmPartitionScanner.MULTILINE_COMMENT,
96:                                 VdmPartitionScanner.STRING };
97:         }
98:
99:
100:
101:         @Override
102:         public IReconciler getReconciler(ISourceViewer sourceViewer)
103:         {
104:•                if (!VdmUIPlugin.getDefault().getPreferenceStore().contains(IVdmUiConstants.ENABLE_EDITOR_RECONFILER) ||VdmUIPlugin.getDefault().getPreferenceStore().getBoolean(IVdmUiConstants.ENABLE_EDITOR_RECONFILER))
105:                 {
106:                         MonoReconciler reconciler = new MonoReconciler(new VdmReconcilingStrategy(), false);
107:                          reconciler.setDelay(500);
108:                         reconciler.install(sourceViewer);
109:
110:                         return reconciler;
111:                 } else
112:                 {
113:                         return null;
114:                 }
115:         }
116:
117:         @Override
118:         public IPresentationReconciler getPresentationReconciler(
119:                         ISourceViewer sourceViewer)
120:         {
121:•                if (reconciler == null)
122:                 {
123:                         reconciler = new PresentationReconciler();
124:                         reconciler.setDocumentPartitioning(IVdmPartitions.VDM_PARTITIONING);
125:                         
126:                         DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getVdmSingleLineCommentScanner());
127:                         reconciler.setDamager(dr, VdmPartitionScanner.SINGLELINE_COMMENT);
128:                         reconciler.setRepairer(dr, VdmPartitionScanner.SINGLELINE_COMMENT);
129:
130:                         dr = new DefaultDamagerRepairer(getVdmMultiLineCommentScanner());
131:                         reconciler.setDamager(dr, VdmPartitionScanner.MULTILINE_COMMENT);
132:                         reconciler.setRepairer(dr, VdmPartitionScanner.MULTILINE_COMMENT);
133:
134:                         dr = new DefaultDamagerRepairer(getVdmStringScanner());
135:                         reconciler.setDamager(dr, VdmPartitionScanner.STRING);
136:                         reconciler.setRepairer(dr, VdmPartitionScanner.STRING);
137:
138:                         dr = new DefaultDamagerRepairer(getVdmCodeScanner());
139:                         reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
140:                         reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
141:                 }
142:                 return reconciler;
143:         }
144:
145:         private ITokenScanner getVdmStringScanner()
146:         {
147:•                if(vdmStringScanner == null)
148:                 {
149:                         vdmStringScanner = new VdmStringScanner(new VdmColorProvider());
150:                 }
151:                 
152:                 return vdmStringScanner;
153:         }
154:
155:         protected ITokenScanner getVdmSingleLineCommentScanner()
156:         {
157:•                if(vdmSingleLineCommentScanner == null)
158:                 {
159:                         vdmSingleLineCommentScanner = new VdmSingleLineCommentScanner(new VdmColorProvider());
160:                 }
161:                 
162:                 return vdmSingleLineCommentScanner;
163:         }
164:         
165:         private ITokenScanner getVdmMultiLineCommentScanner()
166:         {
167:•                if(vdmMultiLineCommentScanner == null)
168:                 {
169:                         vdmMultiLineCommentScanner = new VdmMultiLineCommentScanner(new VdmColorProvider());
170:                 }
171:                 
172:                 return vdmMultiLineCommentScanner;
173:         }
174:
175:         protected abstract ITokenScanner getVdmCodeScanner();
176:
177:         @Override
178:         public IAutoEditStrategy[] getAutoEditStrategies(
179:                         ISourceViewer sourceViewer, String contentType)
180:         {
181:                 //IAutoEditStrategy strategy = //(IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) ? new VdmAutoEditStrategy() :
182:                 //                 new DefaultIndentLineAutoEditStrategy();
183:                 //return new IAutoEditStrategy[] { strategy };
184:                 return new IAutoEditStrategy[] {new DefaultIndentLineAutoEditStrategy()};
185:         }
186:
187:         @Override
188:         public ITextHover getTextHover(ISourceViewer sourceViewer,
189:                         String contentType)
190:         {
191:                 return new ITextHover()
192:                 {
193:
194:                         public IRegion getHoverRegion(ITextViewer textViewer, int offset)
195:                         {
196:                                 return new Region(offset, 5);
197:                         }
198:
199:                         public String getHoverInfo(ITextViewer textViewer,
200:                                         IRegion hoverRegion)
201:                         {
202:                                 return null;
203:                         }
204:                 };
205:         }
206:
207:         /*
208:          * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
209:          */
210:         @Override
211:         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer)
212:         {
213:
214:                 return new VdmAnnotationHover(false);
215:         }
216:
217:         @Override
218:         abstract public IContentAssistant getContentAssistant(
219:                         ISourceViewer sourceViewer);
220:
221:         @Override
222:         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
223:                         String contentType)
224:         {
225:•                if (contentType.equals(IDocument.DEFAULT_CONTENT_TYPE))
226:                 {
227:                         return commentingPrefix;
228:                 }
229:•                if (contentType.equals(VdmPartitionScanner.SINGLELINE_COMMENT))
230:                 {
231:                         return commentingPrefix;
232:                 }
233:
234:                 return super.getDefaultPrefixes(sourceViewer, contentType);
235:         }
236:         
237:         
238:         @SuppressWarnings("restriction")
239:         @Override
240:         public IQuickAssistAssistant getQuickAssistAssistant(
241:                         ISourceViewer sourceViewer)
242:         {
243:                 QuickAssistAssistant assistant= new QuickAssistAssistant();
244:                 assistant.setRestoreCompletionProposalSize(EditorsPlugin.getDefault().getDialogSettingsSection("quick_assist_proposal_size")); //$NON-NLS-1$
245:                 assistant.setQuickAssistProcessor(new VdmQuickAssistantProcessor());
246:                 
247:                 return assistant;
248:         }
249:
250: }