blob: 30cd0d75d76fac55cfe4981f1a923737165722f7 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 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.redocs.tex.r.core.source;
import java.util.List;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.statet.jcommons.collections.ImCollections;
import org.eclipse.statet.ecommons.text.core.sections.AbstractDocContentSections;
import org.eclipse.statet.ecommons.text.core.treepartitioner.ITreePartitionNode;
import org.eclipse.statet.docmlet.tex.core.source.TexDocumentConstants;
import org.eclipse.statet.r.core.source.IRDocumentConstants;
import org.eclipse.statet.redocs.r.core.source.DocContentSectionsRweaveExtension;
import org.eclipse.statet.redocs.r.core.source.RweaveDocSectionTreePartImpl;
public class LtxRweaveDocumentContentInfo extends AbstractDocContentSections
implements DocContentSectionsRweaveExtension {
public static final String LTX= TexDocumentConstants.LTX_PARTITIONING;
public static final String R_CHUNK_CONTROL= "org.eclipse.statet.LtxR-ChunkControl"; //$NON-NLS-1$
public static final String R= IRDocumentConstants.R_PARTITIONING;
public static final DocContentSectionsRweaveExtension INSTANCE= new LtxRweaveDocumentContentInfo();
private final RweaveDocSectionTreePartImpl rweaveImpl;
public LtxRweaveDocumentContentInfo() {
super(TexRweaveDocumentConstants.LTX_R_PARTITIONING, LTX,
ImCollections.newList(LTX, R_CHUNK_CONTROL, R) );
this.rweaveImpl= new RweaveDocSectionTreePartImpl(this);
}
@Override
public final String getTypeByPartition(final String contentType) {
if (IRDocumentConstants.R_ANY_CONTENT_CONSTRAINT.matches(contentType)) {
return R;
}
if (TexRweaveDocumentConstants.RCHUNK_PARTITION_CONSTRAINT.matches(contentType)) {
return R_CHUNK_CONTROL;
}
return LTX;
}
@Override
public ITreePartitionNode getRChunkRegion(final IDocument document, final int offset)
throws BadLocationException {
return this.rweaveImpl.getRChunkRegion(document, offset);
}
@Override
public List<ITreePartitionNode> getRChunkRegions(final IDocument document,
final int offset, final int length)
throws BadLocationException {
return this.rweaveImpl.getRChunkCodeRegions(document, offset, length);
}
@Override
public IRegion getRChunkContentRegion(final IDocument document, final int offset)
throws BadLocationException {
return this.rweaveImpl.getRChunkContentRegion(document, offset);
}
@Override
public ITreePartitionNode getRCodeRegion(final IDocument document, final int offset)
throws BadLocationException {
return this.rweaveImpl.getRCodeRegion(document, offset);
}
@Override
public List<ITreePartitionNode> getRChunkCodeRegions(final IDocument document,
final int offset, final int length)
throws BadLocationException {
return this.rweaveImpl.getRChunkCodeRegions(document, offset, length);
}
}