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

public Class Preview

extends Object
Class Inheritance
Imports
com.sun.tools.javac.code.Lint.LintCategory, .Source.Feature, .Symbol.ModuleSymbol, com.sun.tools.javac.jvm.Target, com.sun.tools.javac.resources.CompilerProperties.Errors, .CompilerProperties.LintWarnings, .CompilerProperties.Warnings, com.sun.tools.javac.util.Assert, .Context, .JCDiagnostic.DiagnosticFlag, .JCDiagnostic.DiagnosticPosition, .JCDiagnostic.Error, .JCDiagnostic.LintWarning, .JCDiagnostic.SimpleDiagnosticPosition, .JCDiagnostic.Warning, .Log, .Names, .Options, .JCDiagnostic, javax.tools.JavaFileObject, java.util.HashMap, .HashSet, .Map, .Set

Helper class to handle preview language features. This class maps certain language features (see Feature into 'preview' features; the mapping is completely ad-hoc, so as to allow for maximum flexibility, which allows to migrate preview feature into supported features with ease. This class acts as a centralized point against which usages of preview features are reported by clients (e.g. other javac classes). Internally, this class collects all such usages and generates diagnostics to inform the user of such usages. Such diagnostics can be enabled using the LintCategory#PREVIEW lint category, and are suppressible by usual means.

Field Summary

Modifier and TypeField and Description
private final boolean
enabled

flag: are preview features enabled

private final boolean
forcePreview

test flag: should all features be considered as preview features?

private final Log
private final Map<Integer, Source>
majorVersionToSource

a mapping from classfile numbers to Java SE versions

private final Names
protected static final Context.Key<Preview>
private final Source
private final Set<JavaFileObject>

Constructor Summary

AccessConstructor and Description
protected
Preview(Context context)

Method Summary

Modifier and TypeMethod and Description
public void
public boolean

Returns:

true iff sym has been declared using a preview language feature
declaredUsingPreviewFeature
(Symbol
Symbol to check
sym
)

Check whether the given symbol has been declared using a preview language feature.

public JCDiagnostic.Error

Returns:

the diagnostic.
disabledError
(Source.Feature
the feature for which the diagnostic has to be generated.
feature
)

Generate an error key which captures the fact that a given preview feature could not be used due to the preview feature support being disabled.

public JCDiagnostic.Error
disabledError(JavaFileObject
the name of the classfile with preview features enabled
classfile
,
int
the major version found in the classfile.
majorVersion
)

Generate an error key which captures the fact that a preview classfile cannot be loaded due to the preview feature support being disabled.

private Map<Integer, Source>
public static Preview
instance(Context context)

public boolean

Returns:

true, if preview features are enabled.
isEnabled
()

Are preview features enabled?

public boolean

Returns:

true, if given feature is a preview feature.
isPreview
(Source.Feature
the feature to be tested.
feature
)

Is given feature a preview feature?

public void
markUsesPreview(JCDiagnostic.DiagnosticPosition
the position at which the preview feature was used.
pos
)

Mark the current source file as using a preview feature.

public boolean

Returns:

true if s is participating in the preview of previewSymbol
participatesInPreview
(Symtab
the symbol table
syms
,
Symbol
the symbol depending on the preview symbol
s
,
Symbol
the preview symbol marked with @Preview
previewSymbol
)

Returns true if s is deemed to participate in the preview of previewSymbol, and therefore no warnings or errors will be produced.

public boolean

Returns:

true if m is participating in the preview of previewSymbol
participatesInPreview
(Symtab
the symbol table
syms
,
Symbol.ModuleSymbol
the module to check
m
)

Returns true if module m is deemed to participate in the preview, and therefore no warnings or errors will be produced.

public boolean
public void
warnPreview(JCDiagnostic.DiagnosticFlag
a flag to set on the diagnostic
flag
,
int
the position at which the preview feature was used.
pos
,
Source.Feature
the preview feature used.
feature
)

Report usage of a preview feature.

public void
warnPreview(JCDiagnostic.DiagnosticFlag
a flag to set on the diagnostic
flag
,
JCDiagnostic.DiagnosticPosition
the position at which the preview feature was used.
pos
,
Source.Feature
the preview feature used.
feature
)

Report usage of a preview feature.

public void
warnPreview(JavaFileObject
the name of the classfile with preview features enabled
classfile
,
int
the major version found in the classfile.
majorVersion
)

Report usage of a preview feature in classfile.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

enabledback to summary
private final boolean enabled

flag: are preview features enabled

forcePreviewback to summary
private final boolean forcePreview

test flag: should all features be considered as preview features?

logback to summary
private final Log log
majorVersionToSourceback to summary
private final Map<Integer, Source> majorVersionToSource

a mapping from classfile numbers to Java SE versions

namesback to summary
private final Names names
previewKeyback to summary
protected static final Context.Key<Preview> previewKey
sourceback to summary
private final Source source
sourcesWithPreviewFeaturesback to summary
private final Set<JavaFileObject> sourcesWithPreviewFeatures

Constructor Detail

Previewback to summary
protected Preview(Context context)
Annotations
@SuppressWarnings:this-escape

Method Detail

checkSourceLevelback to summary
public void checkSourceLevel(JCDiagnostic.DiagnosticPosition pos, Source.Feature feature)
declaredUsingPreviewFeatureback to summary
public boolean declaredUsingPreviewFeature(Symbol sym)

Check whether the given symbol has been declared using a preview language feature.

Parameters
sym:Symbol

Symbol to check

Returns:boolean

true iff sym has been declared using a preview language feature

disabledErrorback to summary
public JCDiagnostic.Error disabledError(Source.Feature feature)

Generate an error key which captures the fact that a given preview feature could not be used due to the preview feature support being disabled.

Parameters
feature:Source.Feature

the feature for which the diagnostic has to be generated.

Returns:JCDiagnostic.Error

the diagnostic.

disabledErrorback to summary
public JCDiagnostic.Error disabledError(JavaFileObject classfile, int majorVersion)

Generate an error key which captures the fact that a preview classfile cannot be loaded due to the preview feature support being disabled.

Parameters
classfile:JavaFileObject

the name of the classfile with preview features enabled

majorVersion:int

the major version found in the classfile.

initMajorVersionToSourceMapback to summary
private Map<Integer, Source> initMajorVersionToSourceMap()
instanceback to summary
public static Preview instance(Context context)
isEnabledback to summary
public boolean isEnabled()

Are preview features enabled?

Returns:boolean

true, if preview features are enabled.

isPreviewback to summary
public boolean isPreview(Source.Feature feature)

Is given feature a preview feature?

Parameters
feature:Source.Feature

the feature to be tested.

Returns:boolean

true, if given feature is a preview feature.

markUsesPreviewback to summary
public void markUsesPreview(JCDiagnostic.DiagnosticPosition pos)

Mark the current source file as using a preview feature. The corresponding classfile will be generated with minor version ClassFile#PREVIEW_MINOR_VERSION.

Parameters
pos:JCDiagnostic.DiagnosticPosition

the position at which the preview feature was used.

participatesInPreviewback to summary
public boolean participatesInPreview(Symtab syms, Symbol s, Symbol previewSymbol)

Returns true if s is deemed to participate in the preview of previewSymbol, and therefore no warnings or errors will be produced.

Parameters
syms:Symtab

the symbol table

s:Symbol

the symbol depending on the preview symbol

previewSymbol:Symbol

the preview symbol marked with @Preview

Returns:boolean

true if s is participating in the preview of previewSymbol

participatesInPreviewback to summary
public boolean participatesInPreview(Symtab syms, Symbol.ModuleSymbol m)

Returns true if module m is deemed to participate in the preview, and therefore no warnings or errors will be produced.

Parameters
syms:Symtab

the symbol table

m:Symbol.ModuleSymbol

the module to check

Returns:boolean

true if m is participating in the preview of previewSymbol

usesPreviewback to summary
public boolean usesPreview(JavaFileObject file)
warnPreviewback to summary
public void warnPreview(JCDiagnostic.DiagnosticFlag flag, int pos, Source.Feature feature)

Report usage of a preview feature. Usages reported through this method will affect the set of sourcefiles with dependencies on preview features.

Parameters
flag:JCDiagnostic.DiagnosticFlag

a flag to set on the diagnostic

pos:int

the position at which the preview feature was used.

feature:Source.Feature

the preview feature used.

warnPreviewback to summary
public void warnPreview(JCDiagnostic.DiagnosticFlag flag, JCDiagnostic.DiagnosticPosition pos, Source.Feature feature)

Report usage of a preview feature. Usages reported through this method will affect the set of sourcefiles with dependencies on preview features.

Parameters
flag:JCDiagnostic.DiagnosticFlag

a flag to set on the diagnostic

pos:JCDiagnostic.DiagnosticPosition

the position at which the preview feature was used.

feature:Source.Feature

the preview feature used.

warnPreviewback to summary
public void warnPreview(JavaFileObject classfile, int majorVersion)

Report usage of a preview feature in classfile.

Parameters
classfile:JavaFileObject

the name of the classfile with preview features enabled

majorVersion:int

the major version found in the classfile.