Package com.google.googlejavaformat.java
Class JavaInputAstVisitor
- Direct Known Subclasses:
Java17InputAstVisitor
An AST visitor that builds a stream of
Ops to format from the given CompilationUnitTree.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumWhether to allow leading blank lines in blocks.protected static enumWhether to allow trailing blank lines in blocks.(package private) static classRepresents an annotation or a modifier in aModifiersTree.protected static enumWhether to include braces.protected static enumWhether to break or not.protected static enumWhether to collapse empty blocks.protected static enumKind of declaration.(package private) static classThe modifiers annotations for a declaration, grouped in to a prefix that contains all of the declaration annotations and modifiers, and a suffix of type annotations.(package private) static enumWhether or not to include dimensions.protected static enumDirection for Annotations (usually VERTICAL).protected static enumWhether these declarations are the first in the block.(package private) static enumWhether the formal parameter declaration is a receiver.(package private) static enumWhether or not the declaration is Varargs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OpsBuilderprotected static final longprivate static final Patternprotected final intA record of whether we have visited into an expression.(package private) static final com.google.common.collect.ImmutableSet<String> private static final intAllow multi-line filling (of array initializers, argument lists, and boolean expressions) for items with length less than or equal to this threshold.protected final Indent.Constprotected final Indent.Constprotected final Indent.Constprotected final Indent.Constprotected static final longprotected static final Indent.Const -
Constructor Summary
ConstructorsConstructorDescriptionJavaInputAstVisitor(OpsBuilder builder, int indentMultiplier) TheVisitorconstructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate IntegeractualColumn(com.sun.source.tree.ExpressionTree expression) (package private) voidaddArguments(List<? extends com.sun.source.tree.ExpressionTree> arguments, Indent plusIndent) Add arguments to a method invocation, etc.protected voidaddBodyDeclarations(List<? extends com.sun.source.tree.Tree> bodyDeclarations, JavaInputAstVisitor.BracesOrNot braces, JavaInputAstVisitor.FirstDeclarationsOrNot first0) Add a list of declarations.(package private) voidaddTypeArguments(List<? extends com.sun.source.tree.Tree> typeArguments, Indent plusIndent) Helper methods for method invocations.private booleanambiguousUnaryOperator(com.sun.source.tree.UnaryTree node, String operatorName) private voidprivate intargumentsAreTabular(List<? extends com.sun.source.tree.ExpressionTree> arguments) Returns the number of columns if the arguments arg laid out in a grid, or else-1.private static final com.google.common.collect.ImmutableList<Op> breakFillList(Optional<Output.BreakTag> breakTag) private static final com.google.common.collect.ImmutableList<Op> breakList(Optional<Output.BreakTag> breakTag) private static JavaInputAstVisitor.DirectioncanLocalHaveHorizontalAnnotations(com.sun.source.tree.ModifiersTree modifiers) Can a local with a set of modifiers be declared with horizontal annotations? This is currently true if there is at most one parameterless annotation, and no others.private voidcheckForTypeAnnotation(com.sun.source.tree.ImportTree node) private voidclassDeclarationTypeList(String token, List<? extends com.sun.source.tree.Tree> types) private voiddeclareMany(List<com.sun.source.tree.VariableTree> fragments, JavaInputAstVisitor.Direction annotationDirection) protected intdeclareOne(JavaInputAstVisitor.DeclarationKind kind, JavaInputAstVisitor.Direction annotationsDirection, Optional<com.sun.source.tree.ModifiersTree> modifiers, com.sun.source.tree.Tree type, Name name, String op, String equals, Optional<com.sun.source.tree.ExpressionTree> initializer, Optional<String> trailing, Optional<com.sun.source.tree.ExpressionTree> receiverExpression, Optional<DimensionHelpers.TypeWithDims> typeWithDims) Declare one variable or variable-like thing.private voiddotExpressionArgsAndParen(com.sun.source.tree.ExpressionTree expression, Indent tyargIndent, Indent indent) private voiddotExpressionUpToArgs(com.sun.source.tree.ExpressionTree expression, Optional<Output.BreakTag> tyargTag) protected voidSkips over extra semi-colons at the top-level, or in a class member declaration lists.private static booleanexpressionsAreParallel(List<List<com.sun.source.tree.ExpressionTree>> rows, int column, int atLeastM) Returns true ifatLeastMof the expressions in the given column are the same kind.private static JavaInputAstVisitor.DirectionfieldAnnotationDirection(com.sun.source.tree.ModifiersTree modifiers) Should a field with a set of modifiers be declared with horizontal annotations? This is currently true if all annotations are parameterless annotations.private booleanfillFirstArgument(com.sun.source.tree.ExpressionTree e, List<com.sun.source.tree.ExpressionTree> items, Indent indent) private static final com.google.common.collect.ImmutableList<Op> forceBreakList(Optional<Output.BreakTag> breakTag) private voidprivate voidformatArrayIndices(Deque<com.sun.source.tree.ExpressionTree> indices) Lays out one or more array indices.(package private) final Output.BreakTaggenSym()private static com.sun.source.tree.ExpressionTreegetArrayBase(com.sun.source.tree.ExpressionTree node) Returns the base expression of an erray access, e.g.private static Deque<com.sun.source.tree.ExpressionTree> getArrayIndices(com.sun.source.tree.ExpressionTree expression) Returns all array indices for the given expression, e.g.private static com.sun.source.tree.ExpressionTreegetMethodReceiver(com.sun.source.tree.MethodInvocationTree methodInvocation) private static Optional<? extends Input.Token> getNextToken(Input input, int position) protected List<? extends com.sun.source.tree.Tree> getPermitsClause(com.sun.source.tree.ClassTree node) Gets the permits clause for the given node.private static NamegetSimpleName(com.sun.source.tree.ImportTree importTree) private booleanhandleLogStatement(com.sun.source.tree.MethodInvocationTree node) Special-cases log statements, to output:protected voidhandleModule(boolean afterFirstToken, com.sun.source.tree.CompilationUnitTree node) handleStream(List<com.sun.source.tree.ExpressionTree> parts) private booleanhasJavaDoc(com.sun.source.tree.Tree bodyDeclaration) Does this declaration have javadoc preceding it?private booleanhasOnlyShortItems(List<? extends com.sun.source.tree.ExpressionTree> expressions) private booleanhasTrailingToken(Input input, List<? extends com.sun.source.tree.Tree> nodes, String token) Does this list of trees end with the specified token?private booleanprivate static booleanisArrayValue(com.sun.source.tree.ExpressionTree argument) private booleanisFormatMethod(List<? extends com.sun.source.tree.ExpressionTree> arguments) Identifies String formatting methods likeString.format(java.lang.String, java.lang.Object...)which we prefer to format as:private static booleanisModifier(String token) private booleanisStringConcat(com.sun.source.tree.ExpressionTree first) (package private) booleanisTypeAnnotation(com.sun.source.tree.AnnotationTree annotationTree) private static booleanisUnaryMinusLiteral(String literalTreeSource) protected voidprivate voidmaybeAddDims(Deque<com.sun.source.tree.ExpressionTree> dimExpressions, Deque<List<? extends com.sun.source.tree.AnnotationTree>> annotations) The compiler does not always preserve the concrete syntax of annotated array dimensions, and mixed-notation array dimensions.private voidmaybeAddDims(Deque<List<? extends com.sun.source.tree.AnnotationTree>> annotations) private voidmethodBody(com.sun.source.tree.MethodTree node) (package private) static intprivate static com.google.common.collect.ImmutableList<String> simpleNames(Deque<com.sun.source.tree.ExpressionTree> stack) Returns the simple names of expressions in a "." chain.(package private) JavaInputAstVisitor.DeclarationModifiersAndTypeAnnotationssplitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, List<? extends com.sun.source.tree.AnnotationTree> annotations) Examines the token stream to convert the modifiers for a declaration into aJavaInputAstVisitor.DeclarationModifiersAndTypeAnnotations.private voidsplitToken(String operatorName) protected final voidsync(com.sun.source.tree.Tree node) Sync to position in the input.protected final voidEmit aDoc.Token.protected final voidEmit aDoc.Token.(package private) final voidtokenBreakTrailingComment(String token, Indent breakAndIndentTrailingComment) Emit aDoc.Token, and breaks and indents trailing javadoc or block comments.final StringtoString()protected voidtypeDeclarationModifiers(com.sun.source.tree.ModifiersTree modifiers) protected voidtypeParametersRest(List<? extends com.sun.source.tree.TypeParameterTree> typeParameters, Indent plusIndent) Does not omit the leading"<", which should be associated with the type name.private com.sun.tools.javac.tree.JCTree.TagunaryTag(com.sun.source.tree.ExpressionTree expression) private static DimensionHelpers.TypeWithDimsvariableFragmentDims(boolean afterFirstToken, int leadingDims, com.sun.source.tree.Tree type) private static List<com.sun.source.tree.VariableTree> variableFragments(com.google.common.collect.PeekingIterator<? extends com.sun.source.tree.Tree> it, com.sun.source.tree.Tree first) The parser expands multi-variable declarations into separate single-variable declarations.protected voidvariableName(Name name) (package private) voidverticalAnnotations(List<com.sun.source.tree.AnnotationTree> annotations) boolean(package private) voidvisitAndBreakModifiers(com.sun.source.tree.ModifiersTree modifiers, JavaInputAstVisitor.Direction annotationDirection, Optional<Output.BreakTag> declarationAnnotationBreak) Output combined modifiers and annotations and the trailing break.private voidvisitAnnotatedArrayType(com.sun.source.tree.Tree node) visitAnnotatedType(com.sun.source.tree.AnnotatedTypeTree node, Void unused) visitAnnotation(com.sun.source.tree.AnnotationTree node, Void unused) voidvisitAnnotationArgument(com.sun.source.tree.AssignmentTree node) protected voidvisitAnnotations(List<? extends com.sun.source.tree.AnnotationTree> annotations, JavaInputAstVisitor.BreakOrNot breakBefore, JavaInputAstVisitor.BreakOrNot breakAfter) Helper method for annotations.voidvisitAnnotationType(com.sun.source.tree.ClassTree node) visitArrayAccess(com.sun.source.tree.ArrayAccessTree node, Void unused) booleanvisitArrayInitializer(List<? extends com.sun.source.tree.ExpressionTree> expressions) visitArrayType(com.sun.source.tree.ArrayTypeTree node, Void unused) visitAssert(com.sun.source.tree.AssertTree node, Void unused) visitAssignment(com.sun.source.tree.AssignmentTree node, Void unused) visitBinary(com.sun.source.tree.BinaryTree node, Void unused) protected voidvisitBlock(com.sun.source.tree.BlockTree node, JavaInputAstVisitor.CollapseEmptyOrNot collapseEmptyOrNot, JavaInputAstVisitor.AllowLeadingBlankLine allowLeadingBlankLine, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlankLine) Helper method for blocks.visitBlock(com.sun.source.tree.BlockTree node, Void unused) visitBreak(com.sun.source.tree.BreakTree node, Void unused) visitCatch(com.sun.source.tree.CatchTree node, Void unused) private voidvisitCatchClause(com.sun.source.tree.CatchTree node, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlankLine) Helper method forCatchTrees.visitClass(com.sun.source.tree.ClassTree tree, Void unused) voidvisitClassDeclaration(com.sun.source.tree.ClassTree node) visitCompilationUnit(com.sun.source.tree.CompilationUnitTree node, Void unused) visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node, Void unused) visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node, Void unused) visitContinue(com.sun.source.tree.ContinueTree node, Void unused) private voidvisitDirective(String name, String separator, com.sun.source.tree.ExpressionTree nameExpression, @Nullable List<? extends com.sun.source.tree.ExpressionTree> items) (package private) voidvisitDot(com.sun.source.tree.ExpressionTree node0) Output a "." node.private voidvisitDotWithPrefix(List<com.sun.source.tree.ExpressionTree> items, boolean needDot, Collection<Integer> prefixes, Doc.FillMode prefixFillMode) Output a chain of dereferences where some prefix should be treated as a single syntactic unit, either because it looks like a type name or because there is only a single method invocation in the chain.visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree node, Void unused) visitEmptyStatement(com.sun.source.tree.EmptyStatementTree node, Void unused) visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node, Void unused) private voidvisitEnumConstantDeclaration(com.sun.source.tree.VariableTree enumConstant) booleanvisitEnumDeclaration(com.sun.source.tree.ClassTree node) visitExports(com.sun.source.tree.ExportsTree node, Void unused) visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree node, Void unused) visitForLoop(com.sun.source.tree.ForLoopTree node, Void unused) protected voidvisitFormals(Optional<com.sun.source.tree.VariableTree> receiver, List<? extends com.sun.source.tree.VariableTree> parameters) visitIdentifier(com.sun.source.tree.IdentifierTree node, Void unused) visitImport(com.sun.source.tree.ImportTree node, Void unused) visitInstanceOf(com.sun.source.tree.InstanceOfTree node, Void unused) visitIntersectionType(com.sun.source.tree.IntersectionTypeTree node, Void unused) visitLabeledStatement(com.sun.source.tree.LabeledStatementTree node, Void unused) visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree node, Void unused) visitLiteral(com.sun.source.tree.LiteralTree node, Void unused) visitMemberReference(com.sun.source.tree.MemberReferenceTree node, Void unused) visitMemberSelect(com.sun.source.tree.MemberSelectTree node, Void unused) visitMethod(com.sun.source.tree.MethodTree node, Void unused) visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, Void unused) private com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(JavaInputAstVisitor.DeclarationModifiersAndTypeAnnotations splitModifiers, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) protected com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) Output combined modifiers and annotations and returns the trailing break.visitModifiers(com.sun.source.tree.ModifiersTree node, Void unused) protected com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, List<? extends com.sun.source.tree.AnnotationTree> annotationTrees, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) visitModule(com.sun.source.tree.ModuleTree node, Void unused) private voidvisitName(com.sun.source.tree.Tree node) Helper method for import declarations, names, and qualified names.visitNewArray(com.sun.source.tree.NewArrayTree node, Void unused) visitNewClass(com.sun.source.tree.NewClassTree node, Void unused) visitOpens(com.sun.source.tree.OpensTree node, Void unused) private voidvisitPackage(com.sun.source.tree.ExpressionTree packageName, List<? extends com.sun.source.tree.AnnotationTree> packageAnnotations) visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree node, Void unused) visitParenthesized(com.sun.source.tree.ParenthesizedTree node, Void unused) visitPrimitiveType(com.sun.source.tree.PrimitiveTypeTree node, Void unused) visitProvides(com.sun.source.tree.ProvidesTree node, Void unused) private voidvisitRegularDot(List<com.sun.source.tree.ExpressionTree> items, boolean needDot) Output a "regular" chain of dereferences, possibly in builder-style.visitRequires(com.sun.source.tree.RequiresTree node, Void unused) visitReturn(com.sun.source.tree.ReturnTree node, Void unused) (package private) booleanvisitSingleMemberAnnotation(com.sun.source.tree.AnnotationTree node) private voidvisitStatement(com.sun.source.tree.StatementTree node, JavaInputAstVisitor.CollapseEmptyOrNot collapseEmptyOrNot, JavaInputAstVisitor.AllowLeadingBlankLine allowLeadingBlank, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlank) Helper method for statements.protected voidvisitStatements(List<? extends com.sun.source.tree.StatementTree> statements) protected voidvisitSwitch(com.sun.source.tree.ExpressionTree expression, List<? extends com.sun.source.tree.CaseTree> cases) visitSwitch(com.sun.source.tree.SwitchTree node, Void unused) visitSynchronized(com.sun.source.tree.SynchronizedTree node, Void unused) visitThrow(com.sun.source.tree.ThrowTree node, Void unused) private voidvisitThrowsClause(List<? extends com.sun.source.tree.ExpressionTree> thrownExceptionTypes) private voidvisitToDeclare(JavaInputAstVisitor.DeclarationKind kind, JavaInputAstVisitor.Direction annotationsDirection, com.sun.source.tree.VariableTree node, Optional<com.sun.source.tree.ExpressionTree> initializer, String equals, Optional<String> trailing) visitTypeCast(com.sun.source.tree.TypeCastTree node, Void unused) visitTypeParameter(com.sun.source.tree.TypeParameterTree node, Void unused) visitUnary(com.sun.source.tree.UnaryTree node, Void unused) visitUnionType(com.sun.source.tree.UnionTypeTree node, Void unused) private voidvisitUnionType(com.sun.source.tree.VariableTree declaration) Formats a union type declaration in a catch clause.visitVariable(com.sun.source.tree.VariableTree node, Void unused) (package private) voidvisitVariables(List<com.sun.source.tree.VariableTree> fragments, JavaInputAstVisitor.DeclarationKind declarationKind, JavaInputAstVisitor.Direction annotationDirection) visitWhileLoop(com.sun.source.tree.WhileLoopTree node, Void unused) visitWildcard(com.sun.source.tree.WildcardTree node, Void unused) private static voidwalkInfix(int precedence, com.sun.source.tree.ExpressionTree expression, List<com.sun.source.tree.ExpressionTree> operands, List<String> operators) Accumulate the operands and operators.Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scanMethods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnyPattern, visitBindingPattern, visitConstantCaseLabel, visitDeconstructionPattern, visitDefaultCaseLabel, visitErroneous, visitOther, visitPackage, visitPatternCaseLabel, visitStringTemplate, visitSwitchExpression, visitYield
-
Field Details
-
TYPE_ANNOTATIONS
-
builder
-
ZERO
-
indentMultiplier
protected final int indentMultiplier -
minusTwo
-
minusFour
-
plusTwo
-
plusFour
-
typeAnnotationSimpleNames
-
MAX_ITEM_LENGTH_FOR_FILLING
private static final int MAX_ITEM_LENGTH_FOR_FILLINGAllow multi-line filling (of array initializers, argument lists, and boolean expressions) for items with length less than or equal to this threshold.- See Also:
-
inExpression
A record of whether we have visited into an expression. -
COMPACT_RECORD_CONSTRUCTOR
protected static final long COMPACT_RECORD_CONSTRUCTOR- See Also:
-
RECORD
protected static final long RECORD- See Also:
-
LOG_METHODS
-
FORMAT_SPECIFIER
-
-
Constructor Details
-
JavaInputAstVisitor
TheVisitorconstructor.- Parameters:
builder- theOpsBuilder
-
-
Method Details
-
typeAnnotations
-
breakList
private static final com.google.common.collect.ImmutableList<Op> breakList(Optional<Output.BreakTag> breakTag) -
breakFillList
private static final com.google.common.collect.ImmutableList<Op> breakFillList(Optional<Output.BreakTag> breakTag) -
forceBreakList
private static final com.google.common.collect.ImmutableList<Op> forceBreakList(Optional<Output.BreakTag> breakTag) -
inExpression
private boolean inExpression() -
scan
-
visitCompilationUnit
-
handleModule
protected void handleModule(boolean afterFirstToken, com.sun.source.tree.CompilationUnitTree node) -
dropEmptyDeclarations
protected void dropEmptyDeclarations()Skips over extra semi-colons at the top-level, or in a class member declaration lists. -
visitClass
-
visitAnnotationType
public void visitAnnotationType(com.sun.source.tree.ClassTree node) -
visitArrayAccess
-
visitNewArray
-
visitArrayInitializer
public boolean visitArrayInitializer(List<? extends com.sun.source.tree.ExpressionTree> expressions) -
hasOnlyShortItems
-
visitArrayType
-
visitAnnotatedArrayType
private void visitAnnotatedArrayType(com.sun.source.tree.Tree node) -
visitAssert
-
visitAssignment
-
visitBlock
-
visitCompoundAssignment
-
visitBreak
-
visitTypeCast
-
visitNewClass
-
visitConditionalExpression
-
visitContinue
-
visitDoWhileLoop
-
visitEmptyStatement
-
visitEnhancedForLoop
-
visitEnumConstantDeclaration
private void visitEnumConstantDeclaration(com.sun.source.tree.VariableTree enumConstant) -
visitEnumDeclaration
public boolean visitEnumDeclaration(com.sun.source.tree.ClassTree node) -
visitMemberReference
-
visitExpressionStatement
-
visitVariable
-
visitVariables
void visitVariables(List<com.sun.source.tree.VariableTree> fragments, JavaInputAstVisitor.DeclarationKind declarationKind, JavaInputAstVisitor.Direction annotationDirection) -
variableFragmentDims
private static DimensionHelpers.TypeWithDims variableFragmentDims(boolean afterFirstToken, int leadingDims, com.sun.source.tree.Tree type) -
visitForLoop
-
visitIf
-
visitImport
-
checkForTypeAnnotation
private void checkForTypeAnnotation(com.sun.source.tree.ImportTree node) -
getSimpleName
-
visitBinary
-
visitInstanceOf
-
visitIntersectionType
-
visitLabeledStatement
-
visitLambdaExpression
-
visitAnnotation
-
isArrayValue
private static boolean isArrayValue(com.sun.source.tree.ExpressionTree argument) -
visitAnnotationArgument
public void visitAnnotationArgument(com.sun.source.tree.AssignmentTree node) -
visitAnnotatedType
-
visitMethod
-
methodBody
private void methodBody(com.sun.source.tree.MethodTree node) -
visitMethodInvocation
-
handleLogStatement
private boolean handleLogStatement(com.sun.source.tree.MethodInvocationTree node) Special-cases log statements, to output:logger.atInfo().log( "Number of foos: %d, foos.size());Instead of:
logger .atInfo() .log( "Number of foos: %d, foos.size()); -
handleStream
-
indexes
-
visitMemberSelect
-
visitLiteral
-
isUnaryMinusLiteral
-
visitPackage
private void visitPackage(com.sun.source.tree.ExpressionTree packageName, List<? extends com.sun.source.tree.AnnotationTree> packageAnnotations) -
visitParameterizedType
-
visitParenthesized
-
visitUnary
-
splitToken
-
ambiguousUnaryOperator
-
unaryTag
private com.sun.tools.javac.tree.JCTree.Tag unaryTag(com.sun.source.tree.ExpressionTree expression) -
visitPrimitiveType
-
visit
-
visitReturn
-
visitSingleMemberAnnotation
boolean visitSingleMemberAnnotation(com.sun.source.tree.AnnotationTree node) -
visitCase
-
visitSwitch
-
visitSwitch
protected void visitSwitch(com.sun.source.tree.ExpressionTree expression, List<? extends com.sun.source.tree.CaseTree> cases) -
visitSynchronized
-
visitThrow
-
visitTry
-
visitClassDeclaration
public void visitClassDeclaration(com.sun.source.tree.ClassTree node) -
visitTypeParameter
-
visitUnionType
-
visitWhileLoop
-
visitWildcard
-
visitAnnotations
protected void visitAnnotations(List<? extends com.sun.source.tree.AnnotationTree> annotations, JavaInputAstVisitor.BreakOrNot breakBefore, JavaInputAstVisitor.BreakOrNot breakAfter) Helper method for annotations. -
verticalAnnotations
-
visitBlock
protected void visitBlock(com.sun.source.tree.BlockTree node, JavaInputAstVisitor.CollapseEmptyOrNot collapseEmptyOrNot, JavaInputAstVisitor.AllowLeadingBlankLine allowLeadingBlankLine, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlankLine) Helper method for blocks. -
visitStatement
private void visitStatement(com.sun.source.tree.StatementTree node, JavaInputAstVisitor.CollapseEmptyOrNot collapseEmptyOrNot, JavaInputAstVisitor.AllowLeadingBlankLine allowLeadingBlank, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlank) Helper method for statements. -
visitStatements
-
typeDeclarationModifiers
protected void typeDeclarationModifiers(com.sun.source.tree.ModifiersTree modifiers) -
visitAndBreakModifiers
void visitAndBreakModifiers(com.sun.source.tree.ModifiersTree modifiers, JavaInputAstVisitor.Direction annotationDirection, Optional<Output.BreakTag> declarationAnnotationBreak) Output combined modifiers and annotations and the trailing break. -
visitModifiers
-
visitModifiers
@CheckReturnValue protected com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) Output combined modifiers and annotations and returns the trailing break. -
visitModifiers
@CheckReturnValue protected com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, List<? extends com.sun.source.tree.AnnotationTree> annotationTrees, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) -
visitModifiers
@CheckReturnValue private com.google.common.collect.ImmutableList<com.sun.source.tree.AnnotationTree> visitModifiers(JavaInputAstVisitor.DeclarationModifiersAndTypeAnnotations splitModifiers, JavaInputAstVisitor.Direction annotationsDirection, Optional<Output.BreakTag> declarationAnnotationBreak) -
splitModifiers
JavaInputAstVisitor.DeclarationModifiersAndTypeAnnotations splitModifiers(com.sun.source.tree.ModifiersTree modifiersTree, List<? extends com.sun.source.tree.AnnotationTree> annotations) Examines the token stream to convert the modifiers for a declaration into aJavaInputAstVisitor.DeclarationModifiersAndTypeAnnotations. -
formatAnnotationOrModifier
-
isTypeAnnotation
boolean isTypeAnnotation(com.sun.source.tree.AnnotationTree annotationTree) -
isModifier
-
visitCatch
-
visitCatchClause
private void visitCatchClause(com.sun.source.tree.CatchTree node, JavaInputAstVisitor.AllowTrailingBlankLine allowTrailingBlankLine) Helper method forCatchTrees. -
visitUnionType
private void visitUnionType(com.sun.source.tree.VariableTree declaration) Formats a union type declaration in a catch clause. -
walkInfix
private static void walkInfix(int precedence, com.sun.source.tree.ExpressionTree expression, List<com.sun.source.tree.ExpressionTree> operands, List<String> operators) Accumulate the operands and operators. -
visitFormals
-
visitThrowsClause
private void visitThrowsClause(List<? extends com.sun.source.tree.ExpressionTree> thrownExceptionTypes) -
visitIdentifier
-
visitModule
-
visitDirective
-
visitExports
-
visitOpens
-
visitProvides
-
visitRequires
-
visitUses
-
visitName
private void visitName(com.sun.source.tree.Tree node) Helper method for import declarations, names, and qualified names. -
visitToDeclare
private void visitToDeclare(JavaInputAstVisitor.DeclarationKind kind, JavaInputAstVisitor.Direction annotationsDirection, com.sun.source.tree.VariableTree node, Optional<com.sun.source.tree.ExpressionTree> initializer, String equals, Optional<String> trailing) -
typeParametersRest
protected void typeParametersRest(List<? extends com.sun.source.tree.TypeParameterTree> typeParameters, Indent plusIndent) Does not omit the leading"<", which should be associated with the type name. -
visitDot
void visitDot(com.sun.source.tree.ExpressionTree node0) Output a "." node.- Parameters:
node0- the "." node
-
visitRegularDot
Output a "regular" chain of dereferences, possibly in builder-style. Break before every dot.- Parameters:
items- in the chainneedDot- whether a leading dot is needed
-
fillFirstArgument
-
visitDotWithPrefix
private void visitDotWithPrefix(List<com.sun.source.tree.ExpressionTree> items, boolean needDot, Collection<Integer> prefixes, Doc.FillMode prefixFillMode) Output a chain of dereferences where some prefix should be treated as a single syntactic unit, either because it looks like a type name or because there is only a single method invocation in the chain.- Parameters:
items- in the chainneedDot- whether a leading dot is neededprefixes- the terminal indices of 'prefixes' of the expression that should be treated as a syntactic unit
-
simpleNames
private static com.google.common.collect.ImmutableList<String> simpleNames(Deque<com.sun.source.tree.ExpressionTree> stack) Returns the simple names of expressions in a "." chain. -
dotExpressionUpToArgs
private void dotExpressionUpToArgs(com.sun.source.tree.ExpressionTree expression, Optional<Output.BreakTag> tyargTag) -
getArrayBase
private static com.sun.source.tree.ExpressionTree getArrayBase(com.sun.source.tree.ExpressionTree node) Returns the base expression of an erray access, e.g. givenfoo[0][0]returnsfoo. -
getMethodReceiver
private static com.sun.source.tree.ExpressionTree getMethodReceiver(com.sun.source.tree.MethodInvocationTree methodInvocation) -
dotExpressionArgsAndParen
-
formatArrayIndices
Lays out one or more array indices. Does not output the expression for the array itself. -
getArrayIndices
private static Deque<com.sun.source.tree.ExpressionTree> getArrayIndices(com.sun.source.tree.ExpressionTree expression) Returns all array indices for the given expression, e.g. givenfoo[0][0]returns the expressions for[0][0]. -
addTypeArguments
Helper methods for method invocations. -
addArguments
Add arguments to a method invocation, etc. The arguments indentedplusFour, filled, from the current indent. The arguments may be output two at a time if they seem to be arguments to a map constructor, etc.- Parameters:
arguments- the argumentsplusIndent- the extra indent for the arguments
-
argList
-
isFormatMethod
Identifies String formatting methods likeString.format(java.lang.String, java.lang.Object...)which we prefer to format as:String.format( "the format string: %s %s %s", arg, arg, arg);And not:
String.format( "the format string: %s %s %s", arg, arg, arg); -
isStringConcat
private boolean isStringConcat(com.sun.source.tree.ExpressionTree first) -
argumentsAreTabular
Returns the number of columns if the arguments arg laid out in a grid, or else-1. -
rowLength
-
actualColumn
-
expressionsAreParallel
private static boolean expressionsAreParallel(List<List<com.sun.source.tree.ExpressionTree>> rows, int column, int atLeastM) Returns true ifatLeastMof the expressions in the given column are the same kind. -
declareOne
protected int declareOne(JavaInputAstVisitor.DeclarationKind kind, JavaInputAstVisitor.Direction annotationsDirection, Optional<com.sun.source.tree.ModifiersTree> modifiers, com.sun.source.tree.Tree type, Name name, String op, String equals, Optional<com.sun.source.tree.ExpressionTree> initializer, Optional<String> trailing, Optional<com.sun.source.tree.ExpressionTree> receiverExpression, Optional<DimensionHelpers.TypeWithDims> typeWithDims) Declare one variable or variable-like thing. -
variableName
-
maybeAddDims
-
maybeAddDims
private void maybeAddDims(Deque<com.sun.source.tree.ExpressionTree> dimExpressions, Deque<List<? extends com.sun.source.tree.AnnotationTree>> annotations) The compiler does not always preserve the concrete syntax of annotated array dimensions, and mixed-notation array dimensions. Use look-ahead to preserve the original syntax.It is assumed that any number of regular dimension specifiers (
[]with no annotations) may be present in the input.- Parameters:
dimExpressions- an ordered list of dimension expressions (e.g. the0innew int[0]annotations- an ordered list of type annotations grouped by dimension (e.g.[[@A, @B], [@C]]forint @A [] @B @C []
-
declareMany
private void declareMany(List<com.sun.source.tree.VariableTree> fragments, JavaInputAstVisitor.Direction annotationDirection) -
addBodyDeclarations
protected void addBodyDeclarations(List<? extends com.sun.source.tree.Tree> bodyDeclarations, JavaInputAstVisitor.BracesOrNot braces, JavaInputAstVisitor.FirstDeclarationsOrNot first0) Add a list of declarations. -
getPermitsClause
protected List<? extends com.sun.source.tree.Tree> getPermitsClause(com.sun.source.tree.ClassTree node) Gets the permits clause for the given node. This is only available in Java 15 and later. -
classDeclarationTypeList
-
variableFragments
private static List<com.sun.source.tree.VariableTree> variableFragments(com.google.common.collect.PeekingIterator<? extends com.sun.source.tree.Tree> it, com.sun.source.tree.Tree first) The parser expands multi-variable declarations into separate single-variable declarations. All of the fragments in the original declaration have the same start position, so we use that as a signal to collect them and preserve the multi-variable declaration in the output.e.g.
int x, y;is parsed asint x; int y;. -
hasJavaDoc
private boolean hasJavaDoc(com.sun.source.tree.Tree bodyDeclaration) Does this declaration have javadoc preceding it? -
getNextToken
-
hasTrailingToken
private boolean hasTrailingToken(Input input, List<? extends com.sun.source.tree.Tree> nodes, String token) Does this list of trees end with the specified token? -
canLocalHaveHorizontalAnnotations
private static JavaInputAstVisitor.Direction canLocalHaveHorizontalAnnotations(com.sun.source.tree.ModifiersTree modifiers) Can a local with a set of modifiers be declared with horizontal annotations? This is currently true if there is at most one parameterless annotation, and no others.- Parameters:
modifiers- the list ofModifiersTrees- Returns:
- whether the local can be declared with horizontal annotations
-
fieldAnnotationDirection
private static JavaInputAstVisitor.Direction fieldAnnotationDirection(com.sun.source.tree.ModifiersTree modifiers) Should a field with a set of modifiers be declared with horizontal annotations? This is currently true if all annotations are parameterless annotations. -
token
Emit aDoc.Token. -
token
Emit aDoc.Token. -
tokenBreakTrailingComment
Emit aDoc.Token, and breaks and indents trailing javadoc or block comments. -
markForPartialFormat
protected void markForPartialFormat() -
sync
protected final void sync(com.sun.source.tree.Tree node) Sync to position in the input. If we've skipped outputting any tokens that were present in the input tokens, output them here and complain.- Parameters:
node- the ASTNode holding the input position
-
genSym
-
toString
-