How do I enhance java parser to capture information from PsiComment and PsiDocComment?

已回答

I would like to capture some valuable information from a comment block either PsiComment or PsiDocComment which, say, is enclosed into curly brackets, for example:

/**
* Documentation string 1
* {
* valuable information
* to capture
* }
*
* documentation ends
*/

or in single line commit:

// { value information }

I assume I will require a custom PsiNode to store this valuable information.

Is there a way to enhance the parser in such a way? Is there a way to achieve it in a different way?

0

You can check the PsiInlineDocTag implementation - it handles curly brackets inside PsiDocComment/PsiComment in a way that you expect.

 

0

@... , thank you for your suggestion, I was thinking about using {@code } for this, but I need a PSI Tree inside of it, so I can implement all the fancy things, like "Go To Symbol", "Rename", "Autocompletion", etc. It appears to me that the only option is to tweak the JavadocParser parser, but I don't think this API is accessible to me, is it?

I think I might need to implement a custom parser to build a PSI Tree from the tokens I find in the {@code } tag and then add it somehow to JavadocParser, is my intuition correct?

Should I define a custom FileViewProvider so I can build my own PSI Tree?

0

Jakub Chrzanowski , Thank you for your suggestion, I have looked into it and noticed that com.intellij.psi.javadoc.PsiDocComment is not an instance of com.intellij.psi.PsiLanguageInjectionHost, which is required by com.intellij.lang.injection.MultiHostRegistrar#addPlace. I guess I will have to stick to JavaTokenType.C_STYLE_COMMENT or JavaTokenType.END_OF_LINE_COMMENT.

0

请先登录再写评论。