public static boolean isDeprecatedScannerSide(Object extension) { return AnnotationUtils.getAnnotation(extension, org.sonar.api.batch.ScannerSide.class) != null; }
@Test public void getClassAnnotationWithDeprecatedMethod() { FakeAnnotation annotation = AnnotationUtils.getClassAnnotation(new SuperClass(), FakeAnnotation.class); assertThat(annotation.value()).isEqualTo("foo"); }
public static boolean isScannerSide(Object extension) { return AnnotationUtils.getAnnotation(extension, ScannerSide.class) != null; }
private <T> boolean hasSupportedAnnotation(T component) { return AnnotationUtils.getAnnotation(component, supportedAnnotationType) != null; }
/** * Searches for a class annotation. All inheritance tree is analysed. * * @deprecated As of 3.1, replaced by {@link #getAnnotation(Object,Class)} */ @Deprecated public static <A> A getClassAnnotation(Object object, Class<A> annotationClass) { return (A) getAnnotation(object, (Class<? extends Annotation>) annotationClass); } }
public static boolean isInstantiationStrategy(Object extension, String strategy) { InstantiationStrategy annotation = AnnotationUtils.getAnnotation(extension, InstantiationStrategy.class); if (annotation != null) { return strategy.equals(annotation.value()); } return InstantiationStrategy.PER_PROJECT.equals(strategy); }
private static Phase.Name evaluatePhase(Object extension) { Phase phaseAnnotation = AnnotationUtils.getAnnotation(extension, Phase.class); if (phaseAnnotation != null) { return phaseAnnotation.name(); } return Phase.Name.DEFAULT; }
@CheckForNull RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(clazz, org.sonar.check.Rule.class); if (ruleAnnotation != null) { return loadRule(repo, clazz, ruleAnnotation); } else { LOG.warn("The class " + clazz.getCanonicalName() + " should be annotated with " + org.sonar.check.Rule.class); return null; } }
private static String annotatedEngineKey(Object annotatedClassOrObject) { String key = null; org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, org.sonar.check.Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); } Class clazz = annotatedClassOrObject.getClass(); if (annotatedClassOrObject instanceof Class) { clazz = (Class) annotatedClassOrObject; } return StringUtils.defaultIfEmpty(key, clazz.getCanonicalName()); }
private PropertyDefinitions addComponentFromAnnotationProperty(Object component, String defaultCategory) { Properties annotations = AnnotationUtils.getAnnotation(component, Properties.class); if (annotations != null) { for (Property property : annotations.value()) { addProperty(property, defaultCategory); } } Property annotation = AnnotationUtils.getAnnotation(component, Property.class); if (annotation != null) { addProperty(annotation, defaultCategory); } return this; }
public static String getRuleKey(Class annotatedClass) { String key = null; org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); } return StringUtils.defaultIfEmpty(key, annotatedClass.getCanonicalName()); } }
private static Rule create(String repositoryKey, Class annotatedClass) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class); if (ruleAnnotation != null) { return toRule(repositoryKey, annotatedClass, ruleAnnotation); } LOG.warn("The class " + annotatedClass.getCanonicalName() + " should be annotated with " + Rule.class); return null; }
Object installExtension(ComponentContainer container, PluginInfo pluginInfo, Object extension, boolean acceptProvider) { for (Class<? extends Annotation> supportedAnnotationType : supportedAnnotationTypes) { if (AnnotationUtils.getAnnotation(extension, supportedAnnotationType) != null) { if (!acceptProvider && isExtensionProvider(extension)) { throw new IllegalStateException("ExtensionProvider can not include providers itself: " + extension); } container.addExtension(pluginInfo, extension); return extension; } } return null; }
public static Predicate<Object> hasPlatformLevel4OrNone() { return o -> { PlatformLevel platformLevel = AnnotationUtils.getAnnotation(o, PlatformLevel.class); return platformLevel == null || checkSupportedLevel(platformLevel.value(), o) == 4; }; } }
private static void ensureSupportBlueGreen(List<RegisteredMigrationStep> steps) { for (RegisteredMigrationStep step : steps) { if (AnnotationUtils.getAnnotation(step.getStepClass(), SupportsBlueGreen.class) == null) { throw new IllegalStateException(format("All migrations canceled. #%d does not support blue/green deployment: %s", step.getMigrationNumber(), step.getDescription())); } } } }
public static Predicate<Object> hasPlatformLevel(int i) { checkSupportedLevel(i, null); return o -> { PlatformLevel platformLevel = AnnotationUtils.getAnnotation(o, PlatformLevel.class); return platformLevel != null && checkSupportedLevel(platformLevel.value(), o) == i; }; }
@Test public void shouldAcceptClasses() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(SuperClass.class, FakeAnnotation.class); assertThat(annotation.value()).isEqualTo("foo"); annotation = AnnotationUtils.getAnnotation(ChildClass.class, FakeAnnotation.class); assertThat(annotation.value()).isEqualTo("foo"); }
@Test public void noClassAnnotation() { FakeAnnotation annotation = AnnotationUtils.getAnnotation("a string", FakeAnnotation.class); assertThat(annotation).isNull(); }
@Test public void searchClassAnnotationInSuperClass() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(new ChildClass(), FakeAnnotation.class); assertThat(annotation.value()).isEqualTo("foo"); }
@Test public void getClassAnnotation() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(new SuperClass(), FakeAnnotation.class); assertThat(annotation.value()).isEqualTo("foo"); }