Checking in some Java 5 changes

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5023 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch
2007-01-31 20:36:56 +00:00
parent 096f80bb5b
commit 86f600ea5d
11 changed files with 30 additions and 26 deletions

View File

@ -23,7 +23,7 @@ import java.util.List;
public class XMLRendererTest extends TestCase {
public void test_no_dupes() {
Renderer renderer = new XMLRenderer();
List list = new ArrayList();
List<Match> list = new ArrayList<Match>();
String report = renderer.render(list.iterator());
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(report.getBytes()));

View File

@ -17,7 +17,7 @@ import net.sourceforge.pmd.util.Benchmark;
* extracts interesting nodes from an AST, and lets each Rule visit
* the nodes it has expressed interest in.
*/
public abstract class AbstractRuleChainVisitor<E extends CompilationUnit> implements RuleChainVisitor<E> {
public abstract class AbstractRuleChainVisitor implements RuleChainVisitor {
/**
* These are all the rules participating in the RuleChain.
*/
@ -38,7 +38,7 @@ public abstract class AbstractRuleChainVisitor<E extends CompilationUnit> implem
/**
* @see RuleChainVisitor#visitAll(List, RuleContext)
*/
public void visitAll(List<E> astCompilationUnits, RuleContext ctx) {
public void visitAll(List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
initialize();
clear();
@ -75,7 +75,7 @@ public abstract class AbstractRuleChainVisitor<E extends CompilationUnit> implem
/**
* Index all nodes for visitation by rules.
*/
protected abstract void indexNodes(List<E> astCompilationUnits, RuleContext ctx);
protected abstract void indexNodes(List<CompilationUnit> astCompilationUnits, RuleContext ctx);
/**
* Index a single node for visitation by rules.

View File

@ -3,6 +3,7 @@
*/
package net.sourceforge.pmd;
import net.sourceforge.pmd.ast.CompilationUnit;
import net.sourceforge.pmd.ast.ParseException;
import net.sourceforge.pmd.cpd.FileFinder;
import net.sourceforge.pmd.cpd.SourceFileOrDirectoryFilter;
@ -82,7 +83,7 @@ public class PMD {
Parser parser = sourceTypeHandler.getParser();
parser.setExcludeMarker(excludeMarker);
long start = System.nanoTime();
Object rootNode = parser.parse(reader);
CompilationUnit rootNode = (CompilationUnit) parser.parse(reader);
ctx.excludeLines(parser.getExcludeMap());
long end = System.nanoTime();
Benchmark.mark(Benchmark.TYPE_PARSER, end - start, 0);
@ -108,7 +109,7 @@ public class PMD {
Benchmark.mark(Benchmark.TYPE_TYPE_RESOLUTION, end - start, 0);
}
List acus = new ArrayList();
List<CompilationUnit> acus = new ArrayList<CompilationUnit>();
acus.add(rootNode);
ruleSets.apply(acus, ctx, language);

View File

@ -16,7 +16,7 @@ import net.sourceforge.pmd.jsp.ast.JspRuleChainVisitor;
*/
public class RuleChain {
// Mapping from Language to RuleChainVisitor
private final Map<Language, RuleChainVisitor<? extends CompilationUnit>> languageToRuleChainVisitor = new HashMap<Language, RuleChainVisitor<? extends CompilationUnit>>();
private final Map<Language, RuleChainVisitor> languageToRuleChainVisitor = new HashMap<Language, RuleChainVisitor>();
/**
* Add all Rules from the given RuleSet which want to participate in the
@ -58,20 +58,20 @@ public class RuleChain {
* @param language
* The Language.
*/
public void apply(List astCompilationUnits, RuleContext ctx,
public void apply(List<CompilationUnit> astCompilationUnits, RuleContext ctx,
Language language) {
RuleChainVisitor<? extends CompilationUnit> visitor = getRuleChainVisitor(language);
RuleChainVisitor visitor = getRuleChainVisitor(language);
if (visitor != null) {
visitor.visitAll(astCompilationUnits, ctx);
}
}
// Get the RuleChainVisitor for the appropriate Language.
private RuleChainVisitor<? extends CompilationUnit> getRuleChainVisitor(Language language) {
private RuleChainVisitor getRuleChainVisitor(Language language) {
if (language == null) {
language = Language.JAVA;
}
RuleChainVisitor<? extends CompilationUnit> visitor = languageToRuleChainVisitor.get(language);
RuleChainVisitor visitor = languageToRuleChainVisitor.get(language);
if (visitor == null) {
if (Language.JAVA.equals(language)) {
visitor = new JavaRuleChainVisitor();

View File

@ -8,7 +8,7 @@ import net.sourceforge.pmd.ast.CompilationUnit;
* The RuleChainVisitor understands how to visit an AST for a particular
* Language.
*/
public interface RuleChainVisitor<E extends CompilationUnit> {
public interface RuleChainVisitor {
/**
* Add the given rule to the visitor.
*
@ -26,5 +26,5 @@ public interface RuleChainVisitor<E extends CompilationUnit> {
* @param ctx
* The RuleContext.
*/
void visitAll(List<E> astCompilationUnits, RuleContext ctx);
void visitAll(List<CompilationUnit> astCompilationUnits, RuleContext ctx);
}

View File

@ -7,6 +7,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.sourceforge.pmd.ast.CompilationUnit;
/**
* Grouping of Rules per Language in a RuleSet.
*
@ -102,7 +104,7 @@ public class RuleSets {
* @param ctx the RuleContext
* @param language the Language of the source
*/
public void apply(List acuList, RuleContext ctx, Language language) {
public void apply(List<CompilationUnit> acuList, RuleContext ctx, Language language) {
ruleChain.apply(acuList, ctx, language);
for (RuleSet ruleSet: ruleSets) {
if (applies(language, ruleSet.getLanguage())) {

View File

@ -7,9 +7,9 @@ import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.rules.XPathRule;
public class JavaRuleChainVisitor extends AbstractRuleChainVisitor<ASTCompilationUnit> {
public class JavaRuleChainVisitor extends AbstractRuleChainVisitor {
protected void indexNodes(List<ASTCompilationUnit> astCompilationUnits, RuleContext ctx) {
protected void indexNodes(List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
JavaParserVisitor javaParserVistor = new JavaParserVisitorAdapter() {
// Perform a visitation of the AST to index nodes which need
// visiting by type
@ -20,7 +20,7 @@ public class JavaRuleChainVisitor extends AbstractRuleChainVisitor<ASTCompilatio
};
for (int i = 0; i < astCompilationUnits.size(); i++) {
javaParserVistor.visit(astCompilationUnits.get(i), ctx);
javaParserVistor.visit((ASTCompilationUnit)astCompilationUnits.get(i), ctx);
}
}

View File

@ -6,10 +6,11 @@ import net.sourceforge.pmd.AbstractRuleChainVisitor;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.rules.XPathRule;
import net.sourceforge.pmd.ast.CompilationUnit;
public class JspRuleChainVisitor extends AbstractRuleChainVisitor<ASTCompilationUnit> {
public class JspRuleChainVisitor extends AbstractRuleChainVisitor {
protected void indexNodes(List<ASTCompilationUnit> astCompilationUnits, RuleContext ctx) {
protected void indexNodes(List<CompilationUnit> astCompilationUnits, RuleContext ctx) {
JspParserVisitor jspParserVisitor = new JspParserVisitorAdapter() {
// Perform a visitation of the AST to index nodes which need
// visiting by type
@ -20,7 +21,7 @@ public class JspRuleChainVisitor extends AbstractRuleChainVisitor<ASTCompilation
};
for (int i = 0; i < astCompilationUnits.size(); i++) {
jspParserVisitor.visit(astCompilationUnits.get(i), ctx);
jspParserVisitor.visit((ASTCompilationUnit)astCompilationUnits.get(i), ctx);
}
}

View File

@ -8,18 +8,18 @@ import java.util.List;
public class DFAGraphRule extends AbstractRule {
private List methods;
private List constructors;
private List<ASTMethodDeclaration> methods;
private List<ASTMethodDeclaration> constructors;
public DFAGraphRule() {
super.setUsesDFA();
}
public List getMethods() {
public List<ASTMethodDeclaration> getMethods() {
return this.methods;
}
public List getConstructors() {
public List<ASTMethodDeclaration> getConstructors() {
return this.constructors;
}

View File

@ -15,7 +15,6 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.Iterator;
import java.util.List;
public class DFAPanel extends JComponent implements ListSelectionListener {

View File

@ -11,6 +11,7 @@ import net.sourceforge.pmd.TargetJDK1_3;
import net.sourceforge.pmd.TargetJDK1_4;
import net.sourceforge.pmd.TargetJDK1_5;
import net.sourceforge.pmd.TargetJDK1_6;
import net.sourceforge.pmd.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.ast.Node;
import net.sourceforge.pmd.ast.ParseException;
import net.sourceforge.pmd.ast.SimpleNode;
@ -358,7 +359,7 @@ public class Designer implements ClipboardOwner {
e.printStackTrace();
}
List methods = dfaGraphRule.getMethods();
List<ASTMethodDeclaration> methods = dfaGraphRule.getMethods();
if (methods != null && !methods.isEmpty()) {
dfaPanel.resetTo(methods, codeEditorPane);
dfaPanel.repaint();