/** * Returns description for the plugin. */ private String getPluginDescription(Class<?> cls) { Description annotation = cls.getAnnotation(Description.class); return annotation == null ? "" : annotation.value(); }
/** * Returns description for the plugin. */ private String getPluginDescription(Class<?> cls) { Description annotation = cls.getAnnotation(Description.class); return annotation == null ? "" : annotation.value(); }
/** * Adds a class that extends from <code>AbstractDirective</code> to usage registry. * * @param classz representing an AbstractDirective</code> implementation. */ public void addUsage(Class<? extends Executor> classz) { Name name = classz.getAnnotation(Name.class); Description description = classz.getAnnotation(Description.class); Usage usage = classz.getAnnotation(Usage.class); if (usage == null || name == null || description == null) { return; } usages.put(name.value(), new UsageEntry(name.value(), usage.value(), description.value())); usageList.add(new UsageEntry(name.value(), usage.value(), description.value())); }
/** * Creates a {@link PluginPropertyField} based on the given field. */ private PluginPropertyField createPluginProperty(Field field, TypeToken<?> resolvingType) throws UnsupportedTypeException { TypeToken<?> fieldType = resolvingType.resolveType(field.getGenericType()); Class<?> rawType = fieldType.getRawType(); Name nameAnnotation = field.getAnnotation(Name.class); Description descAnnotation = field.getAnnotation(Description.class); String name = nameAnnotation == null ? field.getName() : nameAnnotation.value(); String description = descAnnotation == null ? "" : descAnnotation.value(); Macro macroAnnotation = field.getAnnotation(Macro.class); boolean macroSupported = macroAnnotation != null; if (rawType.isPrimitive()) { return new PluginPropertyField(name, description, rawType.getName(), true, macroSupported); } rawType = Primitives.unwrap(rawType); if (!rawType.isPrimitive() && !String.class.equals(rawType)) { throw new UnsupportedTypeException("Only primitive and String types are supported"); } boolean required = true; for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType().getName().endsWith(".Nullable")) { required = false; break; } } return new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported); }
/** * Creates a {@link PluginPropertyField} based on the given field. */ private PluginPropertyField createPluginProperty(Field field, TypeToken<?> resolvingType) throws UnsupportedTypeException { TypeToken<?> fieldType = resolvingType.resolveType(field.getGenericType()); Class<?> rawType = fieldType.getRawType(); Name nameAnnotation = field.getAnnotation(Name.class); Description descAnnotation = field.getAnnotation(Description.class); String name = nameAnnotation == null ? field.getName() : nameAnnotation.value(); String description = descAnnotation == null ? "" : descAnnotation.value(); Macro macroAnnotation = field.getAnnotation(Macro.class); boolean macroSupported = macroAnnotation != null; if (rawType.isPrimitive()) { return new PluginPropertyField(name, description, rawType.getName(), true, macroSupported); } rawType = Primitives.unwrap(rawType); if (!rawType.isPrimitive() && !String.class.equals(rawType)) { throw new UnsupportedTypeException("Only primitive and String types are supported"); } boolean required = true; for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType().getName().endsWith(".Nullable")) { required = false; break; } } return new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported); }
public DirectiveInfo(Scope scope, Class<?> directive) throws IllegalAccessException, InstantiationException { this.scope = scope; this.directive = directive; Object object = directive.newInstance(); this.definition = ((Directive) object).define(); if (definition != null) { this.usage = definition.toString(); } else { this.usage = "No definition available for directive '" + directive + "'"; } this.name = directive.getAnnotation(Name.class).value(); Description desc = directive.getAnnotation(Description.class); if (desc == null) { this.description = "No description specified for directive class '" + directive.getSimpleName() + "'"; } else { this.description = desc.value(); } Deprecated annotation = directive.getAnnotation(Deprecated.class); if (annotation == null) { deprecated = false; } else { deprecated = true; } Categories category = directive.getAnnotation(Categories.class); if (category == null) { categories = new String[] { "default" }; } else { categories = category.categories(); } }