public class TestDiagnosticUtils extends Object
Modifier and Type | Field and Description |
---|---|
static Pattern |
DIAGNOSTIC_FILE_PATTERN |
static String |
DIAGNOSTIC_FILE_REGEX |
static Pattern |
DIAGNOSTIC_FILE_WARNING_PATTERN |
static String |
DIAGNOSTIC_FILE_WARNING_REGEX |
static Pattern |
DIAGNOSTIC_IN_JAVA_PATTERN
How the diagnostics appear in Java source files.
|
static String |
DIAGNOSTIC_IN_JAVA_REGEX
How the diagnostics appear in Java source files.
|
static Pattern |
DIAGNOSTIC_PATTERN |
static String |
DIAGNOSTIC_REGEX |
static Pattern |
DIAGNOSTIC_WARNING_IN_JAVA_PATTERN |
static String |
DIAGNOSTIC_WARNING_IN_JAVA_REGEX |
static Pattern |
DIAGNOSTIC_WARNING_PATTERN |
static String |
DIAGNOSTIC_WARNING_REGEX |
Constructor and Description |
---|
TestDiagnosticUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
continuationPart(String originalLine)
Return the continuation part.
|
static List<String> |
diagnosticsToString(List<TestDiagnostic> diagnostics)
Converts the given diagnostics to strings (as they would appear in a source file individually).
|
static Pair<String,String> |
formatJavaxToolString(String original,
boolean noMsgText)
Given a javax diagnostic, return a pair of (trimmed, fileame), where "trimmed" is the first
line of the message, without the leading filename.
|
static TestDiagnosticLine |
fromDiagnosticFileLine(String diagnosticLine)
Convert a line in a DiagnosticFile to a TestDiagnosticLine.
|
static TestDiagnostic |
fromDiagnosticFileString(String stringFromDiagnosticFile)
Instantiate the diagnostic based on a string that would appear in diagnostic files (i.e.
|
static TestDiagnostic |
fromJavaFileComment(String filename,
long lineNumber,
String stringFromJavaFile)
Instantiate the diagnostic from a string that would appear in a Java file, e.g.: "error:
(message)"
|
static TestDiagnosticLine |
fromJavaSourceLine(String filename,
String line,
long lineNumber)
Convert a line in a Java source file to a TestDiagnosticLine.
|
static Set<TestDiagnostic> |
fromJavaxDiagnosticList(List<Diagnostic<? extends JavaFileObject>> javaxDiagnostics,
boolean noMsgText) |
static TestDiagnostic |
fromJavaxToolsDiagnostic(String diagnosticString,
boolean noMsgText)
Instantiate a diagnostic from output produced by the Java compiler.
|
static TestDiagnostic |
fromJSpecifyFileComment(String filename,
long lineNumber,
String stringFromJavaFile)
Instantiate the diagnostic from a JSpecify string that would appear in a Java file, e.g.:
"jspecify_some_category".
|
protected static TestDiagnostic |
fromPatternMatching(Pattern diagnosticPattern,
Pattern warningPattern,
String filename,
@Nullable Long lineNumber,
String diagnosticString)
Instantiate the diagnostic via pattern-matching against patterns.
|
static String |
handleEndOfLineJavaDiagnostic(String originalLine)
Convert an end-of-line diagnostic message to a beginning-of-line one.
|
static boolean |
isJavaDiagnosticLineContinuation(@Nullable String originalLine)
Return true if this line in a Java file continues an expected diagnostic.
|
static boolean |
isJavaDiagnosticLineStart(String originalLine)
Return true if this line in a Java file indicates an expected diagnostic that might be
continued on the next line.
|
static void |
removeDiagnosticsOfKind(DiagnosticKind kind,
List<TestDiagnostic> expectedDiagnostics) |
public static final String DIAGNOSTIC_IN_JAVA_REGEX
public static final Pattern DIAGNOSTIC_IN_JAVA_PATTERN
public static final String DIAGNOSTIC_WARNING_IN_JAVA_REGEX
public static final Pattern DIAGNOSTIC_WARNING_IN_JAVA_PATTERN
public static final String DIAGNOSTIC_REGEX
public static final Pattern DIAGNOSTIC_PATTERN
public static final String DIAGNOSTIC_WARNING_REGEX
public static final Pattern DIAGNOSTIC_WARNING_PATTERN
public static final String DIAGNOSTIC_FILE_REGEX
public static final Pattern DIAGNOSTIC_FILE_PATTERN
public static final String DIAGNOSTIC_FILE_WARNING_REGEX
public static final Pattern DIAGNOSTIC_FILE_WARNING_PATTERN
public static TestDiagnostic fromDiagnosticFileString(String stringFromDiagnosticFile)
stringFromDiagnosticFile
- a single diagnostic string to parsepublic static TestDiagnostic fromJavaFileComment(String filename, long lineNumber, String stringFromJavaFile)
filename
- the file containing the diagnostic (and the error)lineNumber
- the line number of the line immediately below the diagnostic comment in the
Java filestringFromJavaFile
- the string containing the diagnosticpublic static TestDiagnostic fromJavaxToolsDiagnostic(String diagnosticString, boolean noMsgText)
public static TestDiagnostic fromJSpecifyFileComment(String filename, long lineNumber, String stringFromJavaFile)
filename
- the file containing the diagnostic (and the error)lineNumber
- the line number of the line immediately below the diagnostic comment in the
Java filestringFromJavaFile
- the string containing the diagnosticprotected static TestDiagnostic fromPatternMatching(Pattern diagnosticPattern, Pattern warningPattern, String filename, @Nullable Long lineNumber, String diagnosticString)
diagnosticPattern
- a pattern that matches any diagnosticwarningPattern
- a pattern that matches a warning diagnosticfilename
- the file namelineNumber
- the line numberdiagnosticString
- the string to parsepublic static Pair<String,String> formatJavaxToolString(String original, boolean noMsgText)
original
- a javax diagnosticnoMsgText
- whether to do work; if false, this returns a pair of (argument, "")public static boolean isJavaDiagnosticLineStart(String originalLine)
public static String handleEndOfLineJavaDiagnostic(String originalLine)
Most diagnostics in Java files start at the beginning of a line. Occasionally, javac issues a warning about implicit code, such as an implicit constructor, on the line immediately after a curly brace. The only place to put the expected diagnostic message is on the line with the curly brace.
This implementation replaces "{ // ::" by "// ::", converting the end-of-line diagnostic message to a beginning-of-line one that the rest of the code can handle. It is rather specific (to avoid false positive matches, such as when "// ::" is commented out in source code). It could be extended in the future if such an extension is necessary.
@EnsuresNonNullIf(result=true, expression="#1") public static boolean isJavaDiagnosticLineContinuation(@Nullable String originalLine)
public static String continuationPart(String originalLine)
isJavaDiagnosticLineContinuation(java.lang.String)
returns true.public static TestDiagnosticLine fromJavaSourceLine(String filename, String line, long lineNumber)
The input line
is possibly the concatenation of multiple source lines, if the
diagnostic was split across lines in the source code.
public static TestDiagnosticLine fromDiagnosticFileLine(String diagnosticLine)
public static Set<TestDiagnostic> fromJavaxDiagnosticList(List<Diagnostic<? extends JavaFileObject>> javaxDiagnostics, boolean noMsgText)
public static List<String> diagnosticsToString(List<TestDiagnostic> diagnostics)
diagnostics
- a list of diagnosticspublic static void removeDiagnosticsOfKind(DiagnosticKind kind, List<TestDiagnostic> expectedDiagnostics)