src/share/classes/java/lang/Class.java

Print this page
rev 10452 : imported patch lang-Typos


1305      * @return the simple name of the underlying class
1306      * @since 1.5
1307      */
1308     public String getSimpleName() {
1309         if (isArray())
1310             return getComponentType().getSimpleName()+"[]";
1311 
1312         String simpleName = getSimpleBinaryName();
1313         if (simpleName == null) { // top level class
1314             simpleName = getName();
1315             return simpleName.substring(simpleName.lastIndexOf('.')+1); // strip the package name
1316         }
1317         // According to JLS3 "Binary Compatibility" (13.1) the binary
1318         // name of non-package classes (not top level) is the binary
1319         // name of the immediately enclosing class followed by a '$' followed by:
1320         // (for nested and inner classes): the simple name.
1321         // (for local classes): 1 or more digits followed by the simple name.
1322         // (for anonymous classes): 1 or more digits.
1323 
1324         // Since getSimpleBinaryName() will strip the binary name of
1325         // the immediatly enclosing class, we are now looking at a
1326         // string that matches the regular expression "\$[0-9]*"
1327         // followed by a simple name (considering the simple of an
1328         // anonymous class to be the empty string).
1329 
1330         // Remove leading "\$[0-9]*" from the name
1331         int length = simpleName.length();
1332         if (length < 1 || simpleName.charAt(0) != '$')
1333             throw new InternalError("Malformed class name");
1334         int index = 1;
1335         while (index < length && isAsciiDigit(simpleName.charAt(index)))
1336             index++;
1337         // Eventually, this is the empty string iff this is an anonymous class
1338         return simpleName.substring(index);
1339     }
1340 
1341     /**
1342      * Return an informative string for the name of this type.
1343      *
1344      * @return an informative string for the name of this type
1345      * @since 1.8




1305      * @return the simple name of the underlying class
1306      * @since 1.5
1307      */
1308     public String getSimpleName() {
1309         if (isArray())
1310             return getComponentType().getSimpleName()+"[]";
1311 
1312         String simpleName = getSimpleBinaryName();
1313         if (simpleName == null) { // top level class
1314             simpleName = getName();
1315             return simpleName.substring(simpleName.lastIndexOf('.')+1); // strip the package name
1316         }
1317         // According to JLS3 "Binary Compatibility" (13.1) the binary
1318         // name of non-package classes (not top level) is the binary
1319         // name of the immediately enclosing class followed by a '$' followed by:
1320         // (for nested and inner classes): the simple name.
1321         // (for local classes): 1 or more digits followed by the simple name.
1322         // (for anonymous classes): 1 or more digits.
1323 
1324         // Since getSimpleBinaryName() will strip the binary name of
1325         // the immediately enclosing class, we are now looking at a
1326         // string that matches the regular expression "\$[0-9]*"
1327         // followed by a simple name (considering the simple of an
1328         // anonymous class to be the empty string).
1329 
1330         // Remove leading "\$[0-9]*" from the name
1331         int length = simpleName.length();
1332         if (length < 1 || simpleName.charAt(0) != '$')
1333             throw new InternalError("Malformed class name");
1334         int index = 1;
1335         while (index < length && isAsciiDigit(simpleName.charAt(index)))
1336             index++;
1337         // Eventually, this is the empty string iff this is an anonymous class
1338         return simpleName.substring(index);
1339     }
1340 
1341     /**
1342      * Return an informative string for the name of this type.
1343      *
1344      * @return an informative string for the name of this type
1345      * @since 1.8