Java 类org.springframework.boot.configurationmetadata.ValueHint 实例源码

项目:nb-springboot    文件:SpringBootServiceImpl.java   
@Override
public List<ValueHint> queryHintMetadata(String propertyName, String filter) {
    if (cpExec == null) {
        init();
    }
    List<ValueHint> ret = new LinkedList<>();
    ConfigurationMetadataProperty cfgMeta = getPropertyMetadata(propertyName);
    if (cfgMeta != null) {
        for (ValueHint valueHint : cfgMeta.getHints().getValueHints()) {
            if (filter == null || valueHint.getValue().toString().contains(filter)) {
                ret.add(valueHint);
            }
        }
    }
    return ret;
}
项目:spring-cloud-dataflow    文件:ProposalsCollectorSupportUtils.java   
void addValueHintsProposals(final String dsl, AppRegistration appRegistration, final List<CompletionProposal> collector, final String propertyName, final ValueHintProvider[] valueHintProviders){
    final Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration);
    if (metadataResource != null) {
        final URLClassLoader classLoader = metadataResolver.createAppClassLoader(metadataResource);
        this.doWithClassLoader(classLoader, () -> {
            CompletionProposal.Factory proposals = expanding(dsl);
            List<ConfigurationMetadataProperty> whiteList = metadataResolver.listProperties(metadataResource);
            for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource, true)) {
                if (CompletionUtils.isMatchingProperty(propertyName, property, whiteList)) {
                    for (ValueHintProvider valueHintProvider : valueHintProviders) {
                        for (ValueHint valueHint : valueHintProvider.generateValueHints(property, classLoader)) {
                            collector.add(proposals.withSuffix(String.valueOf(valueHint.getValue()),
                                    valueHint.getShortDescription()));
                        }
                    }
                }
            }
            return null;
        });
    }
}
项目:spring-cloud-dashboard    文件:EnumValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    List<ValueHint> result = new ArrayList<>();
    if (ClassUtils.isPresent(property.getType(), classLoader)) {
        Class<?> clazz = ClassUtils.resolveClassName(property.getType(), classLoader);
        if (clazz.isEnum()) {
            for (Object o : clazz.getEnumConstants()) {
                ValueHint hint = new ValueHint();
                hint.setValue(o);
                result.add(hint);
            }
        }
    }
    return result;
}
项目:nb-springboot    文件:CfgPropsCompletionProvider.java   
public void completePropValue(SpringBootService sbs, CompletionResultSet completionResultSet, String propName, String filter,
        int startOffset, int caretOffset) {
    long mark = System.currentTimeMillis();
    logger.log(FINER, "Completing property value: {0}", filter);
    for (ValueHint valueHint : sbs.queryHintMetadata(propName, filter)) {
        completionResultSet.addItem(new CfgPropValueCompletionItem(valueHint, startOffset, caretOffset));
    }
    final long elapsed = System.currentTimeMillis() - mark;
    logger.log(FINER, "Value completion of ''{0}'' on ''{1}'' took: {2} msecs", new Object[]{filter, propName, elapsed});
}
项目:nb-springboot    文件:CfgPropValueCompletionDocumentation.java   
@Override
public String getText() {
    ValueHint valueHint = item.getHint();
    StringBuilder sb = new StringBuilder();
    // name and type
    sb.append("<b>").append(valueHint.getValue()).append("</b>");
    final String description = valueHint.getDescription();
    if (description != null) {
        sb.append("<br/>").append(simpleHtmlEscape(description));
    }
    return sb.toString();
}
项目:spring-cloud-dataflow    文件:ProposalsCollectorSupportUtils.java   
boolean addAlreadyTypedValueHintsProposals(final String text, AppRegistration appRegistration, final List<CompletionProposal> collector, final String propertyName, final ValueHintProvider[] valueHintProviders, final String alreadyTyped){
    final Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration);
    if (metadataResource == null) {
        return false;
    }
    final URLClassLoader classLoader = metadataResolver.createAppClassLoader(metadataResource);
    return this.doWithClassLoader(classLoader, () -> {
        CompletionProposal.Factory proposals = expanding(text);
        List<ConfigurationMetadataProperty> allProps = metadataResolver.listProperties(metadataResource, true);
        List<ConfigurationMetadataProperty> whiteListedProps = metadataResolver.listProperties(metadataResource);
        for (ConfigurationMetadataProperty property : allProps) {
            if (CompletionUtils.isMatchingProperty(propertyName, property, whiteListedProps)) {
                for (ValueHintProvider valueHintProvider : valueHintProviders) {
                    List<ValueHint> valueHints = valueHintProvider.generateValueHints(property, classLoader);
                    if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
                        collector.clear();
                    }
                    for (ValueHint valueHint : valueHints) {
                        String candidate = String.valueOf(valueHint.getValue());
                        if (!candidate.equals(alreadyTyped) && candidate.startsWith(alreadyTyped)) {
                            collector.add(proposals.withSuffix(candidate.substring(alreadyTyped.length()),
                                    valueHint.getShortDescription()));
                        }
                    }
                    if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
                        return true;
                    }
                }
            }
        }
        return false;
    });
}
项目:spring-cloud-dataflow    文件:EnumValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    List<ValueHint> result = new ArrayList<>();
    if (ClassUtils.isPresent(property.getType(), classLoader)) {
        Class<?> clazz = ClassUtils.resolveClassName(property.getType(), classLoader);
        if (clazz.isEnum()) {
            for (Object o : clazz.getEnumConstants()) {
                ValueHint hint = new ValueHint();
                hint.setValue(o);
                result.add(hint);
            }
        }
    }
    return result;
}
项目:spring-cloud-dashboard    文件:DefaultValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    return property.getValueHints();
}
项目:spring-cloud-dashboard    文件:BooleanValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    return "java.lang.Boolean".equals(property.getType())
            ? BOOLEANS
            : Collections.<ValueHint>emptyList();
}
项目:nb-springboot    文件:CfgPropValueCompletionItem.java   
public CfgPropValueCompletionItem(ValueHint hint, int dotOffset, int caretOffset) {
    this.hint = hint;
    this.dotOffset = dotOffset;
    this.caretOffset = caretOffset;
}
项目:nb-springboot    文件:CfgPropValueCompletionItem.java   
public ValueHint getHint() {
    return hint;
}
项目:nb-springboot    文件:CfgPropCompletionDocumentation.java   
@Override
public String getText() {
    ConfigurationMetadataProperty configurationMeta = item.getConfigurationMetadata();
    StringBuilder sb = new StringBuilder();
    // name and type
    sb.append("<b>").append(configurationMeta.getId()).append("</b>");
    sb.append("<br/>").append(simpleHtmlEscape(configurationMeta.getType()));
    // deprecation (optional)
    Deprecation deprecation = configurationMeta.getDeprecation();
    if (deprecation != null) {
        sb.append("<br/><br/><b><i>");
        if (Utils.isErrorDeprecated(configurationMeta)) {
            sb.append("REMOVED");
        } else {
            sb.append("Deprecated");
        }
        // deprecation reason if present
        String reason = deprecation.getReason();
        if (reason != null) {
            sb.append(":</i></b> ").append(simpleHtmlEscape(reason));
        } else {
            sb.append("</i></b>");
        }
        String replacement = deprecation.getReplacement();
        if (replacement != null) {
            sb.append("<br/><i>Replaced by:</i> <code>").append(replacement).append("</code>");
        }
    }
    // default value (optional)
    final Object defaultValue = configurationMeta.getDefaultValue();
    if (null != defaultValue) {
        sb.append("<br/><br/><i>Default:</i> ");
        if (defaultValue instanceof Object[]) {
            sb.append(Arrays.toString((Object[]) defaultValue));
        } else {
            sb.append(String.valueOf(defaultValue));
        }
    }
    // description (optional)
    final String description = configurationMeta.getDescription();
    if (description != null) {
        sb.append("<br/><br/>").append(description);
    }
    // list of values (optional)
    Hints hints = configurationMeta.getHints();
    List<ValueHint> valueHints = hints.getValueHints();
    if (valueHints != null && !valueHints.isEmpty()) {
        sb.append("<br/><br/><table><tr><td><i>Value</i></td><td><i>Description</i></td></tr>");
        for (ValueHint vHint : valueHints) {
            sb.append("<tr><td>").append(vHint.getValue()).append("</td><td>");
            final String vDesc = vHint.getDescription();
            if (vDesc != null) {
                sb.append(simpleHtmlEscape(vDesc)).append("</th></tr>");
            }
        }
        sb.append("</table>");
    }
    return sb.toString();
}
项目:spring-cloud-dataflow    文件:DefaultValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    return property.getHints().getValueHints();
}
项目:spring-cloud-dataflow    文件:BooleanValueHintProvider.java   
@Override
public List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader) {
    return "java.lang.Boolean".equals(property.getType()) ? BOOLEANS : Collections.<ValueHint>emptyList();
}
项目:spring-cloud-dashboard    文件:ValueHintProvider.java   
/**
 * For a given property, return a list of {@link ValueHint} that may apply.
 *
 * @param property     property for which to generate value hints
 * @param classLoader  class loader for the artifact/module that this
 * property applies to; this may be used to load other classes/resources
 * for generating value hints
 * @return list of value hints for the provided property
 */
List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader);
项目:spring-cloud-dataflow    文件:ValueHintProvider.java   
/**
 * For a given property, return a list of {@link ValueHint} that may apply.
 *
 * @param property property for which to generate value hints
 * @param classLoader class loader for the artifact/module that this property applies
 * to; this may be used to load other classes/resources for generating value hints
 * @return list of value hints for the provided property
 */
List<ValueHint> generateValueHints(ConfigurationMetadataProperty property, ClassLoader classLoader);
项目:nb-springboot    文件:SpringBootService.java   
List<ValueHint> queryHintMetadata(String propertyName, String filter);