Maven: How I get line number for maven file given the dependency? highlight dependency directly?

Answered

Currently I use MavenXpp3Reader to get the dependencies from maven file.

I wonder can I get the line num of the <groupId> for each dependency directly according to the dependency instance? My goal is to highlight the line of <groupId> so that is why I want to know the line number.

MavenXpp3Reader Xpp3Reader = new MavenXpp3Reader();

Model model = Xpp3Reader.read(new FileReader(path));

List<Dependency> dependencies = model.getDependencies();

 

3 comments
Comment actions Permalink

Maven plugin uses DOM Model (https://plugins.jetbrains.com/docs/intellij/xml-dom-api.html) under the hood, see community/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom in IJ Community sources.

Your plugin can provide com.intellij.util.xml.highlighting.BasicDomElementsInspection to add additional highlighting for any element in the editor.

0
Comment actions Permalink

Thank you Yann. I use PSI structure now, because PsiNodes can easily be turned into line numbers using `Document.getLineNumber(ASTNode)` (https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000883500-How-to-get-method-boundaries-with-Intellij-openapi-) the project also want to highlight in java file. Is that a way I can do with PSI structure? look like XML DOM model is under PSI section

0

Please sign in to leave a comment.