<s> package org . eclipse . jdt . internal . core . dom . rewrite ; import java . util . List ; import org . eclipse . jdt . core . dom . * ; import org . eclipse . jdt . internal . compiler . util . Util ; public class ASTRewriteFlattener extends ASTVisitor { static final int JLS2_INTERNAL = AST . JLS2 ; public static String asString ( ASTNode node , RewriteEventStore store ) { ASTRewriteFlattener flattener = new ASTRewriteFlattener ( store ) ; node . accept ( flattener ) ; return flattener . getResult ( ) ; } protected StringBuffer result ; private RewriteEventStore store ; public ASTRewriteFlattener ( RewriteEventStore store ) { this . store = store ; this . result = new StringBuffer ( ) ; } public String getResult ( ) { return new String ( this . result . toString ( ) ) ; } public void reset ( ) { this . result . setLength ( 0 ) ; } public static void printModifiers ( int modifiers , StringBuffer buf ) { if ( Modifier . isPublic ( modifiers ) ) { buf . append ( "public " ) ; } if ( Modifier . isProtected ( modifiers ) ) { buf . append ( "protected " ) ; } if ( Modifier . isPrivate ( modifiers ) ) { buf . append ( "private " ) ; } if ( Modifier . isStatic ( modifiers ) ) { buf . append ( "static " ) ; } if ( Modifier . isAbstract ( modifiers ) ) { buf . append ( "abstract " ) ; } if ( Modifier . isFinal ( modifiers ) ) { buf . append ( "final " ) ; } if ( Modifier . isSynchronized ( modifiers ) ) { buf . append ( "" ) ; } if ( Modifier . isVolatile ( modifiers ) ) { buf . append ( "volatile " ) ; } if ( Modifier . isNative ( modifiers ) ) { buf . append ( "native " ) ; } if ( Modifier . isStrictfp ( modifiers ) ) { buf . append ( "strictfp " ) ; } if ( Modifier . isTransient ( modifiers ) ) { buf . append ( "transient " ) ; } } protected List getChildList ( ASTNode parent , StructuralPropertyDescriptor childProperty ) { return ( List ) getAttribute ( parent , childProperty ) ; } protected ASTNode getChildNode ( ASTNode parent , StructuralPropertyDescriptor childProperty ) { return ( ASTNode ) getAttribute ( parent , childProperty ) ; } protected int getIntAttribute ( ASTNode parent , StructuralPropertyDescriptor childProperty ) { return ( ( Integer ) getAttribute ( parent , childProperty ) ) . intValue ( ) ; } protected boolean getBooleanAttribute ( ASTNode parent , StructuralPropertyDescriptor childProperty ) { return ( ( Boolean ) getAttribute ( parent , childProperty ) ) . booleanValue ( ) ; } protected Object getAttribute ( ASTNode parent , StructuralPropertyDescriptor childProperty ) { return this . store . getNewValue ( parent , childProperty ) ; } protected void visitList ( ASTNode parent , StructuralPropertyDescriptor childProperty , String separator ) { List list = getChildList ( parent , childProperty ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( separator != null && i > 0 ) { this . result . append ( separator ) ; } ( ( ASTNode ) list . get ( i ) ) . accept ( this ) ; } } protected void visitList ( ASTNode parent , StructuralPropertyDescriptor childProperty , String separator , String lead , String post ) { List list = getChildList ( parent , childProperty ) ; if ( ! list . isEmpty ( ) ) { this . result . append ( lead ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( separator != null && i > 0 ) { this . result . append ( separator ) ; } ( ( ASTNode ) list . get ( i ) ) . accept ( this ) ; } this . result . append ( post ) ; } } public boolean visit ( AnonymousClassDeclaration node ) { this . result . append ( '{' ) ; visitList ( node , AnonymousClassDeclaration . BODY_DECLARATIONS_PROPERTY , null ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( ArrayAccess node ) { getChildNode ( node , ArrayAccess . ARRAY_PROPERTY ) . accept ( this ) ; this . result . append ( '[' ) ; getChildNode ( node , ArrayAccess . INDEX_PROPERTY ) . accept ( this ) ; this . result . append ( ']' ) ; return false ; } public boolean visit ( ArrayCreation node ) { this . result . append ( "new " ) ; ArrayType arrayType = ( ArrayType ) getChildNode ( node , ArrayCreation . TYPE_PROPERTY ) ; Type elementType = ( Type ) getChildNode ( arrayType , ArrayType . COMPONENT_TYPE_PROPERTY ) ; int dimensions = 1 ; while ( elementType . isArrayType ( ) ) { dimensions ++ ; elementType = ( Type ) getChildNode ( elementType , ArrayType . COMPONENT_TYPE_PROPERTY ) ; } elementType . accept ( this ) ; List list = getChildList ( node , ArrayCreation . DIMENSIONS_PROPERTY ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { this . result . append ( '[' ) ; ( ( ASTNode ) list . get ( i ) ) . accept ( this ) ; this . result . append ( ']' ) ; dimensions -- ; } for ( int i = 0 ; i < dimensions ; i ++ ) { this . result . append ( "[]" ) ; } ASTNode initializer = getChildNode ( node , ArrayCreation . INITIALIZER_PROPERTY ) ; if ( initializer != null ) { getChildNode ( node , ArrayCreation . INITIALIZER_PROPERTY ) . accept ( this ) ; } return false ; } public boolean visit ( ArrayInitializer node ) { this . result . append ( '{' ) ; visitList ( node , ArrayInitializer . EXPRESSIONS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( ArrayType node ) { getChildNode ( node , ArrayType . COMPONENT_TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( "[]" ) ; return false ; } public boolean visit ( AssertStatement node ) { this . result . append ( "assert " ) ; getChildNode ( node , AssertStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; ASTNode message = getChildNode ( node , AssertStatement . MESSAGE_PROPERTY ) ; if ( message != null ) { this . result . append ( ':' ) ; message . accept ( this ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( Assignment node ) { getChildNode ( node , Assignment . LEFT_HAND_SIDE_PROPERTY ) . accept ( this ) ; this . result . append ( getAttribute ( node , Assignment . OPERATOR_PROPERTY ) . toString ( ) ) ; getChildNode ( node , Assignment . RIGHT_HAND_SIDE_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( Block node ) { this . result . append ( '{' ) ; visitList ( node , Block . STATEMENTS_PROPERTY , null ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( BooleanLiteral node ) { if ( node . booleanValue ( ) == true ) { this . result . append ( "true" ) ; } else { this . result . append ( "false" ) ; } return false ; } public boolean visit ( BreakStatement node ) { this . result . append ( "break" ) ; ASTNode label = getChildNode ( node , BreakStatement . LABEL_PROPERTY ) ; if ( label != null ) { this . result . append ( ' ' ) ; label . accept ( this ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( CastExpression node ) { this . result . append ( '(' ) ; getChildNode ( node , CastExpression . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , CastExpression . EXPRESSION_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( CatchClause node ) { this . result . append ( "catch (" ) ; getChildNode ( node , CatchClause . EXCEPTION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , CatchClause . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( CharacterLiteral node ) { this . result . append ( getAttribute ( node , CharacterLiteral . ESCAPED_VALUE_PROPERTY ) ) ; return false ; } public boolean visit ( ClassInstanceCreation node ) { ASTNode expression = getChildNode ( node , ClassInstanceCreation . EXPRESSION_PROPERTY ) ; if ( expression != null ) { expression . accept ( this ) ; this . result . append ( '.' ) ; } this . result . append ( "new " ) ; if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { getChildNode ( node , ClassInstanceCreation . NAME_PROPERTY ) . accept ( this ) ; } else { visitList ( node , ClassInstanceCreation . TYPE_ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; getChildNode ( node , ClassInstanceCreation . TYPE_PROPERTY ) . accept ( this ) ; } this . result . append ( '(' ) ; visitList ( node , ClassInstanceCreation . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ')' ) ; ASTNode decl = getChildNode ( node , ClassInstanceCreation . ANONYMOUS_CLASS_DECLARATION_PROPERTY ) ; if ( decl != null ) { decl . accept ( this ) ; } return false ; } public boolean visit ( CompilationUnit node ) { ASTNode pack = getChildNode ( node , CompilationUnit . PACKAGE_PROPERTY ) ; if ( pack != null ) { pack . accept ( this ) ; } visitList ( node , CompilationUnit . IMPORTS_PROPERTY , null ) ; visitList ( node , CompilationUnit . TYPES_PROPERTY , null ) ; return false ; } public boolean visit ( ConditionalExpression node ) { getChildNode ( node , ConditionalExpression . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( '?' ) ; getChildNode ( node , ConditionalExpression . THEN_EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ':' ) ; getChildNode ( node , ConditionalExpression . ELSE_EXPRESSION_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( ConstructorInvocation node ) { if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { visitList ( node , ConstructorInvocation . TYPE_ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } this . result . append ( "this(" ) ; visitList ( node , ConstructorInvocation . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ");" ) ; return false ; } public boolean visit ( ContinueStatement node ) { this . result . append ( "continue" ) ; ASTNode label = getChildNode ( node , ContinueStatement . LABEL_PROPERTY ) ; if ( label != null ) { this . result . append ( ' ' ) ; label . accept ( this ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( DoStatement node ) { this . result . append ( "do " ) ; getChildNode ( node , DoStatement . BODY_PROPERTY ) . accept ( this ) ; this . result . append ( " while (" ) ; getChildNode ( node , DoStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ");" ) ; return false ; } public boolean visit ( EmptyStatement node ) { this . result . append ( ';' ) ; return false ; } public boolean visit ( ExpressionStatement node ) { getChildNode ( node , ExpressionStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ';' ) ; return false ; } public boolean visit ( FieldAccess node ) { getChildNode ( node , FieldAccess . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( '.' ) ; getChildNode ( node , FieldAccess . NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( FieldDeclaration node ) { ASTNode javadoc = getChildNode ( node , FieldDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , FieldDeclaration . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , FieldDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } getChildNode ( node , FieldDeclaration . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; visitList ( node , FieldDeclaration . FRAGMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ';' ) ; return false ; } public boolean visit ( ForStatement node ) { this . result . append ( "for (" ) ; visitList ( node , ForStatement . INITIALIZERS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ';' ) ; ASTNode expression = getChildNode ( node , ForStatement . EXPRESSION_PROPERTY ) ; if ( expression != null ) { expression . accept ( this ) ; } this . result . append ( ';' ) ; visitList ( node , ForStatement . UPDATERS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ')' ) ; getChildNode ( node , ForStatement . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( IfStatement node ) { this . result . append ( "if (" ) ; getChildNode ( node , IfStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , IfStatement . THEN_STATEMENT_PROPERTY ) . accept ( this ) ; ASTNode elseStatement = getChildNode ( node , IfStatement . ELSE_STATEMENT_PROPERTY ) ; if ( elseStatement != null ) { this . result . append ( " else " ) ; elseStatement . accept ( this ) ; } return false ; } public boolean visit ( ImportDeclaration node ) { this . result . append ( "import " ) ; if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { if ( getBooleanAttribute ( node , ImportDeclaration . STATIC_PROPERTY ) ) { this . result . append ( "static " ) ; } } getChildNode ( node , ImportDeclaration . NAME_PROPERTY ) . accept ( this ) ; if ( getBooleanAttribute ( node , ImportDeclaration . ON_DEMAND_PROPERTY ) ) { this . result . append ( ".*" ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( InfixExpression node ) { getChildNode ( node , InfixExpression . LEFT_OPERAND_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; String operator = getAttribute ( node , InfixExpression . OPERATOR_PROPERTY ) . toString ( ) ; this . result . append ( operator ) ; this . result . append ( ' ' ) ; getChildNode ( node , InfixExpression . RIGHT_OPERAND_PROPERTY ) . accept ( this ) ; List list = getChildList ( node , InfixExpression . EXTENDED_OPERANDS_PROPERTY ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { this . result . append ( operator ) ; ( ( ASTNode ) list . get ( i ) ) . accept ( this ) ; } return false ; } public boolean visit ( InstanceofExpression node ) { getChildNode ( node , InstanceofExpression . LEFT_OPERAND_PROPERTY ) . accept ( this ) ; this . result . append ( " instanceof " ) ; getChildNode ( node , InstanceofExpression . RIGHT_OPERAND_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( Initializer node ) { ASTNode javadoc = getChildNode ( node , Initializer . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , Initializer . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , Initializer . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } getChildNode ( node , Initializer . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( Javadoc node ) { this . result . append ( "/**" ) ; List list = getChildList ( node , Javadoc . TAGS_PROPERTY ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { this . result . append ( "n * " ) ; ( ( ASTNode ) list . get ( i ) ) . accept ( this ) ; } this . result . append ( "n */" ) ; return false ; } public boolean visit ( LabeledStatement node ) { getChildNode ( node , LabeledStatement . LABEL_PROPERTY ) . accept ( this ) ; this . result . append ( ": " ) ; getChildNode ( node , LabeledStatement . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( MethodDeclaration node ) { ASTNode javadoc = getChildNode ( node , MethodDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , MethodDeclaration . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , MethodDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; visitList ( node , MethodDeclaration . TYPE_PARAMETERS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } if ( ! getBooleanAttribute ( node , MethodDeclaration . CONSTRUCTOR_PROPERTY ) ) { if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { getChildNode ( node , MethodDeclaration . RETURN_TYPE_PROPERTY ) . accept ( this ) ; } else { ASTNode returnType = getChildNode ( node , MethodDeclaration . RETURN_TYPE2_PROPERTY ) ; if ( returnType != null ) { returnType . accept ( this ) ; } else { this . result . append ( "void" ) ; } } this . result . append ( ' ' ) ; } getChildNode ( node , MethodDeclaration . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; visitList ( node , MethodDeclaration . PARAMETERS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ')' ) ; int extraDims = getIntAttribute ( node , MethodDeclaration . EXTRA_DIMENSIONS_PROPERTY ) ; for ( int i = 0 ; i < extraDims ; i ++ ) { this . result . append ( "[]" ) ; } visitList ( node , MethodDeclaration . THROWN_EXCEPTIONS_PROPERTY , String . valueOf ( ',' ) , " throws " , Util . EMPTY_STRING ) ; ASTNode body = getChildNode ( node , MethodDeclaration . BODY_PROPERTY ) ; if ( body == null ) { this . result . append ( ';' ) ; } else { body . accept ( this ) ; } return false ; } public boolean visit ( MethodInvocation node ) { ASTNode expression = getChildNode ( node , MethodInvocation . EXPRESSION_PROPERTY ) ; if ( expression != null ) { expression . accept ( this ) ; this . result . append ( '.' ) ; } if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { visitList ( node , MethodInvocation . TYPE_ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } getChildNode ( node , MethodInvocation . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; visitList ( node , MethodInvocation . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( NullLiteral node ) { this . result . append ( "null" ) ; return false ; } public boolean visit ( NumberLiteral node ) { this . result . append ( getAttribute ( node , NumberLiteral . TOKEN_PROPERTY ) . toString ( ) ) ; return false ; } public boolean visit ( PackageDeclaration node ) { if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { ASTNode javadoc = getChildNode ( node , PackageDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } visitList ( node , PackageDeclaration . ANNOTATIONS_PROPERTY , String . valueOf ( ' ' ) ) ; } this . result . append ( "package " ) ; getChildNode ( node , PackageDeclaration . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( ';' ) ; return false ; } public boolean visit ( ParenthesizedExpression node ) { this . result . append ( '(' ) ; getChildNode ( node , ParenthesizedExpression . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( PostfixExpression node ) { getChildNode ( node , PostfixExpression . OPERAND_PROPERTY ) . accept ( this ) ; this . result . append ( getAttribute ( node , PostfixExpression . OPERATOR_PROPERTY ) . toString ( ) ) ; return false ; } public boolean visit ( PrefixExpression node ) { this . result . append ( getAttribute ( node , PrefixExpression . OPERATOR_PROPERTY ) . toString ( ) ) ; getChildNode ( node , PrefixExpression . OPERAND_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( PrimitiveType node ) { this . result . append ( getAttribute ( node , PrimitiveType . PRIMITIVE_TYPE_CODE_PROPERTY ) . toString ( ) ) ; return false ; } public boolean visit ( QualifiedName node ) { getChildNode ( node , QualifiedName . QUALIFIER_PROPERTY ) . accept ( this ) ; this . result . append ( '.' ) ; getChildNode ( node , QualifiedName . NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( ReturnStatement node ) { this . result . append ( "return" ) ; ASTNode expression = getChildNode ( node , ReturnStatement . EXPRESSION_PROPERTY ) ; if ( expression != null ) { this . result . append ( ' ' ) ; expression . accept ( this ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( SimpleName node ) { this . result . append ( getAttribute ( node , SimpleName . IDENTIFIER_PROPERTY ) ) ; return false ; } public boolean visit ( SimpleType node ) { return true ; } public boolean visit ( SingleVariableDeclaration node ) { if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , SingleVariableDeclaration . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , SingleVariableDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } getChildNode ( node , SingleVariableDeclaration . TYPE_PROPERTY ) . accept ( this ) ; if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { if ( getBooleanAttribute ( node , SingleVariableDeclaration . VARARGS_PROPERTY ) ) { this . result . append ( "..." ) ; } } this . result . append ( ' ' ) ; getChildNode ( node , SingleVariableDeclaration . NAME_PROPERTY ) . accept ( this ) ; int extraDimensions = getIntAttribute ( node , SingleVariableDeclaration . EXTRA_DIMENSIONS_PROPERTY ) ; for ( int i = 0 ; i < extraDimensions ; i ++ ) { this . result . append ( "[]" ) ; } ASTNode initializer = getChildNode ( node , SingleVariableDeclaration . INITIALIZER_PROPERTY ) ; if ( initializer != null ) { this . result . append ( '=' ) ; initializer . accept ( this ) ; } return false ; } public boolean visit ( StringLiteral node ) { this . result . append ( getAttribute ( node , StringLiteral . ESCAPED_VALUE_PROPERTY ) ) ; return false ; } public boolean visit ( SuperConstructorInvocation node ) { ASTNode expression = getChildNode ( node , SuperConstructorInvocation . EXPRESSION_PROPERTY ) ; if ( expression != null ) { expression . accept ( this ) ; this . result . append ( '.' ) ; } if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { visitList ( node , SuperConstructorInvocation . TYPE_ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } this . result . append ( "super(" ) ; visitList ( node , SuperConstructorInvocation . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ");" ) ; return false ; } public boolean visit ( SuperFieldAccess node ) { ASTNode qualifier = getChildNode ( node , SuperFieldAccess . QUALIFIER_PROPERTY ) ; if ( qualifier != null ) { qualifier . accept ( this ) ; this . result . append ( '.' ) ; } this . result . append ( "super." ) ; getChildNode ( node , SuperFieldAccess . NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( SuperMethodInvocation node ) { ASTNode qualifier = getChildNode ( node , SuperMethodInvocation . QUALIFIER_PROPERTY ) ; if ( qualifier != null ) { qualifier . accept ( this ) ; this . result . append ( '.' ) ; } this . result . append ( "super." ) ; if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { visitList ( node , SuperMethodInvocation . TYPE_ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } getChildNode ( node , SuperMethodInvocation . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; visitList ( node , SuperMethodInvocation . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( SwitchCase node ) { ASTNode expression = getChildNode ( node , SwitchCase . EXPRESSION_PROPERTY ) ; if ( expression == null ) { this . result . append ( "default" ) ; } else { this . result . append ( "case " ) ; expression . accept ( this ) ; } this . result . append ( ':' ) ; return false ; } public boolean visit ( SwitchStatement node ) { this . result . append ( "switch (" ) ; getChildNode ( node , SwitchStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; this . result . append ( '{' ) ; visitList ( node , SwitchStatement . STATEMENTS_PROPERTY , null ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( SynchronizedStatement node ) { this . result . append ( "" ) ; getChildNode ( node , SynchronizedStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , SynchronizedStatement . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( ThisExpression node ) { ASTNode qualifier = getChildNode ( node , ThisExpression . QUALIFIER_PROPERTY ) ; if ( qualifier != null ) { qualifier . accept ( this ) ; this . result . append ( '.' ) ; } this . result . append ( "this" ) ; return false ; } public boolean visit ( ThrowStatement node ) { this . result . append ( "throw " ) ; getChildNode ( node , ThrowStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ';' ) ; return false ; } public boolean visit ( TryStatement node ) { this . result . append ( "try " ) ; getChildNode ( node , TryStatement . BODY_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; visitList ( node , TryStatement . CATCH_CLAUSES_PROPERTY , null ) ; ASTNode finallyClause = getChildNode ( node , TryStatement . FINALLY_PROPERTY ) ; if ( finallyClause != null ) { this . result . append ( " finally " ) ; finallyClause . accept ( this ) ; } return false ; } public boolean visit ( TypeDeclaration node ) { int apiLevel = node . getAST ( ) . apiLevel ( ) ; ASTNode javadoc = getChildNode ( node , TypeDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } if ( apiLevel == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , TypeDeclaration . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , TypeDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } boolean isInterface = getBooleanAttribute ( node , TypeDeclaration . INTERFACE_PROPERTY ) ; this . result . append ( isInterface ? "interface " : "class " ) ; getChildNode ( node , TypeDeclaration . NAME_PROPERTY ) . accept ( this ) ; if ( apiLevel >= AST . JLS3 ) { visitList ( node , TypeDeclaration . TYPE_PARAMETERS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '<' ) , String . valueOf ( '>' ) ) ; } this . result . append ( ' ' ) ; ChildPropertyDescriptor superClassProperty = ( apiLevel == JLS2_INTERNAL ) ? TypeDeclaration . SUPERCLASS_PROPERTY : TypeDeclaration . SUPERCLASS_TYPE_PROPERTY ; ASTNode superclass = getChildNode ( node , superClassProperty ) ; if ( superclass != null ) { this . result . append ( "extends " ) ; superclass . accept ( this ) ; this . result . append ( ' ' ) ; } ChildListPropertyDescriptor superInterfaceProperty = ( apiLevel == JLS2_INTERNAL ) ? TypeDeclaration . SUPER_INTERFACES_PROPERTY : TypeDeclaration . SUPER_INTERFACE_TYPES_PROPERTY ; String lead = isInterface ? "extends " : "implements " ; visitList ( node , superInterfaceProperty , String . valueOf ( ',' ) , lead , Util . EMPTY_STRING ) ; this . result . append ( '{' ) ; visitList ( node , TypeDeclaration . BODY_DECLARATIONS_PROPERTY , null ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( TypeDeclarationStatement node ) { if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { getChildNode ( node , TypeDeclarationStatement . TYPE_DECLARATION_PROPERTY ) . accept ( this ) ; } else { getChildNode ( node , TypeDeclarationStatement . DECLARATION_PROPERTY ) . accept ( this ) ; } return false ; } public boolean visit ( TypeLiteral node ) { getChildNode ( node , TypeLiteral . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ".class" ) ; return false ; } public boolean visit ( VariableDeclarationExpression node ) { if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , VariableDeclarationExpression . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , VariableDeclarationExpression . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } getChildNode ( node , VariableDeclarationExpression . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; visitList ( node , VariableDeclarationExpression . FRAGMENTS_PROPERTY , String . valueOf ( ',' ) ) ; return false ; } public boolean visit ( VariableDeclarationFragment node ) { getChildNode ( node , VariableDeclarationFragment . NAME_PROPERTY ) . accept ( this ) ; int extraDimensions = getIntAttribute ( node , VariableDeclarationFragment . EXTRA_DIMENSIONS_PROPERTY ) ; for ( int i = 0 ; i < extraDimensions ; i ++ ) { this . result . append ( "[]" ) ; } ASTNode initializer = getChildNode ( node , VariableDeclarationFragment . INITIALIZER_PROPERTY ) ; if ( initializer != null ) { this . result . append ( '=' ) ; initializer . accept ( this ) ; } return false ; } public boolean visit ( VariableDeclarationStatement node ) { if ( node . getAST ( ) . apiLevel ( ) == JLS2_INTERNAL ) { printModifiers ( getIntAttribute ( node , VariableDeclarationStatement . MODIFIERS_PROPERTY ) , this . result ) ; } else { visitList ( node , VariableDeclarationStatement . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; } getChildNode ( node , VariableDeclarationStatement . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; visitList ( node , VariableDeclarationStatement . FRAGMENTS_PROPERTY , String . valueOf ( ',' ) ) ; this . result . append ( ';' ) ; return false ; } public boolean visit ( WhileStatement node ) { this . result . append ( "while (" ) ; getChildNode ( node , WhileStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , WhileStatement . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( BlockComment node ) { return false ; } public boolean visit ( LineComment node ) { return false ; } public boolean visit ( MemberRef node ) { ASTNode qualifier = getChildNode ( node , MemberRef . QUALIFIER_PROPERTY ) ; if ( qualifier != null ) { qualifier . accept ( this ) ; } this . result . append ( '#' ) ; getChildNode ( node , MemberRef . NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( MethodRef node ) { ASTNode qualifier = getChildNode ( node , MethodRef . QUALIFIER_PROPERTY ) ; if ( qualifier != null ) { qualifier . accept ( this ) ; } this . result . append ( '#' ) ; getChildNode ( node , MethodRef . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; visitList ( node , MethodRef . PARAMETERS_PROPERTY , "," ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( MethodRefParameter node ) { getChildNode ( node , MethodRefParameter . TYPE_PROPERTY ) . accept ( this ) ; if ( node . getAST ( ) . apiLevel ( ) >= AST . JLS3 ) { if ( getBooleanAttribute ( node , MethodRefParameter . VARARGS_PROPERTY ) ) { this . result . append ( "..." ) ; } } ASTNode name = getChildNode ( node , MethodRefParameter . NAME_PROPERTY ) ; if ( name != null ) { this . result . append ( ' ' ) ; name . accept ( this ) ; } return false ; } public boolean visit ( TagElement node ) { Object tagName = getAttribute ( node , TagElement . TAG_NAME_PROPERTY ) ; if ( tagName != null ) { this . result . append ( ( String ) tagName ) ; } List list = getChildList ( node , TagElement . FRAGMENTS_PROPERTY ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( i > 0 || tagName != null ) { this . result . append ( ' ' ) ; } ASTNode curr = ( ASTNode ) list . get ( i ) ; if ( curr instanceof TagElement ) { this . result . append ( '{' ) ; curr . accept ( this ) ; this . result . append ( '}' ) ; } else { curr . accept ( this ) ; } } return false ; } public boolean visit ( TextElement node ) { this . result . append ( getAttribute ( node , TextElement . TEXT_PROPERTY ) ) ; return false ; } public boolean visit ( AnnotationTypeDeclaration node ) { ASTNode javadoc = getChildNode ( node , AnnotationTypeDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } visitList ( node , AnnotationTypeDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; this . result . append ( "@interface " ) ; getChildNode ( node , AnnotationTypeDeclaration . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '{' ) ; visitList ( node , AnnotationTypeDeclaration . BODY_DECLARATIONS_PROPERTY , Util . EMPTY_STRING ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( AnnotationTypeMemberDeclaration node ) { ASTNode javadoc = getChildNode ( node , AnnotationTypeMemberDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } visitList ( node , AnnotationTypeMemberDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; getChildNode ( node , AnnotationTypeMemberDeclaration . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; getChildNode ( node , AnnotationTypeMemberDeclaration . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( "()" ) ; ASTNode def = getChildNode ( node , AnnotationTypeMemberDeclaration . DEFAULT_PROPERTY ) ; if ( def != null ) { this . result . append ( " default " ) ; def . accept ( this ) ; } this . result . append ( ';' ) ; return false ; } public boolean visit ( EnhancedForStatement node ) { this . result . append ( "for (" ) ; getChildNode ( node , EnhancedForStatement . PARAMETER_PROPERTY ) . accept ( this ) ; this . result . append ( ':' ) ; getChildNode ( node , EnhancedForStatement . EXPRESSION_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; getChildNode ( node , EnhancedForStatement . BODY_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( EnumConstantDeclaration node ) { ASTNode javadoc = getChildNode ( node , EnumConstantDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } visitList ( node , EnumConstantDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; getChildNode ( node , EnumConstantDeclaration . NAME_PROPERTY ) . accept ( this ) ; visitList ( node , EnumConstantDeclaration . ARGUMENTS_PROPERTY , String . valueOf ( ',' ) , String . valueOf ( '(' ) , String . valueOf ( ')' ) ) ; ASTNode classDecl = getChildNode ( node , EnumConstantDeclaration . ANONYMOUS_CLASS_DECLARATION_PROPERTY ) ; if ( classDecl != null ) { classDecl . accept ( this ) ; } return false ; } public boolean visit ( EnumDeclaration node ) { ASTNode javadoc = getChildNode ( node , EnumDeclaration . JAVADOC_PROPERTY ) ; if ( javadoc != null ) { javadoc . accept ( this ) ; } visitList ( node , EnumDeclaration . MODIFIERS2_PROPERTY , String . valueOf ( ' ' ) , Util . EMPTY_STRING , String . valueOf ( ' ' ) ) ; this . result . append ( "enum " ) ; getChildNode ( node , EnumDeclaration . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( ' ' ) ; visitList ( node , EnumDeclaration . SUPER_INTERFACE_TYPES_PROPERTY , String . valueOf ( ',' ) , "implements " , Util . EMPTY_STRING ) ; this . result . append ( '{' ) ; visitList ( node , EnumDeclaration . ENUM_CONSTANTS_PROPERTY , String . valueOf ( ',' ) , Util . EMPTY_STRING , Util . EMPTY_STRING ) ; visitList ( node , EnumDeclaration . BODY_DECLARATIONS_PROPERTY , Util . EMPTY_STRING , String . valueOf ( ';' ) , Util . EMPTY_STRING ) ; this . result . append ( '}' ) ; return false ; } public boolean visit ( MarkerAnnotation node ) { this . result . append ( '@' ) ; getChildNode ( node , MarkerAnnotation . TYPE_NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( MemberValuePair node ) { getChildNode ( node , MemberValuePair . NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '=' ) ; getChildNode ( node , MemberValuePair . VALUE_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( Modifier node ) { this . result . append ( getAttribute ( node , Modifier . KEYWORD_PROPERTY ) . toString ( ) ) ; return false ; } public boolean visit ( NormalAnnotation node ) { this . result . append ( '@' ) ; getChildNode ( node , NormalAnnotation . TYPE_NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; visitList ( node , NormalAnnotation . VALUES_PROPERTY , ", " ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( ParameterizedType node ) { getChildNode ( node , ParameterizedType . TYPE_PROPERTY ) . accept ( this ) ; this . result . append ( '<' ) ; visitList ( node , ParameterizedType . TYPE_ARGUMENTS_PROPERTY , ", " ) ; this . result . append ( '>' ) ; return false ; } public boolean visit ( QualifiedType node ) { getChildNode ( node , QualifiedType . QUALIFIER_PROPERTY ) . accept ( this ) ; this . result . append ( '.' ) ; getChildNode ( node , QualifiedType . NAME_PROPERTY ) . accept ( this ) ; return false ; } public boolean visit ( SingleMemberAnnotation node ) { this . result . append ( '@' ) ; getChildNode ( node , SingleMemberAnnotation . TYPE_NAME_PROPERTY ) . accept ( this ) ; this . result . append ( '(' ) ; getChildNode ( node , SingleMemberAnnotation . VALUE_PROPERTY ) . accept ( this ) ; this . result . append ( ')' ) ; return false ; } public boolean visit ( TypeParameter node ) { getChildNode ( node , TypeParameter . NAME_PROPERTY ) . accept ( this ) ; visitList ( node , TypeParameter . TYPE_BOUNDS_PROPERTY , " & " , " extends " , Util . EMPTY_STRING ) ; return false ; } public boolean visit ( WildcardType node ) { this . result . append ( '?' ) ; ASTNode bound = getChildNode ( node , WildcardType . BOUND_PROPERTY ) ; if ( bound != null ) { if ( getBooleanAttribute ( node , WildcardType . UPPER_BOUND_PROPERTY ) ) { this . result . append ( " extends " ) ; } else { this . result . append ( " super " ) ; } bound . accept ( this ) ; } return false ; } } </s>