Java Code Examples for org.sonar.api.utils.AnnotationUtils#getAnnotation()
The following examples show how to use
org.sonar.api.utils.AnnotationUtils#getAnnotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebDriverRulesDefinition.java From sonar-webdriver-plugin with MIT License | 6 votes |
@VisibleForTesting protected void newRule(Class<?> ruleClass, NewRepository repository) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class); if (ruleAnnotation == null) { throw new IllegalArgumentException("No Rule annotation was found on " + ruleClass); } String ruleKey = ruleAnnotation.key(); if (StringUtils.isEmpty(ruleKey)) { throw new IllegalArgumentException("No key is defined in Rule annotation of " + ruleClass); } NewRule rule = repository.rule(ruleKey); if (rule == null) { throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key()); } ruleMetadata(ruleClass, rule); }
Example 2
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 6 votes |
@VisibleForTesting protected void newRule(Class<?> ruleClass, NewRepository repository) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class); if (ruleAnnotation == null) { throw new IllegalArgumentException("No Rule annotation was found on " + ruleClass); } String ruleKey = ruleAnnotation.key(); if (StringUtils.isEmpty(ruleKey)) { throw new IllegalArgumentException("No key is defined in Rule annotation of " + ruleClass); } NewRule rule = repository.rule(ruleKey); if (rule == null) { throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key()); } ruleMetadata(ruleClass, rule); rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null); if (ruleAnnotation.cardinality() == Cardinality.MULTIPLE) { throw new IllegalArgumentException("Cardinality is not supported, use the RuleTemplate annotation instead for " + ruleClass); } }
Example 3
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 6 votes |
@VisibleForTesting protected void newRule(Class<?> ruleClass, NewRepository repository) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class); if (ruleAnnotation == null) { throw new IllegalArgumentException("No Rule annotation was found on " + ruleClass); } String ruleKey = ruleAnnotation.key(); if (StringUtils.isEmpty(ruleKey)) { throw new IllegalArgumentException("No key is defined in Rule annotation of " + ruleClass); } NewRule rule = repository.rule(ruleKey); if (rule == null) { throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key()); } ruleMetadata(ruleClass, rule); rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null); if (ruleAnnotation.cardinality() == Cardinality.MULTIPLE) { throw new IllegalArgumentException("Cardinality is not supported, use the RuleTemplate annotation instead for " + ruleClass); } }
Example 4
Source File: ApexRulesDefinition.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * Loads HTML descriptions and meta data from JSON file to checks. * * @param ruleClass Class type of given rule. * @param repository current repository. */ @VisibleForTesting protected void newRule(Class<?> ruleClass, NewRepository repository) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class); if (ruleAnnotation == null) { throw new IllegalArgumentException( String.format("No Rule annotation was found on %s", ruleClass)); } String ruleKey = ruleAnnotation.key(); if (StringUtils.isEmpty(ruleKey)) { throw new IllegalArgumentException( String.format("No key is defined in Rule annotation of %s", ruleClass)); } NewRule rule = repository.rule(ruleKey); if (rule == null) { throw new IllegalStateException( String.format("No rule was created for %s in %s", ruleClass, repository.key())); } addHtmlDescription(rule, rule.key()); addMetadata(rule, rule.key()); }
Example 5
Source File: WebDriverRulesDefinition.java From sonar-webdriver-plugin with MIT License | 5 votes |
private String ruleMetadata(Class<?> ruleClass, NewRule rule) { String metadataKey = rule.key(); org.sonar.java.RspecKey rspecKeyAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.java.RspecKey.class); if (rspecKeyAnnotation != null) { metadataKey = rspecKeyAnnotation.value(); rule.setInternalKey(metadataKey); } addHtmlDescription(rule, metadataKey); addMetadata(rule, metadataKey); return metadataKey; }
Example 6
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 5 votes |
private String ruleMetadata(Class<?> ruleClass, NewRule rule) { String metadataKey = rule.key(); org.sonar.java.RspecKey rspecKeyAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.java.RspecKey.class); if (rspecKeyAnnotation != null) { metadataKey = rspecKeyAnnotation.value(); rule.setInternalKey(metadataKey); } addHtmlDescription(rule, metadataKey); addMetadata(rule, metadataKey); return metadataKey; }
Example 7
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 5 votes |
private String ruleMetadata(Class<?> ruleClass, NewRule rule) { String metadataKey = rule.key(); org.sonar.java.RspecKey rspecKeyAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.java.RspecKey.class); if (rspecKeyAnnotation != null) { metadataKey = rspecKeyAnnotation.value(); rule.setInternalKey(metadataKey); } addHtmlDescription(rule, metadataKey); addMetadata(rule, metadataKey); return metadataKey; }