org.sonar.check.Rule.key()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.sonar.check.Rule.key方法的一些代码示例,展示了Rule.key的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule.key方法的具体详情如下:
包路径:org.sonar.check.Rule
类名称:Rule
方法名:key

Rule.key介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

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());
}

代码示例来源:origin: SonarSource/sonarqube

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());
 }
}

代码示例来源:origin: SonarSource/sonarqube

private static Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
 String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
 String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
 String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);
 Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
 rule.setDescription(description);
 rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
 rule.setCardinality(ruleAnnotation.cardinality());
 rule.setStatus(ruleAnnotation.status());
 rule.setTags(ruleAnnotation.tags());
 List<Field> fields = FieldUtils2.getFields(clazz, true);
 for (Field field : fields) {
  addRuleProperty(rule, field);
 }
 return rule;
}

代码示例来源:origin: SonarSource/sonarqube

private static RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz, org.sonar.check.Rule ruleAnnotation) {
 String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
 String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
 String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);
 RulesDefinition.NewRule rule = repo.createRule(ruleKey);
 rule.setName(ruleName).setHtmlDescription(description);
 rule.setSeverity(ruleAnnotation.priority().name());
 rule.setTemplate(ruleAnnotation.cardinality() == Cardinality.MULTIPLE);
 rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status()));
 rule.setTags(ruleAnnotation.tags());
 List<Field> fields = FieldUtils2.getFields(clazz, true);
 for (Field field : fields) {
  loadParameters(rule, field);
 }
 return rule;
}

代码示例来源:origin: SonarSource/sonar-java

private static Map<Class<? extends JavaCheck>, String> rulesKeysByRulesClass(Set<Class<? extends JavaCheck>> rules) {
 Map<Class<? extends JavaCheck>, String> results = Maps.newHashMap();
 for (Class<? extends JavaCheck> ruleClass : rules) {
  Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, Rule.class);
  if (ruleAnnotation != null) {
   results.put(ruleClass, ruleAnnotation.key());
  }
 }
 return results;
}

代码示例来源:origin: org.codehaus.sonar.sslr-squid-bridge/sslr-squid-bridge

@Override
 @SuppressWarnings("rawtypes")
 public Set<String> enabledRuleKeys() {
  Set<String> keys = Sets.newHashSet();
  for (Class clazz : enabledChecks) {
   keys.add(AnnotationUtils.getAnnotation(clazz, org.sonar.check.Rule.class).key());
  }
  return keys;
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-checks

public static String paramsErrorMessage(Class<? extends CssCheck> clazz, String repository, String message) {
 return "Check " + repository + ":" + clazz.getAnnotation(Rule.class).key()
  + " (" + clazz.getAnnotation(Rule.class).name() + "): "
  + message;
}

代码示例来源:origin: org.codehaus.sonar-plugins.json/json-checks

public static String paramsErrorMessage(Class<? extends JSONCheck> clazz, String message) {
 return "Check json:" + clazz.getAnnotation(Rule.class).key()
  + " (" + clazz.getAnnotation(Rule.class).name() + "): "
  + message;
}

代码示例来源:origin: org.sonarsource.java/java-checks

private static Map<Class<? extends JavaCheck>, String> rulesKeysByRulesClass(Set<Class<? extends JavaCheck>> rules) {
 Map<Class<? extends JavaCheck>, String> results = Maps.newHashMap();
 for (Class<? extends JavaCheck> ruleClass : rules) {
  Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, Rule.class);
  if (ruleAnnotation != null) {
   results.put(ruleClass, ruleAnnotation.key());
  }
 }
 return results;
}

代码示例来源:origin: racodond/sonar-css-plugin

public static String paramsErrorMessage(Class<? extends CssCheck> clazz, String repository, String message) {
 return "Check " + repository + ":" + clazz.getAnnotation(Rule.class).key()
  + " (" + clazz.getAnnotation(Rule.class).name() + "): "
  + message;
}

代码示例来源:origin: SonarSource/sonar-java

private static String getSuppressWarningRuleKey() {
 return AnnotationUtils.getAnnotation(SuppressWarningsCheck.class, Rule.class).key();
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

private 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());
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-checks

private String readFileErrorMessage() {
  return "Check css:" + this.getClass().getAnnotation(Rule.class).key()
   + ": Error while reading " + getContext().getFile().getName();
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

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());
}

代码示例来源:origin: racodond/sonar-css-plugin

private String readFileErrorMessage() {
  return "Check css:" + this.getClass().getAnnotation(Rule.class).key()
   + ": Error while reading " + getContext().getFile().getName();
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

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());
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

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());
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.json/json-checks

@Override
public void visitJson(JsonTree tree) {
 try (RandomAccessFile randomAccessFile = new RandomAccessFile(getContext().getFile(), "r")) {
  if (!endsWithNewline(randomAccessFile)) {
   addFileIssue("Add an empty new line at the end of this file.");
  }
 } catch (IOException e) {
  throw new IllegalStateException("Check json:" + this.getClass().getAnnotation(Rule.class).key()
   + ": Error while reading " + getContext().getFile().getName(), e);
 }
 super.visitJson(tree);
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-checks

@Override
public void visitStyleSheet(StyleSheetTree tree) {
 try (RandomAccessFile randomAccessFile = new RandomAccessFile(getContext().getFile(), "r")) {
  if (!endsWithNewline(randomAccessFile)) {
   addFileIssue("Add an empty new line at the end of this file.");
  }
 } catch (IOException e) {
  throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
   + ": Error while reading " + getContext().getFile().getName(), e);
 }
 super.visitStyleSheet(tree);
}

代码示例来源:origin: racodond/sonar-css-plugin

@Override
public void visitStyleSheet(StyleSheetTree tree) {
 try (RandomAccessFile randomAccessFile = new RandomAccessFile(getContext().getFile(), "r")) {
  if (!endsWithNewline(randomAccessFile) && !tree.all().isEmpty()) {
   addFileIssue("Add an empty new line at the end of this file.");
  }
 } catch (IOException e) {
  throw new IllegalStateException("Check css:" + this.getClass().getAnnotation(Rule.class).key()
   + ": Error while reading " + getContext().getFile().getName(), e);
 }
 super.visitStyleSheet(tree);
}

相关文章