Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/checks/usage/transmogrify/Occurrence.java


1   
2   // Transmogrify License
3   // 
4   // Copyright (c) 2001, ThoughtWorks, Inc.
5   // All rights reserved.
6   // Redistribution and use in source and binary forms, with or without
7   // modification, are permitted provided that the following conditions
8   // are met:
9   // - Redistributions of source code must retain the above copyright notice,
10  //   this list of conditions and the following disclaimer.
11  // - Redistributions in binary form must reproduce the above copyright
12  // notice, this list of conditions and the following disclaimer in the
13  // documentation and/or other materials provided with the distribution.
14  // Neither the name of the ThoughtWorks, Inc. nor the names of its
15  // contributors may be used to endorse or promote products derived from this
16  // software without specific prior written permission.
17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21  // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  
29  package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify;
30  
31  import java.io.File;
32  
33  
34  
35  
36  /**
37   * <code>Occurrence</code> contains file and line number information.
38   * It is used to denote the location of various <code>Definintion</code>s
39   * and <code>Reference</code>s
40   *
41   * @see Reference
42   * @see Definition
43   */
44  
45  public class Occurrence implements Comparable {
46    private File _file;
47    private int _line;
48    private int _column;
49  
50    public Occurrence(File file, int line, int column) {
51      _file = file;
52      _line = line;
53      _column = column;
54    }
55  
56    public Occurrence(SymTabAST node) {
57      _file = node.getFile();
58      _line = node.getLineNo();
59      _column = node.getColumnNo();
60    }
61  
62    /**
63     * returns the File of this <code>Occurrence</code>
64     *
65     * @return File
66     */
67    public File getFile() {
68      return _file;
69    }
70  
71    /**
72     * returns the line number of this <code>Occurrence</code>
73     *
74     * @return the line number of this <code>Occurrence</code>
75     */
76    public int getLine() {
77      return _line;
78    }
79  
80    /**
81     * returns the column that this token starts at
82     *
83     * @return the column that this token starts at
84     */
85    public int getColumn() {
86      return _column;
87    }
88  
89    public int compareTo(Object o) {
90      if (!(o instanceof Occurrence)) {
91        throw new ClassCastException(getClass().getName());
92      }
93  
94      Occurrence other = (Occurrence)o;
95  
96      int result = 0;
97  
98      result = getFile().compareTo(other.getFile());
99  
100     if (result == 0) {
101       result = getLine() - other.getLine();
102     }
103     if (result == 0) {
104       result = getColumn() - other.getColumn();
105     }
106 
107     return result;
108   }
109 
110   public boolean equals(Object o) {
111     boolean result = false;
112     
113     if (o instanceof Occurrence) {
114       Occurrence occ = (Occurrence)o;
115       result = (getFile().equals(occ.getFile())
116                 && getLine() == occ.getLine()
117                 && getColumn() == occ.getColumn());
118     }
119 
120     return result;
121   }
122 
123   public int hashCode() {
124     return getFile().hashCode();
125   }
126 
127   public String toString() {
128     return "[" + getFile() + ":" + getLine() + "," + getColumn() + "]";
129   }
130 
131 }