mirror of
https://github.com/corda/corda.git
synced 2025-06-01 23:20:54 +00:00
add various methods to Class and fix getComponentType for primitive arrays
This commit is contained in:
parent
58e3c3013a
commit
fb37f48237
@ -96,6 +96,32 @@ public final class Class <T> implements Type, GenericDeclaration {
|
|||||||
(replace('/', '.', name, 0, name.length - 1), 0, name.length - 1, false);
|
(replace('/', '.', name, 0, name.length - 1), 0, name.length - 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCanonicalName() {
|
||||||
|
if ((vmFlags & PrimitiveFlag) != 0) {
|
||||||
|
return getName();
|
||||||
|
} else if (isArray()) {
|
||||||
|
return getComponentType().getCanonicalName() + "[]";
|
||||||
|
} else {
|
||||||
|
return getName().replace('$', '.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSimpleName() {
|
||||||
|
if ((vmFlags & PrimitiveFlag) != 0) {
|
||||||
|
return getName();
|
||||||
|
} else if (isArray()) {
|
||||||
|
return getComponentType().getSimpleName() + "[]";
|
||||||
|
} else {
|
||||||
|
String name = getCanonicalName();
|
||||||
|
int index = name.lastIndexOf('.');
|
||||||
|
if (index >= 0) {
|
||||||
|
return name.substring(index + 1);
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Object staticTable() {
|
public Object staticTable() {
|
||||||
return staticTable;
|
return staticTable;
|
||||||
}
|
}
|
||||||
@ -159,6 +185,26 @@ public final class Class <T> implements Type, GenericDeclaration {
|
|||||||
|
|
||||||
public Class getComponentType() {
|
public Class getComponentType() {
|
||||||
if (isArray()) {
|
if (isArray()) {
|
||||||
|
String n = getName();
|
||||||
|
if ("[Z".equals(n)) {
|
||||||
|
return primitiveClass('Z');
|
||||||
|
} else if ("[B".equals(n)) {
|
||||||
|
return primitiveClass('B');
|
||||||
|
} else if ("[S".equals(n)) {
|
||||||
|
return primitiveClass('S');
|
||||||
|
} else if ("[C".equals(n)) {
|
||||||
|
return primitiveClass('C');
|
||||||
|
} else if ("[I".equals(n)) {
|
||||||
|
return primitiveClass('I');
|
||||||
|
} else if ("[F".equals(n)) {
|
||||||
|
return primitiveClass('F');
|
||||||
|
} else if ("[J".equals(n)) {
|
||||||
|
return primitiveClass('J');
|
||||||
|
} else if ("[D".equals(n)) {
|
||||||
|
return primitiveClass('D');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (staticTable == null) throw new AssertionError(name);
|
||||||
return (Class) staticTable;
|
return (Class) staticTable;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -485,6 +531,14 @@ public final class Class <T> implements Type, GenericDeclaration {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> Class<? extends T> asSubclass(Class<T> c) {
|
||||||
|
if (! c.isAssignableFrom(this)) {
|
||||||
|
throw new ClassCastException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Class<? extends T>) this;
|
||||||
|
}
|
||||||
|
|
||||||
public T cast(Object o) {
|
public T cast(Object o) {
|
||||||
return (T) o;
|
return (T) o;
|
||||||
}
|
}
|
||||||
@ -493,6 +547,21 @@ public final class Class <T> implements Type, GenericDeclaration {
|
|||||||
return Static.signers.get(this);
|
return Static.signers.get(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Package getPackage() {
|
||||||
|
if ((vmFlags & PrimitiveFlag) != 0 || isArray()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
String name = getCanonicalName();
|
||||||
|
int index = name.lastIndexOf('.');
|
||||||
|
if (index >= 0) {
|
||||||
|
return new Package(name.substring(0, index),
|
||||||
|
null, null, null, null, null, null, null, null);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Annotation[] getDeclaredAnnotations() {
|
public Annotation[] getDeclaredAnnotations() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@ -505,10 +574,6 @@ public final class Class <T> implements Type, GenericDeclaration {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSimpleName() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Method getEnclosingMethod() {
|
public Method getEnclosingMethod() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user