gnu.java
Class JSBeautifier

java.lang.Object
  extended by gnu.java.JSBeautifier

public class JSBeautifier
extends java.lang.Object

JSBeautifier (formerly called Beautifier) is a filter for automatic indentation of Java source code. Every line of the original source file should be sent one after the other as a String to the beautify(lineString) method, which returns an automatically indented version of the line it recieves, according to the data in the past lines recieved. Every time a JSBeautifier instance is to be reused for a new file, a call must first be made to its init() method. JSBeautifier can be used either as an object in a program or from the command line. When used from the command line, JSBeautifier can be used both as a filter from standard-input to standard-output, i.e.: [/home/tald]$ java jstyle.JSBeautifier [flags] < sourceFile.java > resultingFile.java or as a filter to specifically named files, i.e: [/home/tald]$ java jstyle.JSBeautifier [flags] File1.java File2.java File3.java When Giving JSBeautifier the name of a specific source file, output will be created to another file with the same name, BUT with an added suffix of ".js" Thus, a file named "File1.java" will be renamed to "File1.java.js" Flag options: -t (for tabs) -s# (for '#' spaces per indent, i.e.: -s2) -ib (add extra indentation to brackets) -fs (flush (i.e. don't add extra indentation to) switch statements - ala Java Code Convention). -h (for help message) The current default setup is 4 spaces per indent, 1 space before every comment line Bug Reporting: 1. If anyone corrects a found bug, please send me an example source-file that creates the bug, and the corrected version of this file, so that I can post it. 2. Otherwise, please send me an example source-file cerating the bug, and the bug description, and i will do my best to correct the bug as soon as possible. Acknowledgments: - Thanks to Jim Watson for addition of the Help option !!!

Version:
1.1.1, October 10th, 1998
Author:
Tal Davidson davidsont@bigfoot.com

Constructor Summary
JSBeautifier()
          JSBeautifier's constructor.
 
Method Summary
 java.lang.String beautify(java.lang.String line)
          beautify a line of source code.
 void beautifyReader(java.io.BufferedReader inReader, java.io.PrintWriter outWriter)
          beautify input from inreader to outWriter
 void init()
          initiate the JSBeautifier.
static void main(java.lang.String[] args)
           
 void setBracketIndent(boolean state)
          set the state of the bracket indentation option.
 void setMaxInStatementIndetation(int max)
          set the maximum indentation between two lines in a multi-line statement.
 void setSpaceIndentation(int length)
          ident a number of spaces for each identation.
 void setSwitchIndent(boolean state)
          set the state of the switch indentation option.
 void setTabIndentation()
          ident using one tab per identation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSBeautifier

public JSBeautifier()
JSBeautifier's constructor.

Method Detail

main

public static void main(java.lang.String[] args)

beautifyReader

public void beautifyReader(java.io.BufferedReader inReader,
                           java.io.PrintWriter outWriter)
                    throws java.io.IOException
beautify input from inreader to outWriter

Parameters:
inReader - a BufferedReader from which to input original source code
outWriter - a PrintWriter to output beutified source code to
Throws:
java.io.IOException

init

public void init()
initiate the JSBeautifier. init() should be called every time a JSBeautifier object is to start beautifying a NEW source file.


setTabIndentation

public void setTabIndentation()
ident using one tab per identation


setSpaceIndentation

public void setSpaceIndentation(int length)
ident a number of spaces for each identation.

Parameters:
length - number of spaces per indent.

setMaxInStatementIndetation

public void setMaxInStatementIndetation(int max)
set the maximum indentation between two lines in a multi-line statement.

Parameters:
max - maximum indentation length.

setBracketIndent

public void setBracketIndent(boolean state)
set the state of the bracket indentation option. If true, brackets will be indented one additional indent.

Parameters:
state - state of option.

setSwitchIndent

public void setSwitchIndent(boolean state)
set the state of the switch indentation option. If true, blocks of 'switch' statements will be indented one additional indent.

Parameters:
state - state of option.

beautify

public java.lang.String beautify(java.lang.String line)
beautify a line of source code. every line of source code in a java source code file should be sent one after the other to the beautify method.



Copyright © Madkit Team (O. Gutknecht, J. Ferber, F. Michel et al.) All Rights Reserved.