FileDocCategorySizeDatePackage
Location.javaAPI DocApache Ant 1.705237Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant

Location

public class Location extends Object implements Serializable
Stores the location of a piece of text within a file (file name, line number and column number). Note that the column number is currently ignored.

Fields Summary
private String
fileName
Name of the file.
private int
lineNumber
Line number within the file.
private int
columnNumber
Column number within the file.
public static final Location
UNKNOWN_LOCATION
Location to use when one is needed but no information is available
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Constructors Summary
private Location()
Creates an "unknown" location.


             
      
        this(null, 0, 0);
    
public Location(String fileName)
Creates a location consisting of a file name but no line number or column number.

param
fileName The name of the file. May be null, in which case the location is equivalent to {@link #UNKNOWN_LOCATION UNKNOWN_LOCATION}.

        this(fileName, 0, 0);
    
public Location(Locator loc)
Creates a location from the SAX locator using the system ID as the filename.

param
loc Must not be null.
since
Ant 1.6

        this(loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber());
    
public Location(String fileName, int lineNumber, int columnNumber)
Creates a location consisting of a file name, line number and column number.

param
fileName The name of the file. May be null, in which case the location is equivalent to {@link #UNKNOWN_LOCATION UNKNOWN_LOCATION}.
param
lineNumber Line number within the file. Use 0 for unknown positions within a file.
param
columnNumber Column number within the line.

        if (fileName != null && fileName.startsWith("file:")) {
            this.fileName = FILE_UTILS.fromURI(fileName);
        } else {
            this.fileName = fileName;
        }
        this.lineNumber = lineNumber;
        this.columnNumber = columnNumber;
    
Methods Summary
public booleanequals(java.lang.Object other)
Equality operation.

param
other the object to compare to.
return
true if the other object contains the same information as this object.
since
Ant 1.6.3

        if (this == other) {
            return true;
        }
        if (other == null) {
            return false;
        }
        if (!(other.getClass() == getClass())) {
            return false;
        }
        return toString().equals(other.toString());
    
public intgetColumnNumber()

return
the column number
since
Ant 1.7

        return columnNumber;
    
public java.lang.StringgetFileName()

return
the filename portion of the location
since
Ant 1.6

        return fileName;
    
public intgetLineNumber()

return
the line number
since
Ant 1.6

        return lineNumber;
    
public inthashCode()
Hash operation.

return
a hash code value for this location.
since
Ant 1.6.3

        return toString().hashCode();
    
public java.lang.StringtoString()
Returns the file name, line number, a colon and a trailing space. An error message can be appended easily. For unknown locations, an empty string is returned.

return
a String of the form "fileName:lineNumber: " if both file name and line number are known, "fileName: " if only the file name is known, and the empty string for unknown locations.

        StringBuffer buf = new StringBuffer();

        if (fileName != null) {
            buf.append(fileName);

            if (lineNumber != 0) {
                buf.append(":");
                buf.append(lineNumber);
            }

            buf.append(": ");
        }

        return buf.toString();