Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add descriptorString() method in Class.java #455

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/classes/modules/java.base/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;

import jdk.internal.reflect.ConstantPool;
import sun.invoke.util.Wrapper;
import sun.reflect.annotation.AnnotationType;

/**
Expand All @@ -57,14 +58,14 @@ public final class Class<T> implements Serializable, GenericDeclaration, Type, A

// we init this on demand (from MJIEnv) since it's not used too often
private static Annotation[] emptyAnnotations; // = new Annotation[0];

private String name;

// set by VM
private transient Module module;

private ClassLoader classLoader;

/**
* search global id of the corresponding ClassInfo, which factors in the classloader
*/
Expand Down Expand Up @@ -95,7 +96,7 @@ private Class() {}
public native Class<?> getComponentType ();

public native Field[] getFields() throws SecurityException;

public native Field getDeclaredField (String fieldName) throws NoSuchFieldException,
SecurityException;

Expand All @@ -110,7 +111,7 @@ public native Method getMethod (String mthName, Class<?>... paramTypes)
public native Method[] getDeclaredMethods () throws SecurityException;

public native Method[] getMethods () throws SecurityException;

public native Constructor<?>[] getDeclaredConstructors() throws SecurityException;

public native Constructor<?>[] getConstructors() throws SecurityException;
Expand Down Expand Up @@ -182,7 +183,7 @@ public String getPackageName() {
T[] getEnumConstantsShared() {
return getEnumConstants();
}

// lazy initialized map for field name -> Enum constants
// <2do> we should move this to the native side, since Enum constants don't change
private transient Map<String, T> enumConstantDirectory = null;
Expand Down Expand Up @@ -229,16 +230,33 @@ public String getName () {
public String getSimpleName () {
int idx; // <2do> not really - inner classes?
Class<?> enclosingClass = getEnclosingClass();

if(enclosingClass!=null){
idx = enclosingClass.getName().length();
} else{
idx = name.lastIndexOf('.');
}

return name.substring(idx+1);
}

public String descriptorString(){
if (isPrimitive()){
return Wrapper.forPrimitiveType(this).basicTypeString();
}

if (isArray()){
return "[" + getComponentType().descriptorString();
}else {
String name = getName().replace('.', '/');

StringBuilder s = new StringBuilder(name.length()+2);
s.append('L').append(name).append(';');

return s.toString();
}
}

static native Class<?> getPrimitiveClass (String clsName);

/**
Expand Down
Loading