1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.processor.compat; 18 19 import java.util.Objects; 20 21 /** POJO to represent source position of a tree in Java source file. */ 22 public final class SourcePosition { 23 24 private final String filename; 25 private final long startLineNumber; 26 private final long startColumnNumber; 27 private final long endLineNumber; 28 private final long endColumnNumber; 29 SourcePosition(String filename, long startLineNumber, long startColumnNumber, long endLineNumber, long endColumnNumber)30 public SourcePosition(String filename, long startLineNumber, long startColumnNumber, 31 long endLineNumber, long endColumnNumber) { 32 this.filename = filename; 33 this.startLineNumber = startLineNumber; 34 this.startColumnNumber = startColumnNumber; 35 this.endLineNumber = endLineNumber; 36 this.endColumnNumber = endColumnNumber; 37 } 38 getFilename()39 public String getFilename() { 40 return filename; 41 } 42 getStartLineNumber()43 public long getStartLineNumber() { 44 return startLineNumber; 45 } 46 getStartColumnNumber()47 public long getStartColumnNumber() { 48 return startColumnNumber; 49 } 50 getEndLineNumber()51 public long getEndLineNumber() { 52 return endLineNumber; 53 } 54 getEndColumnNumber()55 public long getEndColumnNumber() { 56 return endColumnNumber; 57 } 58 59 @Override equals(Object o)60 public boolean equals(Object o) { 61 if (this == o) return true; 62 if (o == null || getClass() != o.getClass()) return false; 63 SourcePosition that = (SourcePosition) o; 64 return startLineNumber == that.startLineNumber 65 && startColumnNumber == that.startColumnNumber 66 && endLineNumber == that.endLineNumber 67 && endColumnNumber == that.endColumnNumber 68 && Objects.equals(filename, that.filename); 69 } 70 71 @Override hashCode()72 public int hashCode() { 73 return Objects.hash( 74 filename, 75 startLineNumber, 76 startColumnNumber, 77 endLineNumber, 78 endColumnNumber); 79 } 80 } 81