aboutsummaryrefslogtreecommitdiff
path: root/src/jdiff/ClassAPI.java
blob: 9490cc7cf83fe62c99d65d3eee0906771ebcaf8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package jdiff;

import java.io.*;
import java.util.*;

/** 
 * Class to represent a class, analogous to ClassDoc in the 
 * Javadoc doclet API. 
 * 
 * The method used for Collection comparison (compareTo) must make its
 * comparison based upon everything that is known about this class.
 *
 * See the file LICENSE.txt for copyright details.
 * @author Matthew Doar, mdoar@pobox.com
 */
class ClassAPI implements Comparable {

    /** Name of the class, not fully qualified. */
    public String name_;

    /** Set if this class is an interface. */
    public boolean isInterface_;

    /** Set if this class is abstract. */
    boolean isAbstract_ = false;

    /** Modifiers for this class. */
    public Modifiers modifiers_;

    /** Name of the parent class, or null if there is no parent. */
    public String extends_; // Can only extend zero or one class or interface

    /** Interfaces implemented by this class. */
    public List implements_; // String[]

    /** Constructors in this class. */
    public List ctors_; // ConstructorAPI[]

    /** Methods in this class. */
    public List methods_; // MethodAPI[]

    /** Fields in this class. */
    public List fields_; //FieldAPI[]

    /** The doc block, default is null. */
    public String doc_ = null;

    /** Constructor. */
    public ClassAPI(String name, String parent, boolean isInterface, 
                    boolean isAbstract, Modifiers modifiers) {
        name_ = name;
        extends_ = parent;
        isInterface_ = isInterface;
        isAbstract_ = isAbstract;
        modifiers_ = modifiers;

        implements_ = new ArrayList(); // String[]
        ctors_ = new ArrayList(); // ConstructorAPI[]
        methods_ = new ArrayList(); // MethodAPI[]
        fields_ = new ArrayList(); // FieldAPI[]
    }

    /** Compare two ClassAPI objects by all the known information. */
    public int compareTo(Object o) {
        ClassAPI oClassAPI = (ClassAPI)o;
        int comp = name_.compareTo(oClassAPI.name_);
        if (comp != 0)
            return comp;
        if (isInterface_ != oClassAPI.isInterface_)
            return -1;
        if (isAbstract_ != oClassAPI.isAbstract_)
            return -1;
        comp = modifiers_.compareTo(oClassAPI.modifiers_);
        if (comp != 0)
            return comp;
        if (APIComparator.docChanged(doc_, oClassAPI.doc_))
            return -1;
        return 0;
    }  

    /** 
     * Tests two methods for equality using just the class name, 
     * used by indexOf(). 
     */
    public boolean equals(Object o) {
        if (name_.compareTo(((ClassAPI)o).name_) == 0)
            return true;
        return false;
    }
    
}