8043253: Slow javac compile times in JDK 8
Enable on-demand diagnostic source position completion Reviewed-by: jjg, vromero
This commit is contained in:
parent
e6b9e34ebe
commit
f8e80ec392
@ -354,13 +354,41 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
private final DiagnosticType type;
|
||||
private final DiagnosticSource source;
|
||||
private final DiagnosticPosition position;
|
||||
private final int line;
|
||||
private final int column;
|
||||
private final String key;
|
||||
protected final Object[] args;
|
||||
private final Set<DiagnosticFlag> flags;
|
||||
private final LintCategory lintCategory;
|
||||
|
||||
/** source line position (set lazily) */
|
||||
private SourcePosition sourcePosition;
|
||||
|
||||
/**
|
||||
* This class is used to defer the line/column position fetch logic after diagnostic construction.
|
||||
*/
|
||||
class SourcePosition {
|
||||
|
||||
private final int line;
|
||||
private final int column;
|
||||
|
||||
SourcePosition() {
|
||||
int n = (position == null ? Position.NOPOS : position.getPreferredPosition());
|
||||
if (n == Position.NOPOS || source == null)
|
||||
line = column = -1;
|
||||
else {
|
||||
line = source.getLineNumber(n);
|
||||
column = source.getColumnNumber(n, true);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public int getColumnNumber() {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a diagnostic object.
|
||||
* @param formatter the formatter to use for the diagnostic
|
||||
@ -390,14 +418,6 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
this.position = pos;
|
||||
this.key = key;
|
||||
this.args = args;
|
||||
|
||||
int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition());
|
||||
if (n == Position.NOPOS || source == null)
|
||||
line = column = -1;
|
||||
else {
|
||||
line = source.getLineNumber(n);
|
||||
column = source.getColumnNumber(n, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,7 +514,10 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @return the line number within the source referred to by this diagnostic
|
||||
*/
|
||||
public long getLineNumber() {
|
||||
return line;
|
||||
if (sourcePosition == null) {
|
||||
sourcePosition = new SourcePosition();
|
||||
}
|
||||
return sourcePosition.getLineNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,7 +525,10 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @return the column number within the line of source referred to by this diagnostic
|
||||
*/
|
||||
public long getColumnNumber() {
|
||||
return column;
|
||||
if (sourcePosition == null) {
|
||||
sourcePosition = new SourcePosition();
|
||||
}
|
||||
return sourcePosition.getColumnNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user