< prev index next >
src/java.base/share/classes/java/lang/Class.java
Print this page
*** 1310,1320 ****
// c) Inner classes (non-static member classes)
// d) Local classes (named classes declared within a method)
// e) Anonymous classes
! // JVM Spec 4.8.6: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an
// anonymous class.
EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
Class<?> enclosingCandidate;
--- 1310,1320 ----
// c) Inner classes (non-static member classes)
// d) Local classes (named classes declared within a method)
// e) Anonymous classes
! // JVM Spec 4.7.7: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an
// anonymous class.
EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
Class<?> enclosingCandidate;
*** 1370,1381 ****
// followed by a simple name (considering the simple of an
// anonymous class to be the empty string).
// Remove leading "\$[0-9]*" from the name
int length = simpleName.length();
! if (length < 1 || simpleName.charAt(0) != '$')
! throw new InternalError("Malformed class name");
int index = 1;
while (index < length && isAsciiDigit(simpleName.charAt(index)))
index++;
// Eventually, this is the empty string iff this is an anonymous class
return simpleName.substring(index);
--- 1370,1382 ----
// followed by a simple name (considering the simple of an
// anonymous class to be the empty string).
// Remove leading "\$[0-9]*" from the name
int length = simpleName.length();
! if (length < 1 || simpleName.charAt(0) != '$') {
! return simpleName; // binary name doesn't follow Java source rules
! }
int index = 1;
while (index < length && isAsciiDigit(simpleName.charAt(index)))
index++;
// Eventually, this is the empty string iff this is an anonymous class
return simpleName.substring(index);
*** 1487,1510 ****
*/
private String getSimpleBinaryName() {
Class<?> enclosingClass = getEnclosingClass();
if (enclosingClass == null) // top level class
return null;
! // Otherwise, strip the enclosing class' name
! try {
return getName().substring(enclosingClass.getName().length());
! } catch (IndexOutOfBoundsException ex) {
! throw new InternalError("Malformed class name", ex);
}
}
/**
* Returns {@code true} if this is a local class or an anonymous
* class. Returns {@code false} otherwise.
*/
private boolean isLocalOrAnonymousClass() {
! // JVM Spec 4.8.6: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an
// anonymous class.
return getEnclosingMethodInfo() != null;
}
--- 1488,1517 ----
*/
private String getSimpleBinaryName() {
Class<?> enclosingClass = getEnclosingClass();
if (enclosingClass == null) // top level class
return null;
! if (getName().startsWith(enclosingClass.getName())) {
! // Strip enclosing class name.
return getName().substring(enclosingClass.getName().length());
! } else {
! // The binary name doesn't follow Java source rules. Ask the JVM.
! String name = getSimpleBinaryName0();
! if (name == null) // anonymous class
! return "";
! return name;
}
}
+ private native String getSimpleBinaryName0();
+
/**
* Returns {@code true} if this is a local class or an anonymous
* class. Returns {@code false} otherwise.
*/
private boolean isLocalOrAnonymousClass() {
! // JVM Spec 4.7.7: A class must have an EnclosingMethod
// attribute if and only if it is a local class or an
// anonymous class.
return getEnclosingMethodInfo() != null;
}
< prev index next >