本文整理汇总了Java中javax.tools.Diagnostic.Kind.MANDATORY_WARNING属性的典型用法代码示例。如果您正苦于以下问题:Java Kind.MANDATORY_WARNING属性的具体用法?Java Kind.MANDATORY_WARNING怎么用?Java Kind.MANDATORY_WARNING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.tools.Diagnostic.Kind
的用法示例。
在下文中一共展示了Kind.MANDATORY_WARNING属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportMessage
private void reportMessage(Diagnostic.Kind messageKind, String message, Object... parameters) {
if (messageKind == Kind.WARNING || messageKind == Kind.MANDATORY_WARNING) {
SuppressedWarnings suppressed = SuppressedWarnings.forElement(getElement(), false, false);
if (suppressed.immutables) {
return;
}
}
String formattedMessage = String.format(message, parameters);
if (element().isPresent() && annotation().isPresent()) {
messager().printMessage(messageKind, formattedMessage, getElement(), getAnnotation());
} else if (element().isPresent()) {
messager().printMessage(messageKind, formattedMessage, getElement());
} else {
messager().printMessage(messageKind, formattedMessage);
}
}
示例2: check
void check(Result<?> res) {
EnumSet<WarningKind> foundWarnings = EnumSet.noneOf(WarningKind.class);
for (Diagnostic.Kind kind : new Kind[] { Kind.ERROR, Kind.MANDATORY_WARNING, Kind.WARNING}) {
for (Diagnostic<? extends JavaFileObject> diag : res.diagnosticsForKind(kind)) {
for (WarningKind wk : WarningKind.values()) {
if (wk.code.equals(diag.getCode())) {
foundWarnings.add(wk);
}
}
}
}
EnumSet<WarningKind> expectedWarnings =
EnumSet.noneOf(WarningKind.class);
if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
suppressLevel != SuppressLevel.VARARGS &&
xlint != XlintOption.NONE &&
sig.isVarargs &&
!sig.isReifiableArg &&
body.hasAliasing &&
(methKind == MethodKind.CONSTRUCTOR ||
(methKind == MethodKind.METHOD &&
modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0)))) {
expectedWarnings.add(WarningKind.UNSAFE_BODY);
}
if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.DONT_TRUST &&
sig.isVarargs &&
!sig.isReifiableArg &&
xlint == XlintOption.ALL) {
expectedWarnings.add(WarningKind.UNSAFE_DECL);
}
if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
(!sig.isVarargs ||
((modKind == ModifierKind.NONE ||
modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) < 0 ) &&
methKind == MethodKind.METHOD))) {
expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
}
if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
xlint != XlintOption.NONE &&
suppressLevel != SuppressLevel.VARARGS &&
(modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0) ||
methKind == MethodKind.CONSTRUCTOR) &&
sig.isVarargs &&
sig.isReifiableArg) {
expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS);
}
if (!expectedWarnings.containsAll(foundWarnings) ||
!foundWarnings.containsAll(expectedWarnings)) {
fail("invalid diagnostics for source:\n" +
res.compilationInfo() +
"\nOptions: " + xlint.getXlintOption() +
"\nSource Level: " + sourceLevel +
"\nExpected warnings: " + expectedWarnings +
"\nFound warnings: " + foundWarnings);
}
}