blob: 0f6478c2df011d80cfb02ac15a66da82f617580f [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.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
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.
*/
@NonNullByDefault
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 @Nullable TextLineInformation lines;
public SourceContent(final long stamp, final String text) {
this(stamp, text, 0);
}
public SourceContent(final long stamp, final String text, final int startOffset) {
super(startOffset, startOffset + text.length());
this.stamp= stamp;
this.text= text;
this.lines= null;
}
public SourceContent(final long stamp, final String text,
final int startOffset,
final TextLineInformation lines) {
super(startOffset, startOffset + text.length());
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() {
TextLineInformation lines= this.lines;
if (lines == null) {
synchronized (LINES_CREATOR) {
lines= this.lines;
if (lines == null) {
lines= LINES_CREATOR.create(this.text);
}
}
}
return lines;
}
@Override
public String toString() {
return getText();
}
}