| /*=============================================================================# |
| # Copyright (c) 2009, 2019 Stephan Wahlbrink 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 |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.r.console.ui.page; |
| |
| import java.lang.reflect.InvocationTargetException; |
| import java.util.List; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| |
| import org.eclipse.statet.ecommons.text.core.sections.DocContentSections; |
| import org.eclipse.statet.ecommons.text.core.util.AbstractFragmentDocument; |
| import org.eclipse.statet.ecommons.text.core.util.TextUtils; |
| |
| import org.eclipse.statet.ltk.ast.core.AstInfo; |
| import org.eclipse.statet.ltk.core.SourceContent; |
| import org.eclipse.statet.ltk.model.core.SourceDocumentRunnable; |
| import org.eclipse.statet.ltk.model.core.elements.IModelElement; |
| import org.eclipse.statet.ltk.model.core.elements.ISourceUnitModelInfo; |
| import org.eclipse.statet.nico.ui.console.GenericConsoleSourceUnit; |
| import org.eclipse.statet.r.console.ui.RConsole; |
| import org.eclipse.statet.r.core.IRCoreAccess; |
| import org.eclipse.statet.r.core.model.IRSourceUnit; |
| import org.eclipse.statet.r.core.model.RModel; |
| import org.eclipse.statet.r.core.model.RSuModelContainer; |
| import org.eclipse.statet.r.core.source.RDocumentContentInfo; |
| |
| |
| public class RConsoleSourceUnit extends GenericConsoleSourceUnit implements IRSourceUnit { |
| |
| |
| private final RConsole rConsole; |
| |
| private final RSuModelContainer model = new RSuModelContainer(this) { |
| |
| @Override |
| public SourceContent getParseContent(final IProgressMonitor monitor) { |
| final AbstractFragmentDocument doc= getDocument(); |
| synchronized (TextUtils.getLockObject(doc)) { |
| return new SourceContent(doc.getModificationStamp(), |
| doc.getMasterDocument().get(), |
| -doc.getOffsetInMasterDocument() ); |
| } |
| } |
| |
| }; |
| |
| |
| public RConsoleSourceUnit(final RConsolePage page, final AbstractFragmentDocument document) { |
| super(page.toString(), document); |
| this.rConsole = page.getConsole(); |
| } |
| |
| |
| @Override |
| public String getModelTypeId() { |
| return RModel.R_TYPE_ID; |
| } |
| |
| @Override |
| public DocContentSections getDocumentContentInfo() { |
| return RDocumentContentInfo.INSTANCE; |
| } |
| |
| |
| @Override |
| public AstInfo getAstInfo(final String type, final boolean ensureSync, |
| final IProgressMonitor monitor) { |
| if (type == null || this.model.isContainerFor(type)) { |
| return this.model.getAstInfo(ensureSync, monitor); |
| } |
| return null; |
| } |
| |
| @Override |
| public ISourceUnitModelInfo getModelInfo(final String type, final int flags, |
| final IProgressMonitor monitor) { |
| if (type == null || this.model.isContainerFor(type)) { |
| return this.model.getModelInfo(flags, monitor); |
| } |
| return null; |
| } |
| |
| @Override |
| public void syncExec(final SourceDocumentRunnable runnable) throws InvocationTargetException { |
| throw new UnsupportedOperationException(); |
| } |
| |
| @Override |
| public IRCoreAccess getRCoreAccess() { |
| return this.rConsole; |
| } |
| |
| @Override |
| public boolean hasModelChildren(final Filter filter) { |
| return false; |
| } |
| |
| @Override |
| public List<? extends IModelElement> getModelChildren(final Filter filter) { |
| return null; |
| } |
| |
| } |