001/* 002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 */ 009 010package org.eclipse.golo.compiler.ir; 011 012public final class PositionInSourceCode { 013 014 private final int line; 015 private final int column; 016 017 public PositionInSourceCode(int line, int column) { 018 this.line = line; 019 this.column = column; 020 } 021 022 public int getLine() { 023 return line; 024 } 025 026 public int getColumn() { 027 return column; 028 } 029 030 public boolean isNull() { 031 return line == 0 && column == 0; 032 } 033 034 @Override 035 public String toString() { 036 return String.format("{line=%d, column=%d}", line, column); 037 } 038 039 @Override 040 public boolean equals(Object o) { 041 if (this == o) { return true; } 042 if (o == null || getClass() != o.getClass()) { return false; } 043 044 PositionInSourceCode that = (PositionInSourceCode) o; 045 return column == that.column && line == that.line; 046 } 047 048 @Override 049 public int hashCode() { 050 int result = line; 051 result = 31 * result + column; 052 return result; 053 } 054}