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

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

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

Rule.apply介绍

[英]Apply this rule to the given collection of nodes, using the given context.
[中]使用给定的上下文将此规则应用于给定的节点集合。

代码示例

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

@Override
public void apply(List<? extends Node> nodes, RuleContext ctx) {
  rule.apply(nodes, ctx);
}

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

@Override
protected void visit(Rule rule, Node node, RuleContext ctx) {
  rule.apply(Arrays.asList(node), ctx);
}

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

/**
 * Executes the rules in this ruleset against each of the given nodes.
 *
 * @param acuList
 *            the node list, usually the root nodes like compilation units
 * @param ctx
 *            the current context
 */
public void apply(List<? extends Node> acuList, RuleContext ctx) {
  try (TimedOperation to = TimeTracker.startOperation(TimedOperationCategory.RULE)) {
    for (Rule rule : rules) {
      if (!rule.isRuleChain() && applies(rule, ctx.getLanguageVersion())) {
        try (TimedOperation rto = TimeTracker.startOperation(TimedOperationCategory.RULE, rule.getName())) {
          rule.apply(acuList, ctx);
        } catch (RuntimeException e) {
          if (ctx.isIgnoreExceptions()) {
            ctx.getReport().addError(new Report.ProcessingError(e, ctx.getSourceCodeFilename()));
            if (LOG.isLoggable(Level.WARNING)) {
              LOG.log(Level.WARNING, "Exception applying rule " + rule.getName() + " on file "
                  + ctx.getSourceCodeFilename() + ", continuing with next rule", e);
            }
          } else {
            throw e;
          }
        }
      }
    }
  }
}

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

@Override
public void apply(List<? extends Node> nodes, RuleContext ctx) {
  rule.apply(nodes, ctx);
}

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

@Override
protected void visit(Rule rule, Node node, RuleContext ctx) {
  rule.apply(Arrays.asList(node), ctx);
}

代码示例来源:origin: stackoverflow.com

String markov(String input, List<Rule> rules) {

 // find the first matching rule, apply it and recurse 
 for (Rule rule : rules) {
  if (rule.matches(input)) {
   String temp = rule.apply(input);
   return markov(temp, rules);
  }
 }

 // no rule matched so just return the input text
 // - this is the terminating case for the recursion
 return input;
}

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

/**
 * Executes the rules in this ruleset against each of the given nodes.
 *
 * @param acuList
 *            the node list, usually the root nodes like compilation units
 * @param ctx
 *            the current context
 */
public void apply(List<? extends Node> acuList, RuleContext ctx) {
  try (TimedOperation to = TimeTracker.startOperation(TimedOperationCategory.RULE)) {
    for (Rule rule : rules) {
      if (!rule.isRuleChain() && applies(rule, ctx.getLanguageVersion())) {
        try (TimedOperation rto = TimeTracker.startOperation(TimedOperationCategory.RULE, rule.getName())) {
          rule.apply(acuList, ctx);
        } catch (RuntimeException e) {
          if (ctx.isIgnoreExceptions()) {
            ctx.getReport().addError(new Report.ProcessingError(e, ctx.getSourceCodeFilename()));
            if (LOG.isLoggable(Level.WARNING)) {
              LOG.log(Level.WARNING, "Exception applying rule " + rule.getName() + " on file "
                  + ctx.getSourceCodeFilename() + ", continuing with next rule", e);
            }
          } else {
            throw e;
          }
        }
      }
    }
  }
}

相关文章