use of org.springframework.ide.vscode.java.properties.parser.Parser in project sts4 by spring-projects.
the class ValuePropertyReferencesProvider method findReferencesInPropertiesFile.
private List<Location> findReferencesInPropertiesFile(String filePath, String propertyKey) {
List<Location> foundLocations = new ArrayList<>();
try {
String fileContent = FileUtils.readFileToString(new File(filePath));
Parser parser = new AntlrParser();
ParseResults parseResults = parser.parse(fileContent);
if (parseResults != null && parseResults.ast != null) {
parseResults.ast.getNodes(KeyValuePair.class).forEach(pair -> {
if (pair.getKey() != null && pair.getKey().decode().equals(propertyKey)) {
URI docURI = Paths.get(filePath).toUri();
TextDocument doc = new TextDocument(docURI.toString(), null);
doc.setText(fileContent);
try {
int line = doc.getLineOfOffset(pair.getKey().getOffset());
int startInLine = pair.getKey().getOffset() - doc.getLineOffset(line);
int endInLine = startInLine + (pair.getKey().getLength());
Position start = new Position();
start.setLine(line);
start.setCharacter(startInLine);
Position end = new Position();
end.setLine(line);
end.setCharacter(endInLine);
Range range = new Range();
range.setStart(start);
range.setEnd(end);
Location location = new Location(docURI.toString(), range);
foundLocations.add(location);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
return foundLocations;
}
Aggregations