Bug 560416 - New API: IBuffer.getAnnotationModel()
diff --git a/org.eclipse.handly.ui/src/org/eclipse/handly/ui/texteditor/TextEditorBuffer.java b/org.eclipse.handly.ui/src/org/eclipse/handly/ui/texteditor/TextEditorBuffer.java
index 1147fb5..40c0da0 100644
--- a/org.eclipse.handly.ui/src/org/eclipse/handly/ui/texteditor/TextEditorBuffer.java
+++ b/org.eclipse.handly.ui/src/org/eclipse/handly/ui/texteditor/TextEditorBuffer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2018 1C-Soft LLC and others.
+ * Copyright (c) 2014, 2020 1C-Soft LLC and others.
  *
  * This program and the accompanying materials are made available under
  * the terms of the Eclipse Public License 2.0 which is available at
@@ -26,6 +26,7 @@
 import org.eclipse.handly.util.UiSynchronizer;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.text.edits.MalformedTreeException;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -52,6 +53,7 @@
     private final IEditorInput editorInput;
     private final IDocumentProvider documentProvider;
     private IDocument document;
+    private IAnnotationModel annotationModel;
     private int refCount = 1;
 
     /**
@@ -84,6 +86,7 @@
         {
             if ((document = documentProvider.getDocument(editorInput)) == null)
                 throw new AssertionError();
+            annotationModel = documentProvider.getAnnotationModel(editorInput);
             f = true;
         }
         finally
@@ -105,6 +108,12 @@
     }
 
     @Override
+    public IAnnotationModel getAnnotationModel()
+    {
+        return annotationModel;
+    }
+
+    @Override
     public ISnapshot getSnapshot()
     {
         return new DocumentSnapshot(getDocument());
@@ -162,6 +171,7 @@
         if (--refCount == 0 && document != null)
         {
             document = null;
+            annotationModel = null;
             uiSynchronizer.asyncExec(new Runnable()
             {
                 public void run()
diff --git a/org.eclipse.handly/.settings/.api_filters b/org.eclipse.handly/.settings/.api_filters
index d5ad073..996e7dd 100644
--- a/org.eclipse.handly/.settings/.api_filters
+++ b/org.eclipse.handly/.settings/.api_filters
@@ -25,6 +25,14 @@
             </message_arguments>
         </filter>
     </resource>
+    <resource path="src/org/eclipse/handly/buffer/IBuffer.java" type="org.eclipse.handly.buffer.IBuffer">
+        <filter id="404000815">
+            <message_arguments>
+                <message_argument value="org.eclipse.handly.buffer.IBuffer"/>
+                <message_argument value="getAnnotationModel()"/>
+            </message_arguments>
+        </filter>
+    </resource>
     <resource path="src/org/eclipse/handly/model/impl/ISourceFileImpl.java" type="org.eclipse.handly.model.impl.ISourceFileImpl">
         <filter id="404000815">
             <message_arguments>
diff --git a/org.eclipse.handly/src/org/eclipse/handly/buffer/IBuffer.java b/org.eclipse.handly/src/org/eclipse/handly/buffer/IBuffer.java
index edf925c..b64f3fd 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/buffer/IBuffer.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/buffer/IBuffer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2018 1C-Soft LLC and others.
+ * Copyright (c) 2014, 2020 1C-Soft LLC and others.
  *
  * This program and the accompanying materials are made available under
  * the terms of the Eclipse Public License 2.0 which is available at
@@ -21,6 +21,7 @@
 import org.eclipse.handly.snapshot.StaleSnapshotException;
 import org.eclipse.handly.util.IReferenceCountable;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
 
 /**
  * Represents a potentially shared buffer that contains text contents of a
@@ -114,6 +115,20 @@
      */
     IDocument getDocument();
 
+    /**
+     * Returns the annotation model of this buffer, if any.
+     * <p>
+     * The default method implementation always returns <code>null</code>.
+     * </p>
+     *
+     * @return the buffer's annotation model, or <code>null</code> if none
+     * @since 1.3
+     */
+    default IAnnotationModel getAnnotationModel()
+    {
+        return null;
+    }
+
     @Override
     void addRef();
 
diff --git a/org.eclipse.handly/src/org/eclipse/handly/buffer/TextFileBuffer.java b/org.eclipse.handly/src/org/eclipse/handly/buffer/TextFileBuffer.java
index ad895f1..6c3429a 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/buffer/TextFileBuffer.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/buffer/TextFileBuffer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2019 1C-Soft LLC and others.
+ * Copyright (c) 2014, 2020 1C-Soft LLC and others.
  *
  * This program and the accompanying materials are made available under
  * the terms of the Eclipse Public License 2.0 which is available at
@@ -29,6 +29,7 @@
 import org.eclipse.handly.util.UiSynchronizer;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.text.edits.MalformedTreeException;
 
 /**
@@ -169,6 +170,12 @@
     }
 
     @Override
+    public IAnnotationModel getAnnotationModel()
+    {
+        return getCoreTextFileBufferProvider().getBuffer().getAnnotationModel();
+    }
+
+    @Override
     public ISnapshot getSnapshot()
     {
         ICoreTextFileBufferProvider provider = getCoreTextFileBufferProvider();