Exemplo n.º 1
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;
  }
 public static String declarationToString(@NotNull GenericDeclaration anInterface) {
   return anInterface.toString()
       + Arrays.asList(anInterface.getTypeParameters())
       + " loaded by "
       + ((Class) anInterface).getClassLoader();
 }