You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sb...@apache.org on 2002/02/24 13:15:04 UTC
cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/importscrubber PackageStmt.java PrintListener.java Resources.java Resources_fr.java ScrubTask.java SourceFile.java StatementFormatModel.java WorkingCellRenderer.java
sbailliez 02/02/24 04:15:04
Modified: src/java/org/apache/maven/importscrubber PackageStmt.java
PrintListener.java Resources.java Resources_fr.java
ScrubTask.java SourceFile.java
StatementFormatModel.java WorkingCellRenderer.java
Log:
Apply Turbine coding style
Revision Changes Path
1.3 +90 -87 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/PackageStmt.java
Index: PackageStmt.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/PackageStmt.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PackageStmt.java 21 Feb 2002 14:00:16 -0000 1.2
+++ PackageStmt.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -59,94 +59,97 @@
*/
public class PackageStmt
{
- public static final String MARKER = "package ";
+ public static final String MARKER = "package ";
- private final String _stmt;
- private final boolean _isInDefaultPackage;
- private final String _myPkg;
-
- /**
- * Creates a new PackageStatement that's not in the default package.
- *
- * @param stmt
- */
- public PackageStmt(String stmt)
- {
- this(stmt, false);
- }
-
- /**
- * Creates a new PackageStatement that's in the default package.
- */
- public PackageStmt()
- {
- this(null, true);
- }
-
- private PackageStmt(String stmt, boolean inDefaultPackage)
- {
- _stmt = stmt;
- _isInDefaultPackage = inDefaultPackage;
- if (!_isInDefaultPackage) {
- int firstSpace = _stmt.indexOf(" ") + 1;
- int semiColon = _stmt.indexOf(";");
- _myPkg = _stmt.substring(firstSpace, semiColon);
- } else {
- _myPkg = null;
- }
- }
-
- public boolean isInSamePackageAs(ImportStatement importStmt)
- {
- if (_isInDefaultPackage)
- {
- return importStmt.isInDefaultPackage();
- }
-
- if (dotCount(_myPkg) != dotCount(importStmt.getPackage()))
- {
- // now check to see if this is an inner class
- int lastDot = importStmt.getPackage().lastIndexOf('.');
- if (lastDot == -1)
- {
- return false;
- }
- String uptoLastDot = importStmt.getPackage().substring(0, lastDot);
- if (!_myPkg.equals(uptoLastDot))
- {
- return false;
- }
- return Character.isUpperCase(importStmt.getPackage().substring(lastDot+1, lastDot+2).charAt(0));
- }
-
- return _myPkg.equals(importStmt.getPackage()) || importStmt.getPackage().startsWith(_myPkg);
- }
-
- private int dotCount(String pkg)
- {
- int total = 0;
- for (int i=0; i<pkg.length(); i++)
- {
- if (pkg.charAt(i) == '.')
- {
- total++;
- }
- }
- return total;
- }
-
- public StringBuffer getOutput()
- {
- StringBuffer buffer = new StringBuffer(64);
- if (_isInDefaultPackage)
- {
- return buffer;
- }
- buffer.append(_stmt);
- buffer.append(ImportScrubber.LINE_SEPARATOR);
- buffer.append(ImportScrubber.LINE_SEPARATOR);
- return buffer;
- }
+ private final String _stmt;
+ private final boolean _isInDefaultPackage;
+ private final String _myPkg;
+
+ /**
+ * Creates a new PackageStatement that's not in the default package.
+ *
+ * @param stmt
+ */
+ public PackageStmt(String stmt)
+ {
+ this(stmt, false);
+ }
+
+ /**
+ * Creates a new PackageStatement that's in the default package.
+ */
+ public PackageStmt()
+ {
+ this(null, true);
+ }
+
+ private PackageStmt(String stmt, boolean inDefaultPackage)
+ {
+ _stmt = stmt;
+ _isInDefaultPackage = inDefaultPackage;
+ if (!_isInDefaultPackage)
+ {
+ int firstSpace = _stmt.indexOf(" ") + 1;
+ int semiColon = _stmt.indexOf(";");
+ _myPkg = _stmt.substring(firstSpace, semiColon);
+ }
+ else
+ {
+ _myPkg = null;
+ }
+ }
+
+ public boolean isInSamePackageAs(ImportStatement importStmt)
+ {
+ if (_isInDefaultPackage)
+ {
+ return importStmt.isInDefaultPackage();
+ }
+
+ if (dotCount(_myPkg) != dotCount(importStmt.getPackage()))
+ {
+ // now check to see if this is an inner class
+ int lastDot = importStmt.getPackage().lastIndexOf('.');
+ if (lastDot == -1)
+ {
+ return false;
+ }
+ String uptoLastDot = importStmt.getPackage().substring(0, lastDot);
+ if (!_myPkg.equals(uptoLastDot))
+ {
+ return false;
+ }
+ return Character.isUpperCase(importStmt.getPackage().substring(lastDot + 1, lastDot + 2).charAt(0));
+ }
+
+ return _myPkg.equals(importStmt.getPackage()) || importStmt.getPackage().startsWith(_myPkg);
+ }
+
+ private int dotCount(String pkg)
+ {
+ int total = 0;
+ for (int i = 0; i < pkg.length(); i++)
+ {
+ if (pkg.charAt(i) == '.')
+ {
+ total++;
+ }
+ }
+ return total;
+ }
+
+ public StringBuffer getOutput()
+ {
+ StringBuffer buffer = new StringBuffer(64);
+ if (_isInDefaultPackage)
+ {
+ return buffer;
+ }
+ buffer.append(_stmt);
+ buffer.append(ImportScrubber.LINE_SEPARATOR);
+ buffer.append(ImportScrubber.LINE_SEPARATOR);
+ return buffer;
+ }
}
1.3 +7 -6 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/PrintListener.java
Index: PrintListener.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/PrintListener.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PrintListener.java 21 Feb 2002 14:00:16 -0000 1.2
+++ PrintListener.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -53,15 +53,16 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
+
public class PrintListener implements IReferenceFoundListener
{
- private int total = 0;
+ private int total = 0;
- public void referenceFound(String className) {
- System.out.println(total + ":" + className);
- total++;
- }
+ public void referenceFound(String className)
+ {
+ System.out.println(total + ":" + className);
+ total++;
+ }
}
1.3 +50 -50 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/Resources.java
Index: Resources.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/Resources.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Resources.java 21 Feb 2002 14:00:16 -0000 1.2
+++ Resources.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -58,57 +58,57 @@
public class Resources extends ListResourceBundle
{
- public static final String APP_NAME = "Importscrubber";
- public static final String FILE_BROWSER_TITLE = "Note: class files and source code files must be in the same directory";
- public static final String VERSION_ID = APP_NAME + " 1.3.9";
- public static final String BROWSE_LABEL = "Browse";
- public static final String GO_LABEL = "Go";
- public static final String FIND_FILES_LABEL = "Find files";
- public static final String ALL_DONE = "All done!";
- public static final String HELP_LABEL = "Help";
- public static final String FILE_LABEL = "File";
- public static final String ABOUT_LABEL = "About";
- public static final String RECURSE_LABEL = "Recurse";
- public static final String EXIT_LABEL = "Exit";
- public static final String HELP_MESSAGE = " " + APP_NAME + "\nThis is a utility to clean up import statements. To use it:\n1) Make sure your Java source code file and class file are in the same directory\n2) Select your source code file\n3) Click \"Find files\"\n4) Click \"Go\"\nImportscrubber will crank away for a few seconds and then pop up a box telling you it's done.\nTo process multiple files, just pick a directory and toggle the \"recursive\" checkbox\nQuestions? Comments? Contact tomcopeland@users.sourceforge.net";
- public static final String BREAK_EACH_PACKAGE = "Break for each package";
- public static final String BREAK_TOP_PACKAGE = "Break for top package";
- public static final String BREAK_NONE = "No breaks";
+ public static final String APP_NAME = "Importscrubber";
+ public static final String FILE_BROWSER_TITLE = "Note: class files and source code files must be in the same directory";
+ public static final String VERSION_ID = APP_NAME + " 1.3.9";
+ public static final String BROWSE_LABEL = "Browse";
+ public static final String GO_LABEL = "Go";
+ public static final String FIND_FILES_LABEL = "Find files";
+ public static final String ALL_DONE = "All done!";
+ public static final String HELP_LABEL = "Help";
+ public static final String FILE_LABEL = "File";
+ public static final String ABOUT_LABEL = "About";
+ public static final String RECURSE_LABEL = "Recurse";
+ public static final String EXIT_LABEL = "Exit";
+ public static final String HELP_MESSAGE = " " + APP_NAME + "\nThis is a utility to clean up import statements. To use it:\n1) Make sure your Java source code file and class file are in the same directory\n2) Select your source code file\n3) Click \"Find files\"\n4) Click \"Go\"\nImportscrubber will crank away for a few seconds and then pop up a box telling you it's done.\nTo process multiple files, just pick a directory and toggle the \"recursive\" checkbox\nQuestions? Comments? Contact tomcopeland@users.sourceforge.net";
+ public static final String BREAK_EACH_PACKAGE = "Break for each package";
+ public static final String BREAK_TOP_PACKAGE = "Break for top package";
+ public static final String BREAK_NONE = "No breaks";
- public static final String ERR_NOT_DIR = "File is not a directory!";
- public static final String ERR_UNABLE_TO_FINISH = "Unable to finish due to:";
- public static final String ERR_DIR_NOT_EXIST = "Directory does not exist!";
- public static final String ERR_CLASS_FILE_MUST_EXIST = "Class file must exist: ";
- public static final String ERR_MUST_NOT_BE_DIR = "Input file cannot be a directory: ";
- public static final String SORT_JAVA_LIBS_LABEL = "Sort std libs high";
+ public static final String ERR_NOT_DIR = "File is not a directory!";
+ public static final String ERR_UNABLE_TO_FINISH = "Unable to finish due to:";
+ public static final String ERR_DIR_NOT_EXIST = "Directory does not exist!";
+ public static final String ERR_CLASS_FILE_MUST_EXIST = "Class file must exist: ";
+ public static final String ERR_MUST_NOT_BE_DIR = "Input file cannot be a directory: ";
+ public static final String SORT_JAVA_LIBS_LABEL = "Sort std libs high";
- private static final Object[][] contents = {
- {FILE_BROWSER_TITLE, FILE_BROWSER_TITLE},
- {VERSION_ID, VERSION_ID},
- {BROWSE_LABEL, BROWSE_LABEL},
- {GO_LABEL, GO_LABEL},
- {HELP_LABEL, HELP_LABEL},
- {EXIT_LABEL, EXIT_LABEL},
- {ABOUT_LABEL, ABOUT_LABEL},
- {RECURSE_LABEL, RECURSE_LABEL},
- {FILE_LABEL, FILE_LABEL},
- {FIND_FILES_LABEL, FIND_FILES_LABEL},
- {ALL_DONE, ALL_DONE},
- {APP_NAME, APP_NAME},
- {HELP_MESSAGE, HELP_MESSAGE},
- {BREAK_EACH_PACKAGE, BREAK_EACH_PACKAGE},
- {BREAK_TOP_PACKAGE, BREAK_TOP_PACKAGE},
- {BREAK_NONE, BREAK_NONE},
- {ERR_NOT_DIR, ERR_NOT_DIR},
- {ERR_DIR_NOT_EXIST, ERR_DIR_NOT_EXIST},
- {ERR_CLASS_FILE_MUST_EXIST, ERR_CLASS_FILE_MUST_EXIST},
- {ERR_MUST_NOT_BE_DIR, ERR_MUST_NOT_BE_DIR},
- {ERR_UNABLE_TO_FINISH, ERR_UNABLE_TO_FINISH},
- {SORT_JAVA_LIBS_LABEL, SORT_JAVA_LIBS_LABEL}
- };
+ private static final Object[][] contents = {
+ {FILE_BROWSER_TITLE, FILE_BROWSER_TITLE},
+ {VERSION_ID, VERSION_ID},
+ {BROWSE_LABEL, BROWSE_LABEL},
+ {GO_LABEL, GO_LABEL},
+ {HELP_LABEL, HELP_LABEL},
+ {EXIT_LABEL, EXIT_LABEL},
+ {ABOUT_LABEL, ABOUT_LABEL},
+ {RECURSE_LABEL, RECURSE_LABEL},
+ {FILE_LABEL, FILE_LABEL},
+ {FIND_FILES_LABEL, FIND_FILES_LABEL},
+ {ALL_DONE, ALL_DONE},
+ {APP_NAME, APP_NAME},
+ {HELP_MESSAGE, HELP_MESSAGE},
+ {BREAK_EACH_PACKAGE, BREAK_EACH_PACKAGE},
+ {BREAK_TOP_PACKAGE, BREAK_TOP_PACKAGE},
+ {BREAK_NONE, BREAK_NONE},
+ {ERR_NOT_DIR, ERR_NOT_DIR},
+ {ERR_DIR_NOT_EXIST, ERR_DIR_NOT_EXIST},
+ {ERR_CLASS_FILE_MUST_EXIST, ERR_CLASS_FILE_MUST_EXIST},
+ {ERR_MUST_NOT_BE_DIR, ERR_MUST_NOT_BE_DIR},
+ {ERR_UNABLE_TO_FINISH, ERR_UNABLE_TO_FINISH},
+ {SORT_JAVA_LIBS_LABEL, SORT_JAVA_LIBS_LABEL}
+ };
- public Object[][] getContents()
- {
- return contents;
- }
+ public Object[][] getContents()
+ {
+ return contents;
+ }
}
1.3 +27 -27 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/Resources_fr.java
Index: Resources_fr.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/Resources_fr.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Resources_fr.java 21 Feb 2002 14:00:16 -0000 1.2
+++ Resources_fr.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -56,34 +56,34 @@
public class Resources_fr extends Resources
{
- private static final Object[][] contents = {
- {FILE_BROWSER_TITLE, "Note: les fichiers binaires (.class) et les fichiers sources doivent �tre dans le m�me r�pertoire"},
- {VERSION_ID, "Nettoyeur d'imports 1.3.9"},
- {BROWSE_LABEL, "Naviguer"},
- {GO_LABEL, "Aller"},
- {HELP_LABEL, "Aide"},
- {EXIT_LABEL, "Quitter"},
- {ABOUT_LABEL, "� propos"},
- {RECURSE_LABEL, "R�cursivement"},
- {FILE_LABEL, "Fichiers"},
- {FIND_FILES_LABEL, "Trouver les fichiers"},
- {ALL_DONE, "C'est fini!"},
- {APP_NAME, "Nettoyeur d'imports"},
- {HELP_MESSAGE, " Nettoyeur d'imports\nC'est un utilitaire pour nettoyer les imports. Pour l'utiliser:\n1) S'assurer que les fichiers sources et les fichiers binaires (.class) sont dans le m�me r�pertoire. \n2) S�lectionner le fichier contenant du source\n3) Cliquer sur \"Trouver les fichiers\"\n4) Cliquer sur \"Ex�cuter\"\n Nettoyeur d'imports va mouliner pour quelques secondes et montrer un dialogue pour dire que c'est termin�.\n Pour traiter plusieurs fichiers, simplement s�lectionner un r�pertoire et cocher le choix \"R�cursivement\".\nQuestions? Commentaires? Contacter tomcopeland@users.sourceforge.net"},
- {BREAK_EACH_PACKAGE, "Stopper pour chaque package"},
- {BREAK_TOP_PACKAGE, "Stopper pour les packages principaux"},
- {BREAK_NONE, "Pas d'arr�ts"},
- {ERR_NOT_DIR, "Le fichier n'est pas un r�pertoire!"},
- {ERR_DIR_NOT_EXIST, "Ce r�pertoire n'existe pas!"},
- {ERR_CLASS_FILE_MUST_EXIST, "Le fichier binaire (.class) doit exister:"},
- {ERR_MUST_NOT_BE_DIR, "Le fichier d'entr�e ne peut pas �tre un r�pertoire: "},
- {ERR_UNABLE_TO_FINISH, "Incapable de finir � cause de:"}
- };
+ private static final Object[][] contents = {
+ {FILE_BROWSER_TITLE, "Note: les fichiers binaires (.class) et les fichiers sources doivent �tre dans le m�me r�pertoire"},
+ {VERSION_ID, "Nettoyeur d'imports 1.3.9"},
+ {BROWSE_LABEL, "Naviguer"},
+ {GO_LABEL, "Aller"},
+ {HELP_LABEL, "Aide"},
+ {EXIT_LABEL, "Quitter"},
+ {ABOUT_LABEL, "� propos"},
+ {RECURSE_LABEL, "R�cursivement"},
+ {FILE_LABEL, "Fichiers"},
+ {FIND_FILES_LABEL, "Trouver les fichiers"},
+ {ALL_DONE, "C'est fini!"},
+ {APP_NAME, "Nettoyeur d'imports"},
+ {HELP_MESSAGE, " Nettoyeur d'imports\nC'est un utilitaire pour nettoyer les imports. Pour l'utiliser:\n1) S'assurer que les fichiers sources et les fichiers binaires (.class) sont dans le m�me r�pertoire. \n2) S�lectionner le fichier contenant du source\n3) Cliquer sur \"Trouver les fichiers\"\n4) Cliquer sur \"Ex�cuter\"\n Nettoyeur d'imports va mouliner pour quelques secondes et montrer un dialogue pour dire que c'est termin�.\n Pour traiter plusieurs fichiers, simplement s�lectionner un r�pertoire et cocher le choix \"R�cursivement\".\nQuestions? Commentaires? Contacter tomcopeland@users.sourceforge.net"},
+ {BREAK_EACH_PACKAGE, "Stopper pour chaque package"},
+ {BREAK_TOP_PACKAGE, "Stopper pour les packages principaux"},
+ {BREAK_NONE, "Pas d'arr�ts"},
+ {ERR_NOT_DIR, "Le fichier n'est pas un r�pertoire!"},
+ {ERR_DIR_NOT_EXIST, "Ce r�pertoire n'existe pas!"},
+ {ERR_CLASS_FILE_MUST_EXIST, "Le fichier binaire (.class) doit exister:"},
+ {ERR_MUST_NOT_BE_DIR, "Le fichier d'entr�e ne peut pas �tre un r�pertoire: "},
+ {ERR_UNABLE_TO_FINISH, "Incapable de finir � cause de:"}
+ };
- public Object[][] getContents()
- {
- return contents;
- }
+ public Object[][] getContents()
+ {
+ return contents;
+ }
}
1.3 +51 -49 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ScrubTask.java
Index: ScrubTask.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ScrubTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ScrubTask.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ScrubTask.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -57,6 +57,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ListIterator;
+
import org.apache.maven.importscrubber.format.IStatementFormat;
/**
@@ -64,53 +65,54 @@
*/
public class ScrubTask implements IReferenceFoundListener
{
- private SourceFile _sourceFile;
- private final FilePair _pair;
- private IStatementFormat _format;
-
- public ScrubTask(FilePair pair, IStatementFormat format) throws IOException {
- _pair = pair;
- _format = format;
- }
-
- public void run() throws IOException
- {
- _sourceFile = new SourceFile(_pair.getSourceFile());
- for (ListIterator iter = _pair.getClassFiles(); iter.hasNext();)
- {
- ClassParserWrapper.parse((File)iter.next(), this);
- }
- _sourceFile.save(_format);
- }
-
- public void referenceFound(String className)
- {
- _sourceFile.addImport(className);
- }
-
- public String toString()
- {
- return getSourcePath();
- }
-
- public String getSourcePath()
- {
- return _pair.getSourceFile().getAbsolutePath();
- }
-
- public static void main(String[] args)
- {
- FilePair pair = new FilePair(new File("d:\\importscrubber\\tmp\\NodeListener.java"), new File("d:\\importscrubber\\tmp\\NodeListener.class"));
- for (ListIterator iter = pair.getClassFiles(); iter.hasNext();)
- {
- try
- {
- ClassParserWrapper.parse((File)iter.next(), new PrintListener());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
+ private SourceFile _sourceFile;
+ private final FilePair _pair;
+ private IStatementFormat _format;
+
+ public ScrubTask(FilePair pair, IStatementFormat format) throws IOException
+ {
+ _pair = pair;
+ _format = format;
+ }
+
+ public void run() throws IOException
+ {
+ _sourceFile = new SourceFile(_pair.getSourceFile());
+ for (ListIterator iter = _pair.getClassFiles(); iter.hasNext();)
+ {
+ ClassParserWrapper.parse((File) iter.next(), this);
+ }
+ _sourceFile.save(_format);
+ }
+
+ public void referenceFound(String className)
+ {
+ _sourceFile.addImport(className);
+ }
+
+ public String toString()
+ {
+ return getSourcePath();
+ }
+
+ public String getSourcePath()
+ {
+ return _pair.getSourceFile().getAbsolutePath();
+ }
+
+ public static void main(String[] args)
+ {
+ FilePair pair = new FilePair(new File("d:\\importscrubber\\tmp\\NodeListener.java"), new File("d:\\importscrubber\\tmp\\NodeListener.class"));
+ for (ListIterator iter = pair.getClassFiles(); iter.hasNext();)
+ {
+ try
+ {
+ ClassParserWrapper.parse((File) iter.next(), new PrintListener());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
}
1.3 +117 -115 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/SourceFile.java
Index: SourceFile.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/SourceFile.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceFile.java 21 Feb 2002 14:00:16 -0000 1.2
+++ SourceFile.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -60,128 +60,130 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
+
import org.apache.maven.importscrubber.format.IStatementFormat;
/**
* Encapsulates operations on the Java source code file
- *
+ *
* TODO: refactor this into a parser class - this constructor is getting heinous
*/
public class SourceFile
{
- private File _file;
- private PackageStmt _package;
- private String _classBody;
- private ImportStatements _imports;
- private String _firstCommentHeader;
- private String _secondCommentHeader;
-
- public SourceFile(File file) throws IOException {
- _file = file;
- _imports = new ImportStatements();
-
- // read in the source
- FileReader reader = new FileReader(_file);
- BufferedReader buff = new BufferedReader(reader);
-
- StringBuffer classBodyBuffer = new StringBuffer((int)file.length());
- StringBuffer firstCommentHeaderBuffer = new StringBuffer();
- StringBuffer secondCommentHeaderBuffer = new StringBuffer();
-
- String currentLine = null;
- boolean passedFirstCommentHeader = false;
- boolean passedSecondCommentHeader = false;
-
- while ((currentLine = buff.readLine()) != null)
- {
- // discard imports
- if (currentLine.startsWith(ImportStatements.MARKER))
- {
- passedFirstCommentHeader = true;
- passedSecondCommentHeader = true;
- continue;
- }
+ private File _file;
+ private PackageStmt _package;
+ private String _classBody;
+ private ImportStatements _imports;
+ private String _firstCommentHeader;
+ private String _secondCommentHeader;
+
+ public SourceFile(File file) throws IOException
+ {
+ _file = file;
+ _imports = new ImportStatements();
+
+ // read in the source
+ FileReader reader = new FileReader(_file);
+ BufferedReader buff = new BufferedReader(reader);
+
+ StringBuffer classBodyBuffer = new StringBuffer((int) file.length());
+ StringBuffer firstCommentHeaderBuffer = new StringBuffer();
+ StringBuffer secondCommentHeaderBuffer = new StringBuffer();
+
+ String currentLine = null;
+ boolean passedFirstCommentHeader = false;
+ boolean passedSecondCommentHeader = false;
+
+ while ((currentLine = buff.readLine()) != null)
+ {
+ // discard imports
+ if (currentLine.startsWith(ImportStatements.MARKER))
+ {
+ passedFirstCommentHeader = true;
+ passedSecondCommentHeader = true;
+ continue;
+ }
+
+ // check for package stmt
+ if (currentLine.startsWith(PackageStmt.MARKER))
+ {
+ passedFirstCommentHeader = true;
+ _package = new PackageStmt(currentLine);
+ continue;
+ }
+
+ // TODO - what happens if there are no import statements and no package header?
+ // preserve comment headers, if any exist
+ if (!passedFirstCommentHeader)
+ {
+ firstCommentHeaderBuffer.append(currentLine);
+ firstCommentHeaderBuffer.append(ImportScrubber.LINE_SEPARATOR);
+ continue;
+ }
+
+ if (passedFirstCommentHeader && !passedSecondCommentHeader)
+ {
+ secondCommentHeaderBuffer.append(currentLine);
+ secondCommentHeaderBuffer.append(ImportScrubber.LINE_SEPARATOR);
+ continue;
+ }
- // check for package stmt
- if (currentLine.startsWith(PackageStmt.MARKER))
- {
- passedFirstCommentHeader = true;
- _package = new PackageStmt(currentLine);
- continue;
- }
-
- // TODO - what happens if there are no import statements and no package header?
- // preserve comment headers, if any exist
- if(!passedFirstCommentHeader)
- {
- firstCommentHeaderBuffer.append(currentLine);
- firstCommentHeaderBuffer.append(ImportScrubber.LINE_SEPARATOR);
- continue;
- }
-
- if(passedFirstCommentHeader && !passedSecondCommentHeader)
- {
- secondCommentHeaderBuffer.append(currentLine);
- secondCommentHeaderBuffer.append(ImportScrubber.LINE_SEPARATOR);
- continue;
- }
-
- // everything else is part of the class body
- passedSecondCommentHeader = true;
- classBodyBuffer.append(currentLine);
- classBodyBuffer.append(ImportScrubber.LINE_SEPARATOR);
- }
-
- if (_package == null)
- {
- _package = new PackageStmt();
- }
-
- buff.close();
- reader.close();
- if (ImportScrubber.DEBUG) {
- System.out.println("Done parsing source code file " + file.getAbsolutePath());
- }
-
- _classBody = classBodyBuffer.toString();
- _firstCommentHeader = firstCommentHeaderBuffer.toString();
- _secondCommentHeader = secondCommentHeaderBuffer.toString();
- }
-
- public void addImport(String className)
- {
- _imports.add(className);
- }
-
- public void save(IStatementFormat format) throws IOException {
- _imports.removeUnreferenced(_classBody);
- _imports.removeLocalToPackage(_package);
-
- // push everything together
- StringBuffer finishedSource = new StringBuffer((int)(_classBody.length() * 1.1));
- finishedSource.append(_firstCommentHeader);
- finishedSource.append(_package.getOutput());
-
- finishedSource.append(removeMultipleBlankLines(_secondCommentHeader));
- finishedSource.append(_imports.getOutput(format));
-
- _classBody = ImportScrubber.LINE_SEPARATOR + removeMultipleBlankLines(_classBody);
- finishedSource.append(_classBody);
-
- // write it to disk
- BufferedWriter writer = new BufferedWriter(new FileWriter(_file));
- writer.write(finishedSource.toString());
- writer.close();
- }
-
- private String removeMultipleBlankLines(String in)
- {
- while (in.startsWith(ImportScrubber.LINE_SEPARATOR))
- {
- in = in.substring(ImportScrubber.LINE_SEPARATOR.length());
- }
- return in;
- }
+ // everything else is part of the class body
+ passedSecondCommentHeader = true;
+ classBodyBuffer.append(currentLine);
+ classBodyBuffer.append(ImportScrubber.LINE_SEPARATOR);
+ }
+
+ if (_package == null)
+ {
+ _package = new PackageStmt();
+ }
+
+ buff.close();
+ reader.close();
+ if (ImportScrubber.DEBUG)
+ {
+ System.out.println("Done parsing source code file " + file.getAbsolutePath());
+ }
+
+ _classBody = classBodyBuffer.toString();
+ _firstCommentHeader = firstCommentHeaderBuffer.toString();
+ _secondCommentHeader = secondCommentHeaderBuffer.toString();
+ }
+
+ public void addImport(String className)
+ {
+ _imports.add(className);
+ }
+
+ public void save(IStatementFormat format) throws IOException
+ {
+ _imports.removeUnreferenced(_classBody);
+ _imports.removeLocalToPackage(_package);
+
+ // push everything together
+ StringBuffer finishedSource = new StringBuffer((int) (_classBody.length() * 1.1));
+ finishedSource.append(_firstCommentHeader);
+ finishedSource.append(_package.getOutput());
+
+ finishedSource.append(removeMultipleBlankLines(_secondCommentHeader));
+ finishedSource.append(_imports.getOutput(format));
+
+ _classBody = ImportScrubber.LINE_SEPARATOR + removeMultipleBlankLines(_classBody);
+ finishedSource.append(_classBody);
+
+ // write it to disk
+ BufferedWriter writer = new BufferedWriter(new FileWriter(_file));
+ writer.write(finishedSource.toString());
+ writer.close();
+ }
+
+ private String removeMultipleBlankLines(String in)
+ {
+ while (in.startsWith(ImportScrubber.LINE_SEPARATOR))
+ {
+ in = in.substring(ImportScrubber.LINE_SEPARATOR.length());
+ }
+ return in;
+ }
}
1.3 +35 -21 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/StatementFormatModel.java
Index: StatementFormatModel.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/StatementFormatModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatementFormatModel.java 21 Feb 2002 14:00:16 -0000 1.2
+++ StatementFormatModel.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -54,32 +54,46 @@
* <http://www.apache.org/>.
*/
-import java.util.List;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import javax.swing.event.ListDataListener;
+
import org.apache.maven.importscrubber.format.IStatementFormat;
import org.apache.maven.importscrubber.format.StatementFormatFactory;
public class StatementFormatModel implements ComboBoxModel
{
- private IStatementFormat _format;
+ private IStatementFormat _format;
+
+ public StatementFormatModel()
+ {
+ setSelectedItem(StatementFormatFactory.getInstance().createStatementFormat(StatementFormatFactory.DEFAULT));
+ }
+
+ public void setSelectedItem(Object anItem)
+ {
+ _format = (IStatementFormat) anItem;
+ }
+
+ public Object getSelectedItem()
+ {
+ return _format;
+ }
+
+ public int getSize()
+ {
+ return StatementFormatFactory.getInstance().getFormatsList().size();
+ }
+
+ public Object getElementAt(int index)
+ {
+ return StatementFormatFactory.getInstance().getFormatsList().get(index);
+ }
+
+ public void addListDataListener(ListDataListener l)
+ {
+ }
- public StatementFormatModel() {
- setSelectedItem(StatementFormatFactory.getInstance().createStatementFormat(StatementFormatFactory.DEFAULT));
- }
-
- public void setSelectedItem(Object anItem) {
- _format = (IStatementFormat)anItem;
- }
- public Object getSelectedItem() {
- return _format;
- }
- public int getSize() {
- return StatementFormatFactory.getInstance().getFormatsList().size();
- }
- public Object getElementAt(int index) {
- return StatementFormatFactory.getInstance().getFormatsList().get(index);
- }
- public void addListDataListener(ListDataListener l) {}
- public void removeListDataListener(ListDataListener l) {}
+ public void removeListDataListener(ListDataListener l)
+ {
+ }
}
1.3 +21 -21 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/WorkingCellRenderer.java
Index: WorkingCellRenderer.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/WorkingCellRenderer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WorkingCellRenderer.java 21 Feb 2002 14:00:16 -0000 1.2
+++ WorkingCellRenderer.java 24 Feb 2002 12:15:03 -0000 1.3
@@ -54,32 +54,32 @@
* <http://www.apache.org/>.
*/
-import java.awt.Component;
-import java.awt.Font;
-import javax.swing.BorderFactory;
-import javax.swing.DefaultListCellRenderer;
-import javax.swing.JList;
-import javax.swing.ListCellRenderer;
-import javax.swing.border.Border;
+import java.awt.*;
+import javax.swing.*;
/**
* Encapsulates the appearance of an item in the file list.
*/
-public class WorkingCellRenderer extends DefaultListCellRenderer implements ListCellRenderer {
+public class WorkingCellRenderer extends DefaultListCellRenderer implements ListCellRenderer
+{
- private final Font _bold = new Font("foo", Font.BOLD, 12);
- private final Font _normal = new Font("foo", Font.PLAIN, 12);
+ private final Font _bold = new Font("foo", Font.BOLD, 12);
+ private final Font _normal = new Font("foo", Font.PLAIN, 12);
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
- if (isSelected) {
- setBorder(BorderFactory.createRaisedBevelBorder());
- setFont(_bold);
- } else {
- setBorder(BorderFactory.createEmptyBorder());
- setFont(_normal);
- }
- return this;
- }
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
+ {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (isSelected)
+ {
+ setBorder(BorderFactory.createRaisedBevelBorder());
+ setFont(_bold);
+ }
+ else
+ {
+ setBorder(BorderFactory.createEmptyBorder());
+ setFont(_normal);
+ }
+ return this;
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>