more CPD-aided refactoring

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@659 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-08-08 19:43:58 +00:00
parent b4787d1201
commit 98ad2717f7
3 changed files with 6 additions and 13 deletions

View File

@ -20,4 +20,8 @@ public class UnusedCodeRule extends AbstractRule {
ctx.getReport().addRuleViolation(createRuleViolation(ctx, symbol.getLine(), MessageFormat.format(getMessage(), new Object[] {symbol.getImage()})));
}
}
protected String getEndName(String name) {
return (name.indexOf('.') == -1) ? name : name.substring(0, name.indexOf('.'));
}
}

View File

@ -56,21 +56,11 @@ public class UnusedLocalVariableRule extends UnusedCodeRule {
*/
public Object visit(ASTName node, Object data) {
if (node.jjtGetParent() instanceof ASTPrimaryPrefix) {
String img = (node.getImage().indexOf('.') == -1) ? node.getImage() : node.getImage().substring(0, node.getImage().indexOf('.'));
nameSpace.peek().recordPossibleUsageOf(new Symbol(img, node.getBeginLine()));
nameSpace.peek().recordPossibleUsageOf(new Symbol(getEndName(node.getImage()), node.getBeginLine()));
}
return super.visit(node, data);
}
/*
private void reportUnusedLocals(RuleContext ctx, SymbolTable table) {
for (Iterator i = table.getUnusedSymbols(); i.hasNext();) {
Symbol symbol = (Symbol)i.next();
ctx.getReport().addRuleViolation(createRuleViolation(ctx, symbol.getLine(), MessageFormat.format(getMessage(), new Object[] {symbol.getImage()})));
}
}
*/
private Object addTable(SimpleNode node, Object data) {
nameSpace.addTable();
RuleContext ctx = (RuleContext)data;

View File

@ -99,10 +99,9 @@ public class UnusedPrivateInstanceVariableRule extends UnusedCodeRule {
}
private void recordPossibleUsage(SimpleNode node) {
String img = (node.getImage().indexOf('.') == -1) ? node.getImage() : node.getImage().substring(0, node.getImage().indexOf('.'));
String otherImg = (node.getImage().indexOf('.') == -1) ? node.getImage() : node.getImage().substring(node.getImage().indexOf('.')+1);
Namespace group = (Namespace)nameSpaces.peek();
group.peek().recordPossibleUsageOf(new Symbol(img, node.getBeginLine()));
group.peek().recordPossibleUsageOf(new Symbol(getEndName(node.getImage()), node.getBeginLine()));
group.peek().recordPossibleUsageOf(new Symbol(otherImg, node.getBeginLine()));
}