KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > apiscan > classfile > ClassFile


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ClassFile.java
26  *
27  * Created on August 17, 2004, 8:43 AM
28  */

29
30 package com.sun.enterprise.tools.verifier.apiscan.classfile;
31
32 import java.util.Collection JavaDoc;
33
34 /**
35  * This represents the information available in a Java .class file. This
36  * interface is used by {@link ClosureCompilerImpl} for closure computation. The
37  * interface only represents the information as needed by api scanning feature
38  * in verifier. I expect it to evolve over time to something very similar to
39  * BCEL's ClassFile. Now a note about different ways a Java class can be named
40  * and in different places different names are used for the same Java class. 1)
41  * In the format "p.a.b". This is what we use when declaring variables etc in a
42  * Java code. I do not use this because this is not an unambiguous
43  * representation of a Java class. By looking at p.a.b it is not possible to say
44  * if b is an inner class in class p.a or b is an outer class in package p.a. 2)
45  * In the format "p.outer$inner". It is what is used when we invoke java command
46  * or Class.forName(). It is same as what is returned by
47  * java.lang.Class.getName() method. It is an unambiguous representation of a
48  * class name, because by looking at it, we can tell "inner" is an inner class
49  * of a class "outer" which belongs to package p. By default our {@link
50  * #getName()} returns in this format. 3) In the format "p/outer$inner" This is
51  * the internal name of a class. It is called internal name because in byte code
52  * this is what is encoded. It is again an unambiguous representation as this a
53  * path expression. It is fairly simple to convert from 2 to 3 by a simple call
54  * to String.replace('.','/'). Similarly to convert from 3 to 2, call
55  * String.replace('/','.'); Here is a test of what you understood. What does
56  * this class name "a$b.c$d.Foo$Bar$Goo" mean? "Goo" is an inner class in a
57  * class "Foo$Bar" which is defined in a package "a$b.c$d".
58  *
59  * @author Sanjeeb.Sahoo@Sun.COM
60  */

61 public interface ClassFile {
62     /**
63      * @return names of the classes that are directly referenced by this class.
64      * The returned class names are in external form.
65      */

66     Collection JavaDoc<String JavaDoc> getAllReferencedClassNames();
67
68     /**
69      * @return names of the classes that are directly referenced by this class.
70      * The returned class names are in internal form. This is done with
71      * a purpose as it is easy to look up files with internal class
72      * name.
73      */

74     Collection JavaDoc getAllReferencedClassNamesInInternalForm();
75
76     /**
77      * @return the external name of this Java class. External name is of the
78      * form java.util.Map$Entry. It is what is used when we invoke java
79      * command or Class.forName(). It is same as what is returned by
80      * java.lang.Class.getName() method. Pl note that a Java Class name
81      * and package name can contain $, so when you see a$b, don't assume
82      * it is an inner class.
83      * @see #getInternalName()
84      */

85     String JavaDoc getName();
86
87     /**
88      * @return the internal name of the Java class. Internal name is what is
89      * available in file system, e.g. java/util/Map$Entry Pl note that a
90      * Java Class name and package name can contain $, so when you see
91      * a$b, don't assume it is an inner class.
92      */

93     String JavaDoc getInternalName();
94
95     /**
96      * @return internal package name of the Java class. Unlike class name,
97      * package names do not have many forms. They are always specified
98      * using dor notation (i.e. java.lang). See getName() method in
99      * java.lang.Package class. Accordingly we have only one API for
100      * package name. Returns "" for default package.
101      */

102     String JavaDoc getPackageName();
103
104     /**
105      * @return all the methods that are present in this class. This includes
106      * methods that are added by compiler as well, e.g. clinit and init
107      * methods.
108      */

109     Collection JavaDoc<? extends Method> getMethods();
110
111     /**
112      * @param methodRef is the reference of the method that is being looked for
113      * @return return the method object that matches the guven criteria. null,
114      * otherwise.
115      */

116     Method getMethod(MethodRef methodRef);
117
118     /**
119      * @return external name of super class
120      */

121     String JavaDoc getNameOfSuperClass();
122
123     /**
124      * @return internal name of super class. Every class other than
125      * java.lang.Object has a super class.
126      */

127     String JavaDoc getInternalNameOfSuperClass();
128
129     /**
130      * @return external names of any interfaces implemented by this class.
131      */

132     String JavaDoc[] getNamesOfInterfaces();
133
134     /**
135      * @return internal names of any interfaces implemented by this class.
136      */

137     String JavaDoc[] getInternalNamesOfInterfaces();
138
139     /**
140      * @return true if this is an interface, else false
141      */

142     boolean isInterface();
143
144 }
145
Popular Tags