identify property when cursor is on prefix

This commit is contained in:
Martin Lippert
2024-11-08 13:46:24 +01:00
parent b51523c2ba
commit 23ea2b2af9
2 changed files with 20 additions and 0 deletions

View File

@@ -61,6 +61,10 @@ public class PropertyExtractor {
String prefix = extractAnnotationParameter(annotation, PARAM_PREFIX);
String name = stringLiteral.getLiteralValue();
return prefix != null && !prefix.isBlank() ? prefix + "." + name : name;
case PARAM_PREFIX:
name = extractAnnotationParameter(annotation, PARAM_NAME);
prefix = stringLiteral.getLiteralValue();
return prefix != null && !prefix.isBlank() ? prefix + "." + name : name;
}
}
return null;

View File

@@ -118,6 +118,22 @@ public class ConditionalOnPropertyReferenceFinderTest {
assertEquals(7, location.getRange().getEnd().getCharacter());
}
@Test
void testFindReferencesToPropertyFromAnnotationWithPrefixOnPrefix() throws Exception {
harness.getServer().getWorkspaceService().setWorkspaceFolders(List.of(new WorkspaceFolder(directory.toURI().toString())));
List<? extends Location> references = getReferences("@ConditionalOnProperty(prefix=\"<*>my\", name=\"prop\")");
assertEquals(1, references.size());
Location location = references.get(0);
assertEquals(directory.toPath().resolve("src/main/java/application.properties").toUri().toString(), location.getUri());
assertEquals(0, location.getRange().getStart().getLine());
assertEquals(0, location.getRange().getStart().getCharacter());
assertEquals(0, location.getRange().getEnd().getLine());
assertEquals(7, location.getRange().getEnd().getCharacter());
}
private List<? extends Location> getReferences(String completionLine) throws Exception {
harness.getServer().getWorkspaceService().setWorkspaceFolders(List.of(new WorkspaceFolder(directory.toURI().toString())));