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@pobox.com 15 */ 16 class ClassAPI implements Comparable<ClassAPI> { 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 final List<String> implements_ = new ArrayList<>(); 35 36 /** Constructors in this class. */ 37 public final List<ConstructorAPI> ctors_ = new ArrayList<>(); 38 39 /** Methods in this class. */ 40 public final List<MethodAPI> methods_ = new ArrayList<>(); 41 42 /** Fields in this class. */ 43 public final List<FieldAPI> fields_ = new ArrayList<>(); 44 45 /** The doc block, default is null. */ 46 public String doc_ = null; 47 48 /** Constructor. */ ClassAPI(String name, String parent, boolean isInterface, boolean isAbstract, Modifiers modifiers)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 58 /** Compare two ClassAPI objects by all the known information. */ compareTo(ClassAPI o)59 public int compareTo(ClassAPI o) { 60 ClassAPI oClassAPI = (ClassAPI)o; 61 int comp = name_.compareTo(oClassAPI.name_); 62 if (comp != 0) 63 return comp; 64 if (isInterface_ != oClassAPI.isInterface_) 65 return -1; 66 if (isAbstract_ != oClassAPI.isAbstract_) 67 return -1; 68 comp = modifiers_.compareTo(oClassAPI.modifiers_); 69 if (comp != 0) 70 return comp; 71 if (APIComparator.docChanged(doc_, oClassAPI.doc_)) 72 return -1; 73 return 0; 74 } 75 76 /** 77 * Tests two methods for equality using just the class name, 78 * used by indexOf(). 79 */ equals(Object o)80 public boolean equals(Object o) { 81 if (name_.compareTo(((ClassAPI)o).name_) == 0) 82 return true; 83 return false; 84 } 85 86 } 87