[jsp] Remove usage of deprecated ImportWrapper (#2658)

This commit is contained in:
Andreas Dangel 2020-07-24 11:38:37 +02:00
parent 900635b664
commit 6464b349cf

View File

@ -1,33 +1,24 @@
/**
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.jsp.rule.codestyle;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.jsp.ast.ASTJspDirectiveAttribute;
import net.sourceforge.pmd.lang.jsp.rule.AbstractJspRule;
import net.sourceforge.pmd.lang.rule.ImportWrapper;
public class DuplicateJspImportsRule extends AbstractJspRule {
private Set<ImportWrapper> imports = new HashSet<>();
private Set<String> imports = new HashSet<>();
@Override
public void apply(List<? extends Node> nodes, RuleContext ctx) {
/*
* TODO: This method is a hack! It's overriding the parent's method
* because the JSP parsing doesn't seem to hit ASTCompilationUnit
* properly
*/
public void start(RuleContext ctx) {
imports.clear();
super.apply(nodes, ctx);
}
@Override
@ -41,11 +32,10 @@ public class DuplicateJspImportsRule extends AbstractJspRule {
int count = st.countTokens();
for (int ix = 0; ix < count; ix++) {
String token = st.nextToken();
ImportWrapper wrapper = new ImportWrapper(token, token, node);
if (imports.contains(wrapper)) {
if (imports.contains(token)) {
addViolation(data, node, node.getImage());
} else {
imports.add(wrapper);
imports.add(token);
}
}
return super.visit(node, data);