コード例 #1
0
 /**
  * get types annotated with a given annotation, both classes and annotations
  *
  * <p>{@link java.lang.annotation.Inherited} is honored according to given honorInherited.
  *
  * <p>when honoring @Inherited, meta-annotation should only effect annotated super classes and
  * it's sub types
  *
  * <p>when not honoring @Inherited, meta annotation effects all subtypes, including annotations
  * interfaces and classes
  *
  * <p><i>Note that this (@Inherited) meta-annotation type has no effect if the annotated type is
  * used for anything other then a class. Also, this meta-annotation causes annotations to be
  * inherited only from superclasses; annotations on implemented interfaces have no effect.</i>
  *
  * <p>depends on TypeAnnotationsScanner and SubTypesScanner configured
  */
 public Set<Class<?>> getTypesAnnotatedWith(
     final Class<? extends Annotation> annotation, boolean honorInherited) {
   Iterable<String> annotated =
       store.get(index(TypeAnnotationsScanner.class), annotation.getName());
   Iterable<String> classes =
       getAllAnnotated(annotated, annotation.isAnnotationPresent(Inherited.class), honorInherited);
   return Sets.newHashSet(concat(forNames(annotated, loaders()), forNames(classes, loaders())));
 }
コード例 #2
0
 private QueryMethod chooseQueryMethodStrategy(
     Method method, RepositoryMetadata metadata, Class<?> repositoryInterface) {
   QueryMethod queryMethod;
   boolean paramAnnotation = false;
   if ((paramAnnotation = hasParamAnnotation(method))
       || repositoryInterface.isAnnotationPresent(Namespace.class)
       || method.isAnnotationPresent(Statement.class)) {
     queryMethod = new AnnotationBasedSqlMapQueryMethod(method, metadata, paramAnnotation);
   } else {
     queryMethod = new QueryMethod(method, metadata);
   }
   return queryMethod;
 }
コード例 #3
0
  private static void convertProtocolToAsciidocTable(Properties props, Class<Protocol> clazz)
      throws Exception {
    boolean isUnsupported = clazz.isAnnotationPresent(Unsupported.class);
    if (isUnsupported) return;

    Map<String, String> nameToDescription = new TreeMap<>();

    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
      if (field.isAnnotationPresent(Property.class)) {
        String property = field.getName();
        Property annotation = field.getAnnotation(Property.class);
        String desc = annotation.description();
        nameToDescription.put(property, desc);
      }
    }

    // iterate methods
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      if (method.isAnnotationPresent(Property.class)) {

        Property annotation = method.getAnnotation(Property.class);
        String desc = annotation.description();

        if (desc == null || desc.isEmpty()) desc = "n/a";

        String name = annotation.name();
        if (name.length() < 1) {
          name = Util.methodNameToAttributeName(method.getName());
        }
        nameToDescription.put(name, desc);
      }
    }

    // do we have more than one property (superclass Protocol has only one property (stats))
    if (nameToDescription.isEmpty()) return;

    List<String[]> rows = new ArrayList<>(nameToDescription.size() + 1);
    rows.add(new String[] {"Name", "Description"});
    for (Map.Entry<String, String> entry : nameToDescription.entrySet())
      rows.add(new String[] {entry.getKey(), entry.getValue()});

    String tmp =
        createAsciidocTable(
            rows,
            clazz.getSimpleName(),
            "[align=\"left\",width=\"90%\",cols=\"2,10\",options=\"header\"]");
    props.put(clazz.getSimpleName(), tmp);
  }
コード例 #4
0
  /** Get the Plugin annotation for the class */
  static Plugin getPluginMetadata(final Class<?> cls) throws PluginException {
    // try to get plugin provider name
    final String pluginname;
    if (!cls.isAnnotationPresent(Plugin.class)) {
      throw new PluginException("No Plugin annotation was found for the class: " + cls.getName());
    }

    final Plugin annotation = (Plugin) cls.getAnnotation(Plugin.class);
    pluginname = annotation.name();
    if (null == pluginname || "".equals(pluginname)) {
      throw new PluginException(
          "Plugin annotation 'name' cannot be empty for the class: " + cls.getName());
    }
    // get service name from annotation
    final String servicename = annotation.service();
    if (null == servicename || "".equals(servicename)) {
      throw new PluginException(
          "Plugin annotation 'service' cannot be empty for the class: " + cls.getName());
    }
    return annotation;
  }