KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jdiff > FieldAPI


1 package jdiff;
2
3 import java.io.*;
4 import java.util.*;
5
6 /**
7  * Class to represent a field, analogous to FieldDoc in the
8  * Javadoc doclet API.
9  *
10  * The method used for Collection comparison (compareTo) must make its
11  * comparison based upon everything that is known about this field.
12  *
13  * See the file LICENSE.txt for copyright details.
14  * @author Matthew Doar, doar@pobox.com
15  */

16 class FieldAPI implements Comparable JavaDoc {
17     /** Name of the field. */
18     public String JavaDoc name_;
19
20     /** Type of the field. */
21     public String JavaDoc type_;
22
23     /**
24      * The fully qualified name of the class or interface this field is
25      * inherited from. If this is null, then the field is defined locally
26      * in this class or interface.
27      */

28     public String JavaDoc inheritedFrom_ = null;
29
30     /** Set if this field is transient. */
31     public boolean isTransient_ = false;
32
33     /** Set if this field is volatile. */
34     public boolean isVolatile_ = false;
35
36     /** If non-null, this is the value of this field. */
37     public String JavaDoc value_ = null;
38
39     /** Modifiers for this class. */
40     public Modifiers modifiers_;
41
42     /** The doc block, default is null. */
43     public String JavaDoc doc_ = null;
44
45     /** Constructor. */
46     public FieldAPI(String JavaDoc name, String JavaDoc type,
47                     boolean isTransient, boolean isVolatile,
48                     String JavaDoc value, Modifiers modifiers) {
49         name_ = name;
50         type_ = type;
51         isTransient_ = isTransient;
52         isVolatile_ = isVolatile;
53         value_ = value;
54         modifiers_ = modifiers;
55     }
56
57     /** Copy constructor. */
58     public FieldAPI(FieldAPI f) {
59         name_ = f.name_;
60         type_ = f.type_;
61         inheritedFrom_ = f.inheritedFrom_;
62         isTransient_ = f.isTransient_;
63         isVolatile_ = f.isVolatile_;
64         value_ = f.value_;
65         modifiers_ = f.modifiers_; // Note: shallow copy
66
doc_ = f.doc_;
67     }
68
69     /** Compare two FieldAPI objects, including name, type and modifiers. */
70     public int compareTo(Object JavaDoc o) {
71         FieldAPI oFieldAPI = (FieldAPI)o;
72         int comp = name_.compareTo(oFieldAPI.name_);
73         if (comp != 0)
74             return comp;
75         comp = type_.compareTo(oFieldAPI.type_);
76         if (comp != 0)
77             return comp;
78         if (APIComparator.changedInheritance(inheritedFrom_, oFieldAPI.inheritedFrom_) != 0)
79             return -1;
80         if (isTransient_ != oFieldAPI.isTransient_) {
81             return -1;
82         }
83         if (isVolatile_ != oFieldAPI.isVolatile_) {
84             return -1;
85         }
86         if (value_ != null && oFieldAPI.value_ != null) {
87             comp = value_.compareTo(oFieldAPI.value_);
88             if (comp != 0)
89                 return comp;
90         }
91         comp = modifiers_.compareTo(oFieldAPI.modifiers_);
92         if (comp != 0)
93             return comp;
94         if (APIComparator.docChanged(doc_, oFieldAPI.doc_))
95             return -1;
96         return 0;
97     }
98   
99     /**
100      * Tests two fields, using just the field name, used by indexOf().
101      */

102     public boolean equals(Object JavaDoc o) {
103         if (name_.compareTo(((FieldAPI)o).name_) == 0)
104             return true;
105         return false;
106     }
107 }
108
Popular Tags