Fix missing proposal if the prefix starts with "/" for @ContextConfiguration

This commit is contained in:
ksankaranara
2024-08-19 19:39:14 +05:30
committed by Martin Lippert
parent e75dd45d86
commit 007ba15da2
2 changed files with 34 additions and 1 deletions

View File

@@ -169,6 +169,7 @@ public class ContextConfigurationProcessor implements CompletionProvider {
}
private String[] findResources(IJavaProject project, String prefix) {
String filteredPrefix = prefix.replaceAll("^/+", "");
String[] resources = IClasspathUtil.getClasspathResources(project.getClasspath()).stream()
.distinct()
.sorted(new Comparator<String>() {
@@ -178,7 +179,7 @@ public class ContextConfigurationProcessor implements CompletionProvider {
}
})
.map(r -> r.replaceAll("\\\\", "/"))
.filter(r -> ("classpath:" + r).contains(prefix))
.filter(r -> ("classpath:" + r).contains(filteredPrefix))
.toArray(String[]::new);
return resources;

View File

@@ -222,7 +222,39 @@ public class ContextConfigurationCompletionTest {
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")");
}
@Test
void testComplexResourceNameWithSlashPrefixAndWithLocationsAndParamNameCompletion() throws Exception {
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/root.xml<*>\")");
assertClasspathCompletions(
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")");
}
@Test
void testComplexResourceNameWithSlashPrefixAndWithValueAndParamNameCompletion() throws Exception {
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(value=\"/root.xml<*>\")");
assertClasspathCompletions(
"@ContextConfiguration(value=\"/a-random-resource-root.xml<*>\")");
}
@Test
void testComplexResourceNameWithSlashPrefixAndParamNameCompletion() throws Exception {
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(\"/root.xml<*>\")");
assertClasspathCompletions(
"@ContextConfiguration(\"/a-random-resource-root.xml<*>\")");
}
@Test
void testComplexResourceNameWithSlashPrefixAndDifferentParamNameCompletion() throws Exception {
prepareCase("@ContextConfiguration(\"onClass\")", "@ContextConfiguration(locations=\"/random<*>\")");
assertClasspathCompletions(
"@ContextConfiguration(locations=\"/a-random-resource-root.xml<*>\")",
"@ContextConfiguration(locations=\"/org/random-resource-org.xml<*>\")",
"@ContextConfiguration(locations=\"/org/test/random-resource-org-test.xml<*>\")");
}
private void prepareCase(String selectedAnnotation, String annotationStatementBeforeTest) throws Exception {
InputStream resource = this.getClass().getResourceAsStream("/test-projects/test-annotation-contextconfiguration/src/main/java/org/test/TestContextConfigurationCompletion.java");