下面列出了怎么用javax.annotation.processing.SupportedOptions的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Add a {@link Plugin} class to the list of known plugins
*
* @param plugin the plugin class
* @param priority the priority to give the plugin
*/
private void addPlugin(Class<? extends Plugin> plugin, PluginPriority priority) {
switch (priority) {
case LOW:
lowPriorityPlugins.add(plugin);
break;
case HIGH:
highPriorityPlugins.add(plugin);
break;
case NORMAL:
default:
normalPriorityPlugins.add(plugin);
break;
}
SupportedOptions supportedOptionsAnnotation = plugin.getAnnotation(SupportedOptions.class);
if (supportedOptionsAnnotation != null) {
String[] options = supportedOptionsAnnotation.value();
Collections.addAll(pluginSupportedOptions, options);
}
}
/**
* Analogous to {@link Processor#getSupportedOptions()}, here to allow extensions to report their
* own.
*
* <p>By default, if the extension class is annotated with {@link SupportedOptions}, this will
* return a set with the strings in the annotation. If the class is not so annotated, an empty set
* is returned.
*
* @return the set of options recognized by this extension or an empty set if none
* @see SupportedOptions
*/
public Set<String> getSupportedOptions() {
SupportedOptions so = this.getClass().getAnnotation(SupportedOptions.class);
if (so == null) {
return ImmutableSet.of();
} else {
return ImmutableSet.copyOf(so.value());
}
}