001/*-------------------------------------------------------------------------+ 002| | 003| Copyright (c) 2009-2019 CQSE GmbH | 004| | 005+-------------------------------------------------------------------------*/ 006package eu.cqse.check; 007 008import java.io.Serializable; 009import java.util.Objects; 010 011import eu.cqse.check.framework.core.phase.ECodeViewOption.ETextViewOption; 012 013/** 014 * Partial clone (only core components) of TextRegionLocation from 015 * com.teamscale.commons, since that bundle is not accessible from the custom 016 * checks. 017 * 018 * All offsets/line numbers are based on 019 * {@link ETextViewOption#UNFILTERED_CONTENT}. 020 */ 021public class CheckTextRegionLocation implements Serializable { 022 private static final long serialVersionUID = 1L; 023 024 /** The uniform path of this location. */ 025 public final String uniformPath; 026 /** 027 * The absolute start position of the region in the (raw) text (zero based, 028 * inclusive). 029 */ 030 public final int rawStartOffset; 031 032 /** 033 * The absolute end position in the (raw) text (zero based, inclusive). 034 */ 035 public final int rawEndOffset; 036 037 /** 038 * The line corresponding to {@link #rawStartOffset} (one-based, inclusive). 039 */ 040 public final int rawStartLine; 041 042 /** 043 * The line corresponding to {@link #rawEndOffset} (one-based, inclusive). 044 */ 045 public final int rawEndLine; 046 047 /** Constructor. */ 048 public CheckTextRegionLocation(String uniformPath, int rawStartOffset, int rawEndOffset, int rawStartLine, 049 int rawEndLine) { 050 this.uniformPath = uniformPath; 051 this.rawStartOffset = rawStartOffset; 052 this.rawEndOffset = rawEndOffset; 053 this.rawStartLine = rawStartLine; 054 this.rawEndLine = rawEndLine; 055 } 056 057 /** {@inheritDoc} */ 058 @Override 059 public String toString() { 060 return uniformPath + " tokens " + rawStartOffset + "--" + rawEndOffset + " lines " + rawStartLine + "--" 061 + rawEndLine; 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public int hashCode() { 067 return Objects.hash(uniformPath, rawStartOffset, rawEndOffset, rawStartLine, rawEndLine); 068 } 069 070 /** {@inheritDoc} */ 071 @Override 072 public boolean equals(Object obj) { 073 if (this == obj) { 074 return true; 075 } 076 if (obj == null) { 077 return false; 078 } 079 if (getClass() != obj.getClass()) { 080 return false; 081 } 082 CheckTextRegionLocation other = (CheckTextRegionLocation) obj; 083 return Objects.equals(uniformPath, other.uniformPath) && rawStartOffset == other.rawStartOffset 084 && rawEndOffset == other.rawEndOffset && rawStartLine == other.rawStartLine 085 && rawEndLine == other.rawEndLine; 086 } 087 088}