private List<ParameterMeta> translate(final List<ParameterMeta> metas, final String name) { if (metas == null) { return null; } return metas .stream() .filter(it -> it.getName().equals(name)) .flatMap(it -> it.getNestedParameters().stream()) .collect(toList()); }
private Map.Entry<String, Object> normalize(final Map.Entry<String, Object> it, final List<ParameterMeta> metas) { return metas == null ? it : metas.stream().filter(m -> m.getName().equals(it.getKey())).findFirst().map(m -> { final String name = findName(m); if (name.equals(it.getKey())) { return it; } return new AbstractMap.SimpleEntry<>(name, it.getValue()); }).orElse(it); }
private String findName(final ParameterMeta meta) { return ofNullable(meta.getSource()).map(ParameterMeta.Source::name).orElse(meta.getName()); }
private String findName(final ParameterMeta m) { return ofNullable(m.getSource()).map(ParameterMeta.Source::name).orElse(m.getName()); }
private String findDocumentation(final ParameterMeta p) { final String inline = p.getMetadata().get("documentation"); if (inline != null) { if (inline.startsWith("resource:")) { final InputStream stream = Thread .currentThread() .getContextClassLoader() .getResourceAsStream(inline.substring("resource:".length())); if (stream != null) { try (final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) { return reader.lines().collect(joining("\n")); } catch (final IOException e) { throw new IllegalArgumentException("Bad resource: '" + inline + "'", e); } } else { throw new IllegalArgumentException("No resource: '" + inline + "'"); } } return inline; } return p.getName() + " configuration"; }
private <C, T, A> A create(final Class<A> api, final Class<T> componentType, final C configuration) { final ComponentFamilyMeta.BaseMeta<? extends Lifecycle> meta = findMeta(componentType); return api .cast(meta .getInstantiator() .apply(configuration == null || meta.getParameterMetas().isEmpty() ? emptyMap() : configurationByExample(configuration, meta .getParameterMetas() .stream() .filter(p -> p.getName().equals(p.getPath())) .findFirst() .map(p -> p.getName() + '.') .orElseThrow(() -> new IllegalArgumentException( "Didn't find any option and therefore " + "can't convert the configuration instance to a configuration"))))); }
private Object findField(final Object rootInstance, final ParameterMeta param) { if (param.getPath().startsWith("$") || param.getName().startsWith("$")) { // virtual param return null; } if (Collection.class.isInstance(rootInstance)) { return findCollectionField(rootInstance, param); } Class<?> current = rootInstance.getClass(); while (current != null) { try { final Field declaredField = current.getDeclaredField(findName(param)); if (!declaredField.isAccessible()) { declaredField.setAccessible(true); } return declaredField.get(rootInstance); } catch (final IllegalAccessException | NoSuchFieldException e) { // next } current = current.getSuperclass(); } throw new IllegalArgumentException("Didn't find field '" + param.getName() + "' in " + rootInstance); }
.getNestedParameters() .stream() .anyMatch(p -> it.startsWith(prefix + '.' + p.getName()))) .collect(toMap(identity(), config::get)); return factory.apply(configMap);
.getNestedParameters() .stream() .filter(field -> !fieldsInGridLayout.contains(field.getName())) .map(field -> "Field '" + field.getName() + "' in " + config.getKey() + " is not declared in any layout.") .forEach(this.log::error); .getNestedParameters() .stream() .filter(field -> !fieldsInOptionOrder.contains(field.getName())) .map(field -> "Field '" + field.getName() + "' in " + config.getKey() + " is not declared in any layout.") .forEach(this.log::error);
private void addProcessorsBuiltInParameters(final Class<?> type, final List<ParameterMeta> parameterMetas) { final ParameterMeta root = parameterMetas.stream().filter(p -> p.getName().equals(p.getPath())).findFirst().orElseGet(() -> { final ParameterMeta umbrella = new ParameterMeta(new ParameterMeta.Source() { final String layoutType = paramBuilder.getLayoutType(); if (layoutType == null) { root.getMetadata().put("tcomp::ui::gridlayout::Advanced::value", maxBatchSize.getName()); root .getMetadata() root .getMetadata() .put(layoutType, layoutType.contains("gridlayout") ? maxBatchSize.getName() : "true"); } else if (layoutType.contains("gridlayout")) { final String oldLayout = root.getMetadata().get(layoutType); root.getMetadata().put(layoutType, maxBatchSize.getName() + "|" + oldLayout);
private String toAsciidoctor(final ParameterMeta p, final DefaultValueInspector.Instance instance, final ParameterBundle parent) { final ParameterBundle bundle = findBundle(p); return "|" + bundle.displayName(parent).orElse(p.getName()) + '|' + bundle.documentation(parent).orElseGet(() -> findDocumentation(p)) + '|' + ofNullable(findDefault(p, instance)).orElse("-") + '|' + renderConditions(p.getPath(), p.getMetadata()) + '|' + p.getPath(); }
private void onProperty(final String contextualPrefix, final Collection<ParameterMeta> definitions, final Map<String, String> config, final JsonObjectBuilder json, final ParameterMeta definition) { final String name = definition.getName(); final String newPath = contextualPrefix + (contextualPrefix.isEmpty() ? "" : ".") + name; switch (definition.getType()) {
private ParameterMeta translate(final ParameterMeta config, final int replacedPrefixLen, final String newPrefix) { return new ParameterMeta(config.getSource(), config.getJavaType(), config.getType(), newPrefix + config.getPath().substring(replacedPrefixLen), config.getPath().length() == replacedPrefixLen ? newPrefix : config.getName(), config.getI18nPackages(), config .getNestedParameters() .stream() .map(it -> translate(it, replacedPrefixLen, newPrefix)) .collect(toList()), config.getProposals(), config.getMetadata(), config.isLogMissingResourceBundle()); } }
return meta.stream().flatMap(p -> { final String path = sanitizePropertyName(p.getPath()); final String name = sanitizePropertyName(p.getName()); final String type = p.getType().name(); final boolean isEnum = p.getType() == ParameterMeta.Type.ENUM; .concat(Stream .of(new SimplePropertyDefinition(path, name, bundle.displayName(parentBundle).orElse(p.getName()), type, toDefault(instance, p), validation, rewriteMetadataForLocale(metadata, parentBundle, bundle), bundle.placeholder(parentBundle).orElse(p.getName()), !isEnum ? null : p
private Class<?> toJavaType(final ParameterMeta p) { if (p.getType().equals(OBJECT) || p.getType().equals(ENUM)) { if (Class.class.isInstance(p.getJavaType())) { return Class.class.cast(p.getJavaType()); } throw new IllegalArgumentException("Unsupported type for parameter " + p.getPath() + " (from " + p.getSource().declaringClass() + "), ensure it is a Class<?>"); } if (p.getType().equals(ARRAY) && ParameterizedType.class.isInstance(p.getJavaType())) { final ParameterizedType parameterizedType = ParameterizedType.class.cast(p.getJavaType()); final Type[] arguments = parameterizedType.getActualTypeArguments(); if (arguments.length == 1 && Class.class.isInstance(arguments[0])) { return Class.class.cast(arguments[0]); } throw new IllegalArgumentException("Unsupported type for parameter " + p.getPath() + " (from " + p.getSource().declaringClass() + "), " + "ensure it is a ParameterizedType with one argument"); } throw new IllegalStateException("Parameter '" + p.getName() + "' is not an object."); }
final String forcedPrefix = c.getMeta().getName(); node .setProperties(propertiesService