private Class<?>[] getModulesFor(Class<?> klass) throws InitializationError {
   GuiceModules annotation = klass.getAnnotation(GuiceModules.class);
   if (annotation == null)
     throw new InitializationError(
         "Missing @GuiceModules annotation for unit test '" + klass.getName() + "'");
   return annotation.value();
 }
示例#2
0
 private ClassNode makeClassNode(CompileUnit cu, Type t, Class c) {
   ClassNode back = null;
   if (cu != null) back = cu.getClass(c.getName());
   if (back == null) back = ClassHelper.make(c);
   if (!(t instanceof Class)) {
     ClassNode front = configureType(t);
     front.setRedirect(back);
     return front;
   }
   return back;
 }
示例#3
0
 static int getArgumentsStackSize(Method method) {
   int total = 0;
   Type[] paramTypes = method.getGenericParameterTypes();
   Annotation[][] anns = method.getParameterAnnotations();
   for (int iArg = 0, nArgs = paramTypes.length; iArg < nArgs; iArg++) {
     Class<?> paramType = getTypeClass(paramTypes[iArg]);
     if (paramType == int.class) {
       total += 4;
     } else if (paramType == long.class) {
       Annotation[] as = anns[iArg];
       if (isAnnotationPresent(Ptr.class, as)
           || isAnnotationPresent(
               org.bridj.ann.CLong.class,
               as)) // if (hasInstance(anns[iArg], Ptr.class, CLong.class))
       {
         total += Pointer.SIZE;
       } else {
         total += 8;
       }
     } else if (paramType == float.class) {
       total += 4;
     } else if (paramType == double.class) {
       total += 8;
     } else if (paramType == byte.class) {
       total += 1;
     } else if (paramType == char.class) {
       total += Platform.WCHAR_T_SIZE;
     } else if (paramType == CLong.class) {
       total += Platform.CLONG_SIZE;
     } else if (paramType == SizeT.class) {
       total += Platform.SIZE_T_SIZE;
     } else if (paramType == TimeT.class) {
       total += Platform.TIME_T_SIZE;
     } else if (paramType == short.class) {
       total += 2;
     } else if (paramType == boolean.class) {
       total += 1;
     } else if (Pointer.class.isAssignableFrom(paramType)) {
       total += Pointer.SIZE;
     } else if (NativeObject.class.isAssignableFrom(paramType)) {
       total += ((CRuntime) BridJ.getRuntime(paramType)).sizeOf(paramTypes[iArg], null);
     } else if (FlagSet.class.isAssignableFrom(paramType)) {
       total += 4; // TODO
     } else {
       throw new RuntimeException("Type not handled : " + paramType.getName());
     }
   }
   return total;
 }
示例#4
0
 private void sendResponse(long requestId, Object value, Class<?> declaredType)
     throws IOException {
   DataOutputStream out = newFlusher();
   out.writeByte(RESPONSE);
   out.writeLong(requestId);
   if (value == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     Class<?> clazz = value.getClass();
     out.writeUTF(clazz.getName());
     Serializer<Object> s = serializerFor(clazz, declaredType);
     s.serialize(out, value);
   }
   out.writeBoolean(false);
   out.flush();
 }
示例#5
0
  public void printAnnotations() {
    // Get Class object of the AnnotatedClass class
    Class c = ac.getClass();
    // Get all annotations applied to the AnnotatedClass class.
    // Only the annotations with RUNTIME retention are retained during runtime.
    Annotation[] annotations = c.getAnnotations();
    int numberOfAnnotations = annotations.length;
    System.out.println(
        "La Clase " + c.getName() + " tiene " + numberOfAnnotations + " anotaciones");

    for (int i = 0; i < numberOfAnnotations; i++) {
      System.out.println(
          "Anotacion "
              + i
              + ": "
              + annotations[i]
              + ", tipo"
              + annotations[i].annotationType().getName());
    }
  }
