KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > structure > AbstractClassInfo


1 /*______________________________________________________________________________
2  *
3  * Macker http://innig.net/macker/
4  *
5  * Copyright 2002-2003 Paul Cantrell
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License version 2, as published by the
9  * Free Software Foundation. See the file LICENSE.html for more information.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the license for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
17  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
18  *______________________________________________________________________________
19  */

20
21 package net.innig.macker.structure;
22
23 import java.util.*;
24 import net.innig.collect.*;
25
26 public abstract class AbstractClassInfo
27     implements ClassInfo
28     {
29     public AbstractClassInfo(ClassManager classManager)
30         { this.classManager = classManager; }
31     
32     public String JavaDoc getClassName()
33         {
34         String JavaDoc className = getFullName();
35         return className.substring(className.lastIndexOf('.') + 1);
36         }
37         
38     public String JavaDoc getPackageName()
39         {
40         String JavaDoc className = getFullName();
41         int lastDotPos = className.lastIndexOf('.');
42         return (lastDotPos > 0) ? className.substring(0, lastDotPos) : "";
43         }
44     
45     public Set/*<ClassInfo>*/ getDirectSupertypes()
46         {
47         if(cachedAllDirectSuper == null)
48             {
49             Set newAllDirectSuper = new HashSet(getImplements());
50             newAllDirectSuper.add(getExtends());
51             cachedAllDirectSuper = newAllDirectSuper; // failure atomicity
52
}
53         return cachedAllDirectSuper;
54         }
55     
56     public Set/*<ClassInfo>*/ getSupertypes()
57         {
58         if(cachedAllSuper == null)
59             cachedAllSuper = Graphs.reachableNodes(
60                 this,
61                 new GraphWalker()
62                     {
63                     public Collection getEdgesFrom(Object JavaDoc node)
64                         { return ((ClassInfo) node).getDirectSupertypes(); }
65                     } );
66         return cachedAllSuper;
67         }
68     
69     public final ClassManager getClassManager()
70         { return classManager; }
71     
72     public abstract boolean isComplete();
73     public abstract String JavaDoc getFullName();
74     public abstract boolean isInterface();
75     public abstract boolean isAbstract();
76     public abstract boolean isFinal();
77     public abstract AccessModifier getAccessModifier();
78     public abstract ClassInfo getExtends();
79     public abstract Set/*<ClassInfo>*/ getImplements();
80     public abstract MultiMap/*<ClassInfo,Reference>*/ getReferences();
81     
82     public int compareTo(Object JavaDoc that)
83         { return getFullName().compareTo(((ClassInfo) that).getFullName()); }
84     
85     public final boolean equals(Object JavaDoc that)
86         {
87         if(this == that)
88             return true;
89         if(that == null)
90             return false;
91         if(!(that instanceof ClassInfo))
92             return false;
93         return getFullName().equals(((ClassInfo) that).getFullName());
94         }
95     
96     public final int hashCode()
97         { return getFullName().hashCode(); }
98     
99     public String JavaDoc toString()
100         { return getFullName(); }
101     
102     private ClassManager classManager;
103     private Set cachedAllSuper, cachedAllDirectSuper;
104     }
105
106
Popular Tags