Coverage Report - org.owasp.dependencycheck.org.apache.tools.ant.Location
 
Classes in this File Line Coverage Branch Coverage Complexity
Location
0%
0/34
0%
0/14
2
 
 1  
 /*
 2  
  *  Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  *  contributor license agreements.  See the NOTICE file distributed with
 4  
  *  this work for additional information regarding copyright ownership.
 5  
  *  The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  *  (the "License"); you may not use this file except in compliance with
 7  
  *  the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  *  Unless required by applicable law or agreed to in writing, software
 12  
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  *  See the License for the specific language governing permissions and
 15  
  *  limitations under the License.
 16  
  *
 17  
  */
 18  
 
 19  
 package org.owasp.dependencycheck.org.apache.tools.ant;
 20  
 
 21  
 import java.io.Serializable;
 22  
 import org.owasp.dependencycheck.org.apache.tools.ant.util.FileUtils;
 23  
 import org.xml.sax.Locator;
 24  
 
 25  
 /**
 26  
  * Stores the location of a piece of text within a file (file name,
 27  
  * line number and column number). Note that the column number is
 28  
  * currently ignored.
 29  
  *
 30  
  */
 31  
 public class Location implements Serializable {
 32  
     private static final long serialVersionUID = 1L;
 33  
 
 34  
     /** Name of the file. */
 35  
     private final String fileName;
 36  
     /** Line number within the file. */
 37  
     private final int lineNumber;
 38  
     /** Column number within the file. */
 39  
     private final int columnNumber;
 40  
 
 41  
     /** Location to use when one is needed but no information is available */
 42  0
     public static final Location UNKNOWN_LOCATION = new Location();
 43  
 
 44  0
     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
 45  
 
 46  
     /**
 47  
      * Creates an "unknown" location.
 48  
      */
 49  
     private Location() {
 50  0
         this(null, 0, 0);
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Creates a location consisting of a file name but no line number or
 55  
      * column number.
 56  
      *
 57  
      * @param fileName The name of the file. May be <code>null</code>,
 58  
      *                 in which case the location is equivalent to
 59  
      *                 {@link #UNKNOWN_LOCATION UNKNOWN_LOCATION}.
 60  
      */
 61  
     public Location(String fileName) {
 62  0
         this(fileName, 0, 0);
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Creates a location from the SAX locator using the system ID as
 67  
      * the filename.
 68  
      *
 69  
      * @param loc Must not be <code>null</code>.
 70  
      *
 71  
      * @since Ant 1.6
 72  
      */
 73  
     public Location(Locator loc) {
 74  0
         this(loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber());
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Creates a location consisting of a file name, line number and
 79  
      * column number.
 80  
      *
 81  
      * @param fileName The name of the file. May be <code>null</code>,
 82  
      *                 in which case the location is equivalent to
 83  
      *                 {@link #UNKNOWN_LOCATION UNKNOWN_LOCATION}.
 84  
      *
 85  
      * @param lineNumber Line number within the file. Use 0 for unknown
 86  
      *                   positions within a file.
 87  
      * @param columnNumber Column number within the line.
 88  
      */
 89  0
     public Location(String fileName, int lineNumber, int columnNumber) {
 90  0
         if (fileName != null && fileName.startsWith("file:")) {
 91  0
             this.fileName = FILE_UTILS.fromURI(fileName);
 92  
         } else {
 93  0
             this.fileName = fileName;
 94  
         }
 95  0
         this.lineNumber = lineNumber;
 96  0
         this.columnNumber = columnNumber;
 97  0
     }
 98  
 
 99  
     /**
 100  
      * @return the filename portion of the location
 101  
      * @since Ant 1.6
 102  
      */
 103  
     public String getFileName() {
 104  0
         return fileName;
 105  
     }
 106  
 
 107  
     /**
 108  
      * @return the line number
 109  
      * @since Ant 1.6
 110  
      */
 111  
     public int getLineNumber() {
 112  0
         return lineNumber;
 113  
     }
 114  
 
 115  
     /**
 116  
      * @return the column number
 117  
      * @since Ant 1.7
 118  
      */
 119  
     public int getColumnNumber() {
 120  0
         return columnNumber;
 121  
     }
 122  
 
 123  
     /**
 124  
      * Returns the file name, line number, a colon and a trailing space.
 125  
      * An error message can be appended easily. For unknown locations, an
 126  
      * empty string is returned.
 127  
      *
 128  
      * @return a String of the form <code>"fileName:lineNumber: "</code>
 129  
      *         if both file name and line number are known,
 130  
      *         <code>"fileName: "</code> if only the file name is known,
 131  
      *         and the empty string for unknown locations.
 132  
      */
 133  
     public String toString() {
 134  0
         StringBuffer buf = new StringBuffer();
 135  
 
 136  0
         if (fileName != null) {
 137  0
             buf.append(fileName);
 138  
 
 139  0
             if (lineNumber != 0) {
 140  0
                 buf.append(":");
 141  0
                 buf.append(lineNumber);
 142  
             }
 143  
 
 144  0
             buf.append(": ");
 145  
         }
 146  
 
 147  0
         return buf.toString();
 148  
     }
 149  
 
 150  
     /**
 151  
      * Equality operation.
 152  
      * @param other the object to compare to.
 153  
      * @return true if the other object contains the same information
 154  
      *              as this object.
 155  
      * @since Ant 1.6.3
 156  
      */
 157  
     public boolean equals(Object other) {
 158  0
         if (this == other) {
 159  0
             return true;
 160  
         }
 161  0
         if (other == null) {
 162  0
             return false;
 163  
         }
 164  0
         if (!(other.getClass() == getClass())) {
 165  0
             return false;
 166  
         }
 167  0
         return toString().equals(other.toString());
 168  
     }
 169  
 
 170  
     /**
 171  
      * Hash operation.
 172  
      * @return a hash code value for this location.
 173  
      * @since Ant 1.6.3
 174  
      */
 175  
     public int hashCode() {
 176  0
         return toString().hashCode();
 177  
     }
 178  
 }