All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.conqat.engine.commons.findings.location.TextRegionLocationUtils Maven / Gradle / Ivy

There is a newer version: 2025.1.0-rc2
Show newest version
package org.conqat.engine.commons.findings.location;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.conqat.engine.resource.text.filter.util.StringOffsetTransformer;
import org.conqat.lib.commons.string.LineOffsetConverter;

import eu.cqse.check.framework.shallowparser.framework.ShallowEntity;

/**
 * Utility for creating a {@link TextRegionLocation} for a
 * {@link ShallowEntity}.
 */
public class TextRegionLocationUtils {

	/** Creates a {@link TextRegionLocation} for the given shallow entity. */
	public static @NonNull TextRegionLocation createLocationForShallowEntity(String uniformPath,
			ShallowEntity shallowEntity) {
		return new TextRegionLocation(uniformPath, shallowEntity.getStartOffset(), shallowEntity.getEndOffset(),
				shallowEntity.getStartLine(), shallowEntity.getEndLine());
	}

	/**
	 * Creates a new
	 * {@link org.conqat.engine.commons.findings.location.TextRegionLocation} for
	 * the given uniform path and offsets.
	 */
	public static TextRegionLocation createTextRegionLocationForFilteredOffsets(String uniformPath, int startOffset,
			int endOffset, StringOffsetTransformer offsetTransformer, LineOffsetConverter rawLineOffsetConverter) {
		int rawStartOffset = offsetTransformer.getUnfilteredOffset(startOffset);
		int rawEndOffset = offsetTransformer.getUnfilteredOffset(endOffset);
		int rawStartLine = rawLineOffsetConverter.getLine(rawStartOffset);
		int rawEndLine = rawLineOffsetConverter.getLine(rawEndOffset);
		return new TextRegionLocation(uniformPath, rawStartOffset, rawEndOffset, rawStartLine, rawEndLine);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy