Checking in some Java 5 changes - Using the MessageFormatter.format varargs construct

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5024 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Allan Caplan
2007-01-31 21:29:24 +00:00
parent 86f600ea5d
commit 2167342314
9 changed files with 12 additions and 15 deletions

View File

@ -402,7 +402,7 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
*/
protected final void addViolation(Object data, SimpleNode node, String embed) {
RuleContext ctx = (RuleContext) data;
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), embed)));
}
/**

View File

@ -70,8 +70,7 @@ public class CommandLineOptions {
cpus = Integer.parseInt(args[++i]);
} catch (NumberFormatException e) {
throw new RuntimeException(MessageFormat.format(
"cpus parameter must be a whole number, {0} received",
(Object[]) new String[] { args[i] }));
"cpus parameter must be a whole number, {0} received", args[i]));
}
} else if (args[i].equals("-targetjdk")) {
targetJDK = args[++i];
@ -90,8 +89,7 @@ public class CommandLineOptions {
minPriority = Integer.parseInt(args[++i]);
} catch (NumberFormatException e) {
throw new RuntimeException(MessageFormat.format(
"minimumpriority parameter must be a whole number, {0} received",
(Object[]) new String[] { args[i] }));
"minimumpriority parameter must be a whole number, {0} received", args[i]));
}
} else if (args[i].equals("-reportfile")) {
reportFile = args[++i];

View File

@ -216,7 +216,7 @@ public abstract class CommonAbstractRule implements Rule {
*/
protected final void addViolation(Object data, SimpleNode node, String embed) {
RuleContext ctx = (RuleContext) data;
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), embed)));
}
/**

View File

@ -148,10 +148,9 @@ public class DaaRule extends AbstractRule implements Executable {
&& !violationAlreadyExists(type, var, startLine, endLine)
&& node != null) {
final RuleContext ctx = (RuleContext) data;
final Object[] params = new Object[] { type, var, startLine, endLine };
String msg = type;
if (getMessage() != null) {
msg = MessageFormat.format(getMessage(), params);
msg = MessageFormat.format(getMessage(), type, var, startLine, endLine);
}
final DaaRuleViolation violation = new DaaRuleViolation(this, ctx, node, type, msg, var, startLine, endLine);
ctx.getReport().addRuleViolation(violation);

View File

@ -228,7 +228,7 @@ public abstract class AbstractJspRule extends JspParserVisitorAdapter implements
*/
protected final void addViolation(Object data, SimpleNode node, String embed) {
RuleContext ctx = (RuleContext) data;
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), new Object[]{embed})));
ctx.getReport().addRuleViolation(new RuleViolation(this, ctx, node, MessageFormat.format(getMessage(), embed)));
}
/**

View File

@ -300,9 +300,9 @@ public class Benchmark {
while (buf2.length() <= 50) {
buf2.append(' ');
}
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,0.000}", new Object[]{new Double(benchmarkResult.getTime()/1000000000.0)}), 8));
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,0.000}", new Double(benchmarkResult.getTime()/1000000000.0)), 8));
if (benchmarkResult.getType() <= TYPE_RULE_CHAIN_RULE) {
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,###,###,###,###,###}", new Object[]{new Long(benchmarkResult.getCount())}), 20));
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,###,###,###,###,###}", benchmarkResult.getCount()), 20));
}
switch (benchmarkResult.getType()) {
case TYPE_RULE:

View File

@ -25,7 +25,7 @@ public class TypeMap {
*
* @param types Class[]
*/
public TypeMap(Class[] types) {
public TypeMap(Class... types) {
this(types.length);
add(types);
}
@ -76,7 +76,7 @@ public class TypeMap {
*
* @param types Class[]
*/
public void add(Class[] types) {
public void add(Class... types) {
for (int i=0; i<types.length; i++) {
add(types[i]);
}

View File

@ -23,7 +23,7 @@ public class AttributesSubMenu
private SimpleNode node;
public AttributesSubMenu(ViewerModel model, SimpleNode node) {
super(MessageFormat.format(NLS.nls("AST.MENU.ATTRIBUTES"), new Object[]{node.toString()}));
super(MessageFormat.format(NLS.nls("AST.MENU.ATTRIBUTES"), node.toString()));
this.model = model;
this.node = node;
init();

View File

@ -27,7 +27,7 @@ public class SimpleNodeSubMenu
* @param node menu's owner
*/
public SimpleNodeSubMenu(ViewerModel model, SimpleNode node) {
super(MessageFormat.format(NLS.nls("AST.MENU.NODE.TITLE"), new Object[]{node.toString()}));
super(MessageFormat.format(NLS.nls("AST.MENU.NODE.TITLE"), node.toString()));
this.model = model;
this.node = node;
init();