net.sourceforge.pmd.Rule.getLanguage()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(101)

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

Rule.getLanguage介绍

[英]Get the Language of this Rule.
[中]获取此规则的语言。

代码示例

代码示例来源:origin: pmd/pmd

@Override
public Language getLanguage() {
  return rule.getLanguage();
}

代码示例来源:origin: pmd/pmd

public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule) {
  this(code, description, numberOfProblemsExpected, rule, rule.getLanguage().getDefaultVersion());
}

代码示例来源:origin: pmd/pmd

/**
 * Does any Rule for the given Language use Type Resolution?
 *
 * @param language
 *            The Language.
 * @return <code>true</code> if a Rule for the Language uses Type
 *         Resolution, <code>false</code> otherwise.
 * @deprecated See {@link Rule#isTypeResolution()}
 */
@Deprecated
public boolean usesTypeResolution(Language language) {
  for (Rule r : rules) {
    if (r.getLanguage().equals(language) && r.isTypeResolution()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

/**
 * Does any Rule for the given Language use the DFA layer?
 *
 * @param language
 *            The Language.
 * @return <code>true</code> if a Rule for the Language uses the DFA layer,
 *         <code>false</code> otherwise.
 * @deprecated See {@link Rule#isDfa()}
 */
@Deprecated
public boolean usesDFA(Language language) {
  for (Rule r : rules) {
    if (r.getLanguage().equals(language) && r.isDfa()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

/**
 * Does any Rule for the given Language use multi-file analysis?
 *
 * @param language
 *            The Language.
 *
 * @return {@code true} if a Rule for the Language uses multi file analysis,
 *         {@code false} otherwise.
 * @deprecated See {@link Rule#isMultifile()}
 */
@Deprecated
public boolean usesMultifile(Language language) {
  for (Rule r : rules) {
    if (r.getLanguage().equals(language) && r.isMultifile()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

/**
 * Rulesets could potentially contain rules from various languages.
 * But for built-in rulesets, all rules within one ruleset belong to
 * one language. So we take the language of the first rule.
 * @param ruleset
 * @return the terse name of the ruleset's language
 */
private static Language getRuleSetLanguage(RuleSet ruleset) {
  Collection<Rule> rules = ruleset.getRules();
  if (rules.isEmpty()) {
    throw new RuntimeException("Ruleset " + ruleset.getFileName() + " is empty!");
  }
  return rules.iterator().next().getLanguage();
}

代码示例来源:origin: pmd/pmd

/**
 * Adds a rule. If a rule with the same name and language already
 * existed before in the ruleset, then the new rule will replace it.
 * This makes sure that the rule configured is overridden.
 *
 * @param rule
 *            the new rule to add
 * @return The same builder, for a fluid programming interface
 */
public RuleSetBuilder addRuleReplaceIfExists(final Rule rule) {
  if (rule == null) {
    throw new IllegalArgumentException(MISSING_RULE);
  }
  for (final Iterator<Rule> it = rules.iterator(); it.hasNext();) {
    final Rule r = it.next();
    if (r.getName().equals(rule.getName()) && r.getLanguage() == rule.getLanguage()) {
      it.remove();
    }
  }
  addRule(rule);
  return this;
}

代码示例来源:origin: pmd/pmd

/**
 * Add a new rule to this ruleset. Note that this method does not check
 * for duplicates.
 *
 * @param newRule
 *            the rule to be added
 * @return The same builder, for a fluid programming interface
 */
public RuleSetBuilder addRule(final Rule newRule) {
  if (newRule == null) {
    throw new IllegalArgumentException(MISSING_RULE);
  }
  // check for duplicates - adding more than one rule with the same name will
  // be problematic - see #RuleSet.getRuleByName(String)
  for (Rule rule : rules) {
    if (rule.getName().equals(newRule.getName()) && rule.getLanguage() == newRule.getLanguage()) {
      LOG.warning("The rule with name " + newRule.getName() + " is duplicated. "
          + "Future versions of PMD will reject to load such rulesets.");
      break;
    }
  }
  rules.add(newRule);
  return this;
}

代码示例来源:origin: pmd/pmd

/**
 * Add the given Rule if it wants to participate in the RuleChain.
 *
 * @param ruleSet
 *            The RuleSet to which the rule belongs.
 * @param rule
 *            The Rule to add.
 */
private void add(RuleSet ruleSet, Rule rule) {
  RuleChainVisitor visitor = getRuleChainVisitor(rule.getLanguage());
  if (visitor != null) {
    visitor.add(ruleSet, rule);
  }
}

代码示例来源:origin: pmd/pmd

if (r.getName().equals(rule.getName()) && r.getLanguage() == rule.getLanguage()) {
  exists = true;
  break;

代码示例来源:origin: pmd/pmd

private static Set<Language> getApplicableLanguages(PMDConfiguration configuration, RuleSets ruleSets) {
  Set<Language> languages = new HashSet<>();
  LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer();
  for (Rule rule : ruleSets.getAllRules()) {
    Language language = rule.getLanguage();
    if (languages.contains(language)) {
      continue;
    }
    LanguageVersion version = discoverer.getDefaultLanguageVersion(language);
    if (RuleSet.applies(rule, version)) {
      languages.add(language);
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Using " + language.getShortName() + " version: " + version.getShortName());
      }
    }
  }
  return languages;
}

代码示例来源:origin: pmd/pmd

private void loadLanguageMinMaxVersions(Rule rule) {
  if (minimumVersion != null) {
    LanguageVersion minimumLanguageVersion = rule.getLanguage().getVersion(minimumVersion);
    if (minimumLanguageVersion == null) {
      throwUnknownLanguageVersionException("minimum", minimumVersion);
    } else {
      rule.setMinimumLanguageVersion(minimumLanguageVersion);
    }
  }
  if (maximumVersion != null) {
    LanguageVersion maximumLanguageVersion = rule.getLanguage().getVersion(maximumVersion);
    if (maximumLanguageVersion == null) {
      throwUnknownLanguageVersionException("maximum", maximumVersion);
    } else {
      rule.setMaximumLanguageVersion(maximumLanguageVersion);
    }
  }
  checkLanguageVersionsAreOrdered(rule);
}

代码示例来源:origin: pmd/pmd

/**
 * Does the given Rule apply to the given LanguageVersion? If so, the
 * Language must be the same and be between the minimum and maximums
 * versions on the Rule.
 *
 * @param rule
 *            The rule.
 * @param languageVersion
 *            The language version.
 *
 * @return <code>true</code> if the given rule matches the given language,
 *         which means, that the rule would be executed.
 */
public static boolean applies(Rule rule, LanguageVersion languageVersion) {
  final LanguageVersion min = rule.getMinimumLanguageVersion();
  final LanguageVersion max = rule.getMaximumLanguageVersion();
  return rule.getLanguage().equals(languageVersion.getLanguage())
      && (min == null || min.compareTo(languageVersion) <= 0)
      && (max == null || max.compareTo(languageVersion) >= 0);
}

代码示例来源:origin: pmd/pmd

+ rule.getLanguage().getName() + " " + rule.getMinimumLanguageVersion().getVersion());
lines.add("");

代码示例来源:origin: pmd/pmd

rule.setRuleClass(clazz);
if (rule.getLanguage() == null) {
  rule.setLanguage(language);

代码示例来源:origin: pmd/pmd

Language language = rule.getLanguage();
String group = fileName.substring(fileName.lastIndexOf('/') + 1);
group = group.substring(0, group.indexOf(".xml"));

代码示例来源:origin: pmd/pmd

return createSingleRuleElement(rule instanceof ImmutableLanguage ? null : rule.getLanguage(),
    rule.getMinimumLanguageVersion(), rule.getMaximumLanguageVersion(), rule.isDeprecated(),
    rule.getName(), rule.getSince(), null, rule.getMessage(), rule.getExternalInfoUrl(),

代码示例来源:origin: net.sourceforge.pmd/pmd-core

@Override
public Language getLanguage() {
  return rule.getLanguage();
}

代码示例来源:origin: net.sourceforge.pmd/pmd-test

public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule) {
  this(code, description, numberOfProblemsExpected, rule, rule.getLanguage().getDefaultVersion());
}

代码示例来源:origin: net.sourceforge.pmd/pmd-core

/**
 * Add the given Rule if it wants to participate in the RuleChain.
 *
 * @param ruleSet
 *            The RuleSet to which the rule belongs.
 * @param rule
 *            The Rule to add.
 */
private void add(RuleSet ruleSet, Rule rule) {
  RuleChainVisitor visitor = getRuleChainVisitor(rule.getLanguage());
  if (visitor != null) {
    visitor.add(ruleSet, rule);
  }
}

相关文章