blob: db94d9adf8b720b586a7d80c5d5322e3daf1d3cc [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 2020 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.ltk.core;
import org.eclipse.statet.jcommons.text.core.BasicTextRegion;
import org.eclipse.statet.jcommons.text.core.TextLineInformation;
import org.eclipse.statet.jcommons.text.core.TextRegion;
import org.eclipse.statet.jcommons.text.core.util.TextLineInformationCreator;
/**
* Source code with time stamp.
*/
public class SourceContent extends BasicTextRegion implements TextRegion {
private static final TextLineInformationCreator LINES_CREATOR= new TextLineInformationCreator();
private final long stamp;
private final String text;
private volatile TextLineInformation lines;
public SourceContent(final long stamp, final String text) {
this(stamp, text, 0, null);
}
public SourceContent(final long stamp, final String text, final int startOffset) {
this(stamp, text, startOffset, null);
}
public SourceContent(final long stamp, final String text,
final int startOffset,
final TextLineInformation lines) {
super(startOffset, startOffset + text.length());
if (text == null) {
throw new NullPointerException("text"); //$NON-NLS-1$
}
this.stamp= stamp;
this.text= text;
this.lines= lines;
}
public final long getStamp() {
return this.stamp;
}
public final String getText() {
return this.text;
}
// /**
// * Returns offset of start of the {@link #getText() text} in complete source.
// *
// * @return begin offset
// */
// public final int getStartOffset()
// /**
// * Returns offset of end of the {@link #getText() text} in complete source.
// *
// * @return end offset (exclusive)
// */
// public final int getEndOffset() {
public final TextLineInformation getLines() {
if (this.lines == null) {
synchronized (LINES_CREATOR) {
if (this.lines == null) {
this.lines= LINES_CREATOR.create(this.text);
}
}
}
return this.lines;
}
@Override
public String toString() {
return getText();
}
}