tweaked to fix a line count bug

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@655 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-08-08 15:32:53 +00:00
parent 7268406131
commit eec851b06b
3 changed files with 21 additions and 13 deletions

View File

@ -108,7 +108,8 @@ public class CPD {
Iterator i = results.getOccurrences(tile);
TokenEntry firstToken = (TokenEntry)i.next();
TokenList tl = tokenSets.getTokenList(firstToken);
return tl.getSlice(firstToken.getBeginLine(), firstToken.getBeginLine()+ results.getTileLineCount(tile, tokenSets));
int endLine = firstToken.getBeginLine()+ results.getTileLineCount(tile, tokenSets)-1;
return tl.getSlice(firstToken.getBeginLine()-1, endLine);
} catch (Exception ex) {ex.printStackTrace(); }
return "";
}
@ -121,8 +122,8 @@ public class CPD {
try {
//cpd.add(findFilesRecursively("c:\\data\\pmd\\pmd-cpd\\src\\net\\sourceforge\\pmd\\cpd"));
//cpd.add(new File("c:\\data\\cougaar\\core\\src\\org\\cougaar\\core\\adaptivity\\PlayHelper.java"));
cpd.addRecursively("c:\\data\\cougaar\\core\\src\\org\\cougaar\\core\\adaptivity\\");
//cpd.add(findFilesRecursively("c:\\data\\cougaar\\core\\src\\org\\"));
//cpd.addRecursively("c:\\data\\cougaar\\core\\src\\org\\cougaar\\core\\adaptivity\\");
cpd.addRecursively("c:\\data\\cougaar\\core\\src\\org\\");
} catch (IOException ioe) {
ioe.printStackTrace();
return;

View File

@ -36,7 +36,7 @@ public class GUI implements CPDListener {
}
private class BrowseListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
JFileChooser fc = new JFileChooser(rootDirectoryField.getText());
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showDialog(frame, "Select");
if (fc.getSelectedFile() != null) {
@ -45,7 +45,9 @@ public class GUI implements CPDListener {
}
}
private JTextField rootDirectoryField= new JTextField("c:\\data\\pmd\\pmd\\src\\net\\sourceforge\\pmd\\cpd\\");
private JTextField rootDirectoryField= new JTextField("C:\\data\\datagrabber\\datagrabber\\src\\org\\cougaar\\mlm\\ui\\newtpfdd\\transit\\");
//private JTextField rootDirectoryField= new JTextField("c:\\data\\pmd\\pmd\\src\\net\\sourceforge\\pmd\\cpd\\");
//private JTextField rootDirectoryField = new JTextField(System.getProperty("user.home"));
//private JTextField rootDirectoryField= new JTextField("c:\\data\\cougaar\\core\\src");
private JTextField minimumLengthField= new JTextField("30");
@ -137,10 +139,14 @@ public class GUI implements CPDListener {
cpd.setListener(this);
cpd.setMinimumTileSize(Integer.parseInt(minimumLengthField.getText()));
addingTokensBar.setStringPainted(true);
if (recurseCheckbox.isSelected()) {
cpd.addRecursively(rootDirectoryField.getText());
if (rootDirectoryField.getText().endsWith(".java")) {
cpd.add(new File(rootDirectoryField.getText()));
} else {
cpd.addAllInDirectory(rootDirectoryField.getText());
if (recurseCheckbox.isSelected()) {
cpd.addRecursively(rootDirectoryField.getText());
} else {
cpd.addAllInDirectory(rootDirectoryField.getText());
}
}
cpd.go();
CPDRenderer renderer = new TextRenderer();

View File

@ -18,12 +18,13 @@ public class Results extends TileOccurrences {
}
public int getTileLineCount(Tile tile, TokenSets tokenSets) {
Iterator i = getOccurrences(tile);
TokenEntry firstToken = (TokenEntry)i.next();
TokenEntry firstToken = (TokenEntry)((List)tileToOccurrenceMap.get(tile)).get(0);
TokenList tl = tokenSets.getTokenList(firstToken);
int lastTokenIndex = firstToken.getIndex() + tile.getTokenCount();
TokenEntry lastToken = (TokenEntry)tl.get(lastTokenIndex);
return (lastToken.getBeginLine()+1) - firstToken.getBeginLine();
TokenEntry lastToken = (TokenEntry)tl.get(firstToken.getIndex() + tile.getTokenCount());
// note we subtract 1 here... if we didn't, then this:
// line20: foo =bar;
// line21: baz = bif;
return lastToken.getBeginLine() - firstToken.getBeginLine() - 1;
}
private void removeDupesOf(Tile tile) {