com.spidasoftware.EclipseFormatter
Class Formatter

java.lang.Object
  extended by com.spidasoftware.EclipseFormatter.Formatter

public class Formatter
extends Object

Extracted various classes from Eclipse and Groovy-Eclipse to create an automatic java and groovy source code formatter. This class, containing a main method, will take in command-line arguments and call on the JavaFormat and GroovyFormat classes to automatically format java and groovy files.

Author:
Nicholas Joodi

Constructor Summary
Formatter()
           
 
Method Summary
static String createBackupFile(String fileName, String before)
          A two-argument method that will take a fileName string and the contents of that file (before formatted), and return a backup file.
static String formatOne(File file, org.apache.commons.cli.CommandLine cmd)
          A three-argument method that will take a filename string, the contents of that file as a string (before formatted), and the Command-Line arguments and format the respective file.
static String formatUsingExtension(File file, org.apache.commons.cli.CommandLine cmd)
          Format by using the extension of the file.
static String formatUsingHashBang(File file, org.apache.commons.cli.CommandLine cmd)
          Format by using the first line of the file.
static org.apache.commons.cli.CommandLine getOptions(String[] args, org.apache.commons.cli.Options options)
          A no-argument method that will return the command-line arguments as a CommandLine object.
static boolean groovyFormatting(org.apache.commons.cli.CommandLine cmd)
          If java option was set, return false
static void instantiateLogger()
          A no-argument method used to intantiate the logger.
static boolean javaFormatting(org.apache.commons.cli.CommandLine cmd)
          If groovy option was set, return false
static void main(String[] args)
          This method will pass the command line arguments to the runFormatter method.
static boolean optionToFormat(org.apache.commons.cli.CommandLine cmd, String[] args)
          A two argument method that takes a Command-Line object, as well as the string [], args, and initiates the formatting.
static String readInFile(String fileName)
          A one-argument method that will take a filename and return a string containing the contents of that file.
static void runFormatter(String[] args)
          This method will perform the main logic of the program
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Formatter

public Formatter()
Method Detail

main

public static void main(String[] args)
This method will pass the command line arguments to the runFormatter method.

Parameters:
args - the command-line arguments

runFormatter

public static void runFormatter(String[] args)
This method will perform the main logic of the program

Parameters:
args - the command-line arguments

optionToFormat

public static boolean optionToFormat(org.apache.commons.cli.CommandLine cmd,
                                     String[] args)
A two argument method that takes a Command-Line object, as well as the string [], args, and initiates the formatting.

Parameters:
cmd - the list of command-line arguments.
args - the command-line arguments.
Returns:
boolean indicating if the file/directory exists

formatOne

public static String formatOne(File file,
                               org.apache.commons.cli.CommandLine cmd)
A three-argument method that will take a filename string, the contents of that file as a string (before formatted), and the Command-Line arguments and format the respective file.

Parameters:
file - File that will be formatted
cmd - the list of command-line arguments.

readInFile

public static String readInFile(String fileName)
A one-argument method that will take a filename and return a string containing the contents of that file.

Parameters:
fileName - The name of that file.
Returns:
a String that contans the contents of that file.

createBackupFile

public static String createBackupFile(String fileName,
                                      String before)
A two-argument method that will take a fileName string and the contents of that file (before formatted), and return a backup file.

Parameters:
fileName - string representing the name of the file.
before - string containing the contents of that file
Returns:
a String that represents the name of the backup file created, null otherwise.

getOptions

public static org.apache.commons.cli.CommandLine getOptions(String[] args,
                                                            org.apache.commons.cli.Options options)
A no-argument method that will return the command-line arguments as a CommandLine object.

Parameters:
args - The command line arguments.
options - The options that this class can identify.
Returns:
the CommandLine object holding the command line arguments.

instantiateLogger

public static void instantiateLogger()
A no-argument method used to intantiate the logger.


formatUsingExtension

public static String formatUsingExtension(File file,
                                          org.apache.commons.cli.CommandLine cmd)
Format by using the extension of the file.

Parameters:
file - File that will be formatted
cmd - The list of command line arguments
Returns:
a String that represents the name of the backup file created, null otherwise.

formatUsingHashBang

public static String formatUsingHashBang(File file,
                                         org.apache.commons.cli.CommandLine cmd)
Format by using the first line of the file.

Parameters:
file - File that will be formatted
cmd - the list of command line arguments.
Returns:
a String that represents the name of the backup file created, null otherwise.

javaFormatting

public static boolean javaFormatting(org.apache.commons.cli.CommandLine cmd)
If groovy option was set, return false

Parameters:
cmd - which contains the options passed in
Returns:
a boolean that is false if a groovy option was passed

groovyFormatting

public static boolean groovyFormatting(org.apache.commons.cli.CommandLine cmd)
If java option was set, return false

Parameters:
cmd - which contains the options passed in
Returns:
a boolean that is false if a java option was passed


Copyright © 2013. All rights reserved.