mirror of
https://github.com/openjdk/jdk.git
synced 2026-08-03 14:47:03 +00:00
Address review suggestions.
This commit is contained in:
parent
8d822b1119
commit
2b16d65758
@ -47,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
@ -94,7 +95,8 @@ public class ClassGenerator {
|
||||
WILDCARDS_EXTENDS("wildcards.extends"),
|
||||
SUPPRESS_WARNINGS("suppress.warnings"),
|
||||
LINT_CATEGORY("lint.category"),
|
||||
DIAGNOSTIC_FLAGS("diagnostic.flags");
|
||||
DIAGNOSTIC_FLAGS_EMPTY("diagnostic.flags.empty"),
|
||||
DIAGNOSTIC_FLAGS_NON_EMPTY("diagnostic.flags.non-empty");
|
||||
|
||||
/** stub key (as it appears in the property file) */
|
||||
String key;
|
||||
@ -264,7 +266,8 @@ public class ClassGenerator {
|
||||
.filter(MessageLine::isDiagnosticFlags)
|
||||
.map(MessageLine::diagnosticFlags)
|
||||
.flatMap(Stream::of)
|
||||
.map(s -> "\"" + s + "\"")
|
||||
.map(s -> s.replace('-', '_'))
|
||||
.map(s -> s.toUpperCase(Locale.ROOT))
|
||||
.collect(Collectors.joining(", "));
|
||||
String factoryName = factoryName(key);
|
||||
if (msgInfo.getTypes().isEmpty()) {
|
||||
@ -272,13 +275,17 @@ public class ClassGenerator {
|
||||
String factoryField;
|
||||
if (lintCategory == null) {
|
||||
factoryField = StubKind.FACTORY_FIELD.format(k.keyClazz, factoryName,
|
||||
!diagnosticFlags.isEmpty() ? StubKind.DIAGNOSTIC_FLAGS.format(diagnosticFlags) : "null",
|
||||
diagnosticFlags.isEmpty() ?
|
||||
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
|
||||
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
|
||||
"\"" + keyParts[0] + "\"",
|
||||
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
|
||||
javadoc);
|
||||
} else {
|
||||
factoryField = StubKind.FACTORY_FIELD_LINT.format(k.keyClazz, factoryName,
|
||||
!diagnosticFlags.isEmpty() ? StubKind.DIAGNOSTIC_FLAGS.format(diagnosticFlags) : "null",
|
||||
diagnosticFlags.isEmpty() ?
|
||||
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
|
||||
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
|
||||
StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""),
|
||||
"\"" + keyParts[0] + "\"",
|
||||
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
|
||||
@ -296,13 +303,17 @@ public class ClassGenerator {
|
||||
String methodBody;
|
||||
if (lintCategory == null) {
|
||||
methodBody = StubKind.FACTORY_METHOD_BODY.format(k.keyClazz,
|
||||
!diagnosticFlags.isEmpty() ? StubKind.DIAGNOSTIC_FLAGS.format(diagnosticFlags) : "null",
|
||||
diagnosticFlags.isEmpty() ?
|
||||
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
|
||||
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
|
||||
"\"" + keyParts[0] + "\"",
|
||||
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
|
||||
argNames.stream().collect(Collectors.joining(", ")));
|
||||
} else {
|
||||
methodBody = StubKind.FACTORY_METHOD_BODY_LINT.format(k.keyClazz,
|
||||
!diagnosticFlags.isEmpty() ? StubKind.DIAGNOSTIC_FLAGS.format(diagnosticFlags) : "null",
|
||||
diagnosticFlags.isEmpty() ?
|
||||
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
|
||||
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
|
||||
StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""),
|
||||
"\"" + keyParts[0] + "\"",
|
||||
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
|
||||
|
||||
@ -35,8 +35,9 @@ toplevel.decl=\
|
||||
import com.sun.tools.javac.util.JCDiagnostic.Fragment;\n\
|
||||
import com.sun.tools.javac.code.Lint.LintCategory;\n\
|
||||
\n\
|
||||
import java.util.Locale;\n\
|
||||
import java.util.stream.Stream;\n\
|
||||
import java.util.EnumSet;\n\
|
||||
\n\
|
||||
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;\n\
|
||||
\n\
|
||||
public class {2} '{'\n\
|
||||
{3}\n\
|
||||
@ -88,10 +89,9 @@ suppress.warnings=\
|
||||
lint.category=\
|
||||
LintCategory.get({0}).get()
|
||||
|
||||
diagnostic.flags=\n\
|
||||
' 'Stream.of({0})\n\
|
||||
' '.map(s -> s.replace(''-'', ''_''))\n\
|
||||
' '.map(s -> s.toUpperCase(Locale.ROOT))\n\
|
||||
' '.map(DiagnosticFlag::valueOf)\n\
|
||||
' '.toArray(DiagnosticFlag[]::new)
|
||||
diagnostic.flags.empty=\
|
||||
EnumSet.noneOf(DiagnosticFlag.class)
|
||||
|
||||
diagnostic.flags.non-empty=\
|
||||
EnumSet.of({0})
|
||||
|
||||
|
||||
@ -509,8 +509,8 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
/** The diagnostic kind (i.e. error). */
|
||||
DiagnosticType type;
|
||||
|
||||
/** A set of diagnostic flags to be automatically added to newly created JCDiagnostics (if not null). */
|
||||
DiagnosticFlag[] flags;
|
||||
/** A set of diagnostic flags to be automatically added to newly created JCDiagnostics. */
|
||||
Set<DiagnosticFlag> flags;
|
||||
|
||||
/** The diagnostic prefix (i.e. 'javac'); used to compute full resource key. */
|
||||
String prefix;
|
||||
@ -522,9 +522,9 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
/** The diagnostic arguments. */
|
||||
Object[] args;
|
||||
|
||||
private DiagnosticInfo(DiagnosticType type, DiagnosticFlag[] flags, String prefix, String code, Object... args) {
|
||||
private DiagnosticInfo(DiagnosticType type, Set<DiagnosticFlag> flags, String prefix, String code, Object... args) {
|
||||
this.type = type;
|
||||
this.flags = flags;
|
||||
this.flags = flags != null ? flags : EnumSet.noneOf(DiagnosticFlag.class);
|
||||
this.prefix = prefix;
|
||||
this.code = code;
|
||||
this.args = args;
|
||||
@ -540,11 +540,12 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
/**
|
||||
* Static factory method; build a custom diagnostic key using given kind, prefix, code and args.
|
||||
*/
|
||||
public static DiagnosticInfo of(DiagnosticType type, DiagnosticFlag[] flags, String prefix, String code, Object... args) {
|
||||
public static DiagnosticInfo of(DiagnosticType type, Set<DiagnosticFlag> flags,
|
||||
String prefix, String code, Object... args) {
|
||||
return of(type, flags, null, prefix, code, args);
|
||||
}
|
||||
|
||||
public static DiagnosticInfo of(DiagnosticType type, DiagnosticFlag[] flags,
|
||||
public static DiagnosticInfo of(DiagnosticType type, Set<DiagnosticFlag> flags,
|
||||
LintCategory lc, String prefix, String code, Object... args) {
|
||||
switch (type) {
|
||||
case ERROR:
|
||||
@ -582,7 +583,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
}
|
||||
|
||||
public boolean hasFlag(DiagnosticFlag flag) {
|
||||
return flags != null && Arrays.asList(flags).contains(flag);
|
||||
return flags.contains(flag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -590,7 +591,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* Class representing error diagnostic keys.
|
||||
*/
|
||||
public static final class Error extends DiagnosticInfo {
|
||||
public Error(DiagnosticFlag[] flags, String prefix, String key, Object... args) {
|
||||
public Error(Set<DiagnosticFlag> flags, String prefix, String key, Object... args) {
|
||||
super(DiagnosticType.ERROR, flags, prefix, key, args);
|
||||
}
|
||||
}
|
||||
@ -599,7 +600,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* Class representing warning diagnostic keys.
|
||||
*/
|
||||
public static sealed class Warning extends DiagnosticInfo {
|
||||
public Warning(DiagnosticFlag[] flags, String prefix, String key, Object... args) {
|
||||
public Warning(Set<DiagnosticFlag> flags, String prefix, String key, Object... args) {
|
||||
super(DiagnosticType.WARNING, flags, prefix, key, args);
|
||||
}
|
||||
}
|
||||
@ -610,7 +611,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
public static final class LintWarning extends Warning {
|
||||
final LintCategory category;
|
||||
|
||||
public LintWarning(DiagnosticFlag[] flags, LintCategory category, String prefix, String key, Object... args) {
|
||||
public LintWarning(Set<DiagnosticFlag> flags, LintCategory category, String prefix, String key, Object... args) {
|
||||
super(flags, prefix, key, args);
|
||||
this.category = category;
|
||||
}
|
||||
@ -624,7 +625,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* Class representing note diagnostic keys.
|
||||
*/
|
||||
public static final class Note extends DiagnosticInfo {
|
||||
public Note(DiagnosticFlag[] flags, String prefix, String key, Object... args) {
|
||||
public Note(Set<DiagnosticFlag> flags, String prefix, String key, Object... args) {
|
||||
super(DiagnosticType.NOTE, flags, prefix, key, args);
|
||||
}
|
||||
}
|
||||
@ -633,7 +634,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* Class representing fragment diagnostic keys.
|
||||
*/
|
||||
public static final class Fragment extends DiagnosticInfo {
|
||||
public Fragment(DiagnosticFlag[] flags, String prefix, String key, Object... args) {
|
||||
public Fragment(Set<DiagnosticFlag> flags, String prefix, String key, Object... args) {
|
||||
super(DiagnosticType.FRAGMENT, flags, prefix, key, args);
|
||||
}
|
||||
}
|
||||
@ -680,11 +681,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
this.position = pos;
|
||||
this.rewriter = rewriter;
|
||||
|
||||
if (diagnosticInfo.flags != null) {
|
||||
for (DiagnosticFlag flag : diagnosticInfo.flags) {
|
||||
this.flags.add(flag);
|
||||
}
|
||||
}
|
||||
this.flags.addAll(diagnosticInfo.flags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user