Tabnine Logo
Rule.getKey
Code IndexAdd Tabnine to your IDE (free)

How to use
getKey
method
in
org.sonar.api.rules.Rule

Best Java code snippets using org.sonar.api.rules.Rule.getKey (Showing top 20 results out of 315)

origin: SonarSource/sonarqube

/**
 * @return the key of the active rule
 */
public String getRuleKey() {
 return rule.getKey();
}
origin: SonarSource/sonarqube

@Override
public boolean equals(Object obj) {
 if (!(obj instanceof Rule)) {
  return false;
 }
 if (this == obj) {
  return true;
 }
 Rule other = (Rule) obj;
 return new EqualsBuilder()
  .append(pluginName, other.getRepositoryKey())
  .append(key, other.getKey())
  .isEquals();
}
origin: SonarSource/sonarqube

/**
 * Note: disabled rules are excluded.
 */
@CheckForNull
public ActiveRule getActiveRule(Rule rule) {
 return getActiveRule(rule.getRepositoryKey(), rule.getKey());
}
origin: SonarSource/sonarqube

@CheckForNull
private String ruleDescription(String repositoryKey, org.sonar.api.rules.Rule rule) {
 String description = i18n.getDescription(repositoryKey, rule.getKey());
 if (StringUtils.isNotBlank(description)) {
  return description;
 }
 return StringUtils.defaultIfBlank(rule.getDescription(), null);
}
origin: SonarSource/sonarqube

/**
 * @since 3.6
 */
public RuleKey ruleKey() {
 return RuleKey.of(getRepositoryKey(), getKey());
}
origin: SonarSource/sonarqube

@CheckForNull
private String ruleName(String repositoryKey, org.sonar.api.rules.Rule rule) {
 String name = i18n.getName(repositoryKey, rule.getKey());
 if (StringUtils.isNotBlank(name)) {
  return name;
 }
 return StringUtils.defaultIfBlank(rule.getName(), null);
}
origin: SonarSource/sonarqube

@Override
@CheckForNull
public String getName(Rule rule) {
 String name = message(rule.getRepositoryKey(), rule.getKey(), NAME_SUFFIX);
 return name != null ? name : rule.getName();
}
origin: SonarSource/sonarqube

/**
 * @param optionalSeverity if null, then the default rule severity is used
 */
public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) {
 if (activeRules.stream().anyMatch(ar -> ar.getRule().equals(rule))) {
  throw MessageException.of(String.format(
   "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.",
   getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey()));
 }
 ActiveRule activeRule = new ActiveRule(this, rule, optionalSeverity);
 activeRules.add(activeRule);
 return activeRule;
}
origin: SonarSource/sonarqube

@Test
public void rule_without_key() {
 List<Rule> rules = parseAnnotatedClass(RuleWithoutKey.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo(RuleWithoutKey.class.getCanonicalName());
 assertThat(rule.getName()).isEqualTo("foo");
 assertThat(rule.getDescription()).isNull();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
}
origin: SonarSource/sonarqube

@Test
public void overridden_rule() {
 List<Rule> rules = parseAnnotatedClass(OverridingRule.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("overriding_foo");
 assertThat(rule.getName()).isEqualTo("Overriding Foo");
 assertThat(rule.getDescription()).isNull();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 assertThat(rule.getParams()).hasSize(2);
}
origin: SonarSource/sonarqube

@Test
public void rule_without_name_nor_description() {
 List<Rule> rules = parseAnnotatedClass(RuleWithoutNameNorDescription.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("foo");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 assertThat(rule.getName()).isNull();
 assertThat(rule.getDescription()).isNull();
}
origin: SonarSource/sonarqube

if (Strings.isNullOrEmpty(rule.getKey())) {
 throw new SonarException("Node <key> is missing in <rule>");
origin: SonarSource/sonarqube

private static RuleKey toRuleKey(Rule rule) {
 return RuleKey.of(rule.getRepositoryKey(), rule.getKey());
}
origin: SonarSource/sonarqube

@Test
public void rule_with_property() {
 List<Rule> rules = parseAnnotatedClass(RuleWithProperty.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("foo");
 assertThat(rule.getName()).isEqualTo("bar");
 assertThat(rule.getDescription()).isEqualTo("Foo Bar");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY);
 assertThat(rule.getParams()).hasSize(1);
 RuleParam prop = rule.getParam("property");
 assertThat(prop.getKey()).isEqualTo("property");
 assertThat(prop.getDescription()).isEqualTo("Ignore ?");
 assertThat(prop.getDefaultValue()).isEqualTo("false");
 assertThat(prop.getType()).isEqualTo(PropertyType.STRING.name());
}
origin: SonarSource/sonarqube

 private void verifyRule(Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) {
  assertThat(rule).isNotNull();

  assertThat(rule.getName()).isEqualTo(ruleDefinition.getName());
  assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage());
  assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey());
  assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey());
  assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate());
  assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt());
  assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt());
  assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey());
  assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
  assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new));
  assertThat(rule.getTags()).isEmpty();
  assertThat(rule.getId()).isEqualTo(ruleDefinition.getId());
  assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription());

  assertThat(rule.getParams()).hasSize(1);
  org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next();
  assertThat(param.getRule()).isSameAs(rule);
  assertThat(param.getKey()).isEqualTo(ruleParam.getName());
  assertThat(param.getDescription()).isEqualTo(ruleParam.getDescription());
  assertThat(param.getType()).isEqualTo(ruleParam.getType());
  assertThat(param.getDefaultValue()).isEqualTo(ruleParam.getDefaultValue());
 }
}
origin: SonarSource/sonarqube

