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

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

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

Rule.getName介绍

[英]Get the name of this Rule.
[中]获取此规则的名称。

代码示例

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

@Override
public String getName() {
  return rule.getName();
}

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

@Override
  public int compare(Rule o1, Rule o2) {
    return o1.getName().compareToIgnoreCase(o2.getName());
  }
});

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

@Override
  public int compare(Rule o1, Rule o2) {
    return o1.getName().compareTo(o2.getName());
  }
});

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

@Override
public int compareTo(RuleDuration other) {
  if (other.time < time) {
    return -1;
  } else if (other.time > time) {
    return 1;
  }
  return rule.getName().compareTo(other.rule.getName());
}

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

/**
 * Returns the first Rule found with the given name (case-sensitive).
 *
 * Note: Since we support multiple languages, rule names are not expected to
 * be unique within any specific ruleset.
 *
 * @param ruleName
 *            the exact name of the rule to find
 * @return the rule or null if not found
 */
public Rule getRuleByName(String ruleName) {
  for (Rule r : rules) {
    if (r.getName().equals(ruleName)) {
      return r;
    }
  }
  return null;
}

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

/**
 * getResourceAsStream tries to find the XML file in weird locations if the
 * ruleName includes the package, so we strip it here.
 */
protected String getCleanRuleName(Rule rule) {
  String fullClassName = rule.getClass().getName();
  if (fullClassName.equals(rule.getName())) {
    // We got the full class name, so we'll use the stripped name
    // instead
    String packageName = rule.getClass().getPackage().getName();
    return fullClassName.substring(packageName.length() + 1);
  } else {
    return rule.getName(); // Test is using findRule, smart!
  }
}

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

@Override
  public String get(int idx, RuleViolation rv, String cr) {
    return rv.getRule().getName();
  }
}), };

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

@Override
public void generate(Set<RuleDuration> stressResults, PrintStream stream) {
  stream.println("=========================================================");
  stream.println("Rule\t\t\t\t\t\tTime in ms");
  stream.println("=========================================================");
  for (RuleDuration result : stressResults) {
    StringBuilder buffer = new StringBuilder(result.rule.getName());
    while (buffer.length() < TIME_COLUMN) {
      buffer.append(' ');
    }
    buffer.append(result.time);
    stream.println(stream.toString());
  }
  stream.println("=========================================================");
}

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

/**
   * If in debug modus, print the names of the rules.
   *
   * @param rulesets
   *            the RuleSets to print
   */
  private static void printRuleNamesInDebug(RuleSets rulesets) {
    if (LOG.isLoggable(Level.FINER)) {
      for (Rule r : rulesets.getAllRules()) {
        LOG.finer("Loaded rule " + r.getName());
      }
    }
  }
}

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

private String getRuleSetKeywords(RuleSet ruleset) {
  List<String> ruleNames = new LinkedList<>();
  for (Rule rule : ruleset.getRules()) {
    ruleNames.add(rule.getName());
  }
  return ruleset.getName() + ", " + StringUtils.join(ruleNames, ", ");
}

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

/**
 * Calculate a summary of violations per rule.
 *
 * @return a Map summarizing the Report: String (rule name) -&gt; Integer (count
 *         of violations)
 */
public Map<String, Integer> getSummary() {
  Map<String, Integer> summary = new HashMap<>();
  for (RuleViolation rv : violations) {
    String name = rv.getRule().getName();
    if (!summary.containsKey(name)) {
      summary.put(name, NumericConstants.ZERO);
    }
    Integer count = summary.get(name);
    summary.put(name, count + 1);
  }
  return summary;
}

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

public void filterRulesByPriority(RulePriority minimumPriority) {
    Iterator<Rule> iterator = rules.iterator();
    while (iterator.hasNext()) {
      Rule rule = iterator.next();
      if (rule.getPriority().compareTo(minimumPriority) > 0) {
        LOG.fine("Removing rule " + rule.getName() + " due to priority: " + rule.getPriority() + " required: " + minimumPriority);
        iterator.remove();
      }
    }
  }
}

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

