Java Class.getAnnotationsByType Examples

Java Class.getAnnotationsByType - 2 examples found. These are the top rated real world Java examples of Class.getAnnotationsByType extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 private void addBind(Name moduleName, Class<?> event, String id) {
   List<Input> defaultInputs = Lists.newArrayList();
   for (Annotation annotation : event.getAnnotationsByType(DefaultBinding.class)) {
     DefaultBinding defaultBinding = (DefaultBinding) annotation;
     Input input = defaultBinding.type().getInput(defaultBinding.id());
     if (!data.values().contains(input)) {
       defaultInputs.add(input);
     }
   }
   SimpleUri bindUri = new SimpleUri(moduleName, id);
   setBinds(bindUri, defaultInputs);
 }
Example #2
0
  public static void execute(final Class<?> clazz) {
    try {
      final Method method = clazz.getMethod("main", String[].class);
      final Annotation[] annotations = clazz.getAnnotationsByType(TestDrive.class);

      for (final Annotation annotation : annotations) {
        final TestDrive td = (TestDrive) annotation;
        StdOut.printf("java %s %s%n", clazz.getSimpleName(), Arrays.deepToString(td.value()));

        final String[] value = td.value();
        if (td.valueFile()) {
          for (int i = 0; i < value.length; i++) {
            value[i] = RESOURCES_PATH + value[i];
          }
        }

        if (td.input().length > 0) {
          System.setIn(
              new ByteArrayInputStream(
                  Arrays.stream(getInputValue(td)).collect(Collectors.joining(" ")).getBytes()));

          final Method resync = StdIn.class.getDeclaredMethod("resync");
          resync.setAccessible(true);
          resync.invoke(null);
        }

        method.invoke(null, (Object) value);
      }
    } catch (IllegalArgumentException
        | NoSuchMethodException
        | SecurityException
        | IllegalAccessException exception) {
      StdOut.println(exception.getMessage());
      StdOut.println(exception);
    } catch (final InvocationTargetException exception) {
      StdOut.println(exception.getMessage());
      StdOut.println(exception);
      StdOut.println(exception.getTargetException());
    }
  }