org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty#getDeprecation ( )源码实例Demo

下面列出了org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty#getDeprecation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: nb-springboot   文件: 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
 */
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();
}
 
@Override
protected void internalRun(CfgPropsParser.CfgPropsParserResult cfgResult, SchedulerEvent se, BaseDocument document,
        List<ErrorDescription> errors, Severity unused) {
    logger.fine("Highlighting deprecated properties");
    final Project prj = Utils.getActiveProject();
    if (prj != null) {
        final SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
        if (sbs != null) {
            for (PairElement pair : cfgResult.getCfgFile().getElements()) {
                final CfgElement key = pair.getKey();
                final CfgElement value = pair.getValue();
                final String pName = key.getText();
                ConfigurationMetadataProperty cfgMeta = sbs.getPropertyMetadata(pName);
                if (cfgMeta != null && cfgMeta.getDeprecation() != null) {
                    try {
                        final Deprecation deprecation = cfgMeta.getDeprecation();
                        List<Fix> fixes = new ArrayList<>();
                        final int start = key.getIdxStart();
                        int end = value != null ? value.getIdxEnd() : key.getIdxEnd();
                        fixes.add(new DeletePropFix((StyledDocument) document, key.getText(), key.getIdxStart(), end));
                        if (deprecation.getReplacement() != null) {
                            end = key.getIdxEnd();
                            fixes.add(new ReplacePropFix((StyledDocument) document, start, end, deprecation.getReplacement()));
                        }
                        Deprecation.Level deprLevel = deprecation.getLevel();
                        ErrorDescription errDesc;
                        if (deprLevel == ERROR) {
                            errDesc = ErrorDescriptionFactory.createErrorDescription(
                                    Severity.ERROR,
                                    String.format("No more supported Spring Boot property '%s'", pName),
                                    fixes,
                                    document,
                                    document.createPosition(start),
                                    document.createPosition(end)
                            );
                        } else {
                            errDesc = ErrorDescriptionFactory.createErrorDescription(
                                    Severity.WARNING,
                                    String.format("Deprecated Spring Boot property '%s'", pName),
                                    fixes,
                                    document,
                                    document.createPosition(start),
                                    document.createPosition(end)
                            );
                        }
                        errors.add(errDesc);
                    } catch (BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                if (canceled) {
                    break;
                }
            }
        }
    }
    if (!errors.isEmpty()) {
        logger.log(Level.FINE, "Found {0} deprecated properties", errors.size());
    }
}
 
源代码3 项目: nb-springboot   文件: Utils.java
public static boolean isErrorDeprecated(ConfigurationMetadataProperty meta) {
    Deprecation depr = meta.getDeprecation();
    return depr != null && depr.getLevel() != null && depr.getLevel().equals(Deprecation.Level.ERROR);
}
 
/**
 * Checks if property is error deprecated.
 *
 * @param property the configuration property
 * @return if property is error deprecated
 */
private boolean isDeprecatedError(ConfigurationMetadataProperty property) {
	return property.getDeprecation() != null && property.getDeprecation().getLevel() == Level.ERROR;
}