コード例 #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;
    }
コード例 #2
0
    protected boolean matchesConstructor(Type type, java.lang.reflect.Constructor<?> constr) {
      if (memberName != SpecialName.Constructor) {
        return false;
      }

      if (!matchesEnclosingType(type)) {
        return false;
      }

      Template temp = Utils.getClass(type).getAnnotation(Template.class);
      Annotation[][] anns = constr.getParameterAnnotations();
      Type[] parameterTypes = constr.getGenericParameterTypes();

      int overrideOffset = Utils.getEnclosedConstructorParametersOffset(constr);
      if (!matchesArgs(
          parameterTypes, anns, overrideOffset + (temp == null ? 0 : temp.value().length))) {
        return false;
      }

      return true;
    }
コード例 #3
0
  protected static int getAnnotatedTemplateTypeVariableIndexInArguments(TypeVariable<?> var) {
    GenericDeclaration d = var.getGenericDeclaration();
    AnnotatedElement e = (AnnotatedElement) d;

    Template t = e.getAnnotation(Template.class);
    if (t == null)
      throw new RuntimeException(
          e
              + " is not a C++ class template (misses the @"
              + Template.class.getName()
              + " annotation)");

    int iTypeVar = Arrays.asList(d.getTypeParameters()).indexOf(var);
    int nTypes = 0, iParam = -1;
    Class<?>[] values = t.value();
    for (int i = 0, n = values.length; i < n; i++) {
      Class<?> c = values[i];
      if (c == Class.class || c == Type.class) nTypes++;

      if (nTypes == iTypeVar) {
        iParam = i;
        break;
      }
    }
    if (iParam < 0)
      throw new RuntimeException(
          "Couldn't find the type variable "
              + var
              + " (offset "
              + iTypeVar
              + ") in the @"
              + Template.class.getName()
              + " annotation : "
              + Arrays.asList(values));

    return iParam;
  }
コード例 #4
0
 static int getTemplateParametersCount(Class<?> typeClass) {
   Template t = typeClass.getAnnotation(Template.class);
   // TODO do something with these args !
   int templateParametersCount = t == null ? 0 : t.value().length;
   return templateParametersCount;
 }