|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SourcePosition.java | - | 61,5% | 71,4% | 65% |
|
||||||||||||||
| 1 | /* $Id: SourcePosition.java,v 1.7 2006/10/20 20:23:06 m31 Exp $ | |
| 2 | * | |
| 3 | * This file is part of the project "Hilbert II" - http://www.qedeq.org | |
| 4 | * | |
| 5 | * Copyright 2000-2006, Michael Meyling <mime@qedeq.org>. | |
| 6 | * | |
| 7 | * "Hilbert II" is free software; you can redistribute | |
| 8 | * it and/or modify it under the terms of the GNU General Public | |
| 9 | * License as published by the Free Software Foundation; either | |
| 10 | * version 2 of the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | */ | |
| 17 | ||
| 18 | package org.qedeq.kernel.xml.parser; | |
| 19 | ||
| 20 | import java.io.Serializable; | |
| 21 | import java.net.URL; | |
| 22 | ||
| 23 | ||
| 24 | /** | |
| 25 | * Describes a file position. | |
| 26 | * | |
| 27 | * @version $Revision: 1.7 $ | |
| 28 | * @author Michael Meyling | |
| 29 | */ | |
| 30 | public final class SourcePosition implements Serializable { | |
| 31 | ||
| 32 | /** Address of input, for identifying source. */ | |
| 33 | private final URL address; | |
| 34 | ||
| 35 | /** Local address of input, for loading source. */ | |
| 36 | private final URL localAddress; | |
| 37 | ||
| 38 | /** Line number, starting with 1. */ | |
| 39 | private int line; | |
| 40 | ||
| 41 | /** Column number, starting with 1. */ | |
| 42 | private int column; | |
| 43 | ||
| 44 | /** | |
| 45 | * Constructs source position object. | |
| 46 | * | |
| 47 | * @param localAddress source address | |
| 48 | * @param line Line number. | |
| 49 | * @param column Column number. | |
| 50 | */ | |
| 51 | 6615 | public SourcePosition(final URL localAddress, final int line, final int column) { |
| 52 | 6615 | this.address = localAddress; |
| 53 | 6615 | this.localAddress = localAddress; |
| 54 | 6615 | this.line = line; |
| 55 | 6615 | this.column = column; |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Constructs file position object. | |
| 60 | * | |
| 61 | * @param address for identifying source | |
| 62 | * @param localAddress source address | |
| 63 | * @param line Line number. | |
| 64 | * @param column Column number. | |
| 65 | */ | |
| 66 | 0 | public SourcePosition(final URL address, final URL localAddress, |
| 67 | final int line, final int column) { | |
| 68 | 0 | this.address = address; |
| 69 | 0 | this.localAddress = localAddress; |
| 70 | 0 | this.line = line; |
| 71 | 0 | this.column = column; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * Get address (or something to identify it) of input source. | |
| 76 | * | |
| 77 | * @return address of input source | |
| 78 | */ | |
| 79 | 16 | public final URL getAddress() { |
| 80 | 16 | return this.address; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Get local address (or something to identify it) of input source. | |
| 85 | * | |
| 86 | * @return local address of input source | |
| 87 | */ | |
| 88 | 0 | public final URL getLocalAddress() { |
| 89 | 0 | return this.localAddress; |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Get line number, starting with 1. | |
| 94 | * | |
| 95 | * @return Line number. | |
| 96 | */ | |
| 97 | 33 | public final int getLine() { |
| 98 | 33 | return line; |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Get column number, starting with 1. | |
| 103 | * | |
| 104 | * @return column number | |
| 105 | */ | |
| 106 | 33 | public final int getColumn() { |
| 107 | 33 | return column; |
| 108 | } | |
| 109 | ||
| 110 | // TODO mime 20050608: remove if no use | |
| 111 | /* | |
| 112 | public final int findCaretPosition(final int line, final int column, final String source) { | |
| 113 | if (line == 1) { | |
| 114 | return 0; | |
| 115 | } | |
| 116 | int k = 1; | |
| 117 | for (int j = 0; j < source.length(); j++) { | |
| 118 | if (source.charAt(j) == '\n') { | |
| 119 | k++; | |
| 120 | } | |
| 121 | if (k == line) { | |
| 122 | j += column - 1; | |
| 123 | if (j > source.length()) { | |
| 124 | j = source.length(); | |
| 125 | } | |
| 126 | return j; | |
| 127 | } | |
| 128 | } | |
| 129 | return 0; | |
| 130 | } | |
| 131 | */ | |
| 132 | ||
| 133 | 16 | public final String toString() { |
| 134 | 16 | return getAddress() + ":" + getLine() + ":" + getColumn(); |
| 135 | } | |
| 136 | ||
| 137 | } |
|
||||||||||