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

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

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

origin: SonarSource/sonarqube

 public Rule answer(InvocationOnMock iom) throws Throwable {
  Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
  rule.createParameter("format");
  rule.createParameter("message");
  return rule;
 }
});
origin: SonarSource/sonarqube

 @Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName");
  rule.createParameter("format");
  return Arrays.asList(rule);
 }
}
origin: SonarSource/sonarqube

private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
 RuleParam param = rule.createParameter();
 String keyAttribute = ruleC.getAttrValue("key");
 if (StringUtils.isNotBlank(keyAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setKey(StringUtils.trim(keyAttribute));
 }
 String typeAttribute = ruleC.getAttrValue("type");
 if (StringUtils.isNotBlank(typeAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setType(type(StringUtils.trim(typeAttribute)));
 }
 SMInputCursor paramC = ruleC.childElementCursor();
 while (paramC.getNext() != null) {
  String propNodeName = paramC.getLocalName();
  String propText = StringUtils.trim(paramC.collectDescendantText(false));
  if (StringUtils.equalsIgnoreCase("key", propNodeName)) {
   param.setKey(propText);
  } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) {
   param.setDescription(propText);
  } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) {
   param.setType(type(propText));
  } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) {
   param.setDefaultValue(propText);
  }
 }
 if (StringUtils.isEmpty(param.getKey())) {
  throw new SonarException("Node <key> is missing in <param>");
 }
}
origin: SonarSource/sonarqube

private static void addRuleProperty(Rule rule, Field field) {
 org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
 if (propertyAnnotation != null) {
  String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
  RuleParam param = rule.createParameter(fieldKey);
  param.setDescription(propertyAnnotation.description());
  param.setDefaultValue(propertyAnnotation.defaultValue());
  if (!StringUtils.isBlank(propertyAnnotation.type())) {
   try {
    param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
   } catch (IllegalArgumentException e) {
    throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
   }
  } else {
   param.setType(guessType(field.getType()).name());
  }
 }
}
origin: SonarSource/sonarqube

@Test
public void exportRuleParameters() throws IOException, SAXException {
 Writer writer = new StringWriter();
 RulesProfile profile = RulesProfile.create("sonar way", "java");
 Rule rule = Rule.create("checkstyle", "IllegalRegexp", "illegal regexp");
 rule.createParameter("format");
 rule.createParameter("message");
 rule.createParameter("tokens");
 ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER);
 activeRule.setParameter("format", "foo");
 activeRule.setParameter("message", "with special characters < > &");
 // the tokens parameter is not set
 new XMLProfileSerializer().write(profile, writer);
 assertSimilarXml("exportRuleParameters.xml", writer.toString());
}
origin: SonarSource/sonarqube

 @Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName", "Constant Name");
  rule.setDescription("Checks that constant names conform to the specified format");
  rule.setConfigKey("Checker/TreeWalker/ConstantName");
  rule.setSeverity(RulePriority.BLOCKER);
  rule.setStatus(Rule.STATUS_BETA);
  rule.setTags(new String[] {"style", "clumsy"});
  rule.createParameter("format").setDescription("Regular expression").setDefaultValue("A-Z").setType("REGULAR_EXPRESSION");
  return Arrays.asList(rule);
 }
}
origin: org.codehaus.sonar/sonar-deprecated

private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
 RuleParam param = rule.createParameter();
 String keyAttribute = ruleC.getAttrValue("key");
 if (StringUtils.isNotBlank(keyAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setKey(StringUtils.trim(keyAttribute));
 }
 String typeAttribute = ruleC.getAttrValue("type");
 if (StringUtils.isNotBlank(typeAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setType(type(StringUtils.trim(typeAttribute)));
 }
 SMInputCursor paramC = ruleC.childElementCursor();
 while (paramC.getNext() != null) {
  String propNodeName = paramC.getLocalName();
  String propText = StringUtils.trim(paramC.collectDescendantText(false));
  if (StringUtils.equalsIgnoreCase("key", propNodeName)) {
   param.setKey(propText);
  } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) {
   param.setDescription(propText);
  } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) {
   param.setType(type(propText));
  } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) {
   param.setDefaultValue(propText);
  }
 }
 if (Strings.isNullOrEmpty(param.getKey())) {
  throw new SonarException("Node <key> is missing in <param>");
 }
}
origin: org.codehaus.sonar-plugins/sonar-web-plugin

private static void addRuleProperty(Rule rule, Field field) {
 org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
 if (propertyAnnotation != null) {
  String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
  RuleParam param = rule.createParameter(fieldKey);
  param.setDescription(propertyAnnotation.description());
  param.setDefaultValue(propertyAnnotation.defaultValue());
  if (!StringUtils.isBlank(propertyAnnotation.type())) {
   try {
    param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
   } catch (IllegalArgumentException e) {
    throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
   }
  } else {
   param.setType(guessType(field.getType()).name());
  }
 }
}
origin: org.codehaus.sonar/sonar-deprecated

private void addRuleProperty(Rule rule, Field field) {
 org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
 if (propertyAnnotation != null) {
  String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
  RuleParam param = rule.createParameter(fieldKey);
  param.setDescription(propertyAnnotation.description());
  param.setDefaultValue(propertyAnnotation.defaultValue());
  if (!StringUtils.isBlank(propertyAnnotation.type())) {
   try {
    param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
   } catch (IllegalArgumentException e) {
    throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
   }
  } else {
   param.setType(guessType(field.getType()).name());
  }
 }
}
origin: org.sonarsource.sonarqube/sonar-plugin-api

