站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

ClassName (Classfile Reader) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.classfile/1 1.19

org.netbeans.modules.classfile
Class ClassName

java.lang.Object
  extended by org.netbeans.modules.classfile.ClassName
All Implemented Interfaces:
Serializable, Comparable, Comparator

public final class ClassName
extends Object
implements Comparable, Comparator, Serializable

Class representing the name of a Java class. This class is immutable, and can therefore be safely used by multiple threads.

Warning: The same reference is often returned by the getClassName factory method for multiple calls which use the same type name as its parameter. However, no guarantee is made that this behavior will always be true, so the equals method should always be used to compare ClassName instances.

See Also:
Serialized Form

Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order.
 int compareTo(Object obj)
          Compares this ClassName to another Object.
 boolean equals(Object obj)
           
static ClassName getClassName(String classType)
          Returns the ClassName object referenced by a class type string (field descriptor), as defined in the JVM Specification, sections 4.3.2 and 4.2.
 String getExternalName()
          Returns the "external" classname, as defined by the Java Language Specification, without any parameter or return type information.
 String getExternalName(boolean suppressArrays)
          Returns the "external" classname, as defined by the Java Language Specification, without any parameter or return type information.
 String getInternalName()
          Returns the "internal" classname, as defined by the JVM Specification, without any parameter or return type information.
 String getPackage()
          Return the package portion of this classname.
 String getSimpleName()
          Returns the classname without any package specification.
 String getType()
          Returns the type string of this class, as stored in the classfile (it's "raw" form).
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getClassName

public static ClassName getClassName(String classType)
Returns the ClassName object referenced by a class type string (field descriptor), as defined in the JVM Specification, sections 4.3.2 and 4.2.

Basically, the JVM Specification defines a class type string where the periods ('.') separating a package name are replaced by forward slashes ('/'). Not documented in the second edition of the specification is that periods separating inner and outer classes are replaced with dollar signs ('$'). Array classes have one or more left brackets ('[') prepending the class type. For example:


   java.lang.String         java/lang/String
   java.util.HashMap.Entry  java/util/HashMap$Entry
   java.lang.Integer[]      [java/lang/Integer
   java.awt.Point[][]       [[java/awt/Point
 
 

This method also accepts type strings which contain with 'L' and end with ';' characters. This format is used to reference a class in other type names, such as method arguments. These two characters are removed from the type string.

Because ClassNames are immutable, multiple requests to get the same type string may return identical object references. This cannot be assumed, however, and the ClassName.equals() method should be used instead of "==" to test for equality.

Parameters:
classType - the class type string, as defined by the JVM spec.
Returns:
the ClassName instance, or null if not found.
Throws:
IllegalArgumentException - if classType isn't of the correct format.

getType

public String getType()
Returns the type string of this class, as stored in the classfile (it's "raw" form). For example, an array of Floats would have a type of "[java/lang/Float".

Returns:
the raw string format of the class type

getInternalName

public String getInternalName()
Returns the "internal" classname, as defined by the JVM Specification, without any parameter or return type information. For example, the name for the String class would be "java/lang/String". Inner classes are separated from their outer class with '$'; such as "java/util/HashMap$Entry". Array specifications are stripped; use getType() instead.

Returns:
the internal name

getExternalName

public String getExternalName()
Returns the "external" classname, as defined by the Java Language Specification, without any parameter or return type information. For example, the name for the String class would be "java.lang.String". Inner classes are separated from their outer class with '.'; such as "java.util.HashMap.Entry". Arrays are shown as having one or more "[]" characters behind the base classname, such as "java.io.Files[]".

Returns:
the external name, with array characters if this ClassName is an array

getExternalName

public String getExternalName(boolean suppressArrays)
Returns the "external" classname, as defined by the Java Language Specification, without any parameter or return type information. For example, the name for the String class would be "java.lang.String". Inner classes are separated from their outer class with '.'; such as "java.util.HashMap.Entry". Unless suppressed, arrays are shown as having one or more "[]" characters behind the base classname, such as "java.io.Files[]".

Parameters:
suppressArrays - true if array characters should be included
Returns:
the external name

getPackage

public String getPackage()
Return the package portion of this classname.

Returns:
the package name

getSimpleName

public String getSimpleName()
Returns the classname without any package specification.

Returns:
the simple name

equals

public boolean equals(Object obj)
Specified by:
equals in interface Comparator
Overrides:
equals in class Object

compareTo

public int compareTo(Object obj)
Compares this ClassName to another Object. If the Object is a ClassName, this function compares the ClassName's types. Otherwise, it throws a ClassCastException.

Specified by:
compareTo in interface Comparable
Parameters:
obj - the Object to be compared.
Returns:
the value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
See Also:
Comparable

compare

public int compare(Object o1,
                   Object o2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Specified by:
compare in interface Comparator
Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
Throws:
ClassCastException - if the arguments' types prevent them from being compared by this Comparator.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

org.netbeans.modules.classfile/1 1.19

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.