Some code enhancements:

PMD.java. splited the imports to avoid check style message: Using the '.*' form of import should be avoided - net.sourceforge.pmd.lang.*.
AbstractNodeInfo now has all the overrides
String utils now has the EMPTY_STRING variable declared as private and a getter method to access it. Refactored isSame to avoid using     @SuppressWarnings("PMD.CompareObjectsWithEquals")
DFAPanel uses the getter for empty strings. Also deleted comments that seems to be old code and addd the override to valueChanged
In DBMSMetadadataTest we were passing a parameter to  System.out.format but it hasn't the place holder for the parameter
This commit is contained in:
Dionisio
2016-04-30 23:21:43 +02:00
parent cead3d3a9b
commit 5be8148e99
5 changed files with 108 additions and 64 deletions

View File

@ -27,7 +27,13 @@ import net.sourceforge.pmd.benchmark.Benchmarker;
import net.sourceforge.pmd.benchmark.TextReport;
import net.sourceforge.pmd.cli.PMDCommandLineInterface;
import net.sourceforge.pmd.cli.PMDParameters;
import net.sourceforge.pmd.lang.*;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageFilenameFilter;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.processor.MonoThreadProcessor;
import net.sourceforge.pmd.processor.MultiThreadProcessor;
import net.sourceforge.pmd.renderers.Renderer;

View File

@ -30,6 +30,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getSystemId() {
throw createUnsupportedOperationException("Source.getSystemId()");
}
@ -37,6 +38,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public void setSystemId(String systemId) {
throw createUnsupportedOperationException("Source.setSystemId(String)");
}
@ -44,6 +46,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getStringValue() {
throw createUnsupportedOperationException("ValueRepresentation.getStringValue()");
}
@ -51,6 +54,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public CharSequence getStringValueCS() {
throw createUnsupportedOperationException("ValueRepresentation.getStringValueCS()");
}
@ -58,6 +62,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public SequenceIterator getTypedValue() throws XPathException {
throw createUnsupportedOperationException("Item.getTypedValue()");
}
@ -65,6 +70,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public Object getUnderlyingNode() {
throw createUnsupportedOperationException("VirtualNode.getUnderlyingNode()");
}
@ -72,6 +78,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getSiblingPosition() {
throw createUnsupportedOperationException("SiblingCountingNode.getSiblingPosition()");
}
@ -79,6 +86,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public Value atomize() throws XPathException {
throw createUnsupportedOperationException("NodeInfo.atomize()");
}
@ -86,6 +94,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int compareOrder(NodeInfo other) {
throw createUnsupportedOperationException("NodeInfo.compareOrder(NodeInfo)");
}
@ -93,6 +102,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public void copy(Receiver receiver, int whichNamespaces, boolean copyAnnotations, int locationId)
throws XPathException {
throw createUnsupportedOperationException("ValueRepresentation.copy(Receiver, int, boolean, int)");
@ -118,6 +128,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public void generateId(FastStringBuffer buffer) {
throw createUnsupportedOperationException("NodeInfo.generateId(FastStringBuffer)");
}
@ -125,6 +136,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getAttributeValue(int fingerprint) {
throw createUnsupportedOperationException("NodeInfo.getAttributeValue(int)");
}
@ -132,6 +144,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getBaseURI() {
throw createUnsupportedOperationException("NodeInfo.getBaseURI()");
}
@ -139,6 +152,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getColumnNumber() {
throw createUnsupportedOperationException("NodeInfo.getColumnNumber()");
}
@ -146,6 +160,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public Configuration getConfiguration() {
throw createUnsupportedOperationException("NodeInfo.getConfiguration()");
}
@ -153,6 +168,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int[] getDeclaredNamespaces(int[] buffer) {
throw createUnsupportedOperationException("NodeInfo.getDeclaredNamespaces(int[])");
}
@ -160,6 +176,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
throw createUnsupportedOperationException("NodeInfo.getDisplayName()");
}
@ -169,6 +186,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
*
* {@inheritDoc}
*/
@Override
public int getDocumentNumber() {
return 0;
}
@ -176,6 +194,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public DocumentInfo getDocumentRoot() {
throw createUnsupportedOperationException("NodeInfo.getDocumentRoot()");
}
@ -183,6 +202,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getFingerprint() {
throw createUnsupportedOperationException("NodeInfo.getFingerprint()");
}
@ -190,6 +210,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getLineNumber() {
throw createUnsupportedOperationException("NodeInfo.getLineNumber()");
}
@ -197,6 +218,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getLocalPart() {
throw createUnsupportedOperationException("NodeInfo.getLocalPart()");
}
@ -204,6 +226,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getNameCode() {
throw createUnsupportedOperationException("NodeInfo.getNameCode()");
}
@ -211,6 +234,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public NamePool getNamePool() {
throw createUnsupportedOperationException("NodeInfo.getNamePool()");
}
@ -218,6 +242,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getNodeKind() {
throw createUnsupportedOperationException("NodeInfo.getNodeKind()");
}
@ -225,6 +250,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public NodeInfo getParent() {
throw createUnsupportedOperationException("NodeInfo.getParent()");
}
@ -232,6 +258,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getPrefix() {
throw createUnsupportedOperationException("NodeInfo.getPrefix()");
}
@ -239,6 +266,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public NodeInfo getRoot() {
throw createUnsupportedOperationException("NodeInfo.getRoot()");
}
@ -246,6 +274,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public int getTypeAnnotation() {
throw createUnsupportedOperationException("NodeInfo.getTypeAnnotation()");
}
@ -253,6 +282,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public String getURI() {
throw createUnsupportedOperationException("NodeInfo.getURI()");
}
@ -260,6 +290,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public boolean hasChildNodes() {
throw createUnsupportedOperationException("NodeInfo.hasChildNodes()");
}
@ -267,6 +298,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public boolean isId() {
throw createUnsupportedOperationException("NodeInfo.isId()");
}
@ -274,6 +306,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public boolean isIdref() {
throw createUnsupportedOperationException("NodeInfo.isIdref()");
}
@ -281,6 +314,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public boolean isNilled() {
throw createUnsupportedOperationException("NodeInfo.isNilled()");
}
@ -291,6 +325,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
*
* {@inheritDoc}
*/
@Override
public boolean isSameNodeInfo(NodeInfo other) {
return this.equals(other);
}
@ -298,6 +333,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
/**
* {@inheritDoc}
*/
@Override
public AxisIterator iterateAxis(byte axisNumber) {
throw createUnsupportedOperationException("NodeInfo.iterateAxis(byte) for axis '" + Axis.axisName[axisNumber]
+ "'");
@ -310,6 +346,7 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
*
* {@inheritDoc}
*/
@Override
public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
AxisIterator axisIterator = iterateAxis(axisNumber);
if (nodeTest != null) {

View File

@ -15,9 +15,8 @@ import java.util.List;
*/
public final class StringUtil {
public static final String[] EMPTY_STRINGS = new String[0];
private static final boolean SUPPORTS_UTF8 = System.getProperty("net.sourceforge.pmd.supportUTF8", "no").equals(
"yes");
private static final String[] EMPTY_STRINGS = new String[0];
private static final boolean SUPPORTS_UTF8 = "yes".equals(System.getProperty("net.sourceforge.pmd.supportUTF8", "no"));
private StringUtil() {
}
@ -509,9 +508,8 @@ public final class StringUtil {
* @return <code>true</code> if the Strings are the same, <code>false</code>
* otherwise.
*/
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public static boolean isSame(String s1, String s2, boolean trim, boolean ignoreCase, boolean standardizeWhitespace) {
if (s1 == s2) {
if (s1 == null && s2 == null) {
return true;
} else if (s1 == null || s2 == null) {
return false;
@ -554,4 +552,12 @@ public final class StringUtil {
return sb.toString();
}
/**
* Returns an empty array of string
* @return String
*/
public static String[] getEmptyStrings() {
return EMPTY_STRINGS;
}
}

View File

@ -76,9 +76,9 @@ public class DFAPanel extends JComponent implements ListSelectionListener {
private String[] deriveAccessLabels(List<DataFlowNode> flow) {
if (flow == null || flow.isEmpty()) {
return StringUtil.EMPTY_STRINGS;
}
if (flow == null || flow.isEmpty()) {
return StringUtil.getEmptyStrings();
}
String[] labels = new String[flow.size()];
@ -200,50 +200,44 @@ public class DFAPanel extends JComponent implements ListSelectionListener {
}
}
private void drawMyLine(int index1, int index2, Graphics g) {
int y1 = this.computeDrawPos(index1);
int y2 = this.computeDrawPos(index2);
private void drawMyLine(int index1, int index2, Graphics g) {
int y1 = this.computeDrawPos(index1);
int y2 = this.computeDrawPos(index2);
//int arrow = 6;
if (index1 < index2) {
if (index2 - index1 == 1) {
x += NODE_RADIUS;
g.drawLine(x, y1 + NODE_DIAMETER, x, y2);
drawArrow(g, x, y2, SwingConstants.SOUTH);
x -= NODE_RADIUS;
} else if (index2 - index1 > 1) {
y1 = y1 + NODE_RADIUS;
y2 = y2 + NODE_RADIUS;
int n = (index2 - index1 - 2) * 10 + 10;
g.drawLine(x, y1, x - n, y1);
g.drawLine(x - n, y1, x - n, y2);
g.drawLine(x - n, y2, x, y2);
drawArrow(g, x, y2, SwingConstants.EAST);
}
if (index1 < index2) {
if (index2 - index1 == 1) {
x += NODE_RADIUS;
g.drawLine(x, y1 + NODE_DIAMETER, x, y2);
// g.fillRect(x - arrow, y2 - arrow, arrow * 2, arrow * 2);
drawArrow(g, x, y2, SwingConstants.SOUTH);
x -= NODE_RADIUS;
} else if (index2 - index1 > 1) {
y1 = y1 + NODE_RADIUS;
y2 = y2 + NODE_RADIUS;
int n = (index2 - index1 - 2) * 10 + 10;
g.drawLine(x, y1, x - n, y1);
g.drawLine(x - n, y1, x - n, y2);
g.drawLine(x - n, y2, x, y2);
// g.fillRect(x - arrow, y2 - arrow, arrow * 2, arrow * 2);
drawArrow(g, x, y2, SwingConstants.EAST);
}
} else {
if (index1 - index2 > 1) {
y1 = y1 + NODE_RADIUS;
y2 = y2 + NODE_RADIUS;
x = x + NODE_DIAMETER;
int n = (index1 - index2 - 2) * 10 + 10;
g.drawLine(x, y1, x + n, y1);
g.drawLine(x + n, y1, x + n, y2);
g.drawLine(x + n, y2, x, y2);
// g.fillRect(x - arrow, y2 - arrow, arrow * 2, arrow * 2);
drawArrow(g, x, y2, SwingConstants.WEST);
x = x - NODE_DIAMETER;
} else if (index1 - index2 == 1) {
y2 = y2 + NODE_DIAMETER;
g.drawLine(x + NODE_RADIUS, y2, x + NODE_RADIUS, y1);
// g.fillRect(x + NODE_RADIUS - arrow, y2 - arrow, arrow * 2, arrow * 2);
drawArrow(g, x + NODE_RADIUS, y2, SwingConstants.NORTH);
}
}
}
} else {
if (index1 - index2 > 1) {
y1 = y1 + NODE_RADIUS;
y2 = y2 + NODE_RADIUS;
x = x + NODE_DIAMETER;
int n = (index1 - index2 - 2) * 10 + 10;
g.drawLine(x, y1, x + n, y1);
g.drawLine(x + n, y1, x + n, y2);
g.drawLine(x + n, y2, x, y2);
drawArrow(g, x, y2, SwingConstants.WEST);
x = x - NODE_DIAMETER;
} else if (index1 - index2 == 1) {
y2 = y2 + NODE_DIAMETER;
g.drawLine(x + NODE_RADIUS, y2, x + NODE_RADIUS, y1);
drawArrow(g, x + NODE_RADIUS, y2, SwingConstants.NORTH);
}
}
}
}
private static class ElementWrapper {
@ -291,19 +285,20 @@ public class DFAPanel extends JComponent implements ListSelectionListener {
add(scrollPane, BorderLayout.CENTER);
}
@Override
public void valueChanged(ListSelectionEvent event) {
ElementWrapper wrapper = null;
if (nodes.size() == 1) {
wrapper = (ElementWrapper) nodes.get(0);
} else if (nodes.isEmpty()) {
return;
} else if (nodeList.getSelectedValue() == null) {
wrapper = (ElementWrapper) nodes.get(0);
} else {
wrapper = (ElementWrapper) nodeList.getSelectedValue();
}
dfaCanvas.setMethod(wrapper.getNode());
dfaCanvas.repaint();
ElementWrapper wrapper = null;
if (nodes.size() == 1) {
wrapper = (ElementWrapper) nodes.get(0);
} else if (nodes.isEmpty()) {
return;
} else if (nodeList.getSelectedValue() == null) {
wrapper = (ElementWrapper) nodes.get(0);
} else {
wrapper = (ElementWrapper) nodeList.getSelectedValue();
}
dfaCanvas.setMethod(wrapper.getNode());
dfaCanvas.repaint();
}
public void resetTo(List<DFAGraphMethod> newNodes, LineGetter lines) {

View File

@ -107,7 +107,7 @@ public class DBMSMetadataTest {
} catch (SQLException ex) {
Logger.getLogger(DBMSMetadataTest.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.format("...\n]\n", description);
System.out.format("...\n]\n");
}
/**