示例#6
0
 public static void main(String[] args) {
   try {
     H2O.main(args);
     TestUtil.stall_till_cloudsize(3);
     List<Class> tests = JUnitRunner.all();
     Result r = org.junit.runner.JUnitCore.runClasses(tests.toArray(new Class[0]));
     if( r.getFailureCount() == 0 ) {
       System.out.println("Successfully ran the following tests in " + (r.getRunTime() / 1000) + "s");
       for( Class c : tests )
         System.out.println(c.getName());
     } else {
       for( Failure f : r.getFailures() ) {
         System.err.println(f.getDescription());
         if( f.getException() != null )
           f.getException().printStackTrace();
       }
     }
     System.exit(r.getFailureCount());
   } catch( Throwable t ) {
     t.printStackTrace();
     System.exit(1);
   }
 }
  @SuppressWarnings({"rawtypes", "unchecked"})
  private <T> T convert(
      MetaData md, String[] data, Class<T> type, T defaultValue, Annotation annotation) {
    Object out = data[md.index];

    if (out == null) {
      out = defaultValue == null ? md.defaultValue : defaultValue;
    }

    if (annotation == null) {
      initializeMetadataConversions(data, md);
      out = md.convert(out);

      if (out == null) {
        out = defaultValue == null ? md.defaultValue : defaultValue;
      }
    }

    if (type != null) {
      if (out != null && type.isAssignableFrom(out.getClass())) {
        return (T) out;
      }
      Conversion conversion;
      if (type != String.class) {
        if (annotation == null) {
          conversion = conversionByType.get(type);
          if (conversion == null) {
            conversion = AnnotationHelper.getDefaultConversion(type, null);
            conversionByType.put(type, conversion);
          }
        } else {
          Map<Annotation, Conversion> m = conversionsByAnnotation.get(type);
          if (m == null) {
            m = new HashMap<Annotation, Conversion>();
            conversionsByAnnotation.put(type, m);
          }
          conversion = m.get(annotation);
          if (conversion == null) {
            conversion = AnnotationHelper.getConversion(type, annotation);
            m.put(annotation, conversion);
          }
        }

        if (conversion == null) {
          String message = "";
          if (type == Date.class || type == Calendar.class) {
            message = ". Need to specify format for date";
          }
          DataProcessingException exception =
              new DataProcessingException(
                  "Cannot convert '{value}' to " + type.getName() + message);
          exception.setValue(out);
          exception.setErrorContentLength(context.errorContentLength());
          throw exception;
        }
        out = conversion.execute(out);
      }
    }
    if (type == null) {
      return (T) out;
    }
    try {
      return type.cast(out);
    } catch (ClassCastException e) {
      DataProcessingException exception =
          new DataProcessingException(
              "Cannot cast value '{value}' of type "
                  + out.getClass().toString()
                  + " to "
                  + type.getName());
      exception.setValue(out);
      exception.setErrorContentLength(context.errorContentLength());
      throw exception;
    }
  }
  /** Calculates a MD5 digest of the class. */
  public String getDigest() {
    try {
      if (_className == null || "".equals(_className)) return "";

      DynamicClassLoader loader =
          (DynamicClassLoader) Thread.currentThread().getContextClassLoader();

      ClassLoader tmpLoader = loader.getNewTempClassLoader();

      Class cl = Class.forName(_className, false, tmpLoader);

      if (cl == null) return "";

      MessageDigest digest = MessageDigest.getInstance("MD5");

      addDigest(digest, cl.getName());

      addDigest(digest, cl.getModifiers());

      Class superClass = cl.getSuperclass();
      if (superClass != null) addDigest(digest, superClass.getName());

      Class[] interfaces = cl.getInterfaces();
      for (int i = 0; i < interfaces.length; i++) addDigest(digest, interfaces[i].getName());

      Field[] fields = cl.getDeclaredFields();

      Arrays.sort(fields, new FieldComparator());

      if (_checkFields) {
        for (Field field : fields) {
          if (Modifier.isPrivate(field.getModifiers()) && !_checkPrivate) continue;
          if (Modifier.isProtected(field.getModifiers()) && !_checkProtected) continue;

          addDigest(digest, field.getName());
          addDigest(digest, field.getModifiers());
          addDigest(digest, field.getType().getName());

          addDigest(digest, field.getAnnotations());
        }
      }

      Method[] methods = cl.getDeclaredMethods();
      Arrays.sort(methods, new MethodComparator());

      for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];

        if (Modifier.isPrivate(method.getModifiers()) && !_checkPrivate) continue;
        if (Modifier.isProtected(method.getModifiers()) && !_checkProtected) continue;
        if (Modifier.isStatic(method.getModifiers()) && !_checkStatic) continue;

        addDigest(digest, method.getName());
        addDigest(digest, method.getModifiers());
        addDigest(digest, method.getName());

        Class[] param = method.getParameterTypes();
        for (int j = 0; j < param.length; j++) addDigest(digest, param[j].getName());

        addDigest(digest, method.getReturnType().getName());

        Class[] exn = method.getExceptionTypes();
        for (int j = 0; j < exn.length; j++) addDigest(digest, exn[j].getName());

        addDigest(digest, method.getAnnotations());
      }

      byte[] digestBytes = new byte[256];

      int len = digest.digest(digestBytes, 0, digestBytes.length);

      return digestToBase64(digestBytes, len);
    } catch (Exception e) {
      log.log(Level.FINER, e.toString(), e);

      return "";
    }
  }
示例#9
0
 public boolean matches(Type type, Annotations annotations) {
   String thisName = getQualifiedName(new StringBuilder(), false).toString();
   Class typeClass = getTypeClass(type);
   String typeName = typeClass.getSimpleName();
   return thisName.equals(typeName) || thisName.equals(typeClass.getName());
 }