コード例 #1
0
  protected VTable synthetizeVirtualTable(
      Type type, Pointer<Pointer> parentVTablePtr, List<VirtMeth> methods, NativeLibrary library) {
    int nMethods = methods.size();
    // Pointer<Pointer> parentVTablePtr = pointerToAddress(getVirtualTable(Utils.getParent(type),
    // library), Pointer.class);
    VTable vtable = new VTable();
    vtable.ptr =
        allocatePointers(nMethods + 2)
            .next(
                2); // leave two null pointers at index -2 and -1, to say there's no runtime type
                    // information available.

    Class<?> c = Utils.getClass(type);
    for (int iMethod = 0; iMethod < nMethods; iMethod++) {
      VirtMeth vm = methods.get(iMethod);
      Pointer<?> pMethod;
      if (Modifier.isNative(vm.implementation.getModifiers())) {
        pMethod = parentVTablePtr == null ? null : parentVTablePtr.get(iMethod);
      } else {
        try {
          MethodCallInfo mci = new MethodCallInfo(vm.implementation, vm.definition);
          mci.setDeclaringClass(vm.implementation.getDeclaringClass());
          pMethod = createCToJavaCallback(mci, c);
          vtable.callbacks.put(vm.implementation, pMethod);
        } catch (Throwable th) {
          BridJ.error(
              "Failed to register overridden method "
                  + vm.implementation
                  + " for type "
                  + type
                  + " (original method = "
                  + vm.definition
                  + ")",
              th);
          pMethod = null;
        }
      }
      vtable.ptr.set(iMethod, (Pointer) pMethod);
    }
    return vtable;
  }
コード例 #2
0
 public void setMethod(Method method) {
   this.method = method;
   if (method != null) this.methodName = method.getName();
   if (declaringClass == null) setDeclaringClass(method.getDeclaringClass());
 }