diff --git a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java index 673ca2e2e0..2ccdccc3c5 100644 --- a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java +++ b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java @@ -56,11 +56,11 @@ public class CsTokenizer implements Tokenizer { } 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(String.valueOf(c) + c, sourceCode .getFileName(), line)); } } else { @@ -76,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 + String.valueOf((char) ic), sourceCode .getFileName(), line)); ic = reader.read(); } else { diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java index f90e7340d6..8d97ecfa49 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.cpd; import java.io.IOException; import net.sourceforge.pmd.testframework.AbstractTokenizerTest; -import net.sourceforge.pmd.testframework.StreamUtil; +import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; @@ -18,14 +18,14 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { @Before @Override - public void buildTokenizer() { + public void buildTokenizer() throws IOException { this.tokenizer = new MatlabTokenizer(); this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME)); } @Override - public String getSampleCode() { - return StreamUtil.toString(MatlabTokenizer.class.getResourceAsStream(FILENAME)); + public String getSampleCode() throws IOException { + return IOUtils.toString(MatlabTokenizer.class.getResourceAsStream(FILENAME)); } @Test @@ -33,8 +33,4 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { this.expectedTokenCount = 3925; super.tokenizeTest(); } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(MatlabTokenizerTest.class); - } } diff --git a/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizerTest.java b/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizerTest.java index c8b2e72743..097f28a221 100644 --- a/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizerTest.java +++ b/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizerTest.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.cpd; import java.io.IOException; import net.sourceforge.pmd.testframework.AbstractTokenizerTest; -import net.sourceforge.pmd.testframework.StreamUtil; +import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; @@ -18,14 +18,14 @@ public class ObjectiveCTokenizerTest extends AbstractTokenizerTest { @Before @Override - public void buildTokenizer() { + public void buildTokenizer() throws IOException { this.tokenizer = new ObjectiveCTokenizer(); this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME)); } @Override - public String getSampleCode() { - return StreamUtil.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME)); + public String getSampleCode() throws IOException { + return IOUtils.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME)); } @Test @@ -33,8 +33,4 @@ public class ObjectiveCTokenizerTest extends AbstractTokenizerTest { this.expectedTokenCount = 884; super.tokenizeTest(); } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(ObjectiveCTokenizerTest.class); - } } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/dfa/StatementAndBraceFinder.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/dfa/StatementAndBraceFinder.java index 1f2b243ca3..e3e88e98cd 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/dfa/StatementAndBraceFinder.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/dfa/StatementAndBraceFinder.java @@ -50,35 +50,29 @@ import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter; * @author raik *
* Sublayer of DataFlowFacade. Finds all data flow nodes and stores the - * type information (@see StackObject). At last it uses this information to - * link the nodes. + * type information (@see StackObject). At last it uses this information + * to link the nodes. */ public class StatementAndBraceFinder extends PLSQLParserVisitorAdapter { - private final static Logger LOGGER = Logger.getLogger(StatementAndBraceFinder.class.getName()); + private final static Logger LOGGER = Logger.getLogger(StatementAndBraceFinder.class.getName()); private final DataFlowHandler dataFlowHandler; private Structure dataFlow; - + public StatementAndBraceFinder(DataFlowHandler dataFlowHandler) { - this.dataFlowHandler = dataFlowHandler; + this.dataFlowHandler = dataFlowHandler; } public void buildDataFlowFor(PLSQLNode node) { - LOGGER.entering(this.getClass().getCanonicalName(),"buildDataFlowFor"); + LOGGER.entering(this.getClass().getCanonicalName(), "buildDataFlowFor"); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("buildDataFlowFor: node class " - + node.getClass().getCanonicalName() + " @ line " - + node.getBeginLine() - +", column " + node.getBeginColumn() - + " --- " + new Throwable().getStackTrace() - ); + LOGGER.finest("buildDataFlowFor: node class " + node.getClass().getCanonicalName() + " @ line " + + node.getBeginLine() + ", column " + node.getBeginColumn() + " --- " + + new Throwable().getStackTrace()); } - if (!(node instanceof ASTMethodDeclaration) - && !(node instanceof ASTProgramUnit) - && !(node instanceof ASTTypeMethod) - && !(node instanceof ASTTriggerUnit) - && !(node instanceof ASTTriggerTimingPointSection) - ) { + if (!(node instanceof ASTMethodDeclaration) && !(node instanceof ASTProgramUnit) + && !(node instanceof ASTTypeMethod) && !(node instanceof ASTTriggerUnit) + && !(node instanceof ASTTriggerTimingPointSection)) { throw new RuntimeException("Can't build a data flow for anything other than a Method or a Trigger"); } @@ -90,9 +84,8 @@ public class StatementAndBraceFinder extends PLSQLParserVisitorAdapter { this.dataFlow.createEndNode(node.getEndLine()); - if (LOGGER.isLoggable(Level.FINE)) - { - LOGGER.fine("DataFlow is " + this.dataFlow.dump() ); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine("DataFlow is " + this.dataFlow.dump()); } Linker linker = new Linker(dataFlowHandler, dataFlow.getBraceStack(), dataFlow.getContinueBreakReturnStack()); try { @@ -104,88 +97,95 @@ public class StatementAndBraceFinder extends PLSQLParserVisitorAdapter { LOGGER.severe("SequenceException"); e.printStackTrace(); } - LOGGER.exiting(this.getClass().getCanonicalName(),"buildDataFlowFor"); + LOGGER.exiting(this.getClass().getCanonicalName(), "buildDataFlowFor"); } - - public Object visit(ASTSqlStatement node, Object data) { + public Object visit(ASTSqlStatement node, Object data) { if (!(data instanceof Structure)) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("immediate return ASTSqlStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("immediate return ASTSqlStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTSqlStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTSqlStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - - public Object visit(ASTEmbeddedSqlStatement node, Object data) { + } + + public Object visit(ASTEmbeddedSqlStatement node, Object data) { if (!(data instanceof Structure)) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("immediate return ASTEmbeddedSqlStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("immediate return ASTEmbeddedSqlStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTEmbeddedSqlStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTEmbeddedSqlStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - - public Object visit(ASTCloseStatement node, Object data) { + } + + public Object visit(ASTCloseStatement node, Object data) { if (!(data instanceof Structure)) { return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTCloseStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTCloseStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - - public Object visit(ASTOpenStatement node, Object data) { + } + + public Object visit(ASTOpenStatement node, Object data) { if (!(data instanceof Structure)) { return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTOpenStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTOpenStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - - public Object visit(ASTFetchStatement node, Object data) { + } + + public Object visit(ASTFetchStatement node, Object data) { if (!(data instanceof Structure)) { return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTFetchStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTFetchStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - - public Object visit(ASTPipelineStatement node, Object data) { + } + + public Object visit(ASTPipelineStatement node, Object data) { if (!(data instanceof Structure)) { return data; } Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTPipelineStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTPipelineStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); - } - + } + /* */ public Object visit(ASTVariableOrConstantDeclarator node, Object data) { @@ -195,79 +195,88 @@ public class StatementAndBraceFinder extends PLSQLParserVisitorAdapter { Structure dataFlow = (Structure) data; dataFlow.createNewNode(node); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTVariableOrConstantDeclarator: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTVariableOrConstantDeclarator: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return super.visit(node, data); } public Object visit(ASTExpression node, Object data) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("Entry ASTExpression: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("Entry ASTExpression: line " + node.getBeginLine() + ", column " + node.getBeginColumn()); } if (!(data instanceof Structure)) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("immediate return ASTExpression: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("immediate return ASTExpression: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } return data; } Structure dataFlow = (Structure) data; - //The equivalent of an ASTExpression is an Expression whose parent is an UnLabelledStatement + // The equivalent of an ASTExpression is an Expression whose parent is + // an UnLabelledStatement if (node.jjtGetParent() instanceof ASTUnlabelledStatement) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("createNewNode ASTSUnlabelledStatement: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("createNewNode ASTSUnlabelledStatement: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } dataFlow.createNewNode(node); - } else + } else // TODO what about throw stmts? if (node.jjtGetParent() instanceof ASTIfStatement) { dataFlow.createNewNode(node); // START IF dataFlow.pushOnStack(NodeType.IF_EXPR, dataFlow.getLast()); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("pushOnStack parent IF_EXPR: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("pushOnStack parent IF_EXPR: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } } else if (node.jjtGetParent() instanceof ASTElsifClause) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("parent (Elsif) IF_EXPR at " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("parent (Elsif) IF_EXPR at " + node.getBeginLine() + ", column " + node.getBeginColumn()); } dataFlow.createNewNode(node); // START IF dataFlow.pushOnStack(NodeType.IF_EXPR, dataFlow.getLast()); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("pushOnStack parent (Elsif) IF_EXPR: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("pushOnStack parent (Elsif) IF_EXPR: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } } else if (node.jjtGetParent() instanceof ASTWhileStatement) { dataFlow.createNewNode(node); // START WHILE dataFlow.pushOnStack(NodeType.WHILE_EXPR, dataFlow.getLast()); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("pushOnStack parent WHILE_EXPR: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("pushOnStack parent WHILE_EXPR: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } } else if (node.jjtGetParent() instanceof ASTCaseStatement) { dataFlow.createNewNode(node); // START SWITCH dataFlow.pushOnStack(NodeType.SWITCH_START, dataFlow.getLast()); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("pushOnStack parent SWITCH_START: line " + node.getBeginLine() +", column " + node.getBeginColumn()); + LOGGER.finest("pushOnStack parent SWITCH_START: line " + node.getBeginLine() + ", column " + + node.getBeginColumn()); } } else if (node.jjtGetParent() instanceof ASTForStatement) { - /* A PL/SQL loop control: - * [
* Note that this calculation applies to Cyclomatic Complexity as well.
*
* @param expr
- * control structure expression
+ * control structure expression
* @return complexity of the boolean expression
*/
public static int sumExpressionComplexity(ASTExpression expr) {
- LOGGER.entering(CLASS_NAME,"visit(ASTExpression)");
- if (expr == null) {
- LOGGER.exiting(CLASS_NAME,"visit(ASTExpression)", 0);
- return 0;
- }
+ LOGGER.entering(CLASS_NAME, "visit(ASTExpression)");
+ if (expr == null) {
+ LOGGER.exiting(CLASS_NAME, "visit(ASTExpression)", 0);
+ return 0;
+ }
- List
+ * Assert it the occurrence is a self assignment such as:
* i += 3;
*
*
* @return true, if the occurrence is self-assignment, false, otherwise.
*/
/*
- @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop")
- public boolean isSelfAssignment() {
- Node l = location;
- while (true) {
- Node p = l.jjtGetParent();
- Node gp = p.jjtGetParent();
- Node node = gp.jjtGetParent();
- if (node instanceof ASTPreDecrementExpression || node instanceof ASTPreIncrementExpression || node instanceof ASTPostfixExpression) {
- return true;
- }
-
- if (hasAssignmentOperator(gp)) {
- return isCompoundAssignment(gp);
- }
-
- if (hasAssignmentOperator(node)) {
- return isCompoundAssignment(node);
- }
-
- // deal with extra parenthesis: "(i)++"
- if (p instanceof ASTPrimaryPrefix && p.jjtGetNumChildren() == 1 &&
- gp instanceof ASTPrimaryExpression && gp.jjtGetNumChildren() == 1&&
- node instanceof ASTExpression && node.jjtGetNumChildren() == 1 &&
- node.jjtGetParent() instanceof ASTPrimaryPrefix && node.jjtGetParent().jjtGetNumChildren() == 1) {
- l = node;
- continue;
- }
-
- // catch this.i++ or ++this.i
- return gp instanceof ASTPreDecrementExpression || gp instanceof ASTPreIncrementExpression || gp instanceof ASTPostfixExpression;
- }
- }
- */
+ * @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop") public
+ * boolean isSelfAssignment() { Node l = location; while (true) { Node p =
+ * l.jjtGetParent(); Node gp = p.jjtGetParent(); Node node =
+ * gp.jjtGetParent(); if (node instanceof ASTPreDecrementExpression || node
+ * instanceof ASTPreIncrementExpression || node instanceof
+ * ASTPostfixExpression) { return true; }
+ *
+ * if (hasAssignmentOperator(gp)) { return isCompoundAssignment(gp); }
+ *
+ * if (hasAssignmentOperator(node)) { return isCompoundAssignment(node); }
+ *
+ * // deal with extra parenthesis: "(i)++" if (p instanceof ASTPrimaryPrefix
+ * && p.jjtGetNumChildren() == 1 && gp instanceof ASTPrimaryExpression &&
+ * gp.jjtGetNumChildren() == 1&& node instanceof ASTExpression &&
+ * node.jjtGetNumChildren() == 1 && node.jjtGetParent() instanceof
+ * ASTPrimaryPrefix && node.jjtGetParent().jjtGetNumChildren() == 1) { l =
+ * node; continue; }
+ *
+ * // catch this.i++ or ++this.i return gp instanceof
+ * ASTPreDecrementExpression || gp instanceof ASTPreIncrementExpression ||
+ * gp instanceof ASTPostfixExpression; } }
+ */
/*
- private boolean hasAssignmentOperator(Node node) {
- if (node instanceof ASTStatementExpression || node instanceof ASTExpression) {
- if (node.jjtGetNumChildren() >= 2 && node.jjtGetChild(1) instanceof ASTAssignmentOperator) {
- return true;
- }
- }
- return false;
- }
- */
+ * private boolean hasAssignmentOperator(Node node) { if (node instanceof
+ * ASTStatementExpression || node instanceof ASTExpression) { if
+ * (node.jjtGetNumChildren() >= 2 && node.jjtGetChild(1) instanceof
+ * ASTAssignmentOperator) { return true; } } return false; }
+ */
/**
* Simply return true is the image is equal to keyword 'this' or 'super'.
@@ -203,26 +179,21 @@ public class PLSQLNameOccurrence implements NameOccurrence {
* @return true, if keyword is used, false otherwise.
*/
/*
- public boolean useThisOrSuper() {
- Node node = location.jjtGetParent();
- if ( node instanceof ASTPrimaryExpression ) {
- ASTPrimaryExpression primaryExpression = (ASTPrimaryExpression)node;
- ASTPrimaryPrefix prefix = (ASTPrimaryPrefix) primaryExpression.jjtGetChild(0);
- if ( prefix != null ) {
- return prefix.usesSuperModifier() || prefix.usesThisModifier();
- }
- }
- return image.startsWith(THIS_DOT) || image.startsWith(SUPER_DOT);
- }
- */
+ * public boolean useThisOrSuper() { Node node = location.jjtGetParent(); if
+ * ( node instanceof ASTPrimaryExpression ) { ASTPrimaryExpression
+ * primaryExpression = (ASTPrimaryExpression)node; ASTPrimaryPrefix prefix =
+ * (ASTPrimaryPrefix) primaryExpression.jjtGetChild(0); if ( prefix != null
+ * ) { return prefix.usesSuperModifier() || prefix.usesThisModifier(); } }
+ * return image.startsWith(THIS_DOT) || image.startsWith(SUPER_DOT); }
+ */
@Override
public boolean equals(Object o) {
- if (o instanceof PLSQLNameOccurrence) {
- PLSQLNameOccurrence n = (PLSQLNameOccurrence) o;
- return n.getImage().equals(getImage());
- }
- return false;
+ if (o instanceof PLSQLNameOccurrence) {
+ PLSQLNameOccurrence n = (PLSQLNameOccurrence) o;
+ return n.getImage().equals(getImage());
+ }
+ return false;
}
@Override
@@ -236,6 +207,7 @@ public class PLSQLNameOccurrence implements NameOccurrence {
@Override
public String toString() {
- return getImage() + ":" + location.getBeginLine() + ":" + location.getClass() + (this.isMethodOrConstructorInvocation() ? "(method call)" : "");
+ return getImage() + ":" + location.getBeginLine() + ":" + location.getClass()
+ + (this.isMethodOrConstructorInvocation() ? "(method call)" : "");
}
}
diff --git a/pmd-plsql/src/test/java/net/sourceforge/pmd/cpd/PLSQLTokenizerTest.java b/pmd-plsql/src/test/java/net/sourceforge/pmd/cpd/PLSQLTokenizerTest.java
index cec2a7ecd6..e006446ea2 100644
--- a/pmd-plsql/src/test/java/net/sourceforge/pmd/cpd/PLSQLTokenizerTest.java
+++ b/pmd-plsql/src/test/java/net/sourceforge/pmd/cpd/PLSQLTokenizerTest.java
@@ -6,8 +6,8 @@ package net.sourceforge.pmd.cpd;
import java.io.IOException;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
-import net.sourceforge.pmd.testframework.StreamUtil;
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
@@ -18,14 +18,14 @@ public class PLSQLTokenizerTest extends AbstractTokenizerTest {
@Before
@Override
- public void buildTokenizer() {
+ public void buildTokenizer() throws IOException {
this.tokenizer = new PLSQLTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
}
@Override
- public String getSampleCode() {
- return StreamUtil.toString(PLSQLTokenizer.class.getResourceAsStream(FILENAME));
+ public String getSampleCode() throws IOException {
+ return IOUtils.toString(PLSQLTokenizer.class.getResourceAsStream(FILENAME));
}
@Test
diff --git a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java
index 315d1d8e94..141446520f 100644
--- a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java
+++ b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java
@@ -6,8 +6,8 @@ package net.sourceforge.pmd.cpd;
import java.io.IOException;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
-import net.sourceforge.pmd.testframework.StreamUtil;
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
@@ -18,14 +18,14 @@ public class PythonTokenizerTest extends AbstractTokenizerTest {
@Before
@Override
- public void buildTokenizer() {
+ public void buildTokenizer() throws IOException {
this.tokenizer = new PythonTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
}
@Override
- public String getSampleCode() {
- return StreamUtil.toString(PythonTokenizer.class.getResourceAsStream(FILENAME));
+ public String getSampleCode() throws IOException {
+ return IOUtils.toString(PythonTokenizer.class.getResourceAsStream(FILENAME));
}
@Test
diff --git a/pmd-scala/src/main/java/org/sonar/plugins/scala/util/StringUtils.java b/pmd-scala/src/main/java/org/sonar/plugins/scala/util/StringUtils.java
index 4ea6ec8830..1db4d308a2 100644
--- a/pmd-scala/src/main/java/org/sonar/plugins/scala/util/StringUtils.java
+++ b/pmd-scala/src/main/java/org/sonar/plugins/scala/util/StringUtils.java
@@ -41,8 +41,6 @@ public final class StringUtils {
while ((line = reader.readLine()) != null) {
lines.add(line);
}
- } catch (IOException ioe) {
- throw ioe;
} finally {
IOUtils.closeQuietly(reader);
}
diff --git a/pmd-scala/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java b/pmd-scala/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java
index 44c00d48dd..d3fc905927 100644
--- a/pmd-scala/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java
+++ b/pmd-scala/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java
@@ -7,9 +7,9 @@ import java.io.File;
import java.io.IOException;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
-import net.sourceforge.pmd.testframework.StreamUtil;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -18,32 +18,29 @@ import org.sonar.plugins.scala.cpd.ScalaTokenizer;
public class ScalaTokenizerTest extends AbstractTokenizerTest {
+ private static final String ENCODING = "UTF-8";
+
private static final String FILENAME = "sample-LiftActor.scala";
private File tempFile;
@Before
@Override
- public void buildTokenizer() {
+ public void buildTokenizer() throws IOException {
createTempFileOnDisk();
this.tokenizer = new ScalaTokenizer();
this.sourceCode = new SourceCode(new SourceCode.FileCodeLoader(tempFile, "UTF-8"));
}
- private void createTempFileOnDisk() {
- try {
- this.tempFile = File.createTempFile("scala-tokenizer-test-", ".scala");
-
- FileUtils.writeStringToFile(tempFile, getSampleCode(), "UTF-8");
- } catch (IOException e) {
- throw new RuntimeException("Unable to create temporary file on disk for Scala tokenizer test", e);
- }
+ private void createTempFileOnDisk() throws IOException {
+ this.tempFile = File.createTempFile("scala-tokenizer-test-", ".scala");
+ FileUtils.writeStringToFile(tempFile, getSampleCode(), ENCODING);
}
@Override
- public String getSampleCode() {
- return StreamUtil.toString(ScalaTokenizer.class.getResourceAsStream(FILENAME));
+ public String getSampleCode() throws IOException {
+ return IOUtils.toString(ScalaTokenizer.class.getResourceAsStream(FILENAME), ENCODING);
}
@Test
@@ -57,8 +54,4 @@ public class ScalaTokenizerTest extends AbstractTokenizerTest {
FileUtils.deleteQuietly(this.tempFile);
this.tempFile = null;
}
-
- public static junit.framework.Test suite() {
- return new junit.framework.JUnit4TestAdapter(ScalaTokenizerTest.class);
- }
}
diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/lang/ParserOptionsTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/lang/ParserOptionsTest.java
index 211e7889f5..deff1a614f 100644
--- a/pmd-test/src/main/java/net/sourceforge/pmd/lang/ParserOptionsTest.java
+++ b/pmd-test/src/main/java/net/sourceforge/pmd/lang/ParserOptionsTest.java
@@ -3,12 +3,7 @@
*/
package net.sourceforge.pmd.lang;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertNotEquals;
-
+import org.junit.Assert;
import org.junit.Test;
/**
@@ -22,9 +17,9 @@ public class ParserOptionsTest {
@Test
public void testSuppressMarker() {
ParserOptions parserOptions = new ParserOptions();
- assertNull(parserOptions.getSuppressMarker());
+ Assert.assertNull(parserOptions.getSuppressMarker());
parserOptions.setSuppressMarker("foo");
- assertEquals("foo", parserOptions.getSuppressMarker());
+ Assert.assertEquals("foo", parserOptions.getSuppressMarker());
}
/**
@@ -55,40 +50,40 @@ public class ParserOptionsTest {
public static void verifyOptionsEqualsHashcode(ParserOptions options1, ParserOptions options2,
ParserOptions options3, ParserOptions options4) {
// Objects should be different
- assertNotSame(options1, options2);
- assertNotSame(options1, options2);
- assertNotSame(options1, options3);
- assertNotSame(options2, options3);
- assertNotSame(options2, options4);
- assertNotSame(options3, options4);
+ Assert.assertNotSame(options1, options2);
+ Assert.assertNotSame(options1, options2);
+ Assert.assertNotSame(options1, options3);
+ Assert.assertNotSame(options2, options3);
+ Assert.assertNotSame(options2, options4);
+ Assert.assertNotSame(options3, options4);
// Check all 16 equality combinations
- assertEquals(options1, options1);
- assertFalse(options1.equals(options2));
- assertEquals(options1, options3);
- assertFalse(options1.equals(options4));
+ Assert.assertEquals(options1, options1);
+ Assert.assertFalse(options1.equals(options2));
+ Assert.assertEquals(options1, options3);
+ Assert.assertFalse(options1.equals(options4));
- assertFalse(options2.equals(options1));
- assertEquals(options2, options2);
- assertFalse(options2.equals(options3));
- assertEquals(options2, options4);
+ Assert.assertFalse(options2.equals(options1));
+ Assert.assertEquals(options2, options2);
+ Assert.assertFalse(options2.equals(options3));
+ Assert.assertEquals(options2, options4);
- assertEquals(options3, options1);
- assertFalse(options3.equals(options2));
- assertEquals(options3, options3);
- assertFalse(options3.equals(options4));
+ Assert.assertEquals(options3, options1);
+ Assert.assertFalse(options3.equals(options2));
+ Assert.assertEquals(options3, options3);
+ Assert.assertFalse(options3.equals(options4));
- assertFalse(options4.equals(options1));
- assertEquals(options4, options2);
- assertFalse(options4.equals(options3));
- assertEquals(options4, options4);
+ Assert.assertFalse(options4.equals(options1));
+ Assert.assertEquals(options4, options2);
+ Assert.assertFalse(options4.equals(options3));
+ Assert.assertEquals(options4, options4);
// Hashcodes should match up
- assertNotEquals(options1.hashCode(), options2.hashCode());
- assertEquals(options1.hashCode(), options3.hashCode());
- assertNotEquals(options1.hashCode(), options4.hashCode());
- assertNotEquals(options2.hashCode(), options3.hashCode());
- assertEquals(options2.hashCode(), options4.hashCode());
- assertNotEquals(options3.hashCode(), options4.hashCode());
+ Assert.assertNotEquals(options1.hashCode(), options2.hashCode());
+ Assert.assertEquals(options1.hashCode(), options3.hashCode());
+ Assert.assertNotEquals(options1.hashCode(), options4.hashCode());
+ Assert.assertNotEquals(options2.hashCode(), options3.hashCode());
+ Assert.assertEquals(options2.hashCode(), options4.hashCode());
+ Assert.assertNotEquals(options3.hashCode(), options4.hashCode());
}
}
diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/AbstractTokenizerTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/AbstractTokenizerTest.java
index 7a54498788..5675184e07 100644
--- a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/AbstractTokenizerTest.java
+++ b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/AbstractTokenizerTest.java
@@ -19,19 +19,19 @@ import net.sourceforge.pmd.cpd.Tokens;
*/
public abstract class AbstractTokenizerTest {
- protected int expectedTokenCount;
- protected Tokenizer tokenizer;
- protected SourceCode sourceCode;
+ protected int expectedTokenCount;
+ protected Tokenizer tokenizer;
+ protected SourceCode sourceCode;
- public abstract void buildTokenizer();
+ public abstract void buildTokenizer() throws IOException;
- public abstract String getSampleCode();
+ public abstract String getSampleCode() throws IOException;
- protected void tokenizeTest() throws IOException {
- Tokens tokens = new Tokens();
- tokenizer.tokenize(sourceCode, tokens);
- List