Is there a way to read file annotations?


I have a lot of files under a folder. For each file, I have some annotations, for example, @file:Tag(“Purpose 1”).

Can I write a little program to read all those files, and figure out what annotations those files have?


I don’t see why not. Just read each file line by line and use regular expressions to check if that line contains a tag and if so which one.


Take a look at It is not that easy to use (in my opinion), but once you get used to it, this is really powerful.


Isn’t KAPT only for source files?

@aug828 didn’t specify that his files are source files, so I assumed he meant text files in general.

An example of text file with annotations would be Gherkin feature file: Tags in Cucumber tests


Yes, kapt is looking only in source files for annotations. But because @aug828 used @file:Tag("Purpose 1") as their example I thought they were talking about source file annotations.


I guess we will have to wait for @aug828 to clarify…


Thanks for the reply.
I was talking about Kotlin source files. I want to tag those source files, and then have a little program to search them by their usage. For example, if I want source files that fulfill purpose 1, I just search files with @file:Tag(“Purpose 1”).

I think @forinil2’s method should work.


If you really want to be fast I think you can even stop after you see the first code, as the @file:Annotation() needs to be at the before the package declaration. But I am not 100% sure about it.