@Test
public void should_success_finder_wrap() {
 // has Id
 assertThat(underTest.findById(rule1.getId()).getId()).isEqualTo(rule1.getId());
 // should_find_by_id
 assertThat(underTest.findById(rule3.getId()).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck");
 // should_not_find_disabled_rule_by_id
 assertThat(underTest.findById(rule2.getId())).isNull();
 // should_find_by_key
 Rule rule = underTest.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
 assertThat(rule).isNotNull();
 assertThat(rule.getKey()).isEqualTo(("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"));
 assertThat(rule.isEnabled()).isTrue();
 // find_should_return_null_if_no_results
 assertThat(underTest.findByKey("checkstyle", "unknown")).isNull();
 assertThat(underTest.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))).isNull();
 // find_repository_rules
 assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2);
 // find_all_enabled
 assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId());
 assertThat(underTest.findAll(RuleQuery.create())).hasSize(3);
 // do_not_find_disabled_rules
 assertThat(underTest.findByKey("checkstyle", "DisabledCheck")).isNull();
 // do_not_find_unknown_rules
 assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"))).isEmpty();
}
origin: SonarSource/sonarqube

RulesDefinition.NewRule newRule = newRepository.createRule(rule.getKey());
newRule.setName(ruleName(repository.getKey(), rule));
newRule.setHtmlDescription(ruleDescription(repository.getKey(), rule));
 RulesDefinition.NewParam newParam = newRule.createParam(param.getKey());
 newParam.setDefaultValue(param.getDefaultValue());
 newParam.setDescription(paramDescription(repository.getKey(), rule.getKey(), param));
 newParam.setType(RuleParamType.parse(param.getType()));
updateRuleDebtDefinitions(newRule, repository.getKey(), rule.getKey(), ruleDebts);
origin: org.codehaus.sonar/sonar-plugin-api

/**
 * @return the key of the active rule
 */
public String getRuleKey() {
 return rule.getKey();
}
origin: org.codehaus.sonar/sonar-plugin-api

/**
 * Note: disabled rules are excluded.
 */
@CheckForNull
public ActiveRule getActiveRule(Rule rule) {
 return getActiveRule(rule.getRepositoryKey(), rule.getKey());
}
origin: org.codehaus.sonar/sonar-plugin-api

/**
 * @since 3.6
 */
public RuleKey ruleKey() {
 return RuleKey.of(getRepositoryKey(), getKey());
}
org.sonar.api.rulesRulegetKey

Popular methods of Rule

  • create
    Create with all required fields
  • getConfigKey
  • setConfigKey
    Sets the configuration key
  • setName
    Sets the rule name
  • setSeverity
  • getName
  • getRepositoryKey
  • ruleKey
  • setDescription
    Sets the rule description
  • createParameter
  • getSeverity
  • setTags
    For definition of rule only
  • getSeverity,
  • setTags,
  • <init>,
  • getParam,
  • getParams,
  • setKey,
  • setStatus,
  • getDescription,
  • setRepositoryKey

Popular in Java

  • Creating JSON documents from java classes using gson
  • findViewById (Activity)
  • requestLocationUpdates (LocationManager)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Path (java.nio.file)
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • JFrame (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now