openjava.ptree.util
Class SourceCodeWriter

java.lang.Object
  |
  +--openjava.ptree.util.ParseTreeVisitor
        |
        +--openjava.ptree.util.SourceCodeWriter
Direct Known Subclasses:
ColoredSourceWriter

public class SourceCodeWriter
extends ParseTreeVisitor

The class SourceCodeWriter is a Visitor role in the Visitor pattern and this also visits each child ParseTree object from left to right.

Since:
%SOFTWARE% 1.0
Version:
1.0
Author:
Michiaki Tatsubori
See Also:
ParseTree, ParseTreeVisitor

Field Summary
private  int debugLevel
          to write debugging code
private  int nest
           
static String NEWLINE
           
protected  PrintWriter out
           
private  String tab
          to write debugging code
 
Constructor Summary
SourceCodeWriter(PrintWriter out)
          Allocates a source code writer.
 
Method Summary
 int getDebugLevel()
           
 int getNest()
           
 String getTab()
           
private static boolean isOperatorNeededLeftPar(int operator, Expression leftexpr)
           
private static boolean isOperatorNeededRightPar(int operator, Expression rightexpr)
           
private static int operatorStrength(int op)
          Returns the strength of the union of the operator.
 void popNest()
           
private  void printComment(NonLeaf p)
           
 void pushNest()
           
 void setDebugLevel(int n)
          to write debugging code
 void setNest(int i)
           
 void setTab(String str)
           
 void visit(AliasedExpression p)
           
 void visit(AllocationExpression p)
           
 void visit(ArrayAccess p)
           
 void visit(ArrayAllocationExpression p)
           
 void visit(ArrayInitializer p)
           
 void visit(AssignmentExpression p)
           
 void visit(BinaryExpression p)
           
 void visit(Block p)
           
 void visit(BreakStatement p)
           
 void visit(CaseGroup p)
           
 void visit(CaseGroupList p)
           
 void visit(CaseLabel p)
           
 void visit(CaseLabelList p)
           
 void visit(CastExpression p)
           
 void visit(CatchBlock p)
           
 void visit(CatchList p)
           
 void visit(ClassDeclaration p)
           
 void visit(ClassDeclarationList p)
           
 void visit(ClassLiteral p)
           
 void visit(CompilationUnit p)
           
 void visit(ConditionalExpression p)
           
 void visit(ConstructorDeclaration p)
           
 void visit(ConstructorInvocation p)
           
 void visit(ContinueStatement p)
           
 void visit(DoWhileStatement p)
           
 void visit(EmptyStatement p)
           
 void visit(ExpressionList p)
           
 void visit(ExpressionStatement p)
           
 void visit(FieldAccess p)
           
 void visit(FieldDeclaration p)
           
 void visit(ForStatement p)
           
 void visit(IfStatement p)
           
 void visit(InsertExpression p)
           
 void visit(InstanceofExpression p)
           
 void visit(JoinExpression p)
           
 void visit(LabeledStatement p)
           
 void visit(Literal p)
           
 void visit(MemberDeclarationList p)
           
 void visit(MemberInitializer p)
           
 void visit(MethodCall p)
           
 void visit(MethodDeclaration p)
           
 void visit(ModifierList p)
           
 void visit(Parameter p)
           
 void visit(ParameterList p)
           
 void visit(QueryExpression p)
           
 void visit(ReturnStatement p)
           
 void visit(SelfAccess p)
           
 void visit(StatementList p)
           
 void visit(SwitchStatement p)
           
 void visit(SynchronizedStatement p)
           
 void visit(ThrowStatement p)
           
 void visit(TryStatement p)
           
 void visit(TypeName p)
          rough around innerclass
 void visit(UnaryExpression p)
           
 void visit(Variable p)
           
 void visit(VariableDeclaration p)
           
 void visit(VariableDeclarator p)
           
 void visit(WhileStatement p)
           
private  void writeAnonymous(Object obj)
           
private  void writeArguments(ExpressionList args)
           
private  void writeDebug(String str)
           
private  void writeDebugL(ParseTree ptree)
           
private  void writeDebugLln()
           
private  void writeDebugln()
           
private  void writeDebugLR()
           
