当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationUtils类代码示例

本文整理汇总了Java中org.sonar.api.utils.AnnotationUtils的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtils类的具体用法?Java AnnotationUtils怎么用?Java AnnotationUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AnnotationUtils类属于org.sonar.api.utils包,在下文中一共展示了AnnotationUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAnnotatedRule

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
private static NewRule addAnnotatedRule(NewRepository repository, Class<?> ruleClass) {
  org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class);
  if (ruleAnnotation == null) {
    throw new IllegalStateException("No Rule annotation was found on " + ruleClass.getName());
  }
  String ruleKey = ruleAnnotation.key();
  if (ruleKey.length() == 0) {
    throw new IllegalStateException("Empty key");
  }
  new RulesDefinitionAnnotationLoader().load(repository, ruleClass);
  NewRule rule = repository.rule(ruleKey);
  if (rule == null) {
    throw new IllegalStateException("Rule not found: " + ruleKey);
  }
  return rule;
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:17,代码来源:RuleMetadataLoader.java

示例2: newRule

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:23,代码来源:MyJavaRulesDefinition.java

示例3: newRule

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:27,代码来源:ApexRulesDefinition.java

示例4: addIssue

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
public void addIssue(@Nullable Integer line, CodeCheck check, String message, @Nullable Double cost) {
  Preconditions.checkNotNull(check);
  Preconditions.checkNotNull(message);
  CheckMessage checkMessage = new CheckMessage(check, message);
  if (line > 0) {
    checkMessage.setLine(line);
  }
  if (cost == null) {
    Annotation linear = AnnotationUtils.getAnnotation(check, SqaleLinearRemediation.class);
    Annotation linearWithOffset = AnnotationUtils.getAnnotation(check, SqaleLinearWithOffsetRemediation.class);
    if (linear != null || linearWithOffset != null) {
      throw new IllegalStateException("A check annotated with a linear SQALE function should provide an effort to fix.");
    }
  } else {
    checkMessage.setCost(cost);
  }

  if (getContext().peekSourceCode() instanceof SourceFile) {
    getContext().peekSourceCode().log(checkMessage);
  } else if (getContext().peekSourceCode().getParent(SourceFile.class) != null) {
    getContext().peekSourceCode().getParent(SourceFile.class).log(checkMessage);
  } else {
    throw new IllegalStateException("Unable to log a check message on source code '"
      + (getContext().peekSourceCode() == null ? "[NULL]" : getContext().peekSourceCode().getKey()) + "'");
  }
}
 
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:27,代码来源:PuppetCheckVisitor.java

示例5: evaluatePhase

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
private static Phase.Name evaluatePhase(Object extension) {
  Object extensionToEvaluate;
  if (extension instanceof SensorWrapper) {
    extensionToEvaluate = ((SensorWrapper) extension).wrappedSensor();
  } else {
    extensionToEvaluate = extension;
  }
  Phase phaseAnnotation = AnnotationUtils.getAnnotation(extensionToEvaluate, Phase.class);
  if (phaseAnnotation != null) {
    return phaseAnnotation.name();
  }
  return Phase.Name.DEFAULT;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:14,代码来源:ScannerExtensionDictionnary.java

示例6: isInstantiationStrategy

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:8,代码来源:ExtensionUtils.java

示例7: ruleMetadata

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
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;
}
 
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:12,代码来源:MyJavaRulesDefinition.java

示例8: createRules

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
@Override
public List<Rule> createRules() {
  List<Rule> result = Lists.newArrayList();
  for (Class ruleClass : TanaguruCheckClasses.getCheckClasses()) {
    if (AnnotationUtils.getAnnotation(ruleClass, WebRule.class) != null) {
      result.add(RuleRepositoryHelper.createRule(
        REPOSITORY_KEY,
        ruleClass,
        AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class),
        AnnotationUtils.getAnnotation(ruleClass, TanaguruRuleTags.class)
      ));
    }
  }
  return result;
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:16,代码来源:TanaguruRulesRepository.java

示例9: loadRule

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
@CheckForNull
RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class<? extends JavaCheck> clazz) {
	Rule ruleAnnotation = AnnotationUtils.getAnnotation(clazz, Rule.class);
	if (ruleAnnotation != null) {
		return loadRule(repo, clazz, ruleAnnotation);
	} else {
		LOG.warn("The class {} should be annotated with {}", clazz.getCanonicalName(), Rule.class);
		return null;
	}
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:11,代码来源:RulesLoader.java

示例10: getCheckClass

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
private static Class<AbstractCheck> getCheckClass(Rule rule) {
    for (Class<?> checkClass : CheckClasses.getChecks()) {

        org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getClassAnnotation(checkClass, org.sonar.check.Rule.class);
        if (ruleAnnotation.key().equals(rule.getConfigKey())) {
            return (Class<AbstractCheck>) checkClass;
        }
    }
    System.out.println("Could not find check class for config key " + rule.getConfigKey());
    return null;
}
 
开发者ID:malteseduck,项目名称:sonar-xquery-plugin,代码行数:12,代码来源:AnalyzeProject.java

示例11: getCheckClass

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Class<BeanCheck> getCheckClass(final ActiveRule activeRule) {
    for (Class<?> checkClass : CheckClasses.getCheckClasses()) {

        org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getClassAnnotation(checkClass, org.sonar.check.Rule.class);
        if (ruleAnnotation.key().equals(activeRule.getConfigKey())) {
            return (Class<BeanCheck>) checkClass;
        }
    }
    LOGGER.error("Could not find check class for config key " + activeRule.getConfigKey());
    return null;
}
 
开发者ID:shmc,项目名称:sonar-spring-rules-plugin,代码行数:13,代码来源:SpringRulesRepository.java

示例12: isSonarLintSide

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
public static boolean isSonarLintSide(Object extension) {
  return AnnotationUtils.getAnnotation(extension, SonarLintSide.class) != null;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:4,代码来源:ExtensionUtils.java

示例13: isScannerSide

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
public static boolean isScannerSide(Object extension) {
  return AnnotationUtils.getAnnotation(extension, BatchSide.class) != null ||
    AnnotationUtils.getAnnotation(extension, ScannerSide.class) != null ||
    AnnotationUtils.getAnnotation(extension, SonarLintSide.class) != null;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:6,代码来源:ExtensionUtils.java

示例14: isTagIncluded

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
@Override
protected boolean isTagIncluded(Class ruleClass) {
  TanaguruRuleTags ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, TanaguruRuleTags.class);
  return Arrays.asList(ruleAnnotation.value()).contains(TanaguruRuleTags.RGAA3);
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:6,代码来源:Rgaa3Profile.java

示例15: isActive

import org.sonar.api.utils.AnnotationUtils; //导入依赖的package包/类
protected boolean isActive(Class ruleClass) {
  WebRule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, WebRule.class);
  return ruleAnnotation != null && ruleAnnotation.activeByDefault() && isTagIncluded(ruleClass);
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:5,代码来源:BaseProfileDefinition.java


注:本文中的org.sonar.api.utils.AnnotationUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。