org.prorefactor.refactor
Class FileStuff

java.lang.Object
  extended by org.prorefactor.refactor.FileStuff

public class FileStuff
extends java.lang.Object

Various file and directory related utilities for the refactoring toolkit.


Field Summary
static java.lang.String LINESEP
          OS specific text file line seperator - '\n' on unix, "\r\n" on Windows
 
Constructor Summary
FileStuff()
           
 
Method Summary
static int countLines(java.io.File file)
          Count lines in a file
static java.io.File findFile(java.lang.String filename)
          Find a file (or directory) on the propath
static java.io.File findFileForClassName(java.lang.String className)
          Find a class file on Proparse's propath, from the "package.classname".
static java.lang.String fullpath(java.io.File file)
          Return the full path name.
static java.lang.String insertBeforeExtension(java.lang.String origName, java.lang.String insert)
          Return a new file name, with extra text before the existing extension.
static java.lang.String prepareTarget(java.lang.String outputDir, java.lang.String sourceFilename)
          Prepare a target path, based on a specified target path name plus an original sourcefile name.
static java.util.ArrayList searchFile(java.io.File file, java.lang.String searchString, java.lang.String messageString)
          Search a file for a given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINESEP

public static final java.lang.String LINESEP
OS specific text file line seperator - '\n' on unix, "\r\n" on Windows

Constructor Detail

FileStuff

public FileStuff()
Method Detail

countLines

public static int countLines(java.io.File file)
                      throws java.io.IOException
Count lines in a file

Throws:
java.io.IOException

findFile

public static java.io.File findFile(java.lang.String filename)
Find a file (or directory) on the propath

Returns:
null if not found

findFileForClassName

public static java.io.File findFileForClassName(java.lang.String className)
Find a class file on Proparse's propath, from the "package.classname".

Returns:
null if not found.

fullpath

public static java.lang.String fullpath(java.io.File file)
Return the full path name. Just takes care of try/catch around getCanonicalPath().


insertBeforeExtension

public static java.lang.String insertBeforeExtension(java.lang.String origName,
                                                     java.lang.String insert)
Return a new file name, with extra text before the existing extension. Ex: FileStuff.insertBeforeExtension("include.i", ".orig") returns "include.orig.i"

Parameters:
origName - The original filename
insert - The text to insert
Returns:
The modified filename

prepareTarget

public static java.lang.String prepareTarget(java.lang.String outputDir,
                                             java.lang.String sourceFilename)
Prepare a target path, based on a specified target path name plus an original sourcefile name.

Parameters:
outputDir - The name of the top of the output directory structure.
sourceFilename - The name of the original sourcefile, used as basis for output filename.
Returns:
The filename that you should use for writing target source to. We build a target directory structure which resembles the source code *absolute* path. Why? Because we may have any number of absolute paths in our PROPATH: "/u1/my/application,/u2/third/party/library,etc" It is easiest and most consistent to just use absolute path for all entries, rather than try to use relative path for some and be forced to use absolute path for others. We even include drive letters, because it is possible for developers to use a PROPATH for version/variant management: "x:/myapp,y:/myapp" To avoid really long target directory names, use an output top directory that is near root, ex: "/temp/out". We replace ':' (Windows drive letter) with '_', so that we are always working with a valid name.

searchFile

public static java.util.ArrayList searchFile(java.io.File file,
                                             java.lang.String searchString,
                                             java.lang.String messageString)
                                      throws java.io.IOException
Search a file for a given string. Search is done line by line; searches across line breaks not supported.

Parameters:
file - The file to search
searchString - The string to search for
messageString - The text to be placed in each Message object created
Returns:
ArrayList of org.prorefactor.refactor.message.Message objects.
Throws:
java.io.IOException


Copyright © 2008 Joanju Software. All Rights Reserved.