Пример #1
0
  static Class<?> getTypeClass(Type type) {

    if (type instanceof Class<?>) {
      return (Class<?>) type;
    }
    if (type instanceof ParameterizedType) {
      ParameterizedType pt = (ParameterizedType) type;
      Class<?> c = (Class<?>) pt.getRawType();
      if (ValuedEnum.class.isAssignableFrom(c)) {
        Type[] types = pt.getActualTypeArguments();
        if (types == null || types.length != 1) {
          c = int.class;
        } else {
          c = getTypeClass(pt.getActualTypeArguments()[0]);
        }
      }
      return c;
    }
    if (type instanceof GenericArrayType) {
      if (Object.class.isAssignableFrom(
          getTypeClass(((GenericArrayType) type).getGenericComponentType()))) {
        return Object[].class;
      }
    }
    throw new UnsupportedOperationException("Unknown type type : " + type.getClass().getName());
  }
Пример #2
0
 public void appendToSignature(
     int iParam,
     ValueType type,
     Class<?> parameterType,
     Type genericParameterType,
     StringBuilder javaSig,
     StringBuilder dcSig,
     StringBuilder asmSig) {
   char dcChar;
   String javaChar, asmChar = null;
   switch (type) {
     case eVoidValue:
       dcChar = DC_SIGCHAR_VOID;
       javaChar = "V";
       break;
     case eIntValue:
       dcChar = DC_SIGCHAR_INT;
       javaChar = "I";
       break;
     case eLongValue:
       dcChar = DC_SIGCHAR_LONGLONG;
       javaChar = "J";
       break;
     case eSizeTValue:
       javaChar = "J";
       if (Platform.SIZE_T_SIZE == 8) {
         dcChar = DC_SIGCHAR_LONGLONG;
       } else {
         dcChar = DC_SIGCHAR_INT;
         direct = false;
       }
       break;
     case eShortValue:
       dcChar = DC_SIGCHAR_SHORT;
       javaChar = "S";
       break;
     case eDoubleValue:
       dcChar = DC_SIGCHAR_DOUBLE;
       javaChar = "D";
       break;
     case eFloatValue:
       dcChar = DC_SIGCHAR_FLOAT;
       javaChar = "F";
       break;
     case eByteValue:
       dcChar = DC_SIGCHAR_CHAR;
       javaChar = "B";
       break;
     case eBooleanValue:
       dcChar = DC_SIGCHAR_BOOL;
       javaChar = "Z";
       break;
     case eWCharValue:
       switch (Platform.WCHAR_T_SIZE) {
         case 1:
           dcChar = DC_SIGCHAR_CHAR;
           direct = false;
           break;
         case 2:
           dcChar = DC_SIGCHAR_SHORT;
           break;
         case 4:
           dcChar = DC_SIGCHAR_INT;
           direct = false;
           break;
         default:
           throw new RuntimeException(
               "Unhandled sizeof(wchar_t) in GetJavaTypeSignature: " + Platform.WCHAR_T_SIZE);
       }
       javaChar = "C";
       break;
     case eIntFlagSet:
       dcChar = DC_SIGCHAR_INT;
       javaChar =
           "L" + parameterType.getName().replace('.', '/') + ";"; // "Lorg/bridj/ValuedEnum;";
       direct = false;
       break;
     case eCLongObjectValue:
       dcChar = DC_SIGCHAR_POINTER;
       javaChar = "Lorg/bridj/CLong;";
       direct = false;
       break;
     case eSizeTObjectValue:
       dcChar = DC_SIGCHAR_POINTER;
       javaChar = "Lorg/bridj/SizeT;";
       direct = false;
       break;
     case eTimeTObjectValue:
       dcChar = DC_SIGCHAR_POINTER;
       javaChar = "Lorg/bridj/TimeT;";
       direct = false;
       break;
     case ePointerValue:
       dcChar = DC_SIGCHAR_POINTER;
       javaChar = "L" + parameterType.getName().replace('.', '/') + ";";
       //                javaChar = "Lorg/bridj/Pointer;";
       direct = false;
       break;
     case eNativeObjectValue:
       dcChar = DC_SIGCHAR_STRUCT; // TODO : unroll struct signature ?
       javaChar = "L" + parameterType.getName().replace('.', '/') + ";";
       direct = false;
       //              if (parameterType.equals(declaringClass)) {
       //                    // special case of self-returning pointers
       //                    dcChar = DC_SIGCHAR_POINTER;
       break;
     case eEllipsis:
       javaChar = "[Ljava/lang/Object;";
       dcChar = '?';
       break;
     default:
       direct = false;
       throw new RuntimeException("Unhandled " + ValueType.class.getSimpleName() + ": " + type);
   }
   if (genericParameterType instanceof ParameterizedType && iParam < 0) {
     ParameterizedType pt = (ParameterizedType) genericParameterType;
     // TODO handle all cases !!!
     Type[] ts = pt.getActualTypeArguments();
     if (ts != null && ts.length == 1) {
       Type t = ts[0];
       if (t instanceof ParameterizedType) t = ((ParameterizedType) t).getRawType();
       if (t instanceof Class) {
         Class c = (Class) t;
         if (javaChar.endsWith(";")) {
           asmChar =
               javaChar.substring(0, javaChar.length() - 1)
                   + "<*L"
                   + c.getName().replace('.', '/')
                   + ";>";
           // asmChar += ";";
         }
       }
     }
   }
   if (javaSig != null) javaSig.append(javaChar);
   if (asmChar == null) asmChar = javaChar;
   if (asmSig != null) asmSig.append(asmChar);
   if (dcSig != null) dcSig.append(dcChar);
 }