System.out.println(interfaces[i]);
}*/
- Method[] methods = SampleClass.class.getMethods();
- Method method = null;
- for(Method mth : methods) {
- if (mth.getName().equals("setSampleField")) {
- method = mth;
- }
+ Method[] methods = Class.class.getMethods();
+ Method method = null;
+ for(Method mth : methods) {
+ //if (mth.getName().equals("getConstructor")) {
+ if (mth.getName().equals("isAssignableFrom")) {
+ method = mth;
}
+ }
Type[] parameters = method.getGenericParameterTypes();
//Type[] parameters = methods[0].getGenericParameterTypes();
for (int i = 0; i < parameters.length; i++) {
genericComponentType = ct;
}
- /**
- * Factory method.
- * @param ct - the desired component type of the generic array type
- * being created
- * @return a generic array type with the desired component type
- */
public static GenericArrayTypeImpl make(Type ct) {
return new GenericArrayTypeImpl(ct);
}
-
- /**
- * Returns a <tt>Type</tt> object representing the component type
- * of this array.
- *
- * @return a <tt>Type</tt> object representing the component type
- * of this array
- * @since 1.5
- */
public Type getGenericComponentType() {
return genericComponentType; // return cached component type
}
int genericStart = currParam.indexOf('<');
if (genericStart != -1) {
if (currParam.charAt(genericStart + 1) == '*') {
- semicolon = genericStart + 4;
+ // Need to offset with idx to anticipate for array types (idx is incremented for array types)
+ semicolon = genericStart + idx + 3;
} else {
int generic = signature.indexOf('>', semicolon);
if (generic != -1) {
return signature.substring(0, opening);
}
+ public static String getArrayClassName(String signature) {
+ int opening = signature.indexOf('[');
+ if (opening == -1)
+ return signature;
+ else
+ return signature.substring(0, opening);
+ }
+
public static String getOwnerClassName(String signature) {
int marker = signature.indexOf('$');
if (marker == -1)
return (opening != -1);
}
+ public static boolean isArraySignature(String signature) {
+ if (signature == null || signature.equals(""))
+ return false;
+ int opening = signature.indexOf('[');
+ return (opening != -1);
+ }
+
public static boolean isTypeParameter(String parameterizedType, String signature) {
if (signature == null || signature.equals(""))
return false;
}
// TODO: Fix for Groovy's model-checking
+ private static int getGenericArrayTypeImplObj(String signature, MJIEnv env, int objRef, MethodInfo mi) {
+
+ ThreadInfo ti = env.getThreadInfo();
+ ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
+ ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl");
+
+ // Create a new object of type GenericArrayTypeImpl
+ int genArrRef = env.newObject(ci);
+ ElementInfo ei = env.getModifiableElementInfo(genArrRef);
+
+ // Get field information and fill out the fields
+ String clsSig = Types.getArrayClassName(signature);
+ int paramTypeRef = getParameterizedTypeImplObj(clsSig, env, objRef, mi);
+ ei.setReferenceField("genericComponentType", paramTypeRef);
+
+ return genArrRef;
+ }
+
private static int getParameterizedTypeImplObj(String signature, MJIEnv env, int objRef, MethodInfo mi) {
ThreadInfo ti = env.getThreadInfo();
for (int i = 0; i < argTypeNames.length; i++) {
// Change this into just the generic class type if it is a generic class
if (Types.isGenericSignature(argTypeNames[i])) {
- ar[i] = getParameterizedTypeImplObj(argTypeNames[i], env, objRef, mi);
+ if (Types.isArraySignature(argTypeNames[i])) {
+ // Generic array
+ ar[i] = getGenericArrayTypeImplObj(argTypeNames[i], env, objRef, mi);
+ } else {
+ ar[i] = getParameterizedTypeImplObj(argTypeNames[i], env, objRef, mi);
+ }
} else {
ClassInfo ci = ClassLoaderInfo.getCurrentResolvedClassInfo(argTypeNames[i]);
if (!ci.isRegistered()) {