@@ -80,8 +80,7 @@ && isRecordPattern(typePattern)) {
8080
8181 private void checkTypePatternVariableUsage (VariableTree patternVariable ) {
8282 var secondaryLocationsTrees = new HashSet <MemberSelectExpressionTree >();
83- var type = patternVariable .symbol ().type ().symbol ();
84- var comps = recordComponentNames (type );
83+ var recordSymbol = patternVariable .symbol ().type ().symbol ();
8584 for (Tree usage : patternVariable .symbol ().usages ()) {
8685 if (usage .parent () instanceof MemberSelectExpressionTree mse && isNotRecordGetter (mse )) {
8786 secondaryLocationsTrees .add (mse );
@@ -90,12 +89,17 @@ private void checkTypePatternVariableUsage(VariableTree patternVariable) {
9089 }
9190 }
9291 // only if all the records components are used we report an issue
93- if (secondaryLocationsTrees . stream (). map ( mse -> mse . identifier (). name ()). toList (). containsAll ( comps )) {
92+ if (isEveryRecordComponentUsed ( secondaryLocationsTrees , recordSymbol )) {
9493 reportIssue (patternVariable , "Use the record pattern instead of this pattern match variable." ,
9594 getSecondaryLocations (secondaryLocationsTrees ), null );
9695 }
9796 }
9897
98+ private static boolean isEveryRecordComponentUsed (Set <MemberSelectExpressionTree > secondaryLocationsTrees , Symbol .TypeSymbol recordSymbol ) {
99+ var recordComponentNames = recordComponentNames (recordSymbol );
100+ return !recordComponentNames .isEmpty () && secondaryLocationsTrees .stream ().map (mse -> mse .identifier ().name ()).toList ().containsAll (recordComponentNames );
101+ }
102+
99103 private static boolean isNotRecordGetter (MemberSelectExpressionTree mse ) {
100104 return !ALLOWED_METHODS .contains (mse .identifier ().name ());
101105 }
0 commit comments