Package: VdmEditor

VdmEditor

nameinstructionbranchcomplexitylinemethod
VdmEditor()
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
computeHighlightRangeSourceReference()
M: 44 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
configureSourceViewerDecorationSupport(SourceViewerDecorationSupport)
M: 54 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
createCombinedPreferenceStore(IEditorInput)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
createOutlinePage()
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%
createOutlineSelectionChangedListener()
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%
createPartControl(Composite)
M: 77 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 24 C: 0
0%
M: 1 C: 0
0%
createSourceViewer(Composite, IVerticalRuler, int)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
doSetInput(IEditorInput)
M: 41 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
doSetSelection(ISelection)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAdapter(Class)
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getElementAt(int)
M: 41 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
getElementAt(int, boolean)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getInputVdmElement()
M: 25 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getNewSourceViewerConfiguration()
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%
getOrientation()
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%
initializeEditor()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
internalDoSetInput(IEditorInput)
M: 51 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
outlinePageClosed()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
selectAndReveal(INode)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
selectionChanged()
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
setHighlightRange(INode)
M: 41 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
setOutlinePageInput(VdmContentOutlinePage, IEditorInput)
M: 19 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
setSelection(INode, boolean)
M: 40 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
synchronizeOutlinePage(INode)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
synchronizeOutlinePage(INode, boolean)
M: 28 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
synchronizeOutlinePageSelection()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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 java.io.IOException;
25: import java.util.ArrayList;
26: import java.util.List;
27:
28: import org.eclipse.core.runtime.Assert;
29: import org.eclipse.core.runtime.CoreException;
30: import org.eclipse.jface.dialogs.MessageDialog;
31: import org.eclipse.jface.preference.IPreferenceStore;
32: import org.eclipse.jface.text.IDocument;
33: import org.eclipse.jface.text.IDocumentExtension3;
34: import org.eclipse.jface.text.ITextSelection;
35: import org.eclipse.jface.text.ITextViewerExtension5;
36: import org.eclipse.jface.text.reconciler.IReconciler;
37: import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
38: import org.eclipse.jface.text.source.ICharacterPairMatcher;
39: import org.eclipse.jface.text.source.ISourceViewer;
40: import org.eclipse.jface.text.source.ISourceViewerExtension2;
41: import org.eclipse.jface.text.source.IVerticalRuler;
42: import org.eclipse.jface.text.source.SourceViewerConfiguration;
43: import org.eclipse.jface.viewers.ISelection;
44: import org.eclipse.jface.viewers.ISelectionChangedListener;
45: import org.eclipse.jface.viewers.IStructuredSelection;
46: import org.eclipse.jface.viewers.SelectionChangedEvent;
47: import org.eclipse.swt.SWT;
48: import org.eclipse.swt.custom.StyledText;
49: import org.eclipse.swt.widgets.Composite;
50: import org.eclipse.ui.IEditorInput;
51: import org.eclipse.ui.PlatformUI;
52: import org.eclipse.ui.editors.text.EditorsUI;
53: import org.eclipse.ui.editors.text.TextEditor;
54: import org.eclipse.ui.ide.FileStoreEditorInput;
55: import org.eclipse.ui.texteditor.ChainedPreferenceStore;
56: import org.eclipse.ui.texteditor.IDocumentProvider;
57: import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
58: import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
59: import org.overture.ast.definitions.AMutexSyncDefinition;
60: import org.overture.ast.definitions.PDefinition;
61: import org.overture.ast.node.INode;
62: import org.overture.ast.statements.ABlockSimpleBlockStm;
63: import org.overture.ast.types.AFieldField;
64: import org.overture.ide.core.IVdmElement;
65: import org.overture.ide.core.parser.SourceParserManager;
66: import org.overture.ide.core.resources.IVdmSourceUnit;
67: import org.overture.ide.ui.IVdmUiConstants;
68: import org.overture.ide.ui.VdmUIPlugin;
69: import org.overture.ide.ui.outline.VdmContentOutlinePage;
70: import org.overture.ide.ui.utility.ast.AstLocationSearcher;
71: import org.overture.ide.ui.utility.ast.AstLocationSearcher2;
72: import org.overture.ide.ui.utility.ast.AstLocationSearcher2.TextReference;
73:
74: public abstract class VdmEditor extends TextEditor {
75:
76:         private final static String MATCHING_BRACKETS = "matchingBrackets";
77:         private final static String MATCHING_BRACKETS_COLOR = "matchingBracketsColor";
78:         private final static String GREY_COLOR_CODE = "128,128,128";
79:
80:         
81:         @Override
82:         protected void configureSourceViewerDecorationSupport(
83:                         SourceViewerDecorationSupport support) {
84:                 super.configureSourceViewerDecorationSupport(support);
85:
86:                 char[] matchChars = { '(', ')', '[', ']', '{', '}' };
87:                 ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher(
88:                                 matchChars, IDocumentExtension3.DEFAULT_PARTITIONING);
89:                 support.setCharacterPairMatcher(matcher);
90:                 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
91:                                 MATCHING_BRACKETS_COLOR);
92:
93:                 // Switch preference on. Need to use EditorsUI because getPreference() returns a read only store
94:                 IPreferenceStore store = EditorsUI.getPreferenceStore();
95:                 store.setDefault(MATCHING_BRACKETS, true);
96:                 store.setDefault(MATCHING_BRACKETS_COLOR, GREY_COLOR_CODE);
97:         }
98:
99:         public static interface ILocationSearcher {
100:                 public INode search(List<INode> nodes, int offSet);
101:
102:                 public int[] getNodeOffset(INode node);
103:         }
104:
105:         /**
106:          * Updates the Java outline page selection and this editor's range
107:          * indicator.
108:          *
109:          * @since 3.0
110:          */
111:         private class EditorSelectionChangedListener extends
112:                         AbstractSelectionChangedListener {
113:
114:                 /*
115:                  * @see
116:                  * org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged
117:                  * (org.eclipse.jface.viewers. SelectionChangedEvent)
118:                  */
119:                 public void selectionChanged(SelectionChangedEvent event) {
120:                         // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
121:                         VdmEditor.this.selectionChanged();
122:                 }
123:         }
124:
125:         /**
126:          * The editor selection changed listener.
127:          *
128:          * @since 3.0
129:          */
130:         private EditorSelectionChangedListener fEditorSelectionChangedListener;
131:         VdmContentOutlinePage fOutlinePage = null;
132:         protected VdmSourceViewerConfiguration fVdmSourceViewer;
133:         final boolean TRACE_GET_ELEMENT_AT = false;
134:         ISourceViewer viewer;
135:         protected ILocationSearcher locationSearcher = null;
136:
137:         public VdmEditor() {
138:
139:                 super();
140:                 setDocumentProvider(new VdmDocumentProvider());
141:                 this.locationSearcher = new ILocationSearcher() {
142:
143:                         @Override
144:                         public INode search(List<INode> nodes, int offSet) {
145:                                 // Fix for bug #185, the location searcher did not consider the
146:                                 // file name.
147:                                 IVdmElement element = getInputVdmElement();
148:                                 if (element instanceof IVdmSourceUnit) {
149:                                         // return AstLocationSearcher.search(nodes, offSet,
150:                                         // (IVdmSourceUnit) element);
151:                                         return new AstLocationSearcher2().getNode(
152:                                                         new TextReference(((IVdmSourceUnit) element)
153:                                                                         .getSystemFile(), offSet), nodes);
154:                                 }
155:                                 return null;
156:                         }
157:
158:                         @Override
159:                         public int[] getNodeOffset(INode node) {
160:                                 return AstLocationSearcher.getNodeOffset(node);
161:                         }
162:                 };
163:
164:         }
165:
166:         @Override
167:         protected ISourceViewer createSourceViewer(Composite parent,
168:                         IVerticalRuler ruler, int styles) {
169:
170:                 viewer = new VdmSourceViewer(parent, ruler, getOverviewRuler(),
171:                                 isOverviewRulerVisible(), styles);
172:                 getSourceViewerDecorationSupport(viewer);
173:
174:                 return viewer;
175:
176:         }
177:
178:         @Override
179:         protected void initializeEditor() {
180:                 super.initializeEditor();
181:                 fVdmSourceViewer = getVdmSourceViewerConfiguration(getPreferenceStore());
182:                 setSourceViewerConfiguration(fVdmSourceViewer);
183:                 setRulerContextMenuId(IVdmUiConstants.RULERBAR_ID);
184:         }
185:
186:         protected abstract VdmSourceViewerConfiguration getVdmSourceViewerConfiguration(
187:                         IPreferenceStore fPreferenceStore);
188:
189:         public Object getAdapter(@SuppressWarnings("rawtypes") Class required) {
190:•                if (IContentOutlinePage.class.equals(required)) {
191:•                        if (fOutlinePage == null) {
192:                                 fOutlinePage = createOutlinePage();
193:                         }
194:                         return fOutlinePage;
195:                 }
196:
197:                 return super.getAdapter(required);
198:         }
199:
200:         /**
201:          * Creates the outline page used with this editor.
202:          *
203:          * @return the created Java outline page
204:          */
205:         protected VdmContentOutlinePage createOutlinePage() {
206:                 // VdmContentOutlinePage page= new
207:                 // VdmContentOutlinePage(fOutlinerContextMenuId, this);
208:                 VdmContentOutlinePage page = new VdmContentOutlinePage(this);
209:                 setOutlinePageInput(page, getEditorInput());
210:                 page.addSelectionChangedListener(createOutlineSelectionChangedListener());
211:                 return page;
212:         }
213:
214:         protected ISelectionChangedListener createOutlineSelectionChangedListener() {
215:                 return new ISelectionChangedListener() {
216:
217:                         public void selectionChanged(SelectionChangedEvent event) {
218:
219:                                 ISelection s = event.getSelection();
220:                                 if (s instanceof IStructuredSelection) {
221:                                         IStructuredSelection ss = (IStructuredSelection) s;
222:                                         @SuppressWarnings("rawtypes")
223:                                         List elements = ss.toList();
224:                                         /*
225:                                          * As a fix for bug #185 the selectAndReveal is changed to
226:                                          * highlight range, and thus just highlights the line
227:                                          * instead of selecting the text. If no selection then the
228:                                          * selection is reset
229:                                          */
230:                                         if (!elements.isEmpty()) {
231:                                                 if (elements.get(0) instanceof INode) {
232:                                                         INode node = (INode) elements.get(0);
233:                                                         // selectAndReveal(node);
234:                                                         if (node != computeHighlightRangeSourceReference()) {
235:                                                                 setHighlightRange(node);
236:                                                         }
237:                                                 }
238:                                         } else {
239:                                                 resetHighlightRange();
240:                                         }
241:                                 }
242:                         }
243:                 };
244:         }
245:
246:         /**
247:          * Selects a node existing within the ast presented by the editor
248:          *
249:          * @param node
250:          */
251:         public void selectAndReveal(INode node) {
252:                 int[] offsetLength = this.locationSearcher.getNodeOffset(node);
253:                 selectAndReveal(offsetLength[0], offsetLength[1]);
254:         }
255:
256:         /**
257:          * highlights a node in the text editor.
258:          *
259:          * @param node
260:          */
261:         public void setHighlightRange(INode node) {
262:                 try {
263:                         int[] offsetLength = this.locationSearcher.getNodeOffset(node);
264:                         // int offset = getSourceViewer().getTextWidget().getCaretOffset();
265:                         Assert.isNotNull(offsetLength);
266:•                        Assert.isTrue(offsetLength[0] > 0, "Illegal start offset");
267:•                        Assert.isTrue(offsetLength[0] > 0, "Illegal offset length");
268:                         super.setHighlightRange(offsetLength[0], offsetLength[1], true);
269:                 } catch (IllegalArgumentException e) {
270:                         super.resetHighlightRange();
271:                 }
272:         }
273:
274:         /*
275:          * @see
276:          * org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets
277:          * .Composite)
278:          */
279:         public void createPartControl(Composite parent) {
280:                 super.createPartControl(parent);
281:
282:                 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
283:                 fEditorSelectionChangedListener.install(getSelectionProvider());
284:
285:                 IEditorInput input = getEditorInput();
286:                 IDocument doc = getDocumentProvider().getDocument(input);
287:•                if (doc instanceof VdmDocument) {
288:                         VdmDocument vdmDoc = (VdmDocument) doc;
289:                         try {
290:•                                if (vdmDoc != null && vdmDoc.getSourceUnit() != null
291:•                                                && !vdmDoc.getSourceUnit().hasParseTree()) {
292:                                         SourceParserManager.parseFile(vdmDoc.getSourceUnit());
293:                                 }
294:                         } catch (CoreException e) {
295:                                 VdmUIPlugin.log(
296:                                                 "Faild to do initial parse of SourceUnit in editor", e);
297:                         } catch (IOException e) {
298:                                 VdmUIPlugin.log(
299:                                                 "Faild to do initial parse of SourceUnit in editor", e);
300:                         }
301:
302:                 } else {
303:•                        if (input instanceof FileStoreEditorInput) {
304:                                 MessageDialog d = new MessageDialog(PlatformUI.getWorkbench()
305:                                                 .getDisplay().getActiveShell(), "Error", null,
306:                                                 "Cannot open a vdm file outside the workspace",
307:                                                 MessageDialog.ERROR, new String[] { "Ok" }, 0);
308:                                 d.open();
309:
310:                         }
311:                         // FileStoreEditorInput fs = (FileStoreEditorInput) input;
312:                         // IFileStore fileStore = EFS.getLocalFileSystem().getStore(
313:                         // fs.getURI());
314:                         //
315:                         // if (!fileStore.fetchInfo().isDirectory()
316:                         // && fileStore.fetchInfo().exists())
317:                         // {
318:                         // IWorkbench wb = PlatformUI.getWorkbench();
319:                         // IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
320:                         //
321:                         // IWorkbenchPage page = win.getActivePage();
322:                         //
323:                         // try
324:                         // {
325:                         //
326:                         // page
327:                         // .openEditor(input,
328:                         // EditorsUI.DEFAULT_TEXT_EDITOR_ID);
329:                         // } catch (PartInitException e)
330:                         // {
331:                         // /* some code */
332:                         // fileStore.toString();
333:                         // }
334:                         //
335:                         // }
336:                         // }
337:
338:                 }
339:
340:                 // IAnnotationModel model=
341:                 // getDocumentProvider().getAnnotationModel(getEditorInput());
342:                 // IDocument document =
343:                 // getDocumentProvider().getDocument(getEditorInput());
344:
345:                 // if(model!=null && document !=null)
346:                 // {
347:                 // getSourceViewer().setDocument(document, model);
348:                 // model.connect(document);
349:
350:                 // }
351:
352:                 // try
353:                 // {
354:                 // doSetInput(getEditorInput());
355:                 // } catch (CoreException e)
356:                 // {
357:                 //
358:                 // e.printStackTrace();
359:                 // }
360:                 // fEditorSelectionChangedListener= new
361:                 // EditorSelectionChangedListener();
362:                 // fEditorSelectionChangedListener.install(getSelectionProvider());
363:                 //
364:                 // if (isSemanticHighlightingEnabled())
365:                 // installSemanticHighlighting();
366:                 //
367:                 // fBreadcrumb= createBreadcrumb();
368:                 // fIsBreadcrumbVisible= isBreadcrumbShown();
369:                 // if (fIsBreadcrumbVisible)
370:                 // showBreadcrumb();
371:                 //
372:                 // PlatformUI.getWorkbench().addWindowListener(fActivationListener);
373:
374:         }
375:
376:         /*
377:          * @see AbstractTextEditor#doSetInput
378:          */
379:         protected void doSetInput(IEditorInput input) throws CoreException {
380:
381:                 ISourceViewer sourceViewer = getSourceViewer();
382:•                if (!(sourceViewer instanceof ISourceViewerExtension2)) {
383:                         setPreferenceStore(createCombinedPreferenceStore(input));
384:                         internalDoSetInput(input);
385:                         return;
386:                 }
387:
388:                 // uninstall & unregister preference store listener
389:                 getSourceViewerDecorationSupport(sourceViewer).uninstall();
390:                 ((ISourceViewerExtension2) sourceViewer).unconfigure();
391:
392:                 setPreferenceStore(createCombinedPreferenceStore(input));
393:
394:                 // install & register preference store listener
395:                 sourceViewer.configure(getSourceViewerConfiguration());
396:                 getSourceViewerDecorationSupport(sourceViewer).install(
397:                                 getPreferenceStore());
398:
399:                 internalDoSetInput(input);
400:                 // ISourceViewer sourceViewer = super.getSourceViewer();
401:                 // // if (!(sourceViewer instanceof ISourceViewerExtension2)) {
402:                 // // //setPreferenceStore(createCombinedPreferenceStore(input));
403:                 // // internalDoSetInput(input);
404:                 // // return;
405:                 // // }
406:                 //
407:                 // // uninstall & unregister preference store listener
408:                 // // getSourceViewerDecorationSupport(sourceViewer).uninstall();
409:                 // // ((ISourceViewerExtension2)sourceViewer).unconfigure();
410:                 //
411:                 // // setPreferenceStore(createCombinedPreferenceStore(input));
412:                 //
413:                 // // install & register preference store listener
414:                 // if (sourceViewer != null)
415:                 // {
416:                 // sourceViewer.configure(getSourceViewerConfiguration());
417:                 // getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
418:                 //
419:                 // internalDoSetInput(input);
420:                 // }else super.doSetInput(input);
421:                 //
422:         }
423:
424:         /*
425:          * @see
426:          * org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
427:          */
428:         protected void doSetSelection(ISelection selection) {
429:                 super.doSetSelection(selection);
430:                 synchronizeOutlinePageSelection();
431:         }
432:
433:         /*
434:          * @see org.eclipse.ui.part.WorkbenchPart#getOrientation()
435:          *
436:          * @since 3.1
437:          */
438:         public int getOrientation() {
439:                 return SWT.LEFT_TO_RIGHT; // Java editors are always left to right by
440:                                                                         // default
441:         }
442:
443:         private void internalDoSetInput(IEditorInput input) throws CoreException {
444:                 ISourceViewer sourceViewer = getSourceViewer();
445:                 VdmSourceViewer vdmSourceViewer = null;
446:•                if (sourceViewer instanceof VdmSourceViewer) {
447:                         vdmSourceViewer = (VdmSourceViewer) sourceViewer;
448:                 }
449:                 // IPreferenceStore store = getPreferenceStore();
450:
451:                 // if (vdmSourceViewer != null && isFoldingEnabled() &&(store == null ||
452:                 // !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS)))
453:                 // vdmSourceViewer.prepareDelayedProjection();
454:
455:                 super.doSetInput(input);
456:
457:•                if (vdmSourceViewer != null && vdmSourceViewer.getReconciler() == null) {
458:                         IReconciler reconciler = getSourceViewerConfiguration()
459:                                         .getReconciler(vdmSourceViewer);
460:•                        if (reconciler != null) {
461:                                 reconciler.install(vdmSourceViewer);
462:                                 vdmSourceViewer.setReconciler(reconciler);
463:
464:                         }
465:                 }
466:
467:•                if (fEncodingSupport != null)
468:                         fEncodingSupport.reset();
469:
470:•                if (fOutlinePage == null) {
471:                         fOutlinePage = createOutlinePage();
472:                 }
473:                 setOutlinePageInput(fOutlinePage, input);
474:
475:                 // if (isShowingOverrideIndicators())
476:                 // installOverrideIndicator(false);
477:
478:         }
479:
480:         /**
481:          * Creates and returns the preference store for this Java editor with the
482:          * given input.
483:          *
484:          * @param input
485:          * The editor input for which to create the preference store
486:          * @return the preference store for this editor
487:          * @since 3.0
488:          */
489:         private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
490:                 List<IPreferenceStore> stores = new ArrayList<IPreferenceStore>(3);
491:
492:                 // IJavaProject project= EditorUtility.getJavaProject(input);
493:                 // if (project != null) {
494:                 // stores.add(new EclipsePreferencesAdapter(new
495:                 // ProjectScope(project.getProject()), JavaCore.PLUGIN_ID));
496:                 // }
497:
498:                 stores.add(VdmUIPlugin.getDefault().getPreferenceStore());
499:                 // stores.add(new
500:                 // PreferencesAdapter(VdmCore.getDefault().getPluginPreferences()));
501:                 stores.add(EditorsUI.getPreferenceStore());
502:                 stores.add(PlatformUI.getPreferenceStore());
503:                 // stores.get(0).setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER,true);
504:
505:                 return new ChainedPreferenceStore(
506:                                 (IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores
507:                                                 .size()]));
508:         }
509:
510:         /**
511:          * Sets the input of the editor's outline page.
512:          *
513:          * @param page
514:          * the Java outline page
515:          * @param input
516:          * the editor input
517:          */
518:         protected void setOutlinePageInput(VdmContentOutlinePage page,
519:                         IEditorInput input) {
520:•                if (page == null)
521:                         return;
522:
523:                 IVdmElement je = getInputVdmElement();
524:•                if (je != null && je.exists())
525:                         page.setInput(je);
526:                 else
527:                         page.setInput(null);
528:
529:         }
530:
531:         public IVdmElement getInputVdmElement() {
532:                 IDocumentProvider docProvider = getDocumentProvider();
533:•                if (docProvider != null) {
534:                         IDocument doc = docProvider.getDocument(getEditorInput());
535:•                        if (doc instanceof VdmDocument) {
536:                                 VdmDocument vdmDoc = (VdmDocument) doc;
537:                                 IVdmSourceUnit sourceUnit = vdmDoc.getSourceUnit();
538:•                                if (sourceUnit != null) {
539:                                         return sourceUnit;
540:                                 }
541:                         }
542:                 }
543:                 return null;
544:         }
545:
546:         /**
547:          * Informs the editor that its outliner has been closed.
548:          */
549:         public void outlinePageClosed() {
550:•                if (fOutlinePage != null) {
551:                         fOutlinePage = null;
552:                         resetHighlightRange();
553:                 }
554:         }
555:
556:         /**
557:          * React to changed selection.
558:          *
559:          * @since 3.0
560:          */
561:         protected void selectionChanged() {
562:•                if (getSelectionProvider() == null)
563:                         return;
564:                 INode element = computeHighlightRangeSourceReference();
565:                 // if
566:                 // (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
567:                 synchronizeOutlinePage(element);
568:                 // if (fIsBreadcrumbVisible && fBreadcrumb != null &&
569:                 // !fBreadcrumb.isActive())
570:                 // setBreadcrumbInput(element);
571:                 setSelection(element, false);
572:                 // if (!fSelectionChangedViaGotoAnnotation)
573:                 // updateStatusLine();
574:                 // fSelectionChangedViaGotoAnnotation= false;
575:
576:         }
577:
578:         protected void setSelection(INode reference, boolean moveCursor) {
579:•                if (getSelectionProvider() == null)
580:                         return;
581:
582:                 ISelection selection = getSelectionProvider().getSelection();
583:•                if (selection instanceof ITextSelection) {
584:                         ITextSelection textSelection = (ITextSelection) selection;
585:                         // PR 39995: [navigation] Forward history cleared after going back
586:                         // in navigation history:
587:                         // mark only in navigation history if the cursor is being moved
588:                         // (which it isn't if
589:                         // this is called from a PostSelectionEvent that should only update
590:                         // the magnet)
591:•                        if (moveCursor
592:•                                        && (textSelection.getOffset() != 0 || textSelection
593:•                                                        .getLength() != 0))
594:                                 markInNavigationHistory();
595:                 }
596:
597:•                if (reference != null) {
598:
599:                         StyledText textWidget = null;
600:
601:                         ISourceViewer sourceViewer = getSourceViewer();
602:•                        if (sourceViewer != null)
603:                                 textWidget = sourceViewer.getTextWidget();
604:
605:•                        if (textWidget == null)
606:                                 return;
607:
608:                         // try {
609:                         // ISourceRange range= null;
610:                         // if (reference instanceof ILocalVariable || reference instanceof
611:                         // ITypeParameter || reference
612:                         // instanceof IAnnotation) {
613:                         // IJavaElement je= ((IJavaElement)reference).getParent();
614:                         // if (je instanceof ISourceReference)
615:                         // range= ((ISourceReference)je).getSourceRange();
616:                         // } else
617:                         // range= reference.getSourceRange();
618:                         //
619:                         // if (range == null)
620:                         // return;
621:                         //
622:                         // int offset= range.getOffset();
623:                         // int length= range.getLength();
624:                         //
625:                         // if (offset < 0 || length < 0)
626:                         // return;
627:                         //
628:                         // setHighlightRange(offset, length, moveCursor);
629:                         //
630:                         // if (!moveCursor)
631:                         // return;
632:                         //
633:                         // offset= -1;
634:                         // length= -1;
635:                         //
636:                         // if (reference instanceof IMember) {
637:                         // range= ((IMember) reference).getNameRange();
638:                         // if (range != null) {
639:                         // offset= range.getOffset();
640:                         // length= range.getLength();
641:                         // }
642:                         // } else if (reference instanceof ITypeParameter) {
643:                         // range= ((ITypeParameter) reference).getNameRange();
644:                         // if (range != null) {
645:                         // offset= range.getOffset();
646:                         // length= range.getLength();
647:                         // }
648:                         // } else if (reference instanceof ILocalVariable) {
649:                         // range= ((ILocalVariable)reference).getNameRange();
650:                         // if (range != null) {
651:                         // offset= range.getOffset();
652:                         // length= range.getLength();
653:                         // }
654:                         // } else if (reference instanceof IAnnotation) {
655:                         // range= ((IAnnotation)reference).getNameRange();
656:                         // if (range != null) {
657:                         // offset= range.getOffset();
658:                         // length= range.getLength();
659:                         // }
660:                         // } else if (reference instanceof IImportDeclaration) {
661:                         // String content= reference.getSource();
662:                         // if (content != null) {
663:                         //                                                int start= content.indexOf("import") + 6; //$NON-NLS-1$
664:                         // while (start < content.length() && content.charAt(start) == ' ')
665:                         // start++;
666:                         //
667:                         // int end= content.indexOf(';');
668:                         // do {
669:                         // end--;
670:                         // } while (end >= 0 && content.charAt(end) == ' ');
671:                         //
672:                         // offset= range.getOffset() + start;
673:                         // length= end - start + 1;
674:                         // } else {
675:                         // // fallback
676:                         // offset= range.getOffset();
677:                         // length= range.getLength();
678:                         // }
679:                         // } else if (reference instanceof IPackageDeclaration) {
680:                         // String name= ((IPackageDeclaration) reference).getElementName();
681:                         // if (name != null && name.length() > 0) {
682:                         // String content= reference.getSource();
683:                         // if (content != null) {
684:                         //                                                        int packageKeyWordIndex = content.lastIndexOf("package"); //$NON-NLS-1$
685:                         // if (packageKeyWordIndex != -1) {
686:                         // offset= range.getOffset() + content.indexOf(name,
687:                         // packageKeyWordIndex + 7);
688:                         // length= name.length();
689:                         // }
690:                         // }
691:                         // }
692:                         // }
693:                         //
694:                         // if (offset > -1 && length > 0) {
695:                         //
696:                         // try {
697:                         // textWidget.setRedraw(false);
698:                         // sourceViewer.revealRange(offset, length);
699:                         // sourceViewer.setSelectedRange(offset, length);
700:                         // } finally {
701:                         // textWidget.setRedraw(true);
702:                         // }
703:                         //
704:                         // markInNavigationHistory();
705:                         // }
706:                         //
707:                         // } catch (JavaModelException x) {
708:                         // } catch (IllegalArgumentException x) {
709:                         // }
710:                         //
711:                         // } else if (moveCursor) {
712:                         // resetHighlightRange();
713:                         // markInNavigationHistory();
714:                 }
715:         }
716:
717:         /**
718:          * Synchronizes the outliner selection with the given element position in
719:          * the editor.
720:          *
721:          * @param element
722:          * the java element to select
723:          */
724:         protected void synchronizeOutlinePage(INode element) {
725:                 // TODO: don't search for mutexes
726:•                if (element instanceof AMutexSyncDefinition)
727:                         return;
728:•                if (element instanceof ABlockSimpleBlockStm)
729:                         return;
730:
731:                 try {
732:                         synchronizeOutlinePage(element, false);// true
733:                 } catch (Exception e) {
734:
735:                 }
736:         }
737:
738:         /**
739:          * Synchronizes the outliner selection with the given element position in
740:          * the editor.
741:          *
742:          * @param element
743:          * the java element to select
744:          * @param checkIfOutlinePageActive
745:          * <code>true</code> if check for active outline page needs to be
746:          * done
747:          */
748:         protected void synchronizeOutlinePage(INode element,
749:                         boolean checkIfOutlinePageActive) {
750:•                if (fOutlinePage != null && element != null
751:•                                && !(checkIfOutlinePageActive)) {// && isJavaOutlinePageActive()
752:
753:                         // if added for bug #185, it prevents the outline from being update
754:                         // if the selection from the searcher determine that the node is the
755:                         // same.
756:•                        if (fOutlinePage.getSelection() != null
757:•                                        && fOutlinePage.getSelection() instanceof IStructuredSelection
758:•                                        && element == ((IStructuredSelection) fOutlinePage
759:                                                         .getSelection()).getFirstElement()) {
760:                                 // skip
761:                         } else {
762:                                 fOutlinePage.selectNode(element);
763:                         }
764:                 }
765:         }
766:
767:         /**
768:          * Synchronizes the outliner selection with the actual cursor position in
769:          * the editor.
770:          */
771:         public void synchronizeOutlinePageSelection() {
772:                 synchronizeOutlinePage(computeHighlightRangeSourceReference());
773:         }
774:
775:         /**
776:          * Computes and returns the source reference that includes the caret and
777:          * serves as provider for the outline page selection and the editor range
778:          * indication.
779:          *
780:          * @return the computed source reference
781:          * @since 3.0
782:          */
783:         protected INode computeHighlightRangeSourceReference() {
784:                 ISourceViewer sourceViewer = getSourceViewer();
785:•                if (sourceViewer == null)
786:                         return null;
787:
788:                 StyledText styledText = sourceViewer.getTextWidget();
789:•                if (styledText == null)
790:                         return null;
791:
792:                 int caret = 0;
793:•                if (sourceViewer instanceof ITextViewerExtension5) {
794:                         ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
795:                         caret = extension.widgetOffset2ModelOffset(styledText
796:                                         .getCaretOffset());
797:                 } else {
798:                         int offset = sourceViewer.getVisibleRegion().getOffset();
799:                         caret = offset + styledText.getCaretOffset();
800:                 }
801:                 // System.out.println("Compute element at "+caret);
802:                 INode element = getElementAt(caret, false);
803:
804:                 // if (!(element instanceof INode))
805:                 // return null;
806:
807:                 // if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
808:                 //
809:                 // IImportDeclaration declaration= (IImportDeclaration) element;
810:                 // IImportContainer container= (IImportContainer)
811:                 // declaration.getParent();
812:                 // ISourceRange srcRange= null;
813:                 //
814:                 // try {
815:                 // srcRange= container.getSourceRange();
816:                 // } catch (JavaModelException e) {
817:                 // }
818:                 //
819:                 // if (srcRange != null && srcRange.getOffset() == caret)
820:                 // return container;
821:                 // }
822:
823:                 return element;
824:         }
825:
826:         /**
827:          * Returns the most narrow java element including the given offset.
828:          *
829:          * @param offset
830:          * the offset inside of the requested element
831:          * @param reconcile
832:          * <code>true</code> if editor input should be reconciled in
833:          * advance
834:          * @return the most narrow java element
835:          * @since 3.0
836:          */
837:         protected INode getElementAt(int offset, boolean reconcile) {
838:                 return getElementAt(offset);
839:         }
840:
841:         public INode getElementAt(int offset) {
842:                 IVdmElement element = getInputVdmElement();
843:                 List<INode> nodes = null;
844:                 INode node = null;
845:•                if (element instanceof IVdmSourceUnit) {
846:                         nodes = ((IVdmSourceUnit) element).getParseList();
847:
848:                         long startTime = System.currentTimeMillis();
849:                         node = this.locationSearcher.search(nodes, offset);
850:
851:                         if (TRACE_GET_ELEMENT_AT) {
852:                                 System.out.println("Search Time for offset " + offset + " in "
853:                                                 + element + " is "
854:                                                 + (System.currentTimeMillis() - startTime) + " found: "
855:                                                 + node);
856:
857:                                 System.out.println("Node offset is: "
858:                                                 + getSourceViewer().getTextWidget().getLineAtOffset(
859:                                                                 offset));
860:                                 System.out.println("This thread is: "
861:                                                 + Thread.currentThread().getName());
862:                         }
863:
864:                 }
865:
866:                 // Get a definition to sync with outline, where only definitions are
867:                 // shown. If not a definition the search up
868:                 // the tree until one is found.
869:                 INode def = null;
870:•                if (node instanceof PDefinition || node instanceof AFieldField) {
871:                         def = node;
872:•                } else if (node != null) {
873:                         def = node.getAncestor(PDefinition.class);
874:                 }
875:                 return def;
876:         }
877:
878:         @Override
879:         public void dispose() {
880:                 super.dispose();
881:•                if (fOutlinePage != null) {
882:                         fOutlinePage.dispose();
883:                 }
884:
885:                 // fEditorSelectionChangedListener
886:         }
887:
888:         public SourceViewerConfiguration getNewSourceViewerConfiguration() {
889:                 return getVdmSourceViewerConfiguration(getPreferenceStore());
890:         }
891:
892:         // @Override
893:         // protected void createActions() {
894:         // super.createActions();
895:         // ResourceBundle bla = new ResourceBundle() {
896:         //
897:         // @Override
898:         // protected Object handleGetObject(String key) {
899:         // if(key.equals("ToggleComment.label")){
900:         // return "Toggle Comment";
901:         // }
902:         // if(key.equals("ToggleComment.tooltip")){
903:         // return "Toggle Comment Tooltip";
904:         // }
905:         // if(key.equals("ToggleComment.description")){
906:         // return "Toggle Comment Description";
907:         // }
908:         // if(key.equals("ToggleComment.image")){
909:         // return null;
910:         // }
911:         //
912:         //
913:         //
914:         // return null;
915:         // }
916:         //
917:         // @Override
918:         // public Enumeration<String> getKeys() {
919:         //
920:         // return null;
921:         // }
922:         // };
923:         //                Action action= new ToggleCommentAction(bla, "ToggleComment.", this); //$NON-NLS-1$
924:         // action.setActionDefinitionId(IVdmActionDefinitionIds.TOGGLE_COMMENT);
925:         //                setAction("ToggleComment", action); //$NON-NLS-1$
926:         //                markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
927:         // configureToggleCommentAction();
928:         // }
929:
930:         // /**
931:         // * Configure actions
932:         // */
933:         // private void configureToggleCommentAction() {
934:         //                IAction action = getAction("ToggleComment"); //$NON-NLS-1$
935:         // if (action instanceof ToggleCommentAction) {
936:         // ISourceViewer sourceViewer = getSourceViewer();
937:         // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
938:         // ((ToggleCommentAction) action).configure(sourceViewer,
939:         // configuration);
940:         // }
941:         // }
942: }