APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.code

public Class LintMapper

extends Object
Class Inheritance
Imports
java.util.HashMap, .Iterator, .LinkedList, .List, .Map, .Optional, java.util.function.Consumer, javax.tools.JavaFileObject, com.sun.tools.javac.tree.JCTree, com.sun.tools.javac.tree.JCTree.*, .TreeInfo, .TreeScanner, com.sun.tools.javac.util.Assert, .Context, .JCDiagnostic.DiagnosticPosition

Maps source code positions to the applicable Lint instance.

Because @SuppressWarnings is a Java symbol, in general this mapping can't be calculated until after attribution. As each top-level declaration (class, package, or module) is attributed, this singleton is notified and the Lints that apply to every source position within that top-level declaration are calculated.

The method lintAt returns the Lint instance applicable to source position; if it can't be determined yet, an empty Optional is returned.

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
private static class
LintMapper.FileInfo

Holds Lint information for a fully parsed source file.

private static record
LintMapper.LintRange

A tree of nested lexical ranges and the Lint configurations that apply therein.

private static record
LintMapper.Span

A lexical range.

Field Summary

Modifier and TypeField and Description
private final Context
private static final Context.Key<LintMapper>
private final Map<JavaFileObject, LintMapper.FileInfo>
private Lint

Constructor Summary

AccessConstructor and Description
protected
LintMapper(Context context)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
calculateLints(JavaFileObject
source file
sourceFile
,
JCTree
top-level declaration (class, package, or module)
tree
)

Calculate {@lint Lint} configurations for all positions within the given top-level declaration.

public void
clear()

Reset this instance.

public void
finishParsingFile(JCTree.JCCompilationUnit tree)

Invoked when file parsing completes to put in place a corresponding FileInfo.

private void
public static LintMapper
instance(Context context)

Obtain the LintMapper context singleton.

public boolean

Returns:

true if file is recognized
isKnown
(JavaFileObject
source file
sourceFile
)

Determine if the given file is known to this instance.

public Optional<Lint>

Returns:

the applicable Lint, if known, otherwise empty
lintAt
(JavaFileObject
source file
sourceFile
,
JCDiagnostic.DiagnosticPosition
source position
pos
)

Obtain the Lint configuration that applies at the given position, if known.

public void
startParsingFile(JavaFileObject sourceFile)

Invoked when file parsing starts to create an entry for the new file (but with a null value).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final Context context
CONTEXT_KEYback to summary
private static final Context.Key<LintMapper> CONTEXT_KEY
fileInfoMapback to summary
private final Map<JavaFileObject, LintMapper.FileInfo> fileInfoMap
rootLintback to summary
private Lint rootLint

Constructor Detail

LintMapperback to summary
protected LintMapper(Context context)

Constructor.

Annotations
@SuppressWarnings:this-escape

Method Detail

calculateLintsback to summary
public void calculateLints(JavaFileObject sourceFile, JCTree tree)

Calculate {@lint Lint} configurations for all positions within the given top-level declaration.

Parameters
sourceFile:JavaFileObject

source file

tree:JCTree

top-level declaration (class, package, or module)

clearback to summary
public void clear()

Reset this instance.

finishParsingFileback to summary
public void finishParsingFile(JCTree.JCCompilationUnit tree)

Invoked when file parsing completes to put in place a corresponding FileInfo.

initializeIfNeededback to summary
private void initializeIfNeeded()
instanceback to summary
public static LintMapper instance(Context context)

Obtain the LintMapper context singleton.

isKnownback to summary
public boolean isKnown(JavaFileObject sourceFile)

Determine if the given file is known to this instance.

Parameters
sourceFile:JavaFileObject

source file

Returns:boolean

true if file is recognized

lintAtback to summary
public Optional<Lint> lintAt(JavaFileObject sourceFile, JCDiagnostic.DiagnosticPosition pos)

Obtain the Lint configuration that applies at the given position, if known.

Parameters
sourceFile:JavaFileObject

source file

pos:JCDiagnostic.DiagnosticPosition

source position

Returns:Optional<Lint>

the applicable Lint, if known, otherwise empty

startParsingFileback to summary
public void startParsingFile(JavaFileObject sourceFile)

Invoked when file parsing starts to create an entry for the new file (but with a null value).

com.sun.tools.javac.code back to summary

private Class LintMapper.FileInfo

extends Object
Class Inheritance

