Commit c8f9aed0 authored by Lubomir Bulej's avatar Lubomir Bulej

- Change getInterfaces() to return an array of ShadowClass instances

  (currently unimplemented) instead of an array of string descriptors.
- Add getInterfaceDescriptors() to return an array of string descriptors
  for consistency with the normal reflection API.
- Renamed getDeclaredClasses() to getDeclaredClassDescriptors().
- Changed getDeclaredClasses() to return an array of type descriptors
  instead of an array of internal names of the declared classes.
parent 4b2b571e
package ch.usi.dag.dislreserver.shadow;
import java.io.Serializable;
import java.lang.reflect.Modifier;
import java.util.Arrays;
......@@ -41,6 +42,12 @@ final class ArrayShadowClass extends ShadowClass {
throw new UnsupportedOperationException ("not yet implemented");
}
@Override
public String getComponentDescriptor () {
return _type ().getElementType ().getDescriptor ();
}
//
/**
......@@ -92,8 +99,17 @@ final class ArrayShadowClass extends ShadowClass {
@Override
public String [] getInterfaces () {
return new String [] { "java.lang.Cloneable", "java.io.Serializable" };
public ShadowClass [] getInterfaces () {
throw new UnsupportedOperationException ("not yet implemented");
}
@Override
public String [] getInterfaceDescriptors () {
return new String [] {
Type.getType (Cloneable.class).getDescriptor (),
Type.getType (Serializable.class).getDescriptor ()
};
}
//
......@@ -165,11 +181,4 @@ final class ArrayShadowClass extends ShadowClass {
return new MethodInfo [0];
}
//
@Override
public String [] getDeclaredClasses () {
return new String [0];
}
}
......@@ -105,6 +105,9 @@ final class ObjectShadowClass extends ShadowClass {
//
/**
* @see Class#isInstance(Object)
*/
@Override
public boolean isInstance (final ShadowObject object) {
// return equals(obj.getShadowClass());
......@@ -112,14 +115,17 @@ final class ObjectShadowClass extends ShadowClass {
}
/**
* @see Class#isAssignableFrom(Class)
*/
@Override
public boolean isAssignableFrom (final ShadowClass klass) {
// while (klass != null) {
// if (klass.equals(this)) {
public boolean isAssignableFrom (final ShadowClass other) {
// while (other != null) {
// if (other.equals(this)) {
// return true;
// }
//
// klass = klass.getSuperclass();
// other = other.getSuperclass();
// }
//
// return false;
......@@ -135,6 +141,9 @@ final class ObjectShadowClass extends ShadowClass {
//
/**
* @see Class#getSuperclass()
*/
@Override
public ShadowClass getSuperclass () {
return __superClass;
......@@ -142,8 +151,15 @@ final class ObjectShadowClass extends ShadowClass {
@Override
public String [] getInterfaces () {
return __classNode.interfaces.toArray (new String [0]);
public ShadowClass [] getInterfaces () {
throw new UnsupportedOperationException ("not yet implemented");
}
@Override
public String [] getInterfaceDescriptors () {
final List <String> interfaces = __classNode.interfaces;
return interfaces.toArray (new String [interfaces.size ()]);
}
//
......@@ -241,8 +257,10 @@ final class ObjectShadowClass extends ShadowClass {
//
@Override
public String [] getDeclaredClasses () {
return innerclasses.toArray (new String [innerclasses.size ()]);
}
public String [] getDeclaredClassDescriptors () {
return __classNode.innerClasses.stream ().unordered ()
.map (icn -> Type.getObjectType (icn.name).getDescriptor ())
.toArray (String []::new);
}
}
......@@ -64,7 +64,13 @@ final class PrimitiveShadowClass extends ShadowClass {
@Override
public String [] getInterfaces () {
public ShadowClass [] getInterfaces () {
return new ShadowClass [0];
}
@Override
public String [] getInterfaceDescriptors () {
return new String [0];
}
......@@ -128,11 +134,4 @@ final class PrimitiveShadowClass extends ShadowClass {
);
}
//
@Override
public String [] getDeclaredClasses () {
return new String [0];
}
}
......@@ -102,16 +102,22 @@ public abstract class ShadowClass extends ShadowObject {
}
/**
* @see Class#getPackage()
*/
public String getPackage () {
final String name = getCanonicalName ();
final int lastIndex = name.lastIndexOf ('.');
// Class.getPackage() returns null for array/primitive classes
// Return null for array/primitive classes or default package.
return (lastIndex >= 0) ? name.substring (0, lastIndex) : null;
}
//
/**
* @see Class#isPrimitive()
*/
public boolean isPrimitive () {
// We rely on the ordering of sorts in ASM Type.
return __type.getSort () < Type.ARRAY;
......@@ -124,11 +130,13 @@ public abstract class ShadowClass extends ShadowObject {
//
public ShadowClass getComponentType () {
// By default, a class has no component type.
return null;
}
public String getComponentDescriptor () {
// By default, a class has no component type descriptor.
return null;
}
......@@ -172,8 +180,9 @@ public abstract class ShadowClass extends ShadowObject {
public abstract ShadowClass getSuperclass ();
public abstract ShadowClass [] getInterfaces ();
public abstract String [] getInterfaces ();
public abstract String [] getInterfaceDescriptors ();
//
......@@ -225,7 +234,18 @@ public abstract class ShadowClass extends ShadowObject {
//
public abstract String [] getDeclaredClasses ();
/**
* Returns type descriptors corresponding to declared inner classes, or an
* empty array if this class does not declare any inner classes.
*
* @return an array of inner class type descriptors
*
* @see Class#getDeclaredClasses()
*/
public String [] getDeclaredClassDescriptors () {
// By default, a class declares no inner classes.
return new String [0];
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment