dogfood, whitespaces

This commit is contained in:
Andreas Dangel
2015-03-23 20:16:03 +01:00
parent b7bf3fbb8c
commit 2fdb51fcb6
17 changed files with 800 additions and 833 deletions
@@ -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 {
@@ -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);
}
}
@@ -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);
}
}
@@ -17,7 +17,6 @@ import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule;
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
import net.sourceforge.pmd.util.NumericConstants;
public class TooManyFieldsRule extends AbstractPLSQLRule {
private static final int DEFAULT_MAXFIELDS = 15;
@@ -25,10 +24,8 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
private Map<String, Integer> stats;
private Map<String, PLSQLNode> nodes;
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty(
"maxfields", "Max allowable fields",
1, 300, DEFAULT_MAXFIELDS, 1.0f
);
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields",
"Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f);
public TooManyFieldsRule() {
definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR);
@@ -37,7 +34,6 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
@Override
public Object visit(ASTInput node, Object data) {
stats = new HashMap<String, Integer>(5);
nodes = new HashMap<String, PLSQLNode>(5);
@@ -51,8 +47,8 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
List<ASTVariableOrConstantDeclaration> l = node.findDescendantsOfType(ASTVariableOrConstantDeclaration.class);
for (ASTVariableOrConstantDeclaration fd: l) {
bumpCounterFor(node);
for (ASTVariableOrConstantDeclaration fd : l) {
bumpCounterFor(fd);
}
for (String k : stats.keySet()) {
int val = stats.get(k);
@@ -71,8 +67,8 @@ public class TooManyFieldsRule extends AbstractPLSQLRule {
List<ASTVariableOrConstantDeclaration> l = node.findDescendantsOfType(ASTVariableOrConstantDeclaration.class);
for (ASTVariableOrConstantDeclaration fd: l) {
bumpCounterFor(node);
for (ASTVariableOrConstantDeclaration fd : l) {
bumpCounterFor(fd);
}
for (String k : stats.keySet()) {
int val = stats.get(k);
@@ -21,7 +21,9 @@ public class ClassScope extends AbstractScope {
// FIXME - this breaks given sufficiently nested code
private static ThreadLocal<Integer> anonymousInnerClassCounter = new ThreadLocal<Integer>() {
protected Integer initialValue() { return Integer.valueOf(1); }
protected Integer initialValue() {
return Integer.valueOf(1);
}
};
private String className;
@@ -34,12 +36,13 @@ public class ClassScope extends AbstractScope {
/**
* This is only for anonymous inner classes
* <p/>
* FIXME - should have name like Foo$1, not Anonymous$1
* to get this working right, the parent scope needs
* to be passed in when instantiating a ClassScope
* FIXME - should have name like Foo$1, not Anonymous$1 to get this working
* right, the parent scope needs to be passed in when instantiating a
* ClassScope
*/
public ClassScope() {
//this.className = getParent().getEnclosingClassScope().getClassName() + "$" + String.valueOf(anonymousInnerClassCounter);
// this.className = getParent().getEnclosingClassScope().getClassName()
// + "$" + String.valueOf(anonymousInnerClassCounter);
int v = anonymousInnerClassCounter.get().intValue();
this.className = "Anonymous$" + v;
anonymousInnerClassCounter.set(v + 1);
@@ -55,7 +58,7 @@ public class ClassScope extends AbstractScope {
@Override
public NameDeclaration addNameOccurrence(NameOccurrence occ) {
PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence)occ;
PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
NameDeclaration decl = findVariableHere(occurrence);
Map<MethodNameDeclaration, List<NameOccurrence>> methodNames = getMethodDeclarations();
if (decl != null && occurrence.isMethodOrConstructorInvocation()) {
@@ -117,7 +120,8 @@ public class ClassScope extends AbstractScope {
// }
return null;
}
// return any name declaration, since all we really want is to get the scope
// return any name declaration, since all we really want is to get
// the scope
// for example, if there's a
// public class Foo {
// private static final int X = 2;
@@ -132,14 +136,16 @@ public class ClassScope extends AbstractScope {
}
if (occurrence.isMethodOrConstructorInvocation()) {
for (MethodNameDeclaration mnd: methodDeclarations.keySet()) {
for (MethodNameDeclaration mnd : methodDeclarations.keySet()) {
if (mnd.getImage().equals(occurrence.getImage())) {
int args = occurrence.getArgumentCount();
if (args == mnd.getParameterCount() || (mnd.isVarargs() && args >= mnd.getParameterCount() - 1)) {
if (args == mnd.getParameterCount() || mnd.isVarargs() && args >= mnd.getParameterCount() - 1) {
// FIXME if several methods have the same name
// and parameter count, only one will get caught here
// we need to make some attempt at type lookup and discrimination
// or, failing that, mark this as a usage of all those methods
// we need to make some attempt at type lookup and
// discrimination
// or, failing that, mark this as a usage of all those
// methods
return mnd;
}
}
@@ -150,16 +156,13 @@ public class ClassScope extends AbstractScope {
List<String> images = new ArrayList<String>();
images.add(occurrence.getImage());
if (null==occurrence.getImage()) {
if (null == occurrence.getImage()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("occurrence==" +occurrence.toString()
+ "with Argumanet Count == "+occurrence.getArgumentCount()
+ " for className="+className
) ;
LOGGER.finest("occurrence==" + occurrence.toString() + "with Argumanet Count == "
+ occurrence.getArgumentCount() + " for className=" + className);
}
}
if (occurrence.getImage().startsWith(className)) {
images.add(clipClassName(occurrence.getImage()));
}
@@ -177,7 +180,7 @@ public class ClassScope extends AbstractScope {
res += "(" + classNames.keySet() + ")";
}
if (!methodNames.isEmpty()) {
for (MethodNameDeclaration mnd: methodNames.keySet()) {
for (MethodNameDeclaration mnd : methodNames.keySet()) {
res += mnd.toString();
int usages = methodNames.get(mnd).size();
res += "(begins at line " + mnd.getNode().getBeginLine() + ", " + usages + " usages)";
@@ -21,9 +21,9 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
super(node);
}
/** Treat a TimingPointSection within a Compound Trigger like a
* packaged FUNCTION or PROCEDURE.
* SRT
/**
* Treat a TimingPointSection within a Compound Trigger like a packaged
* FUNCTION or PROCEDURE. SRT
*
* @param node
*/
@@ -37,16 +37,10 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
/**
* PL/SQL does not currently allow varargs outside the STANDARD package.
*
* @return false
*/
public boolean isVarargs() {
ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0);
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
//if (p.isVarargs()) {
// return true;
//}
}
return false;
}
@@ -62,9 +56,9 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
sb.append(p.getTypeNode().getTypeImage());
//if (p.isVarargs()) {
// if (p.isVarargs()) {
// sb.append("...");
//}
// }
sb.append(',');
}
if (sb.charAt(sb.length() - 1) == ',') {
@@ -87,24 +81,27 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
return false;
}
// compare parameter count - this catches the case where there are no params, too
// compare parameter count - this catches the case where there are no
// params, too
if (((ASTMethodDeclarator) other.node).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
return false;
}
// compare parameter types
//SRT ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
//SRT ASTFormalParameters otherParams = (ASTFormalParameters) other.node.jjtGetChild(0);
ASTFormalParameters myParams = node.getFirstDescendantOfType(ASTFormalParameters.class) ;
ASTFormalParameters otherParams = other.node.getFirstDescendantOfType(ASTFormalParameters.class) ;
// SRT ASTFormalParameters myParams = (ASTFormalParameters)
// node.jjtGetChild(0);
// SRT ASTFormalParameters otherParams = (ASTFormalParameters)
// other.node.jjtGetChild(0);
ASTFormalParameters myParams = node.getFirstDescendantOfType(ASTFormalParameters.class);
ASTFormalParameters otherParams = other.node.getFirstDescendantOfType(ASTFormalParameters.class);
for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
// Compare vararg
//if (myParam.isVarargs() != otherParam.isVarargs()) {
// if (myParam.isVarargs() != otherParam.isVarargs()) {
// return false;
//}
// }
Node myTypeNode = myParam.getTypeNode().jjtGetChild(0);
Node otherTypeNode = otherParam.getTypeNode().jjtGetChild(0);
@@ -120,45 +117,46 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
// once we get real types in here that should get fixed
String myTypeImg;
String otherTypeImg;
//if (myTypeNode instanceof ASTPrimitiveType) {
// if (myTypeNode instanceof ASTPrimitiveType) {
// myTypeImg = myTypeNode.getImage();
// otherTypeImg = otherTypeNode.getImage();
//} else {
myTypeImg = ( (AbstractPLSQLNode) myTypeNode .jjtGetChild(0) ) .getImage();
otherTypeImg = ( (AbstractPLSQLNode) otherTypeNode.jjtGetChild(0) ).getImage();
//}
// } else {
myTypeImg = ((AbstractPLSQLNode) myTypeNode.jjtGetChild(0)).getImage();
otherTypeImg = ((AbstractPLSQLNode) otherTypeNode.jjtGetChild(0)).getImage();
// }
if (!myTypeImg.equals(otherTypeImg)) {
return false;
}
// if type is ASTPrimitiveType and is an array, make sure the other one is also
// if type is ASTPrimitiveType and is an array, make sure the other
// one is also
}
return true;
}
@Override
public int hashCode() {
try
{
return node.hashCode(); //SRT node.getImage().hashCode() + ((ASTMethodDeclarator) node).getParameterCount();
}
catch (Exception e)
{
try {
return node.hashCode(); // SRT node.getImage().hashCode() +
// ((ASTMethodDeclarator)
// node).getParameterCount();
} catch (Exception e) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("MethodNameDeclaration problem for " + node
+" of class " + node.getClass().getCanonicalName()
+" => "+ node.getBeginLine()+"/"+node.getBeginColumn()
);
LOGGER.finest("MethodNameDeclaration problem for " + node + " of class "
+ node.getClass().getCanonicalName() + " => " + node.getBeginLine() + "/"
+ node.getBeginColumn());
}
//@TODO SRT restore the thrown exception - throw e;
// @TODO SRT restore the thrown exception - throw e;
return 0;
}
}
@Override
public String toString() {
//SRT return "Method " + node.getImage() + ", line " + node.getBeginLine() + ", params = " + ((ASTMethodDeclarator) node).getParameterCount();
// SRT return "Method " + node.getImage() + ", line " +
// node.getBeginLine() + ", params = " + ((ASTMethodDeclarator)
// node).getParameterCount();
return node.toString();
}
}
@@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.plsql.symboltable;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.plsql.ast.ASTExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
import net.sourceforge.pmd.lang.plsql.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
@@ -64,7 +63,6 @@ public class PLSQLNameOccurrence implements NameOccurrence {
return node instanceof ASTExpression && node.jjtGetNumChildren() == 3;
}
public boolean isOnLeftHandSide() {
// I detest this method with every atom of my being
Node primaryExpression;
@@ -73,18 +71,16 @@ public class PLSQLNameOccurrence implements NameOccurrence {
} else if (location.jjtGetParent().jjtGetParent() instanceof ASTPrimaryExpression) {
primaryExpression = location.jjtGetParent().jjtGetParent().jjtGetParent();
} else {
throw new RuntimeException("Found a NameOccurrence that didn't have an ASTPrimaryExpression as parent or grandparent. "
+ " Node = " + location.getClass().getCanonicalName()
+ ", Parent = " + location.jjtGetParent().getClass().getCanonicalName()
+ " and grandparent = " + location.jjtGetParent().jjtGetParent().getClass().getCanonicalName()
+ " @ line = " + location.getBeginLine() + ", column = " + location.getBeginColumn()
);
throw new RuntimeException(
"Found a NameOccurrence that didn't have an ASTPrimaryExpression as parent or grandparent. "
+ " Node = " + location.getClass().getCanonicalName() + ", Parent = "
+ location.jjtGetParent().getClass().getCanonicalName() + " and grandparent = "
+ location.jjtGetParent().jjtGetParent().getClass().getCanonicalName() + " @ line = "
+ location.getBeginLine() + ", column = " + location.getBeginColumn());
}
/*
if (isStandAlonePostfix(primaryExpression)) {
return true;
}
* if (isStandAlonePostfix(primaryExpression)) { return true; }
*/
if (primaryExpression.jjtGetNumChildren() <= 1) {
@@ -92,9 +88,8 @@ public class PLSQLNameOccurrence implements NameOccurrence {
}
/*
if (!(primaryExpression.jjtGetChild(1) instanceof ASTAssignmentOperator)) {
return false;
}
* if (!(primaryExpression.jjtGetChild(1) instanceof
* ASTAssignmentOperator)) { return false; }
*/
if (isPartOfQualifiedName() /* or is an array type */) {
@@ -102,90 +97,71 @@ public class PLSQLNameOccurrence implements NameOccurrence {
}
/*
if (isCompoundAssignment(primaryExpression)) {
return false;
}
* if (isCompoundAssignment(primaryExpression)) { return false; }
*/
return true;
}
/*
private boolean isCompoundAssignment(Node primaryExpression) {
return ((ASTAssignmentOperator) primaryExpression.jjtGetChild(1)).isCompound();
}
private boolean isStandAlonePostfix(Node primaryExpression) {
if (!(primaryExpression instanceof ASTPostfixExpression) || !(primaryExpression.jjtGetParent() instanceof ASTStatementExpression)) {
return false;
}
ASTPrimaryPrefix pf = (ASTPrimaryPrefix) ((ASTPrimaryExpression) primaryExpression.jjtGetChild(0)).jjtGetChild(0);
if (pf.usesThisModifier()) {
return true;
}
return thirdChildHasDottedName(primaryExpression);
}
* private boolean isCompoundAssignment(Node primaryExpression) { return
* ((ASTAssignmentOperator) primaryExpression.jjtGetChild(1)).isCompound();
* }
*
* private boolean isStandAlonePostfix(Node primaryExpression) { if
* (!(primaryExpression instanceof ASTPostfixExpression) ||
* !(primaryExpression.jjtGetParent() instanceof ASTStatementExpression)) {
* return false; }
*
* ASTPrimaryPrefix pf = (ASTPrimaryPrefix) ((ASTPrimaryExpression)
* primaryExpression.jjtGetChild(0)).jjtGetChild(0); if
* (pf.usesThisModifier()) { return true; }
*
* return thirdChildHasDottedName(primaryExpression); }
*
* private boolean thirdChildHasDottedName(Node primaryExpression) { Node
* thirdChild =
* primaryExpression.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0); return
* thirdChild instanceof ASTName && ((ASTName)
* thirdChild).getImage().indexOf('.') == -1; }
*/
private boolean thirdChildHasDottedName(Node primaryExpression) {
Node thirdChild = primaryExpression.jjtGetChild(0).jjtGetChild(0).jjtGetChild(0);
return thirdChild instanceof ASTName && ((ASTName) thirdChild).getImage().indexOf('.') == -1;
}
/**
* Assert it the occurrence is a self assignment such as:
* <code>
* Assert it the occurrence is a self assignment such as: <code>
* i += 3;
* </code>
*
* @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; }
*/
/**
@@ -203,17 +179,12 @@ 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
@@ -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)" : "");
}
}
@@ -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
@@ -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
@@ -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);
}
@@ -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 {
private void createTempFileOnDisk() throws IOException {
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);
}
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);
}
}
@@ -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());
}
}
@@ -23,15 +23,15 @@ public abstract class AbstractTokenizerTest {
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<TokenEntry> entries = tokens.getTokens();
assertEquals(expectedTokenCount,entries.size());
assertEquals(expectedTokenCount, entries.size());
}
}
@@ -8,26 +8,25 @@ import java.io.InputStream;
import org.apache.commons.io.IOUtils;
/**
* @deprecated Just use apache {@link IOUtils}
*/
@Deprecated
public final class StreamUtil {
private StreamUtil() {
// utility class
}
public static String toString(InputStream in) {
StringBuilder sb = new StringBuilder();
int c;
/**
* @deprecated use {@link IOUtils#toString(InputStream)} instead
*/
@Deprecated
public static String toString(InputStream stream) {
try {
while ((c = in.read()) != -1) {
sb.append((char) c);
}
return IOUtils.toString(stream);
} catch (IOException e) {
// ignored
} finally {
IOUtils.closeQuietly(in);
throw new RuntimeException(e);
}
return sb.toString();
}
}
+2
View File
@@ -93,3 +93,5 @@ and will be removed with the next release of PMD.
This Mark is useful for reporting the correct line count for each duplication. Previously only one line count was available.
As for some languages CPD can be instructed to ignore comments, the line count could be different in the different files
for the same duplication.
* pmd-test: The utility class `StreamUtil` is deprecated. Just use Apache Commons IO Utils instead.