forked from phoedos/pmd
Fix PMD dogfood issues in pmd-cs, pmd-jsp, pmd-javascript, pmd-test
This commit is contained in:
@@ -21,7 +21,8 @@ public class CsTokenizer implements Tokenizer {
|
||||
BufferedReader reader = new BufferedReader(new CharArrayReader(sourceCode.getCodeBuffer().toString()
|
||||
.toCharArray()));
|
||||
try {
|
||||
int ic = reader.read(), line = 1;
|
||||
int ic = reader.read();
|
||||
int line = 1;
|
||||
char c;
|
||||
StringBuilder b;
|
||||
while (ic != -1) {
|
||||
@@ -50,16 +51,16 @@ public class CsTokenizer implements Tokenizer {
|
||||
case '>':
|
||||
ic = reader.read();
|
||||
if (ic == '=') {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c) + "=", sourceCode.getFileName(), line));
|
||||
tokenEntries.add(new TokenEntry(c + "=", sourceCode.getFileName(), line));
|
||||
ic = reader.read();
|
||||
} else if (ic == c) {
|
||||
ic = reader.read();
|
||||
if (ic == '=') {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf(c) + "=", sourceCode
|
||||
tokenEntries.add(new TokenEntry("" + c + c + "=", sourceCode
|
||||
.getFileName(), line));
|
||||
ic = reader.read();
|
||||
} else {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf(c), sourceCode
|
||||
tokenEntries.add(new TokenEntry("" + c + c, sourceCode
|
||||
.getFileName(), line));
|
||||
}
|
||||
} else {
|
||||
@@ -75,7 +76,7 @@ public class CsTokenizer implements Tokenizer {
|
||||
case '-':
|
||||
ic = reader.read();
|
||||
if (ic == '=' || ic == c) {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c) + String.valueOf((char) ic), sourceCode
|
||||
tokenEntries.add(new TokenEntry("" + c + ((char) ic), sourceCode
|
||||
.getFileName(), line));
|
||||
ic = reader.read();
|
||||
} else {
|
||||
@@ -91,7 +92,7 @@ public class CsTokenizer implements Tokenizer {
|
||||
case '~':
|
||||
ic = reader.read();
|
||||
if (ic == '=') {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c) + "=", sourceCode.getFileName(), line));
|
||||
tokenEntries.add(new TokenEntry(c + "=", sourceCode.getFileName(), line));
|
||||
ic = reader.read();
|
||||
} else {
|
||||
tokenEntries.add(new TokenEntry(String.valueOf(c), sourceCode.getFileName(), line));
|
||||
@@ -104,17 +105,20 @@ public class CsTokenizer implements Tokenizer {
|
||||
b = new StringBuilder();
|
||||
b.append(c);
|
||||
while ((ic = reader.read()) != c) {
|
||||
if (ic == -1)
|
||||
if (ic == -1) {
|
||||
break;
|
||||
}
|
||||
b.append((char) ic);
|
||||
if (ic == '\\') {
|
||||
int next = reader.read();
|
||||
if (next != -1)
|
||||
if (next != -1) {
|
||||
b.append((char) next);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ic != -1)
|
||||
if (ic != -1) {
|
||||
b.append((char) ic);
|
||||
}
|
||||
tokenEntries.add(new TokenEntry(b.toString(), sourceCode.getFileName(), line));
|
||||
ic = reader.read();
|
||||
break;
|
||||
@@ -132,8 +136,9 @@ public class CsTokenizer implements Tokenizer {
|
||||
b.append(c);
|
||||
|
||||
if (state == 1) {
|
||||
if (c == '*')
|
||||
if (c == '*') {
|
||||
state = 2;
|
||||
}
|
||||
} else {
|
||||
if (c == '/') {
|
||||
ic = reader.read();
|
||||
@@ -152,8 +157,9 @@ public class CsTokenizer implements Tokenizer {
|
||||
b = new StringBuilder();
|
||||
b.append("//");
|
||||
while ((ic = reader.read()) != '\n') {
|
||||
if (ic == -1)
|
||||
if (ic == -1) {
|
||||
break;
|
||||
}
|
||||
b.append((char) ic);
|
||||
}
|
||||
// ignore the // comment
|
||||
@@ -189,8 +195,9 @@ public class CsTokenizer implements Tokenizer {
|
||||
b.append(c);
|
||||
if (c == 'e' || c == 'E') {
|
||||
c = (char) (ic = reader.read());
|
||||
if ("1234567890-".indexOf(c) == -1)
|
||||
if ("1234567890-".indexOf(c) == -1) {
|
||||
break;
|
||||
}
|
||||
b.append(c);
|
||||
}
|
||||
c = (char) (ic = reader.read());
|
||||
|
@@ -17,7 +17,7 @@ public class DumpFacade {
|
||||
private boolean recurse;
|
||||
|
||||
public void initializeWith(Writer writer, String prefix, boolean recurse, EcmascriptNode<?> node) {
|
||||
this.writer = (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer);
|
||||
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
|
||||
this.recurse = recurse;
|
||||
this.dump(node, prefix);
|
||||
try {
|
||||
|
@@ -132,14 +132,14 @@ public final class EcmascriptTreeBuilder implements NodeVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ParseProblem> parseProblems;
|
||||
protected Map<ParseProblem, TrailingCommaNode> parseProblemToNode = new HashMap<ParseProblem, TrailingCommaNode>();
|
||||
private List<ParseProblem> parseProblems;
|
||||
private Map<ParseProblem, TrailingCommaNode> parseProblemToNode = new HashMap<ParseProblem, TrailingCommaNode>();
|
||||
|
||||
// The nodes having children built.
|
||||
protected Stack<Node> nodes = new Stack<Node>();
|
||||
private Stack<Node> nodes = new Stack<Node>();
|
||||
|
||||
// The Rhino nodes with children to build.
|
||||
protected Stack<AstNode> parents = new Stack<AstNode>();
|
||||
private Stack<AstNode> parents = new Stack<AstNode>();
|
||||
|
||||
private final SourceCodePositioner sourceCodePositioner;
|
||||
|
||||
|
@@ -17,7 +17,7 @@ public class DumpFacade extends JspParserVisitorAdapter {
|
||||
private boolean recurse;
|
||||
|
||||
public void initializeWith(Writer writer, String prefix, boolean recurse, JspNode node) {
|
||||
this.writer = (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer);
|
||||
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
|
||||
this.recurse = recurse;
|
||||
this.visit(node, prefix);
|
||||
try {
|
||||
|
@@ -23,9 +23,10 @@ public class OpenTagRegister {
|
||||
private List<ASTElement> tagList = new ArrayList<ASTElement>();
|
||||
|
||||
public void openTag(ASTElement elm) {
|
||||
if (elm == null || StringUtil.isEmpty(elm.getName()))
|
||||
if (elm == null || StringUtil.isEmpty(elm.getName())) {
|
||||
throw new IllegalStateException(
|
||||
"Tried to open a tag with empty name");
|
||||
}
|
||||
|
||||
tagList.add(elm);
|
||||
}
|
||||
@@ -37,9 +38,10 @@ public class OpenTagRegister {
|
||||
* was ever opened ( or registered )
|
||||
*/
|
||||
public boolean closeTag(String closingTagName) {
|
||||
if (StringUtil.isEmpty(closingTagName))
|
||||
if (StringUtil.isEmpty(closingTagName)) {
|
||||
throw new IllegalStateException(
|
||||
"Tried to close a tag with empty name");
|
||||
}
|
||||
|
||||
int lastRegisteredTagIdx = tagList.size() - 1;
|
||||
/*
|
||||
|
@@ -459,12 +459,8 @@ public abstract class AbstractRuleSetFactoryTest {
|
||||
.getPropertyDescriptors();
|
||||
List<PropertyDescriptor<?>> propertyDescriptors2 = rule2
|
||||
.getPropertyDescriptors();
|
||||
try {
|
||||
assertEquals(message + ", Rule property descriptor ",
|
||||
propertyDescriptors1, propertyDescriptors2);
|
||||
} catch (Error e) {
|
||||
throw e;
|
||||
}
|
||||
assertEquals(message + ", Rule property descriptor ",
|
||||
propertyDescriptors1, propertyDescriptors2);
|
||||
for (int j = 0; j < propertyDescriptors1.size(); j++) {
|
||||
assertEquals(message + ", Rule property value " + j, rule1
|
||||
.getProperty(propertyDescriptors1.get(j)), rule2
|
||||
|
@@ -45,8 +45,8 @@ public abstract class AbstractAntTestHelper extends BuildFileTest {
|
||||
private void validatePostConstruct() {
|
||||
if ( pathToTestScript == null || "".equals(pathToTestScript) ||
|
||||
antTestScriptFilename == null || "".equals(antTestScriptFilename) ||
|
||||
mvnWorkaround == null || "".equals(mvnWorkaround) )
|
||||
mvnWorkaround == null || "".equals(mvnWorkaround) ) {
|
||||
throw new IllegalStateException("Unit tests for Ant script badly initialized");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -84,8 +84,9 @@ public abstract class BaseCLITest {
|
||||
|
||||
protected void checkStatusCode() {
|
||||
int statusCode = getStatusCode();
|
||||
if (statusCode > 0)
|
||||
if (statusCode > 0) {
|
||||
fail("PMD failed with status code:" + statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getStatusCode() {
|
||||
|
@@ -84,12 +84,12 @@ public abstract class RuleTst {
|
||||
if (test.getProperties() != null) {
|
||||
for (Map.Entry<Object, Object> entry : test.getProperties().entrySet()) {
|
||||
String propertyName = (String)entry.getKey();
|
||||
String strValue = (String)entry.getValue();
|
||||
PropertyDescriptor propertyDescriptor = rule.getPropertyDescriptor(propertyName);
|
||||
if (propertyDescriptor == null) {
|
||||
throw new IllegalArgumentException("No such property '" + propertyName + "' on Rule " + rule.getName());
|
||||
}
|
||||
Object value = propertyDescriptor.valueFrom(strValue);
|
||||
|
||||
Object value = propertyDescriptor.valueFrom((String)entry.getValue());
|
||||
rule.setProperty(propertyDescriptor, value);
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,6 @@ public abstract class RuleTst {
|
||||
String propertyName = ruleProperty.getAttributes().getNamedItem("name").getNodeValue();
|
||||
properties.setProperty(propertyName, parseTextNode(ruleProperty));
|
||||
}
|
||||
int expectedProblems = Integer.parseInt(getNodeValue(testCode, "expected-problems", true));
|
||||
|
||||
NodeList expectedMessagesNodes = testCode.getElementsByTagName("expected-messages");
|
||||
List<String> messages = new ArrayList<String>();
|
||||
@@ -336,7 +335,6 @@ public abstract class RuleTst {
|
||||
}
|
||||
}
|
||||
|
||||
String description = getNodeValue(testCode, "description", true);
|
||||
String code = getNodeValue(testCode, "code", false);
|
||||
if (code == null) {
|
||||
//Should have a coderef
|
||||
@@ -359,6 +357,9 @@ public abstract class RuleTst {
|
||||
}
|
||||
}
|
||||
|
||||
String description = getNodeValue(testCode, "description", true);
|
||||
int expectedProblems = Integer.parseInt(getNodeValue(testCode, "expected-problems", true));
|
||||
|
||||
String languageVersionString = getNodeValue(testCode, "source-type", false);
|
||||
if (languageVersionString == null) {
|
||||
tests[i] = new TestDescriptor(code, description, expectedProblems, rule);
|
||||
|
@@ -9,13 +9,13 @@ import java.io.InputStream;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
|
||||
public class StreamUtil {
|
||||
public final class StreamUtil {
|
||||
|
||||
private StreamUtil() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static String toString(InputStream in) {
|
||||
if (in == null) {
|
||||
throw new NullPointerException("no input stream given");
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int c;
|
||||
try {
|
||||
|
@@ -123,7 +123,6 @@ public class TestDescriptor {
|
||||
inRegressionMode = Boolean.parseBoolean(property);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
|
||||
return inRegressionMode;
|
||||
|
Reference in New Issue
Block a user