Esempio n. 1
0
    public boolean matchesSignature(Method method) {

      if (getArgumentsStackSize() != null
          && getArgumentsStackSize().intValue() != getArgumentsStackSize(method)) {
        return false;
      }

      if (getMemberName() != null && !getMemberName().toString().equals(getMethodName(method))) {
        return false;
      }

      if (getValueType() != null
          && !getValueType().matches(method.getReturnType(), annotations(method))) {
        return false;
      }

      Template temp = method.getAnnotation(Template.class);
      Annotation[][] anns = method.getParameterAnnotations();
      //            Class<?>[] methodArgTypes = method.getParameterTypes();
      Type[] parameterTypes = method.getGenericParameterTypes();
      // boolean hasThisAsFirstArgument = BridJ.hasThisAsFirstArgument(method);//methodArgTypes,
      // anns, true);

      if (paramTypes != null
          && !matchesArgs(
              parameterTypes,
              anns,
              temp == null ? 0 : temp.value().length)) // /*, hasThisAsFirstArgument*/))
      {
        return false;
      }

      // int thisDirac = hasThisAsFirstArgument ? 1 : 0;
      /*
      switch (type) {
      case Constructor:
      case Destructor:
      Annotation ann = method.getAnnotation(type == SpecialName.Constructor ? Constructor.class : Destructor.class);
      if (ann == null)
      return false;
      if (!hasThisAsFirstArgument)
      return false;
      if (methodArgTypes.length - thisDirac != 0 )
      return false;
      break;
      case InstanceMethod:
      if (!hasThisAsFirstArgument)
      return false;
      break;
      case StaticMethod:
      if (hasThisAsFirstArgument)
      return false;
      break;
      }*/

      return true;
    }
Esempio n. 2
0
  public MethodCallInfo(Method method, Method definition) {
    this.setMethod(method);
    // this.setDefinition(definition);
    this.setDeclaringClass(method.getDeclaringClass());
    symbolName = methodName;

    int modifiers = method.getModifiers();
    isStatic = Modifier.isStatic(modifiers);
    isVarArgs = method.isVarArgs();
    boolean isNative = Modifier.isNative(modifiers);
    boolean isVirtual = isAnnotationPresent(Virtual.class, definition);
    boolean isDirectModeAllowed =
        getInheritableAnnotation(DisableDirect.class, definition) == null
            && BridJ.isDirectModeEnabled();

    isCPlusPlus = !isStatic && derivesFrom(method.getDeclaringClass(), "org.bridj.cpp.CPPObject");
    isObjCBlock = !isStatic && derivesFrom(method.getDeclaringClass(), "org.bridj.objc.ObjCBlock");

    init(
        method,
        method.getReturnType(),
        method.getGenericReturnType(),
        method.getAnnotations(),
        method.getParameterTypes(),
        method.getGenericParameterTypes(),
        method.getParameterAnnotations(),
        isNative,
        isVirtual,
        isDirectModeAllowed);

    Convention cc = getInheritableAnnotation(Convention.class, definition);
    if (cc != null) {
      setCallingConvention(cc.value());
    }
    List<Class<?>> exceptionTypes = Arrays.asList(definition.getExceptionTypes());
    if (!exceptionTypes.isEmpty()) {
      this.direct = false; // there is no crash / exception protection for direct raw calls
      if (exceptionTypes.contains(LastError.class)) this.bThrowLastError = true;
    }
  }