Top Description Inners Fields Constructors Methods
com.sun.tools.javac.util

public abstract Class AbstractDiagnosticFormatter

extends Object
implements DiagnosticFormatter<JCDiagnostic>
Class Inheritance
All Implemented Interfaces
com.sun.tools.javac.api.DiagnosticFormatter
Known Direct Subclasses
com.sun.tools.javac.util.BasicDiagnosticFormatter, com.sun.tools.javac.util.RawDiagnosticFormatter
Imports
java.nio.file.Path, java.util.Arrays, .Collection, .EnumSet, .HashMap, .Locale, .Map, .Set, javax.tools.JavaFileObject, com.sun.tools.javac.api.DiagnosticFormatter, .DiagnosticFormatter.Configuration.DiagnosticPart, .DiagnosticFormatter.Configuration.MultilineLimit, .DiagnosticFormatter.PositionKind, .Formattable, com.sun.tools.javac.code.Lint.LintCategory, .Printer, .Source, .Symbol, .Type, .Type.CapturedType, com.sun.tools.javac.file.PathFileObject, com.sun.tools.javac.jvm.Profile, .Target, com.sun.tools.javac.main.Option, com.sun.tools.javac.tree.JCTree.*, .Pretty

This abstract class provides a basic implementation of the functionalities that should be provided by any formatter used by javac. Among the main features provided by AbstractDiagnosticFormatter are:

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private List<Type>
allCaptured

All captured types that have been encountered during diagnostic formatting.

private AbstractDiagnosticFormatter.SimpleConfiguration
config

Configuration object used by this formatter

protected int
depth

Current depth level of the diagnostic being formatted (!= 0 for subdiagnostics)

protected JavacMessages
messages

JavacMessages object used by this formatter for i18n.

protected Printer
printer

An enhanced printer for formatting types/symbols used by AbstractDiagnosticFormatter.

Constructor Summary

AccessConstructor and Description
protected
AbstractDiagnosticFormatter(JavacMessages messages, AbstractDiagnosticFormatter.SimpleConfiguration config)

Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object.

Method Summary

