15
15
package com .google .googlejavaformat .java .java14 ;
16
16
17
17
import static com .google .common .collect .ImmutableList .toImmutableList ;
18
- import static com .google .common .collect .MoreCollectors .toOptional ;
19
18
20
19
import com .google .common .base .Verify ;
21
20
import com .google .common .collect .ImmutableList ;
27
26
import com .sun .source .tree .ClassTree ;
28
27
import com .sun .source .tree .ExpressionTree ;
29
28
import com .sun .source .tree .InstanceOfTree ;
29
+ import com .sun .source .tree .ModifiersTree ;
30
30
import com .sun .source .tree .SwitchExpressionTree ;
31
31
import com .sun .source .tree .Tree ;
32
32
import com .sun .source .tree .VariableTree ;
33
33
import com .sun .source .tree .YieldTree ;
34
34
import com .sun .tools .javac .code .Flags ;
35
35
import com .sun .tools .javac .tree .JCTree ;
36
- import com .sun .tools .javac .tree .JCTree .JCMethodDecl ;
37
36
import com .sun .tools .javac .tree .JCTree .JCVariableDecl ;
38
37
import com .sun .tools .javac .tree .TreeInfo ;
39
38
import java .util .List ;
@@ -56,12 +55,13 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) {
56
55
try {
57
56
VariableTree variableTree =
58
57
(VariableTree ) BindingPatternTree .class .getMethod ("getVariable" ).invoke (node );
59
- visitBindingPattern (variableTree .getType (), variableTree .getName ());
58
+ visitBindingPattern (
59
+ variableTree .getModifiers (), variableTree .getType (), variableTree .getName ());
60
60
} catch (ReflectiveOperationException e1 ) {
61
61
try {
62
62
Tree type = (Tree ) BindingPatternTree .class .getMethod ("getType" ).invoke (node );
63
63
Name name = (Name ) BindingPatternTree .class .getMethod ("getName" ).invoke (node );
64
- visitBindingPattern (type , name );
64
+ visitBindingPattern (/* modifiers= */ null , type , name );
65
65
} catch (ReflectiveOperationException e2 ) {
66
66
e2 .addSuppressed (e1 );
67
67
throw new LinkageError (e2 .getMessage (), e2 );
@@ -70,7 +70,10 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) {
70
70
return null ;
71
71
}
72
72
73
- private void visitBindingPattern (Tree type , Name name ) {
73
+ private void visitBindingPattern (ModifiersTree modifiers , Tree type , Name name ) {
74
+ if (modifiers != null ) {
75
+ builder .addAll (visitModifiers (modifiers , Direction .HORIZONTAL , Optional .empty ()));
76
+ }
74
77
scan (type , null );
75
78
builder .breakOp (" " );
76
79
visit (name );
@@ -136,10 +139,7 @@ public void visitRecordDeclaration(ClassTree node) {
136
139
if (!node .getTypeParameters ().isEmpty ()) {
137
140
typeParametersRest (node .getTypeParameters (), hasSuperInterfaceTypes ? plusFour : ZERO );
138
141
}
139
- ImmutableList <JCVariableDecl > parameters =
140
- compactRecordConstructor (node )
141
- .map (m -> ImmutableList .copyOf (m .getParameters ()))
142
- .orElseGet (() -> recordVariables (node ));
142
+ ImmutableList <JCVariableDecl > parameters = recordVariables (node );
143
143
token ("(" );
144
144
if (!parameters .isEmpty ()) {
145
145
// Break before args.
@@ -178,14 +178,6 @@ public void visitRecordDeclaration(ClassTree node) {
178
178
dropEmptyDeclarations ();
179
179
}
180
180
181
- private static Optional <JCMethodDecl > compactRecordConstructor (ClassTree node ) {
182
- return node .getMembers ().stream ()
183
- .filter (JCMethodDecl .class ::isInstance )
184
- .map (JCMethodDecl .class ::cast )
185
- .filter (m -> (m .mods .flags & COMPACT_RECORD_CONSTRUCTOR ) == COMPACT_RECORD_CONSTRUCTOR )
186
- .collect (toOptional ());
187
- }
188
-
189
181
private static ImmutableList <JCVariableDecl > recordVariables (ClassTree node ) {
190
182
return node .getMembers ().stream ()
191
183
.filter (JCVariableDecl .class ::isInstance )
0 commit comments