public boolean suppresses(Rule rule) {
    final String ruleAnno = "PMD." + rule.getName();

    if (hasImageEqualTo("SuppressWarnings")) {
      for (ASTAnnotationParameter param : findChildrenOfType(ASTAnnotationParameter.class)) {
        String image = param.getImage();

        if (image != null) {
          Set<String> paramValues = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
          paramValues.addAll(Arrays.asList(image.replaceAll("\\s+", "").split(",")));
          if (paramValues.contains("PMD") || paramValues.contains(ruleAnno) || paramValues.contains("all")) {
            return true;
          }
        }
      }
    }

    return false;
  }
}

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

/**
 * Remove and return the misconfigured rules from the rulesets and log them
 * for good measure.
 *
 * @param ruleSets RuleSets to prune of broken rules.
 * @return Set<Rule>
 */
private Set<Rule> removeBrokenRules(final RuleSets ruleSets) {
  final Set<Rule> brokenRules = new HashSet<>();
  ruleSets.removeDysfunctionalRules(brokenRules);
  for (final Rule rule : brokenRules) {
    if (LOG.isLoggable(Level.WARNING)) {
      LOG.log(Level.WARNING,
          "Removed misconfigured rule: " + rule.getName() + "  cause: " + rule.dysfunctionReason());
    }
  }
  return brokenRules;
}

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

/**
 * Code to be executed if the rule is reinitialised.
 *
 * @param rule The rule to reinitialise
 *
 * @return The rule once it has been reinitialised
 */
protected Rule reinitializeRule(Rule rule) {
  return findRule(rule.getRuleSetName(), rule.getName());
}

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

/**
 * Overrides the rule's properties with the values defined in the element.
 *
 * @param rule          The rule
 * @param propertiesElt The {@literal <properties>} element
 */
private void setPropertyValues(Rule rule, Element propertiesElt) {
  Map<String, String> overridden = getPropertyValuesFrom(propertiesElt);
  for (Entry<String, String> e : overridden.entrySet()) {
    PropertyDescriptor<?> descriptor = rule.getPropertyDescriptor(e.getKey());
    if (descriptor == null) {
      throw new IllegalArgumentException(
          "Cannot set non-existent property '" + e.getKey() + "' on Rule " + rule.getName());
    }
    setRulePropertyCapture(rule, descriptor, e.getValue());
  }
}

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

@Override
  public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
    Writer writer = getWriter();
    StringBuffer buf = new StringBuffer();
    while (violations.hasNext()) {
      RuleViolation rv = violations.next();
      buf.setLength(0);
      // Filename
      buf.append(rv.getFilename() + "(");
      // Line number
      buf.append(Integer.toString(rv.getBeginLine())).append(",  ");
      // Name of violated rule
      buf.append(rv.getRule().getName()).append("):  ");
      // Specific violation message
      buf.append(rv.getDescription()).append(PMD.EOL);
      writer.write(buf.toString());
    }
  }
}

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

@Override
protected Description describeChild(TestDescriptor testCase) {
  Description description = testDescriptions.get(testCase);
  if (description == null) {
    description = Description.createTestDescription(getTestClass().getJavaClass(),
      testCase.getRule().getName() + "::"
          + testCase.getNumberInDocument() + " "
          + testCase.getDescription().replaceAll("\n|\r", " "));
    testDescriptions.putIfAbsent(testCase, description);
  }
  return description;
}

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

/**
 * Generates a html table with violation information.
 */
private String displayRuleViolation(RuleViolation vio) {
  StringBuilder sb = new StringBuilder(200);
  sb.append("<table border=\"0\">");
  renderViolationRow(sb, "Rule:", vio.getRule().getName());
  renderViolationRow(sb, "Description:", vio.getDescription());
  if (StringUtils.isNotBlank(vio.getVariableName())) {
    renderViolationRow(sb, "Variable:", vio.getVariableName());
  }
  if (vio.getEndLine() > 0) {
    renderViolationRow(sb, "Line:", vio.getEndLine() + " and " + vio.getBeginLine());
  } else {
    renderViolationRow(sb, "Line:", Integer.toString(vio.getBeginLine()));
  }
  sb.append("</table>");
  return sb.toString();
}

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

private void logRulesUsed(RuleSets rules) {
    project.log("Using these rulesets: " + configuration.getRuleSets(), Project.MSG_VERBOSE);

    RuleSet[] ruleSets = rules.getAllRuleSets();
    for (RuleSet ruleSet : ruleSets) {
      for (Rule rule : ruleSet.getRules()) {
        project.log("Using rule " + rule.getName(), Project.MSG_VERBOSE);
      }
    }
  }
}

相关文章