1 cananian 1.5.2.1 // HMember.java, created Fri Jul 31  9:33:48 1998 by cananian
 2 cananian 1.5     // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.5     // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1     package harpoon.ClassFile;
 5 cananian 1.1     
 6 cananian 1.5.2.3 import harpoon.Util.ArrayFactory;
 7 cananian 1.1     /**
 8 cananian 1.1      * <Code>HMember</code> is an interface that reflects identifying information
 9 cananian 1.1      * about a single member (a field or a method) or a constructor.
10 cananian 1.1      * 
11 cananian 1.3      * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
12 cananian 1.7      * @version $Id: HMember.java,v 1.7 2002/04/10 03:04:15 cananian Exp $
13 cananian 1.1      * @see HClass
14 cananian 1.1      * @see HField
15 cananian 1.1      * @see HMethod
16 cananian 1.1      * @see HConstructor
17 cananian 1.1      */
18 cananian 1.6.2.1 public interface HMember extends java.lang.Comparable<HMember> {
19 cananian 1.1       /** 
20 cananian 1.1        * Returns the <code>HClass</code> object representing the class or
21 cananian 1.1        * interface that declares the member or constructor represented by this
22 cananian 1.1        * <code>HMember</code>.
23 cananian 1.1        */
24 cananian 1.1       public abstract HClass getDeclaringClass();
25 cananian 1.1       /**
26 cananian 1.5.2.2    * Returns the type descriptor for this member.
27 cananian 1.5.2.2    */
28 cananian 1.5.2.2   public abstract String getDescriptor();
29 cananian 1.1       /**
30 cananian 1.1        * Returns the simple name of the underlying member or constructor
31 cananian 1.1        * represented by this <code>HMember</code>.
32 cananian 1.1        */
33 cananian 1.1       public abstract String getName();
34 cananian 1.1       /**
35 cananian 1.1        * Returns the Java language modifiers for the member of constructor
36 cananian 1.1        * represented by this <code>HMember</code>, as an integer.  The
37 cananian 1.1        * <code>Modifier</code> class should be used to decode the
38 cananian 1.1        * modifiers in the integer.
39 cananian 1.1        * @see java.lang.reflect.Modifier
40 cananian 1.1        */
41 cananian 1.1       public abstract int getModifiers();
42 cananian 1.4     
43 cananian 1.4       /**
44 cananian 1.5.2.5    * Returns a hashcode for this <code>HMember</code>.  This is
45 cananian 1.5.2.5    * computed as the exclusive-or of the hashcodes for the
46 cananian 1.5.2.5    * underlying member's declaring class, name, and descriptor
47 cananian 1.5.2.5    * string.
48 cananian 1.5.2.5    */
49 cananian 1.5.2.5   public abstract int hashCode();
50 cananian 1.4     
51 cananian 1.4       /**
52 cananian 1.4        * Indicates whether this field or method is 'real' or if it has
53 cananian 1.4        * been synthesized by the compiler in order to implement scoping
54 cananian 1.4        * of inner classes.
55 cananian 1.4        */
56 cananian 1.4       public abstract boolean isSynthetic();
57 cananian 1.5.2.4 
58 cananian 1.5.2.4   /** Compares two <code>HMember</code>s lexicographically; first by
59 cananian 1.5.2.4    *  declaring class, then by name, and lastly by descriptor. */
60 cananian 1.6.2.1   public abstract int compareTo(HMember o);
61 cananian 1.5.2.4   // implementation of a member comparator, for consistency among 
62 cananian 1.5.2.4   // implementations.
63 cananian 1.6.2.1   static final java.util.Comparator<HMember> memberComparator = new MemberComparator();
64 cananian 1.5.2.6   /** Implementation of <code>java.util.Comparator</code> for objects
65 cananian 1.5.2.6    *  implementing <code>HMember</code>, for consistency among
66 cananian 1.5.2.6    *  implementations.  Compares two <code>HMember</code>s lexicographically,
67 cananian 1.5.2.6    *  first by declaring class, then by name, and lastly by descriptor. */
68 cananian 1.6.2.1   static class MemberComparator implements java.util.Comparator<HMember> {
69 cananian 1.6.2.1     public int compare(HMember hm1, HMember hm2) {
70 cananian 1.5.2.4         int c = hm1.getDeclaringClass().compareTo(hm2.getDeclaringClass());
71 cananian 1.5.2.4         if (c!=0) return c;
72 cananian 1.5.2.4         c = hm1.getName().compareTo(hm2.getName());
73 cananian 1.5.2.4         if (c!=0) return c;
74 cananian 1.5.2.4         c = hm1.getDescriptor().compareTo(hm2.getDescriptor());
75 cananian 1.5.2.4         return c;
76 cananian 1.5.2.4     }
77 cananian 1.5.2.4   }
78 cananian 1.5.2.3 
79 cananian 1.5.2.3   /** Array factory: returns new <code>HMember[]</code>. */
80 cananian 1.6.2.1   public static final ArrayFactory<HMember> arrayFactory =
81 cananian 1.5.2.3     Factories.hmemberArrayFactory;
82 cananian 1.1     }