Skip to content

Commit 3a08fcb

Browse files
authored
codewhisperer: fix java test file regex pattern MyClassTests.java not captured by test supplemental context(#3763)
1 parent bd7af0e commit 3a08fcb

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeWhisperer: fix java test file name MyClassTests.java (plural) will not be captured if file is not living in a test folder"
4+
}

src/codewhisperer/util/supplementalContext/codeParsingUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const utgLanguageConfigs: Record<string, utgLanguageConfig> = {
1919
// Java regexes are not working efficiently for class or function extraction
2020
java: {
2121
extension: '.java',
22-
testFilenamePattern: /(?:Test([^/\\]+)\.java|([^/\\]+)Test\.java)$/,
22+
testFilenamePattern: /(?:Test([^/\\]+)\.java|([^/\\]+)Test\.java|([^/\\]+)Tests\.java)$/,
2323
functionExtractionPattern:
2424
/(?:(?:public|private|protected)\s+)(?:static\s+)?(?:[\w<>]+\s+)?(\w+)\s*\([^)]*\)\s*(?:(?:throws\s+\w+)?\s*)[{;]/gm, // TODO: Doesn't work for generice <T> T functions.
2525
classExtractionPattern: /(?<=^|\n)\s*public\s+class\s+(\w+)/gm, // TODO: Verify these.

src/test/codewhisperer/util/codeParsingUtil.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('RegexValidationForJava', () => {
6363

6464
describe('isTestFile', () => {
6565
it('should return true if the file name matches the test filename pattern - Java', async () => {
66-
const filePaths = ['/path/to/MyClassTest.java', '/path/to/TestMyClass.java']
66+
const filePaths = ['/path/to/MyClassTest.java', '/path/to/TestMyClass.java', '/path/to/MyClassTests.java']
6767
const language = 'java'
6868

6969
for (const filePath of filePaths) {

0 commit comments

Comments
 (0)