Package com.google.googlejavaformat.java
Class DimensionHelpers
java.lang.Object
com.google.googlejavaformat.java.DimensionHelpers
Utilities for working with array dimensions.
javac's parser does not preserve concrete syntax for mixed-notation arrays, so we have to re-lex the input to extra it.
For example, int [] a; cannot be distinguished from int [] a []; in the AST.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum(package private) static classThe array dimension specifiers (including any type annotations) associated with a type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static DimensionHelpers.TypeWithDimsextractDims(com.sun.source.tree.Tree node, DimensionHelpers.SortedDims sorted) Returns a (possibly re-ordered)DimensionHelpers.TypeWithDimsfor the given type.private static com.sun.source.tree.TreeextractDims(Deque<List<com.sun.source.tree.AnnotationTree>> dims, com.sun.source.tree.Tree node) Accumulates a flattened list of array dimensions specifiers with type annotations, and returns the base type.reorderBySourcePosition(Deque<List<com.sun.source.tree.AnnotationTree>> dims) Rotate the list of dimension specifiers until all dimensions with type annotations appear in source order.
-
Constructor Details
-
DimensionHelpers
DimensionHelpers()
-
-
Method Details
-
extractDims
static DimensionHelpers.TypeWithDims extractDims(com.sun.source.tree.Tree node, DimensionHelpers.SortedDims sorted) Returns a (possibly re-ordered)DimensionHelpers.TypeWithDimsfor the given type. -
reorderBySourcePosition
private static Iterable<List<com.sun.source.tree.AnnotationTree>> reorderBySourcePosition(Deque<List<com.sun.source.tree.AnnotationTree>> dims) Rotate the list of dimension specifiers until all dimensions with type annotations appear in source order.javac reorders dimension specifiers in method declarations with mixed-array notation, which means that any type annotations don't appear in source order.
For example, the type of
int @A [] f() @B [] {}is parsed as@B [] @A [].This doesn't handle cases with un-annotated dimension specifiers, so the formatting logic checks the token stream to figure out which side of the method name they appear on.
-
extractDims
private static com.sun.source.tree.Tree extractDims(Deque<List<com.sun.source.tree.AnnotationTree>> dims, com.sun.source.tree.Tree node) Accumulates a flattened list of array dimensions specifiers with type annotations, and returns the base type.Given
int @A @B [][] @C [], adds[[@A, @B], [@C]]to dims and returnsint.
-