forked from phoedos/pmd
split renderers into separate classes
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@639 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -143,17 +143,8 @@ public class CPD {
|
||||
cpd.setMinimumTileSize(26);
|
||||
cpd.go();
|
||||
System.out.println((System.currentTimeMillis() - start));
|
||||
Results results = cpd.getResults();
|
||||
for (Iterator i = results.getTiles(); i.hasNext();) {
|
||||
Tile tile = (Tile)i.next();
|
||||
System.out.println("=============================================================");
|
||||
System.out.println("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
|
||||
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
|
||||
TokenEntry tok = (TokenEntry)j.next();
|
||||
System.out.println(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
|
||||
}
|
||||
System.out.println(cpd.getImage(tile));
|
||||
}
|
||||
CPDRenderer renderer = new TextRenderer();
|
||||
System.out.println(renderer.render(cpd));
|
||||
}
|
||||
|
||||
}
|
||||
|
10
pmd/src/net/sourceforge/pmd/cpd/CPDRenderer.java
Normal file
10
pmd/src/net/sourceforge/pmd/cpd/CPDRenderer.java
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Aug 7, 2002
|
||||
* Time: 9:44:21 AM
|
||||
*/
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
public interface CPDRenderer {
|
||||
public String render(CPD cpd);
|
||||
}
|
@ -43,9 +43,8 @@ public class GUI implements CPDListener {
|
||||
|
||||
private JTextField expandingTileField = new JTextField(50);
|
||||
private JCheckBox recurseCheckbox = new JCheckBox("Recurse?", true);
|
||||
private JFrame f;
|
||||
public GUI() {
|
||||
f = new JFrame("PMD Cut and Paste Detector");
|
||||
JFrame f = new JFrame("PMD Cut and Paste Detector");
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputPanel.setLayout(new GridLayout(4,2));
|
||||
inputPanel.add(new JLabel("Enter a root src directory"));
|
||||
@ -98,17 +97,8 @@ public class GUI implements CPDListener {
|
||||
cpd.addAllInDirectory(rootDirectoryField.getText());
|
||||
}
|
||||
cpd.go();
|
||||
Results results = cpd.getResults();
|
||||
for (Iterator i = results.getTiles(); i.hasNext();) {
|
||||
Tile tile = (Tile)i.next();
|
||||
System.out.println("=============================================================");
|
||||
System.out.println("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
|
||||
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
|
||||
TokenEntry tok = (TokenEntry)j.next();
|
||||
System.out.println(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
|
||||
}
|
||||
System.out.println(cpd.getImage(tile));
|
||||
}
|
||||
CPDRenderer renderer = new TextRenderer();
|
||||
System.out.println(renderer.render(cpd));
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
30
pmd/src/net/sourceforge/pmd/cpd/TextRenderer.java
Normal file
30
pmd/src/net/sourceforge/pmd/cpd/TextRenderer.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Aug 7, 2002
|
||||
* Time: 9:44:40 AM
|
||||
*/
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class TextRenderer implements CPDRenderer {
|
||||
public String render(CPD cpd) {
|
||||
Results results = cpd.getResults();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Iterator i = results.getTiles(); i.hasNext();) {
|
||||
Tile tile = (Tile)i.next();
|
||||
sb.append("=============================================================");
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
sb.append("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
|
||||
TokenEntry tok = (TokenEntry)j.next();
|
||||
sb.append(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
}
|
||||
sb.append(cpd.getImage(tile));
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user