Package com.google.googlejavaformat.java
Class DimensionHelpers
- java.lang.Object
-
- com.google.googlejavaformat.java.DimensionHelpers
-
class DimensionHelpers extends java.lang.ObjectUtilities 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 fromint [] a [];in the AST.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDimensionHelpers.SortedDims(package private) static classDimensionHelpers.TypeWithDimsThe array dimension specifiers (including any type annotations) associated with a type.
-
Constructor Summary
Constructors Constructor Description DimensionHelpers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (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(java.util.Deque<java.util.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.private static java.lang.Iterable<java.util.List<com.sun.source.tree.AnnotationTree>>reorderBySourcePosition(java.util.Deque<java.util.List<com.sun.source.tree.AnnotationTree>> dims)Rotate the list of dimension specifiers until all dimensions with type annotations appear in source order.
-
-
-
Method Detail
-
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 java.lang.Iterable<java.util.List<com.sun.source.tree.AnnotationTree>> reorderBySourcePosition(java.util.Deque<java.util.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(java.util.Deque<java.util.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.
-
-