ycomp
ycomp

Reputation: 8583

annotation to specify what classes can call a method?

Does anyone know of an annotation in any framework or library (or IntelliJ or IntelliJ plugin) that can enforce in my code that only specific methods described in the annotation can call it?

example

@caller(class="UsefulClass")
public static void myMethodToBeCalledOnlyByUsefulClass() {

}

Upvotes: 0

Views: 36

Answers (1)

mernst
mernst

Reputation: 8147

The Checker Framework allows you to define annotations such as @Caller and then have the compiler statically enforce programming rules. You could use the Checker Framework to define your @Caller annotation and a compiler plugin. Then, every time you compile your code using the plugin, it will issue an error if the code is used improperly.

The Checker Framework ships with a number of annotations already built in, but not @Caller which you would have to define yourself.

Upvotes: 1

Related Questions