Modifier and TypeMethod and Description
public boolean
displaySource(JCDiagnostic
diagnostic to be formatted
d
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.displaySource.

Whether the source code output for this diagnostic is to be displayed.

private String
public String
format(JCDiagnostic
the diagnostic to be formatted
d
,
Locale
locale object to be used for i18n
locale
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.format.

Format the contents of a diagnostics.

protected String

Returns:

string representation of the diagnostic argument
formatArgument
(JCDiagnostic
diagnostic whose argument is to be formatted
d
,
Object
argument to be formatted
arg
,
Locale
locale object to be used for i18n
l
)

Format a single argument of a given diagnostic.

protected Collection<String>

Returns:

a Collection whose elements are the formatted arguments of the diagnostic
formatArguments
(JCDiagnostic
diagnostic whose arguments are to be formatted
d
,
Locale
locale object to be used for i18n
l
)

Format the arguments of a given diagnostic.

protected abstract String
protected String

Returns:

string representation of the diagnostic iterable argument
formatIterable
(JCDiagnostic
diagnostic whose argument is to be formatted
d
,
Iterable<?>
iterable argument to be formatted
it
,
Locale
locale object to be used for i18n
l
)

Format an iterable argument of a given diagnostic.

public String
formatKind(JCDiagnostic
diagnostic to be formatted
d
,
Locale
locale object to be used for i18n
l
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatKind.

Controls the way in which a diagnostic kind is displayed.

protected String
public String
formatPosition(JCDiagnostic
diagnostic to be formatted
d
,
DiagnosticFormatter.PositionKind
enum constant representing the position kind
pk
,
Locale
locale object to be used for i18n
l
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatPosition.

Controls the way in which a diagnostic position is displayed.

public String
formatSource(JCDiagnostic
diagnostic to be formatted
d
,
boolean
whether the source fullname should be printed
fullname
,
Locale
locale object to be used for i18n
l
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatSource.

Controls the way in which a diagnostic source is displayed.

protected String
formatSourceLine(JCDiagnostic
The diagnostic for which the error line should be printed
d
,
int nSpaces)

Format the faulty source code line and point to the error.

protected String

Returns:

string representation of the subdiagnostics
formatSubdiagnostic
(JCDiagnostic
multiline diagnostic whose subdiagnostics is to be formatted
parent
,
JCDiagnostic
subdiagnostic to be formatted
sub
,
Locale
locale object to be used for i18n
l
)

Format a subdiagnostics attached to a given diagnostic.

protected List<String>

Returns:

list of all string representations of the subdiagnostics
formatSubdiagnostics
(JCDiagnostic
diagnostic whose subdiagnostics are to be formatted
d
,
Locale
locale object to be used for i18n
l
)

Format all the subdiagnostics attached to a given diagnostic.

public AbstractDiagnosticFormatter.SimpleConfiguration
getConfiguration()

Implements com.sun.tools.javac.api.DiagnosticFormatter.getConfiguration.

Get a list of all the enabled verbosity options.

private long
public Printer
protected String

Returns:

an indented string
indent
(String
the string to be indented
s
,
int
the amount of spaces that should be prepended to each line of the string
nSpaces
)

Indent a string by prepending a given amount of empty spaces to each line of the string.

protected String

Returns:

the indentation string
indentString
(int
the amount of spaces to be added to the result string
nSpaces
)

Creates a string with a given amount of empty spaces.

public boolean
protected String

Returns:

a locale-dependent string
localize
(Locale
locale object to be used for i18n
l
,
String
locale-independent key used for looking up in a resource file
key
,
Object...
localization arguments
args
)

Converts a String into a locale-dependent representation accordingly to a given locale.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allCapturedback to summary
private List<Type> allCaptured

All captured types that have been encountered during diagnostic formatting. This info is used by the FormatterPrinter in order to print friendly unique ids for captured types

configback to summary
private AbstractDiagnosticFormatter.SimpleConfiguration config

Configuration object used by this formatter

depthback to summary
protected int depth

Current depth level of the diagnostic being formatted (!= 0 for subdiagnostics)

messagesback to summary
protected JavacMessages messages

JavacMessages object used by this formatter for i18n.

printerback to summary
protected Printer printer

An enhanced printer for formatting types/symbols used by AbstractDiagnosticFormatter. Provides alternate numbering of captured types (they are numbered starting from 1 on each new diagnostic, instead of relying on the underlying hashcode() method which generates unstable output). Also detects cycles in wildcard messages (e.g. if the wildcard type referred by a given captured type C contains C itself) which might lead to infinite loops.

Constructor Detail

AbstractDiagnosticFormatterback to summary
protected AbstractDiagnosticFormatter(JavacMessages messages, AbstractDiagnosticFormatter.SimpleConfiguration config)

Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object.

Method Detail

displaySourceback to summary
public boolean displaySource(JCDiagnostic d)

Implements com.sun.tools.javac.api.DiagnosticFormatter.displaySource.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.displaySource.

Whether the source code output for this diagnostic is to be displayed.

Parameters
d:JCDiagnostic

diagnostic to be formatted

Returns:boolean

true if the source line this diagnostic refers to is to be displayed

expr2Stringback to summary
private String expr2String(JCTree.JCExpression tree)
formatback to summary
public String format(JCDiagnostic d, Locale locale)

Implements com.sun.tools.javac.api.DiagnosticFormatter.format.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.format.

Format the contents of a diagnostics.

Parameters
d:JCDiagnostic

the diagnostic to be formatted

locale:Locale

locale object to be used for i18n

Returns:String

a string representing the diagnostic

Annotations
@Override
formatArgumentback to summary
protected String formatArgument(JCDiagnostic d, Object arg, Locale l)

Format a single argument of a given diagnostic.

Parameters
d:JCDiagnostic

diagnostic whose argument is to be formatted

arg:Object

argument to be formatted

l:Locale

locale object to be used for i18n

Returns:String

string representation of the diagnostic argument

formatArgumentsback to summary
protected Collection<String> formatArguments(JCDiagnostic d, Locale l)

Format the arguments of a given diagnostic.

Parameters
d:JCDiagnostic

diagnostic whose arguments are to be formatted

l:Locale

locale object to be used for i18n

Returns:Collection<String>

a Collection whose elements are the formatted arguments of the diagnostic

formatDiagnosticback to summary
protected abstract String formatDiagnostic(JCDiagnostic d, Locale locale)
formatIterableback to summary
protected String formatIterable(JCDiagnostic d, Iterable<?> it, Locale l)

Format an iterable argument of a given diagnostic.

Parameters
d:JCDiagnostic

diagnostic whose argument is to be formatted

it:Iterable<?>

iterable argument to be formatted

l:Locale

locale object to be used for i18n

Returns:String

string representation of the diagnostic iterable argument

formatKindback to summary
public String formatKind(JCDiagnostic d, Locale l)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatKind.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.formatKind.

Controls the way in which a diagnostic kind is displayed.

Parameters
d:JCDiagnostic

diagnostic to be formatted

l:Locale

locale object to be used for i18n

Returns:String

string representation of the diagnostic prefix

formatLintCategoryback to summary
protected String formatLintCategory(JCDiagnostic d, Locale l)
formatPositionback to summary
public String formatPosition(JCDiagnostic d, DiagnosticFormatter.PositionKind pk, Locale l)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatPosition.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.formatPosition.

Controls the way in which a diagnostic position is displayed.

Parameters
d:JCDiagnostic

diagnostic to be formatted

pk:DiagnosticFormatter.PositionKind

enum constant representing the position kind

l:Locale

locale object to be used for i18n

Returns:String

string representation of the diagnostic position

formatSourceback to summary
public String formatSource(JCDiagnostic d, boolean fullname, Locale l)

Implements com.sun.tools.javac.api.DiagnosticFormatter.formatSource.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.formatSource.

Controls the way in which a diagnostic source is displayed.

Parameters
d:JCDiagnostic

diagnostic to be formatted

fullname:boolean

whether the source fullname should be printed

l:Locale

locale object to be used for i18n

Returns:String

string representation of the diagnostic source

formatSourceLineback to summary
protected String formatSourceLine(JCDiagnostic d, int nSpaces)

Format the faulty source code line and point to the error.

Parameters
d:JCDiagnostic

The diagnostic for which the error line should be printed

formatSubdiagnosticback to summary
protected String formatSubdiagnostic(JCDiagnostic parent, JCDiagnostic sub, Locale l)

Format a subdiagnostics attached to a given diagnostic.

Parameters
parent:JCDiagnostic

multiline diagnostic whose subdiagnostics is to be formatted

sub:JCDiagnostic

subdiagnostic to be formatted

l:Locale

locale object to be used for i18n

Returns:String

string representation of the subdiagnostics

formatSubdiagnosticsback to summary
protected List<String> formatSubdiagnostics(JCDiagnostic d, Locale l)

Format all the subdiagnostics attached to a given diagnostic.

Parameters
d:JCDiagnostic

diagnostic whose subdiagnostics are to be formatted

l:Locale

locale object to be used for i18n

Returns:List<String>

list of all string representations of the subdiagnostics

getConfigurationback to summary
public AbstractDiagnosticFormatter.SimpleConfiguration getConfiguration()

Implements com.sun.tools.javac.api.DiagnosticFormatter.getConfiguration.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.getConfiguration.

Get a list of all the enabled verbosity options.

Returns:AbstractDiagnosticFormatter.SimpleConfiguration

verbosity options

getPositionback to summary
private long getPosition(JCDiagnostic d, DiagnosticFormatter.PositionKind pk)
getPrinterback to summary
public Printer getPrinter()
indentback to summary
protected String indent(String s, int nSpaces)

Indent a string by prepending a given amount of empty spaces to each line of the string.

Parameters
s:String

the string to be indented

nSpaces:int

the amount of spaces that should be prepended to each line of the string

Returns:String

an indented string

indentStringback to summary
protected String indentString(int nSpaces)

Creates a string with a given amount of empty spaces. Useful for indenting the text of a diagnostic message.

Parameters
nSpaces:int

the amount of spaces to be added to the result string

Returns:String

the indentation string

isRawback to summary
public boolean isRaw()
localizeback to summary
protected String localize(Locale l, String key, Object... args)

Converts a String into a locale-dependent representation accordingly to a given locale.

Parameters
l:Locale

locale object to be used for i18n

key:String

locale-independent key used for looking up in a resource file

args:Object[]

localization arguments

Returns:String

a locale-dependent string

setPrinterback to summary
public void setPrinter(Printer printer)
com.sun.tools.javac.util back to summary

public Class AbstractDiagnosticFormatter.SimpleConfiguration

extends Object
implements Configuration
Class Inheritance
  • java.lang.Object
  • com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration
All Implemented Interfaces
com.sun.tools.javac.api.DiagnosticFormatter.Configuration
Known Direct Subclasses
com.sun.tools.javac.util.BasicDiagnosticFormatter.BasicConfiguration

Field Summary

Modifier and TypeField and Description
protected boolean
protected Map<DiagnosticFormatter.Configuration.MultilineLimit, Integer>
protected EnumSet<DiagnosticFormatter.Configuration.DiagnosticPart>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public int
public EnumSet<DiagnosticFormatter.Configuration.DiagnosticPart>
getVisible()

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.getVisible.

Retrieve the set of diagnostic parts that should be displayed by the formatter.

public boolean

Returns:

true if the caret is enabled
isCaretEnabled
()

Tells whether the caret display is active or not.

public void
setCaretEnabled(boolean
if true enables caret
caretEnabled
)

Shows a '^' sign under the source line displayed by the formatter (if applicable).

public void
setMultilineLimit(DiagnosticFormatter.Configuration.MultilineLimit
the kind of limit to be set
limit
,
int
the limit value
value
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setMultilineLimit.

Set a limit for multiline diagnostics.

public void
setVisible(Set<DiagnosticFormatter.Configuration.DiagnosticPart>
the parts to be set
diagParts
)

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setVisible.

Configure the set of diagnostic parts that should be displayed by the formatter.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

caretEnabledback to summary
protected boolean caretEnabled
multilineLimitsback to summary
protected Map<DiagnosticFormatter.Configuration.MultilineLimit, Integer> multilineLimits
visiblePartsback to summary
protected EnumSet<DiagnosticFormatter.Configuration.DiagnosticPart> visibleParts

Constructor Detail

SimpleConfigurationback to summary
public SimpleConfiguration(Set<DiagnosticFormatter.Configuration.DiagnosticPart> parts)
Annotations
@SuppressWarnings:this-escape
SimpleConfigurationback to summary
public SimpleConfiguration(Options options, Set<DiagnosticFormatter.Configuration.DiagnosticPart> parts)
Annotations
@SuppressWarnings:fallthrough, this-escape

Method Detail

getMultilineLimitback to summary
public int getMultilineLimit(DiagnosticFormatter.Configuration.MultilineLimit limit)

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.getMultilineLimit.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.Configuration.getMultilineLimit.

Get a multiline diagnostic limit.

Parameters
limit:DiagnosticFormatter.Configuration.MultilineLimit

the kind of limit to be retrieved

Returns:int

limit value or -1 if no limit is set

getVisibleback to summary
public EnumSet<DiagnosticFormatter.Configuration.DiagnosticPart> getVisible()

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.getVisible.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.Configuration.getVisible.

Retrieve the set of diagnostic parts that should be displayed by the formatter.

Returns:EnumSet<DiagnosticFormatter.Configuration.DiagnosticPart>

verbosity options

isCaretEnabledback to summary
public boolean isCaretEnabled()

Tells whether the caret display is active or not.

Returns:boolean

true if the caret is enabled

setCaretEnabledback to summary
public void setCaretEnabled(boolean caretEnabled)

Shows a '^' sign under the source line displayed by the formatter (if applicable).

Parameters
caretEnabled:boolean

if true enables caret

setMultilineLimitback to summary
public void setMultilineLimit(DiagnosticFormatter.Configuration.MultilineLimit limit, int value)

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setMultilineLimit.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setMultilineLimit.

Set a limit for multiline diagnostics.

Note

Setting a limit has no effect if multiline diagnostics are either fully enabled or disabled.

Parameters
limit:DiagnosticFormatter.Configuration.MultilineLimit

the kind of limit to be set

value:int

the limit value

setVisibleback to summary
public void setVisible(Set<DiagnosticFormatter.Configuration.DiagnosticPart> diagParts)

Implements com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setVisible.

Doc from com.sun.tools.javac.api.DiagnosticFormatter.Configuration.setVisible.

Configure the set of diagnostic parts that should be displayed by the formatter.

Parameters
diagParts:Set<DiagnosticFormatter.Configuration.DiagnosticPart>

the parts to be set

setVisiblePartback to summary
public void setVisiblePart(DiagnosticFormatter.Configuration.DiagnosticPart diagParts, boolean enabled)