blob: 0a961ca8d6f976b0f545e2c50875892d7f75d28d [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2005, 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.r.core;
import java.net.URI;
import org.eclipse.core.resources.IFile;
import org.eclipse.statet.ecommons.text.core.sections.DocContentSections;
import org.eclipse.statet.ltk.core.ElementName;
import org.eclipse.statet.ltk.model.core.impl.AbstractFilePersistenceSourceUnitFactory;
import org.eclipse.statet.ltk.model.core.impl.GenericResourceSourceUnit;
import org.eclipse.statet.r.core.model.RElementName;
/**
* Generic source unit for R related files.
*/
public abstract class RResourceUnit extends GenericResourceSourceUnit {
public static String createResourceId(final URI uri) {
return AbstractFilePersistenceSourceUnitFactory.createResourceId(uri);
}
@Deprecated
public static RResourceUnit createTempUnit(final IFile file, final String modelTypeId) {
final String id= AbstractFilePersistenceSourceUnitFactory.createResourceId(file);
return new RResourceUnit(id, file) {
@Override
public String getModelTypeId() {
return modelTypeId;
}
@Override
public DocContentSections getDocumentContentInfo() {
return null;
}
};
}
public RResourceUnit(final String id, final IFile file) {
super(id, file);
}
@Override
protected ElementName createElementName() {
return RElementName.create(RElementName.RESOURCE, getResource().getName());
}
public IRCoreAccess getRCoreAccess() {
final RProject rProject= RProjects.getRProject(getResource().getProject());
return (rProject != null) ? rProject : RCore.WORKBENCH_ACCESS;
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(final Class<T> adapterType) {
if (adapterType == IRCoreAccess.class) {
return (T) getRCoreAccess();
}
return super.getAdapter(adapterType);
}
}