Method: reconcile(IRegion)

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.core.runtime.CoreException;
25: import org.eclipse.jface.text.IDocument;
26: import org.eclipse.jface.text.IRegion;
27: import org.eclipse.jface.text.reconciler.DirtyRegion;
28: import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
29: import org.overture.ide.core.VdmCore;
30:
31: import org.overture.ide.core.parser.ISourceParser;
32: import org.overture.ide.core.parser.SourceParserManager;
33: import org.overture.ide.core.resources.IVdmProject;
34:
35: public class VdmReconcilingStrategy implements IReconcilingStrategy
36: {
37:         private VdmDocument currentDocument;
38:         ISourceParser parser;
39:         IVdmProject vdmProject;
40:
41:         public void reconcile(IRegion partition)
42:         {
43:•                if (currentDocument.getSourceUnit() == null)
44:                 {
45:                         return;// No reconcile if the source unit had been removed from the project (build path change)
46:•                } else if (parser != null && !vdmProject.getModel().hasWorkingCopies())
47:                 {
48:                         parser.parse(currentDocument.getSourceUnit(), currentDocument.get(),false /*only process with and display errors*/);
49:
50:                         // Setting type checked to false after some alteration
51:                         vdmProject.getModel().setIsTypeChecked(false);
52:                 }
53:         }
54:
55:         public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion)
56:         {
57:
58:         }
59:
60:         public void setDocument(IDocument document)
61:         {
62:                 if (document instanceof VdmDocument)
63:                 {
64:                         currentDocument = (VdmDocument) document;
65:                         vdmProject = currentDocument.getProject();//.getAdapter(IVdmProject.class);
66:                         if (currentDocument.getSourceUnit() != null && vdmProject != null)
67:                         {
68:
69:                                 try
70:                                 {
71:                                         parser = SourceParserManager.getInstance().getSourceParser(vdmProject);
72:                                 } catch (CoreException e)
73:                                 {
74:                                         if (VdmCore.DEBUG)
75:                                                 e.printStackTrace();
76:                                 }
77:
78:                         }
79:                 }
80:         }
81:
82: }