blob: b90071fdb653057fc011f19a7cc415abf53bd9b6 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 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.core.sourcemodel;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.statet.ecommons.text.core.sections.DocContentSections;
import org.eclipse.statet.ltk.ast.core.AstInfo;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnitModelInfo;
import org.eclipse.statet.r.core.RResourceUnit;
import org.eclipse.statet.r.core.model.IRSourceUnit;
import org.eclipse.statet.r.core.model.IRWorkspaceSourceUnit;
import org.eclipse.statet.r.core.model.RModel;
import org.eclipse.statet.r.core.model.RSuModelContainer;
import org.eclipse.statet.r.core.source.RDocumentContentInfo;
/**
* Source unit implementation for R script files in workspace ("default R file").
*/
public final class RSourceUnit extends RResourceUnit implements IRWorkspaceSourceUnit {
private final RSuModelContainer model= new RSuModelContainer(this);
public RSourceUnit(final String id, final IFile file) {
super(id, file);
}
@Override
public String getModelTypeId() {
return RModel.R_TYPE_ID;
}
@Override
public DocContentSections getDocumentContentInfo() {
return RDocumentContentInfo.INSTANCE;
}
@Override
public int getElementType() {
return IRSourceUnit.R_WORKSPACE_SU;
}
@Override
protected void unregister() {
super.unregister();
this.model.clear();
}
@Override
public AstInfo getAstInfo(final String type, final boolean ensureSync, final IProgressMonitor monitor) {
final AstInfo ast= this.model.getCurrentAst();
final long stamp= getResource().getModificationStamp();
if (ast != null && ast.getStamp().getSourceStamp() == stamp) {
return ast;
}
// TODO ask saved
return null;
}
@Override
public ISourceUnitModelInfo getModelInfo(final String type, final int syncLevel, final IProgressMonitor monitor) {
if (type == null || type.equals(RModel.R_TYPE_ID)) {
return this.model.getModelInfo(syncLevel, monitor);
}
return null;
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(final Class<T> adapterType) {
if (adapterType == RSuModelContainer.class) {
return (T) this.model;
}
return super.getAdapter(adapterType);
}
}