Example usage for org.springframework.boot.configurationmetadata ConfigurationMetadataProperty getType

List of usage examples for org.springframework.boot.configurationmetadata ConfigurationMetadataProperty getType

Introduction

In this page you can find the example usage for org.springframework.boot.configurationmetadata ConfigurationMetadataProperty getType.

Prototype

public String getType() 

Source Link

Document

The class name of the data type of the property.

Usage

From source file:com.github.alexfalappa.nbspringboot.Utils.java

/**
 * Builds an HTML formatted string with details on a Spring Boot configuration property extracted from its {@code ItemMetadata}.
 *
 * @param cfgMeta the configuration property metadata object
 * @return the HTML formatted configuration property details
 *///  w  ww.  j  a  v  a 2s.  c  o  m
public static String cfgPropDetailsHtml(ConfigurationMetadataProperty cfgMeta) {
    StringBuilder sb = new StringBuilder();
    // deprecation (optional)
    Deprecation deprecation = cfgMeta.getDeprecation();
    if (deprecation != null) {
        sb.append("<b>");
        if (isErrorDeprecated(cfgMeta)) {
            sb.append("REMOVED");
        } else {
            sb.append("Deprecated");
        }
        sb.append("</b>");
        // deprecation reason if present
        String reason = deprecation.getReason();
        if (reason != null) {
            sb.append(": ").append(simpleHtmlEscape(reason));
        }
        sb.append("<br/>");
        String replacement = deprecation.getReplacement();
        if (replacement != null) {
            sb.append("<i>Replaced by:</i> <tt>").append(replacement).append("</tt><br/>");
        }
    }
    // description (optional)
    final String description = cfgMeta.getDescription();
    if (description != null) {
        sb.append(description).append("<br/>");
    }
    // type
    sb.append("<tt>").append(simpleHtmlEscape(shortenJavaType(cfgMeta.getType()))).append("</tt>");
    return sb.toString();
}

From source file:com.github.alexfalappa.nbspringboot.cfgprops.completion.CfgPropCompletionItem.java

public CfgPropCompletionItem(ConfigurationMetadataProperty configurationMeta, SpringBootService bootService,
        int propStartOffset, int caretOffset, boolean sortDeprLast) {
    this.overwrite = false;
    this.configurationMeta = configurationMeta;
    if (configurationMeta.getType() != null) {
        type = simpleHtmlEscape(shortenJavaType(configurationMeta.getType()));
    } else {//from ww w  . j a  v a  2  s.  c  om
        type = null;
    }
    this.bootService = bootService;
    this.propStartOffset = propStartOffset;
    this.caretOffset = caretOffset;
    this.sortDeprLast = sortDeprLast;
}

From source file:com.github.alexfalappa.nbspringboot.cfgprops.completion.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 {//from w w w.  ja  va2  s . c  o m
            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();
}

From source file:com.github.alexfalappa.nbspringboot.cfgprops.highlighting.DataTypeMismatchHighlightingTask.java

@Override
protected void internalRun(CfgPropsParser.CfgPropsParserResult cfgResult, SchedulerEvent se, Document document,
        List<ErrorDescription> errors, Severity severity) {
    logger.fine("Highlighting data type mismatches");
    final Project prj = Utilities.actionsGlobalContext().lookup(Project.class);
    if (prj != null) {
        final SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
        final ClassPath cp = getProjectClasspath(prj);
        if (sbs != null && cp != null) {
            final Map<Integer, Pair<String, String>> propLines = cfgResult.getPropLines();
            for (Map.Entry<Integer, Pair<String, String>> entry : propLines.entrySet()) {
                int line = entry.getKey();
                String pName = entry.getValue().first();
                String pValue = entry.getValue().second();
                ConfigurationMetadataProperty cfgMeta = sbs.getPropertyMetadata(pName);
                if (cfgMeta == null) {
                    // try to interpret array notation (strip '[index]' from pName)
                    Matcher mArrNot = pArrayNotation.matcher(pName);
                    if (mArrNot.matches()) {
                        cfgMeta = sbs.getPropertyMetadata(mArrNot.group(1));
                    } else {
                        // try to interpret map notation (see if pName starts with a set of known map props)
                        for (String mapPropertyName : sbs.getMapPropertyNames()) {
                            if (pName.startsWith(mapPropertyName)) {
                                cfgMeta = sbs.getPropertyMetadata(mapPropertyName);
                                break;
                            }//from  ww  w.j  a  va 2 s  .  c  om
                        }
                    }
                }
                if (cfgMeta != null) {
                    final String type = cfgMeta.getType();
                    final ClassLoader cl = cp.getClassLoader(true);
                    if (type.contains("<")) {
                        // maps
                        Matcher mMap = pTwoGenTypeArgs.matcher(type);
                        if (mMap.matches() && mMap.groupCount() == 3) {
                            String keyType = mMap.group(2);
                            check(keyType, pName.substring(pName.lastIndexOf('.') + 1), document, line, errors,
                                    cl, severity);
                            String valueType = mMap.group(3);
                            check(valueType, pValue, document, line, errors, cl, severity);
                        }
                        // collections
                        Matcher mColl = pOneGenTypeArg.matcher(type);
                        if (mColl.matches() && mColl.groupCount() == 2) {
                            String genericType = mColl.group(2);
                            if (pValue.contains(",")) {
                                for (String val : pValue.split("\\s*,\\s*")) {
                                    check(genericType, val, document, line, errors, cl, severity);
                                }
                            } else {
                                check(genericType, pValue, document, line, errors, cl, severity);
                            }
                        }
                    } else {
                        if (pValue.contains(",") && type.endsWith("[]")) {
                            for (String val : pValue.split("\\s*,\\s*")) {
                                check(type.substring(0, type.length() - 2), val, document, line, errors, cl,
                                        severity);
                            }
                        } else {
                            if (type.endsWith("[]")) {
                                check(type.substring(0, type.length() - 2), pValue, document, line, errors, cl,
                                        severity);
                            } else {
                                check(type, pValue, document, line, errors, cl, severity);
                            }
                        }
                    }
                }
            }
        }
    }
    if (!errors.isEmpty()) {
        logger.log(Level.FINE, "Found {0} data type mismatches", errors.size());
    }
}