Home | History | Annotate | Download | only in jdiff
      1 package jdiff;
      2 
      3 import java.io.*;
      4 import java.util.*;
      5 
      6 /**
      7  * Class to represent a class, analogous to ClassDoc 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 class.
     12  *
     13  * See the file LICENSE.txt for copyright details.
     14  * @author Matthew Doar, mdoar (at) pobox.com
     15  */
     16 class ClassAPI implements Comparable {
     17 
     18     /** Name of the class, not fully qualified. */
     19     public String name_;
     20 
     21     /** Set if this class is an interface. */
     22     public boolean isInterface_;
     23 
     24     /** Set if this class is abstract. */
     25     boolean isAbstract_ = false;
     26 
     27     /** Modifiers for this class. */
     28     public Modifiers modifiers_;
     29 
     30     /** Name of the parent class, or null if there is no parent. */
     31     public String extends_; // Can only extend zero or one class or interface
     32 
     33     /** Interfaces implemented by this class. */
     34     public List implements_; // String[]
     35 
     36     /** Constructors in this class. */
     37     public List ctors_; // ConstructorAPI[]
     38 
     39     /** Methods in this class. */
     40     public List methods_; // MethodAPI[]
     41 
     42     /** Fields in this class. */
     43     public List fields_; //FieldAPI[]
     44 
     45     /** The doc block, default is null. */
     46     public String doc_ = null;
     47 
     48     /** Constructor. */
     49     public ClassAPI(String name, String parent, boolean isInterface,
     50                     boolean isAbstract, Modifiers modifiers) {
     51         name_ = name;
     52         extends_ = parent;
     53         isInterface_ = isInterface;
     54         isAbstract_ = isAbstract;
     55         modifiers_ = modifiers;
     56 
     57         implements_ = new ArrayList(); // String[]
     58         ctors_ = new ArrayList(); // ConstructorAPI[]
     59         methods_ = new ArrayList(); // MethodAPI[]
     60         fields_ = new ArrayList(); // FieldAPI[]
     61     }
     62 
     63     /** Compare two ClassAPI objects by all the known information. */
     64     public int compareTo(Object o) {
     65         ClassAPI oClassAPI = (ClassAPI)o;
     66         int comp = name_.compareTo(oClassAPI.name_);
     67         if (comp != 0)
     68             return comp;
     69         if (isInterface_ != oClassAPI.isInterface_)
     70             return -1;
     71         if (isAbstract_ != oClassAPI.isAbstract_)
     72             return -1;
     73         comp = modifiers_.compareTo(oClassAPI.modifiers_);
     74         if (comp != 0)
     75             return comp;
     76         if (APIComparator.docChanged(doc_, oClassAPI.doc_))
     77             return -1;
     78         return 0;
     79     }
     80 
     81     /**
     82      * Tests two methods for equality using just the class name,
     83      * used by indexOf().
     84      */
     85     public boolean equals(Object o) {
     86         if (name_.compareTo(((ClassAPI)o).name_) == 0)
     87             return true;
     88         return false;
     89     }
     90 
     91 }
     92