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

public Class VirtualParser

extends JavacParser
Class Inheritance
Imports
com.sun.tools.javac.parser.Tokens.Token, com.sun.tools.javac.tree.JCTree, .JCTree.JCErroneous, com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition, .JCDiagnostic.Error, .JCDiagnostic.LintWarning, .List, .Position.LineMap, java.util.Optional, .Queue, java.util.function.Consumer, .Function

The virtual parser allows for speculative parsing while not commiting to consuming tokens unless the speculation is successful.

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
VirtualParser.VirtualScanner

Scanner that does token lookahead and throws AssertionErrors if an error occurs.

Field Summary

Modifier and TypeField and Description
private boolean
Inherited from com.sun.tools.javac.parser.JavacParser:
allowRecordsallowSealedTypesallowStringFoldingallowThisIdentallowYieldStatementdanglingCommentserrorEndPosEXPRFkeepDocCommentskeepLineMaplastmodeLAX_IDENTIFIERmodeNOLAMBDAodStackSupplyopStackSupplyreceiverParamStokenTYPE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
protected void
reportSyntaxError(int pos, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Report a syntax using the given the position parameter and arguments, unless one was already reported at the same position.

protected void
reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Report a syntax error using the given DiagnosticPosition object and arguments, unless one was already reported at the same position.

protected JCTree.JCErroneous
protected JCTree.JCErroneous
public static boolean

Returns:

true if successful
tryParse
(JavacParser
parent parser
parser
,
Consumer<JavacParser>
function that takes a parser and invokes a method on that parser
parserAction
)

Attempts a parse action and returns true if successful or false if a parse error is thrown.

Inherited from com.sun.tools.javac.parser.JavacParser:
acceptacceptanalyzeParensanalyzePatternannotationannotationFieldValueannotationFieldValuesannotationFieldValuesOptannotationsOptannotationValueargumentsargumentsargumentsOptarrayCreatorRestarrayInitializerarrayInitializerElementsattachbasicTypeblockblockblockStatementblockStatementsbracketsSuffixcatchClausecatchTypescheckExprStatcheckNoModscheckNoModscheckSourceLevelcheckSourceLevelclassCreatorRestclassDeclarationclassInterfaceOrRecordBodyclassOrInterfaceOrRecordBodyDeclarationclassOrRecordOrInterfaceOrEnumDeclarationcreatorearlierenumBodyenumDeclarationenumeratorDeclarationfoldStringsforInitformalParameterformalParametersformalParametersforUpdategetEndPosgetStartPosidentidentidentidentOrUnderscoreillegalillegalimplicitParameterimplicitParametersimportDeclarationinnerCreatorinterfaceDeclarationisDeclarationisInvalidUnqualifiedMethodIdentifierisModeisNonSealedClassStartisNonSealedIdentifierisRecordStartisSealedClassStartisUnboundMemberRefisZerolambdaExpressionlambdaExpressionOrStatementlambdaExpressionOrStatementRestlambdaStatementliteralliteralmemberReferenceSuffixmemberReferenceSuffixmergemethodDeclaratorRestmodifiersOptmodifiersOptmoduleDeclmoduleDirectiveListmoreStatementExpressionsnewDocCommentTablenextTokenoptagoptFinalparExpressionparseCompilationUnitparseExpressionparseIntersectionTypeparsePatternparseSimpleStatementparseStatementparseStatementAsBlockparseTypeparseTypeparseTypepeekTokenpeekTokenpeekTokenpeekTokenpeekTokenpeekTokenpeekTokenpeekTokenpermitsClauseprecqualidentqualidentListrecordDeclarationreplaceTypeWithVarreportDanglingCommentsreportDanglingDocCommentreportIntegralLiteralErrorresourceresourcesrestrictedTypeNamerestrictedTypeNameStartingAtSourceselectExprModeselectTypeModesetErrorEndPossetLastModesetModeskipstoreEndstrvalsuperSuffixswitchBlockStatementGroupswitchBlockStatementGroupstermtermterm1term1Restterm2term2Restterm3term3ResttermResttotokentoPtypeAnnotationsOpttypeApplytypeApplyOpttypeApplyOrDiamondtypeArgumenttypeArgumentstypeArgumentsOpttypeArgumentsOpttypeDeclarationtypeListtypeNametypeParametertypeParametersOpttypeParametersOpttypetagunannotatedTypeunannotatedTypeunoptagvariableDeclaratorvariableDeclaratorIdvariableDeclaratorRestvariableDeclaratorsvariableDeclaratorsRestvariableInitializerwasTypeMode

Field Detail

hasErrorsback to summary
private boolean hasErrors

Constructor Detail

VirtualParserback to summary
public VirtualParser(JavacParser parser)

Method Detail

hasErrorsback to summary
public boolean hasErrors()
reportSyntaxErrorback to summary
protected void reportSyntaxError(int pos, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Doc from com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Report a syntax using the given the position parameter and arguments, unless one was already reported at the same position.

Annotations
@Override
reportSyntaxErrorback to summary
protected void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Doc from com.sun.tools.javac.parser.JavacParser.reportSyntaxError.

Report a syntax error using the given DiagnosticPosition object and arguments, unless one was already reported at the same position.

Annotations
@Override
syntaxErrorback to summary
protected JCTree.JCErroneous syntaxError(int pos, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.syntaxError.

Annotations
@Override
syntaxErrorback to summary
protected JCTree.JCErroneous syntaxError(int pos, List<? extends JCTree> errs, JCDiagnostic.Error errorKey)

Overrides com.sun.tools.javac.parser.JavacParser.syntaxError.

Annotations
@Override
tryParseback to summary
public static boolean tryParse(JavacParser parser, Consumer<JavacParser> parserAction)

Attempts a parse action and returns true if successful or false if a parse error is thrown.

Parameters
parser:JavacParser

parent parser

parserAction:Consumer<JavacParser>

function that takes a parser and invokes a method on that parser

Returns:boolean

true if successful

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

public Class VirtualParser.VirtualScanner

extends Object
implements Lexer
Class Inheritance
All Implemented Interfaces
com.sun.tools.javac.parser.Lexer

Scanner that does token lookahead and throws AssertionErrors if an error occurs.

Field Summary

Modifier and TypeField and Description
pack-priv int
offset

Token offset from where parent scanner branched.

private Tokens.Token
prevToken

The previous token, set by nextToken().

pack-priv Lexer
S

Parent scanner.

private Tokens.Token
token

The token, set by nextToken().

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
errPos()

Implements com.sun.tools.javac.parser.Lexer.errPos.

Return the position where a lexical error occurred;

public void
errPos(int pos)

Implements com.sun.tools.javac.parser.Lexer.errPos.

Set the position where a lexical error occurred;

public Queue<Tokens.Comment>
getDocComments()

Implements com.sun.tools.javac.parser.Lexer.getDocComments.

Returns a queue for the documentation comments encountered in a compilation unit.

public Position.LineMap
getLineMap()

Implements com.sun.tools.javac.parser.Lexer.getLineMap.

Build a map for translating between line numbers and positions in the input.

public void
lintWarning(JCDiagnostic.DiagnosticPosition pos, JCDiagnostic.LintWarning key)

Implements com.sun.tools.javac.parser.Lexer.lintWarning.

Report a warning that is subject to possible suppression by @SuppressWarnings.

public void
nextToken()

Implements com.sun.tools.javac.parser.Lexer.nextToken.

Consume the next token.

public Tokens.Token
prevToken()

Implements com.sun.tools.javac.parser.Lexer.prevToken.

Return the last character position of the previous token.

public void
setPrevToken(Tokens.Token prevToken)

Implements com.sun.tools.javac.parser.Lexer.setPrevToken.

Sets the previous token.

public Tokens.Token
split()

Implements com.sun.tools.javac.parser.Lexer.split.

Splits the current token in two and return the first (split) token.

public Tokens.Token
token()

Implements com.sun.tools.javac.parser.Lexer.token.

Return current token.

public Tokens.Token
token(int lookahead)

Implements com.sun.tools.javac.parser.Lexer.token.

Return token with given lookahead.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

offsetback to summary
pack-priv int offset

Token offset from where parent scanner branched.

prevTokenback to summary
private Tokens.Token prevToken

The previous token, set by nextToken().

Sback to summary
pack-priv Lexer S

Parent scanner.

tokenback to summary
private Tokens.Token token

The token, set by nextToken().

Constructor Detail

VirtualScannerback to summary
public VirtualScanner(Lexer s)

Method Detail

errPosback to summary
public int errPos()

Implements com.sun.tools.javac.parser.Lexer.errPos.

Doc from com.sun.tools.javac.parser.Lexer.errPos.

Return the position where a lexical error occurred;

Annotations
@Override
errPosback to summary
public void errPos(int pos)

Implements com.sun.tools.javac.parser.Lexer.errPos.

Doc from com.sun.tools.javac.parser.Lexer.errPos.

Set the position where a lexical error occurred;

Annotations
@Override
getDocCommentsback to summary
public Queue<Tokens.Comment> getDocComments()

Implements com.sun.tools.javac.parser.Lexer.getDocComments.

Doc from com.sun.tools.javac.parser.Lexer.getDocComments.

Returns a queue for the documentation comments encountered in a compilation unit. Comments may be added to this queue by the implementation; clients may remove them from the queue as they are analyzed.

Note

all comments may also be associated with the following token.

Annotations
@Override
getLineMapback to summary
public Position.LineMap getLineMap()

Implements com.sun.tools.javac.parser.Lexer.getLineMap.

Doc from com.sun.tools.javac.parser.Lexer.getLineMap.

Build a map for translating between line numbers and positions in the input.

Annotations
@Override
lintWarningback to summary
public void lintWarning(JCDiagnostic.DiagnosticPosition pos, JCDiagnostic.LintWarning key)

Implements com.sun.tools.javac.parser.Lexer.lintWarning.

Doc from com.sun.tools.javac.parser.Lexer.lintWarning.

Report a warning that is subject to possible suppression by @SuppressWarnings.

Annotations
@Override
nextTokenback to summary
public void nextToken()

Implements com.sun.tools.javac.parser.Lexer.nextToken.

Doc from com.sun.tools.javac.parser.Lexer.nextToken.

Consume the next token.

Annotations
@Override
prevTokenback to summary
public Tokens.Token prevToken()

Implements com.sun.tools.javac.parser.Lexer.prevToken.

Doc from com.sun.tools.javac.parser.Lexer.prevToken.

Return the last character position of the previous token.

Annotations
@Override
setPrevTokenback to summary
public void setPrevToken(Tokens.Token prevToken)

Implements com.sun.tools.javac.parser.Lexer.setPrevToken.

Doc from com.sun.tools.javac.parser.Lexer.setPrevToken.

Sets the previous token.

Annotations
@Override
splitback to summary
public Tokens.Token split()

Implements com.sun.tools.javac.parser.Lexer.split.

Doc from com.sun.tools.javac.parser.Lexer.split.

Splits the current token in two and return the first (split) token. For instance '<<<' is split into two tokens '<' and '<<' respectively, and the latter is returned.

Annotations
@Override
tokenback to summary
public Tokens.Token token()

Implements com.sun.tools.javac.parser.Lexer.token.

Doc from com.sun.tools.javac.parser.Lexer.token.

Return current token.

Annotations
@Override
tokenback to summary
public Tokens.Token token(int lookahead)

Implements com.sun.tools.javac.parser.Lexer.token.

Doc from com.sun.tools.javac.parser.Lexer.token.

Return token with given lookahead.

Annotations
@Override