Search in sources :

Example 1 with MarkupModelWindow

use of com.intellij.injected.editor.MarkupModelWindow in project intellij-community by JetBrains.

the class DocumentMarkupModel method forDocument.

/**
   * Returns the markup model for the specified project. A document can have multiple markup
   * models for different projects if the file to which it corresponds belongs to multiple projects
   * opened in different IDEA frames at the same time.
   *
   * @param document the document for which the markup model is requested.
   * @param project the project for which the markup model is requested, or null if the default markup
   *                model is requested.
   * @return the markup model instance.
   * @see com.intellij.openapi.editor.Editor#getMarkupModel()
   */
public static MarkupModel forDocument(@NotNull Document document, @Nullable Project project, boolean create) {
    if (document instanceof DocumentWindow) {
        final Document delegate = ((DocumentWindow) document).getDelegate();
        final MarkupModelEx baseMarkupModel = (MarkupModelEx) forDocument(delegate, project, true);
        return new MarkupModelWindow(baseMarkupModel, (DocumentWindow) document);
    }
    if (project == null) {
        MarkupModelEx markupModel = document.getUserData(MARKUP_MODEL_KEY);
        if (create && markupModel == null) {
            MarkupModelEx newModel = new MarkupModelImpl((DocumentEx) document);
            if ((markupModel = ((UserDataHolderEx) document).putUserDataIfAbsent(MARKUP_MODEL_KEY, newModel)) != newModel) {
                newModel.dispose();
            }
        }
        return markupModel;
    }
    final DocumentMarkupModelManager documentMarkupModelManager = project.isDisposed() ? null : DocumentMarkupModelManager.getInstance(project);
    if (documentMarkupModelManager == null || documentMarkupModelManager.isDisposed() || project.isDisposed()) {
        return new EmptyMarkupModel(document);
    }
    ConcurrentMap<Project, MarkupModelImpl> markupModelMap = getMarkupModelMap(document);
    MarkupModelImpl model = markupModelMap.get(project);
    if (create && model == null) {
        MarkupModelImpl newModel = new MarkupModelImpl((DocumentEx) document);
        if ((model = ConcurrencyUtil.cacheOrGet(markupModelMap, project, newModel)) == newModel) {
            documentMarkupModelManager.registerDocument(document);
        } else {
            newModel.dispose();
        }
    }
    return model;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) Project(com.intellij.openapi.project.Project) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) MarkupModelWindow(com.intellij.injected.editor.MarkupModelWindow) Document(com.intellij.openapi.editor.Document)

Aggregations

DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 MarkupModelWindow (com.intellij.injected.editor.MarkupModelWindow)1 Document (com.intellij.openapi.editor.Document)1 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)1 Project (com.intellij.openapi.project.Project)1