1 30 package org.jruby.lexer.yacc; 31 32 import java.io.Serializable ; 33 34 43 public class SourcePosition implements ISourcePosition, Serializable { 44 private static final long serialVersionUID = 3762529027281400377L; 45 46 private final String file; 48 49 private final int startLine; 51 private final int endLine; 52 53 private int startOffset; 55 private final int endOffset; 56 57 60 public SourcePosition() { 61 this("", 0); 62 } 63 64 70 public SourcePosition(String file, int endLine) { 71 if (file == null) { throw new NullPointerException (); 73 } 74 this.file = file; 75 this.startLine = 0; 76 this.endLine = endLine; 77 this.startOffset = 0; 78 this.endOffset = 0; 79 } 80 81 87 public SourcePosition(String file, int startLine, int endLine, int startOffset, int endOffset) { 88 if (file == null) { throw new NullPointerException (); 90 } 91 this.file = file; 92 this.startLine = startLine; 93 this.endLine = endLine; 94 this.startOffset = startOffset; 95 this.endOffset = endOffset; 96 } 97 98 101 public String getFile() { 102 return file; 103 } 104 105 110 public int getStartLine() { 111 return startLine; 112 } 113 114 117 public int getEndLine() { 118 return endLine; 119 } 120 121 125 public boolean equals(Object object) { 126 if (object == this) { 127 return true; 128 } 129 if (!(object instanceof SourcePosition)) { 130 return false; 131 } 132 133 SourcePosition other = (SourcePosition) object; 134 135 return file.equals(other.file) && endLine == other.endLine; 136 } 137 138 143 public int hashCode() { 144 return file.hashCode() ^ endLine; 145 } 146 147 150 public String toString() { 151 return file + ":[" + startLine + "," + endLine + "]:[" + 152 getStartOffset() + "," + getEndOffset() + "]"; 153 } 154 155 158 public void adjustStartOffset(int relativeValue) { 159 startOffset += relativeValue; 160 if(startOffset < 0) startOffset = 0; 161 } 162 163 168 public int getStartOffset() { 169 return startOffset; 170 } 171 172 177 public int getEndOffset() { 178 return endOffset; 179 } 180 181 184 public ISourcePosition union(ISourcePosition other) { 185 return new SourcePosition(file, startLine, other.getEndLine(), startOffset, other.getEndOffset()); 188 } 189 } 190 | Popular Tags |