Skip to content

Commit

Permalink
Issue checkstyle#15004: Add input file for record pattern syntax in A…
Browse files Browse the repository at this point in the history
…bbreviationAsWordInName
  • Loading branch information
mahfouz72 authored and nrmancuso committed Jun 26, 2024
1 parent 0ba52f3 commit 6781733
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,28 @@ public void testAbbreviationAsWordInNameCheckRecords()
expected);
}

@Test
public void testAbbreviationAsWordInNameCheckRecordPatterns()
throws Exception {

final int expectedCapitalCount = 4;

final String[] expected = {
"23:39: " + getWarningMessage("POINT", expectedCapitalCount),
"27:60: " + getWarningMessage("COLOR", expectedCapitalCount),
"31:53: " + getWarningMessage("INTEGER", expectedCapitalCount),
"31:71: " + getWarningMessage("STRING", expectedCapitalCount),
"39:52: " + getWarningMessage("COLOR", expectedCapitalCount),
"40:52: " + getWarningMessage("INTEGER", expectedCapitalCount),
"40:68: " + getWarningMessage("COLOR", expectedCapitalCount),
};

verifyWithInlineConfigParser(
getNonCompilablePath(
"InputAbbreviationAsWordInNameCheckRecordPatterns.java"),
expected);
}

private String getWarningMessage(String typeName, int expectedCapitalCount) {
return getCheckMessage(MSG_KEY, typeName, expectedCapitalCount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
AbbreviationAsWordInName
allowedAbbreviationLength = (default)3
allowedAbbreviations = (default)
ignoreFinal = (default)true
ignoreStatic = (default)true
ignoreStaticFinal = (default)true
ignoreOverriddenMethods = (default)true
tokens = (default)CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, \
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, \
RECORD_COMPONENT_DEF
*/

//non-compiled with javac: Compilable with Java21
package com.puppycrawl.tools.checkstyle.checks.naming.abbreviationaswordinname;

public class InputAbbreviationAsWordInNameCheckRecordPatterns {

void m(Object o) {
// violation below, 'Abbreviation in name 'POINT'*.'
if (o instanceof ColoredPoint POINT) {

}
// violation below, 'Abbreviation in name 'COLOR'*.'
if (o instanceof ColoredPoint(int x, int y, String COLOR)) {

}

if (o instanceof Rectangle(ColoredPoint(int INTEGER,_, String STRING),ColoredPoint _)) {}
// 2 violations above:
// 'Abbreviation in name 'INTEGER'*.'
// 'Abbreviation in name 'STRING'*.'
}
void m2(Object o) {
switch (o) {
// violation below, 'Abbreviation in name 'COLOR'*.'
case ColoredPoint(int x, int y, String COLOR) -> {}
case Rectangle(ColoredPoint(int x, int INTEGER, String COLOR), _) -> {}
// 2 violations above:
// 'Abbreviation in name 'INTEGER'*.'
// 'Abbreviation in name 'COLOR'*.'
default -> {}
}
}


record ColoredPoint(int x, int y, String color) {}
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) {}
}

0 comments on commit 6781733

Please sign in to comment.