private  void writeDebugR()
           
private  void writeDebugRln()
           
private  void writeList(List list)
           
private  void writeListWithDelimiter(List list, String delimiter)
           
private  void writeListWithSuffix(List list, String suffix)
           
private  void writeParenthesis(Expression expr)
           
private  void writeStatementsBlock(StatementList stmts)
           
private  void writeTab()
           
 
Methods inherited from class openjava.ptree.util.ParseTreeVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected PrintWriter out

NEWLINE

public static String NEWLINE

debugLevel

private int debugLevel
to write debugging code


tab

private String tab
to write debugging code


nest

private int nest
Constructor Detail

SourceCodeWriter

public SourceCodeWriter(PrintWriter out)
Allocates a source code writer.

Method Detail

setDebugLevel

public void setDebugLevel(int n)
to write debugging code


getDebugLevel

public int getDebugLevel()

setTab

public void setTab(String str)

getTab

public String getTab()

setNest

public void setNest(int i)

getNest

public int getNest()

pushNest

public void pushNest()

popNest

public void popNest()

writeDebugL

private final void writeDebugL(ParseTree ptree)

writeDebugR

private final void writeDebugR()

writeDebugLR

private final void writeDebugLR()

writeDebugLln

private final void writeDebugLln()

writeDebugRln

private final void writeDebugRln()

writeDebugln

private final void writeDebugln()

writeDebug

private final void writeDebug(String str)

writeTab

private final void writeTab()

visit

public void visit(AllocationExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ArrayAccess p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ArrayAllocationExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ArrayInitializer p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(AssignmentExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(BinaryExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(Block p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(BreakStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CaseGroup p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CaseGroupList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CaseLabel p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CaseLabelList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CastExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CatchBlock p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CatchList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ClassDeclaration p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ClassDeclarationList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ClassLiteral p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(CompilationUnit p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ConditionalExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ConstructorDeclaration p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ConstructorInvocation p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ContinueStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(DoWhileStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(EmptyStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ExpressionList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ExpressionStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(FieldAccess p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(FieldDeclaration p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ForStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(IfStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(InstanceofExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(LabeledStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(Literal p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(MemberDeclarationList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(MemberInitializer p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(MethodCall p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(MethodDeclaration p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ModifierList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(Parameter p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ParameterList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ReturnStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(SelfAccess p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(StatementList p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(SwitchStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(SynchronizedStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(ThrowStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(TryStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(TypeName p)
           throws ParseTreeException
rough around innerclass

Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(UnaryExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(Variable p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(VariableDeclaration p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(VariableDeclarator p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(WhileStatement p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(QueryExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(AliasedExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(JoinExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

visit

public void visit(InsertExpression p)
           throws ParseTreeException
Specified by:
visit in class ParseTreeVisitor
ParseTreeException

writeArguments

private final void writeArguments(ExpressionList args)
                           throws ParseTreeException
ParseTreeException

writeAnonymous

private final void writeAnonymous(Object obj)
                           throws ParseTreeException
ParseTreeException

writeList

private final void writeList(List list)
                      throws ParseTreeException
ParseTreeException

writeListWithDelimiter

private final void writeListWithDelimiter(List list,
                                          String delimiter)
                                   throws ParseTreeException
ParseTreeException

writeListWithSuffix

private final void writeListWithSuffix(List list,
                                       String suffix)
                                throws ParseTreeException
ParseTreeException

writeParenthesis

private final void writeParenthesis(Expression expr)
                             throws ParseTreeException
ParseTreeException

writeStatementsBlock

private final void writeStatementsBlock(StatementList stmts)
                                 throws ParseTreeException
ParseTreeException

isOperatorNeededLeftPar

private static final boolean isOperatorNeededLeftPar(int operator,
                                                     Expression leftexpr)

isOperatorNeededRightPar

private static final boolean isOperatorNeededRightPar(int operator,
                                                      Expression rightexpr)

operatorStrength

private static final int operatorStrength(int op)
Returns the strength of the union of the operator.

Parameters:
op - the id number of operator.
Returns:
the strength of the union.

printComment

private final void printComment(NonLeaf p)

SourceForge.net_Logo