private static void addRuleProperty(Rule rule, Field field) {
 org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
 if (propertyAnnotation != null) {
  String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
  RuleParam param = rule.createParameter(fieldKey);
  param.setDescription(propertyAnnotation.description());
  param.setDefaultValue(propertyAnnotation.defaultValue());
  if (!StringUtils.isBlank(propertyAnnotation.type())) {
   try {
    param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
   } catch (IllegalArgumentException e) {
    throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
   }
  } else {
   param.setType(guessType(field.getType()).name());
  }
 }
}
origin: org.codehaus.sonar/sonar-batch

private RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
 RulesProfile deprecatedProfile = new RulesProfile();
 // TODO deprecatedProfile.setVersion(qProfile.version());
 deprecatedProfile.setName(qProfile.getName());
 deprecatedProfile.setLanguage(qProfile.getLanguage());
 for (org.sonar.api.batch.rule.ActiveRule activeRule : ((DefaultActiveRules) activeRules).findByLanguage(qProfile.getLanguage())) {
  Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
  rule.setConfigKey(activeRule.internalKey());
  ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule,
   RulePriority.valueOf(activeRule.severity()));
  for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
   rule.createParameter(param.getKey());
   deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
  }
 }
 return deprecatedProfile;
}
origin: org.sonarsource.sonarqube/sonar-batch

private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
 RulesProfile deprecatedProfile = new RulesProfile();
 // TODO deprecatedProfile.setVersion(qProfile.version());
 deprecatedProfile.setName(qProfile.getName());
 deprecatedProfile.setLanguage(qProfile.getLanguage());
 for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
  Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
  rule.setConfigKey(activeRule.internalKey());
  // SONAR-6706
  if (activeRule.templateRuleKey() != null) {
   rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey()));
  }
  ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule,
   RulePriority.valueOf(activeRule.severity()));
  for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
   rule.createParameter(param.getKey());
   deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
  }
 }
 return deprecatedProfile;
}
origin: fabriciocolombo/sonar-delphi

private static Rule createRepositoryRule(DelphiRule fRule) {
 RulePriority priority = severityFromLevel(fRule.getPriority());
 Rule rule = Rule.create(DelphiPmdConstants.REPOSITORY_KEY, fRule.getName(), fRule.getMessage()).setSeverity(
  priority);
 rule.setDescription(fRule.getDescription());
 rule.setTags(fRule.getTags());
 rule.setConfigKey(fRule.getClazz());
 List<RuleParam> ruleParams = new ArrayList<RuleParam>();
 if (fRule.getProperties() != null) {
  for (Property property : fRule.getProperties()) {
   RuleParam param = rule.createParameter()
    .setKey(property.getName())
    .setDescription(property.getName())
    .setType("s");
   if (NumberUtils.isNumber(property.getValue())) {
    param.setType("i");
   }
   param.setDefaultValue(property.getValue());
   ruleParams.add(param);
  }
 }
 rule.setParams(ruleParams);
 return rule;
}
origin: SonarSource/sonarlint-core

private static Rule toRuleNotNull(RulesDefinition.Rule ruleDef) {
 Rule rule = Rule.create(ruleDef.repository().key(), ruleDef.key())
  .setName(ruleDef.name())
  .setSeverity(RulePriority.valueOf(ruleDef.severity()))
  .setLanguage(ruleDef.repository().language())
  .setIsTemplate(ruleDef.template())
  .setConfigKey(ruleDef.internalKey());
 for (Param param : ruleDef.params()) {
  rule.createParameter(param.key()).setDefaultValue(param.defaultValue()).setDescription(param.description());
 }
 return rule;
}
origin: org.sonarsource.sonarqube/sonar-plugin-api

private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
 RuleParam param = rule.createParameter();
 String keyAttribute = ruleC.getAttrValue("key");
 if (StringUtils.isNotBlank(keyAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setKey(StringUtils.trim(keyAttribute));
 }
 String typeAttribute = ruleC.getAttrValue("type");
 if (StringUtils.isNotBlank(typeAttribute)) {
  /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
  param.setType(type(StringUtils.trim(typeAttribute)));
 }
 SMInputCursor paramC = ruleC.childElementCursor();
 while (paramC.getNext() != null) {
  String propNodeName = paramC.getLocalName();
  String propText = StringUtils.trim(paramC.collectDescendantText(false));
  if (StringUtils.equalsIgnoreCase("key", propNodeName)) {
   param.setKey(propText);
  } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) {
   param.setDescription(propText);
  } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) {
   param.setType(type(propText));
  } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) {
   param.setDefaultValue(propText);
  }
 }
 if (StringUtils.isEmpty(param.getKey())) {
  throw new SonarException("Node <key> is missing in <param>");
 }
}
org.sonar.api.rulesRulecreateParameter

Popular methods of Rule

  • create
    Create with all required fields
  • getKey
  • getConfigKey
  • setConfigKey
    Sets the configuration key
  • setName
    Sets the rule name
  • setSeverity
  • getName
  • getRepositoryKey
  • ruleKey
  • setDescription
    Sets the rule description
  • 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
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JPanel (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Best IntelliJ plugins
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