import org.sonar.api.web.WidgetPropertyType;
import org.sonar.api.web.WidgetScope;
+import static org.sonar.api.web.WidgetScope.*;
+
@WidgetCategory({"Filters", "Global"})
-@WidgetScope("GLOBAL")
+@WidgetScope(GLOBAL)
@WidgetProperties({
@WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, optional = false)
})
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WidgetScope {
- String[] value() default "PROJECT";
+ String PROJECT = "PROJECT";
+ String GLOBAL = "GLOBAL";
+
+ String[] value() default PROJECT;
}
WidgetScope scopeAnnotation = AnnotationUtils.getClassAnnotation(view, WidgetScope.class);
if (scopeAnnotation != null) {
checkValidScope(view, scopeAnnotation);
- isGlobal = ImmutableSet.copyOf(scopeAnnotation.value()).contains("GLOBAL");
+ isGlobal = ImmutableSet.copyOf(scopeAnnotation.value()).contains(WidgetScope.GLOBAL);
}
}
private static <V> void checkValidScope(V view, WidgetScope scopeAnnotation) {
for (String scope : scopeAnnotation.value()) {
- if (!scope.equals("PROJECT") && !scope.equalsIgnoreCase("GLOBAL")) {
+ if (!scope.equals(WidgetScope.PROJECT) && !scope.equalsIgnoreCase(WidgetScope.GLOBAL)) {
throw new IllegalArgumentException(String.format("Invalid widget scope %s for widget %s", scope, view.getClass().getSimpleName()));
}
}