Holds Lint information for a fully parsed source file.

Initially (immediately after parsing), "unmappedDecls" contains a Span corresponding to each top-level declaration in the source file. As each top-level declaration is attributed, the corresponding Span is removed and the corresponding LintRange subtree is populated under "rootRange".

Field Summary

Modifier and TypeField and Description
pack-priv final LintMapper.LintRange
pack-priv final List<LintMapper.Span>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv boolean
pack-priv Optional<Lint>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rootRangeback to summary
pack-priv final LintMapper.LintRange rootRange
unmappedDeclsback to summary
pack-priv final List<LintMapper.Span> unmappedDecls

Constructor Detail

FileInfoback to summary
pack-priv FileInfo(Lint rootLint, JCTree.JCCompilationUnit tree)

Method Detail

afterAttrback to summary
pack-priv void afterAttr(JCTree tree)
isTopLevelDeclback to summary
pack-priv boolean isTopLevelDecl(JCTree tree)
lintAtback to summary
pack-priv Optional<Lint> lintAt(JCDiagnostic.DiagnosticPosition pos)
com.sun.tools.javac.code back to summary

private final Record LintMapper.LintRange

extends Record
Class Inheritance
Record Components
span:LintMapper.Span 
lint:Lint 
children:List<LintMapper.LintRange> 

A tree of nested lexical ranges and the Lint configurations that apply therein.

Field Summary

Modifier and TypeField and Description
private final List<LintMapper.LintRange>
children

Record Component accessed by children().

private final Lint
lint

Record Component accessed by lint().

private final LintMapper.Span
span

Record Component accessed by span().

Constructor Summary

AccessConstructor and Description
pack-priv
LintRange(Lint rootLint)

pack-priv
LintRange(JCTree tree, Lint lint)

private

Method Summary

Modifier and TypeMethod and Description
pack-priv LintMapper.LintRange
public List<LintMapper.LintRange>
children()

Record Component getter of children.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Lint
lint()

Record Component getter of lint.

pack-priv void
public LintMapper.Span
span()

Record Component getter of span.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

childrenback to summary
private final List<LintMapper.LintRange> children

Record Component accessed by children().

lintback to summary
private final Lint lint

Record Component accessed by lint().

spanback to summary
private final LintMapper.Span span

Record Component accessed by span().

Constructor Detail

LintRangeback to summary
pack-priv LintRange(Lint rootLint)
LintRangeback to summary
pack-priv LintRange(JCTree tree, Lint lint)
LintRangeback to summary
private LintRange(LintMapper.Span span, Lint lint, List<LintMapper.LintRange> children)

Method Detail

bestMatchback to summary
pack-priv LintMapper.LintRange bestMatch(JCDiagnostic.DiagnosticPosition pos)
childrenback to summary
public List<LintMapper.LintRange> children()

Record Component getter of children.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

lintback to summary
public Lint lint()

Record Component getter of lint.

populateSubtreeback to summary
pack-priv void populateSubtree(JCTree tree)
spanback to summary
public LintMapper.Span span()

Record Component getter of span.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

com.sun.tools.javac.code back to summary

private final Record LintMapper.Span

extends Record
Class Inheritance
Record Components
startPos:int 
endPos:int 

A lexical range.

Field Summary

Modifier and TypeField and Description
private final int
endPos

Record Component accessed by endPos().

pack-priv static final LintMapper.Span
private final int
startPos

Record Component accessed by startPos().

Constructor Summary

AccessConstructor and Description
pack-priv
Span(JCTree tree)

private
Span(int startPos, int endPos)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv boolean
public int
endPos()

Record Component getter of endPos.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public int
startPos()

Record Component getter of startPos.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

endPosback to summary
private final int endPos

Record Component accessed by endPos().

MAXIMALback to summary
pack-priv static final LintMapper.Span MAXIMAL
startPosback to summary
private final int startPos

Record Component accessed by startPos().

Constructor Detail

Spanback to summary
pack-priv Span(JCTree tree)
Spanback to summary
private Span(int startPos, int endPos)

Method Detail

containsback to summary
pack-priv boolean contains(JCDiagnostic.DiagnosticPosition pos)
containsback to summary
pack-priv boolean contains(LintMapper.Span that)
endPosback to summary
public int endPos()

Record Component getter of endPos.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

startPosback to summary
public int startPos()

Record Component getter of startPos.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.