<s> package org . eclipse . jdt . internal . compiler . parser ; import org . eclipse . jdt . internal . compiler . ast . AbstractMethodDeclaration ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . compiler . ast . Block ; import org . eclipse . jdt . internal . compiler . ast . FieldDeclaration ; import org . eclipse . jdt . internal . compiler . ast . ImportReference ; import org . eclipse . jdt . internal . compiler . ast . LocalDeclaration ; import org . eclipse . jdt . internal . compiler . ast . Statement ; import org . eclipse . jdt . internal . compiler . ast . TypeDeclaration ; import org . eclipse . jdt . internal . compiler . util . Util ; public class RecoveredElement { public RecoveredElement parent ; public int bracketBalance ; public boolean foundOpeningBrace ; protected Parser recoveringParser ; public RecoveredElement ( RecoveredElement parent , int bracketBalance ) { this ( parent , bracketBalance , null ) ; } public RecoveredElement ( RecoveredElement parent , int bracketBalance , Parser parser ) { this . parent = parent ; this . bracketBalance = bracketBalance ; this . recoveringParser = parser ; } public RecoveredElement addAnnotationName ( int identifierPtr , int identifierLengthPtr , int annotationStart , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( annotationStart - 1 ) ) ; return this . parent . addAnnotationName ( identifierPtr , identifierLengthPtr , annotationStart , bracketBalanceValue ) ; } public RecoveredElement add ( AbstractMethodDeclaration methodDeclaration , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( methodDeclaration . declarationSourceStart - 1 ) ) ; return this . parent . add ( methodDeclaration , bracketBalanceValue ) ; } public RecoveredElement add ( Block nestedBlockDeclaration , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( nestedBlockDeclaration . sourceStart - 1 ) ) ; return this . parent . add ( nestedBlockDeclaration , bracketBalanceValue ) ; } public RecoveredElement add ( FieldDeclaration fieldDeclaration , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( fieldDeclaration . declarationSourceStart - 1 ) ) ; return this . parent . add ( fieldDeclaration , bracketBalanceValue ) ; } public RecoveredElement add ( ImportReference importReference , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( importReference . declarationSourceStart - 1 ) ) ; return this . parent . add ( importReference , bracketBalanceValue ) ; } public RecoveredElement add ( LocalDeclaration localDeclaration , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( localDeclaration . declarationSourceStart - 1 ) ) ; return this . parent . add ( localDeclaration , bracketBalanceValue ) ; } public RecoveredElement add ( Statement statement , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( statement . sourceStart - 1 ) ) ; return this . parent . add ( statement , bracketBalanceValue ) ; } public RecoveredElement add ( TypeDeclaration typeDeclaration , int bracketBalanceValue ) { resetPendingModifiers ( ) ; if ( this . parent == null ) return this ; this . updateSourceEndIfNecessary ( previousAvailableLineEnd ( typeDeclaration . declarationSourceStart - 1 ) ) ; return this . parent . add ( typeDeclaration , bracketBalanceValue ) ; } protected void addBlockStatement ( RecoveredBlock recoveredBlock ) { Block block = recoveredBlock . blockDeclaration ; if ( block . statements != null ) { Statement [ ] statements = block . statements ; for ( int i = 0 ; i < statements . length ; i ++ ) { recoveredBlock . add ( statements [ i ] , 0 ) ; } } } public void addModifier ( int flag , int modifiersSourceStart ) { } public int depth ( ) { int depth = 0 ; RecoveredElement current = this ; while ( ( current = current . parent ) != null ) depth ++ ; return depth ; } public RecoveredInitializer enclosingInitializer ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current instanceof RecoveredInitializer ) { return ( RecoveredInitializer ) current ; } current = current . parent ; } return null ; } public RecoveredMethod enclosingMethod ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current instanceof RecoveredMethod ) { return ( RecoveredMethod ) current ; } current = current . parent ; } return null ; } public RecoveredType enclosingType ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current instanceof RecoveredType ) { return ( RecoveredType ) current ; } current = current . parent ; } return null ; } public Parser parser ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current . recoveringParser != null ) { return current . recoveringParser ; } current = current . parent ; } return null ; } public ASTNode parseTree ( ) { return null ; } public void resetPendingModifiers ( ) { } public void preserveEnclosingBlocks ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current instanceof RecoveredBlock ) { ( ( RecoveredBlock ) current ) . preserveContent = true ; } if ( current instanceof RecoveredType ) { ( ( RecoveredType ) current ) . preserveContent = true ; } current = current . parent ; } } public int previousAvailableLineEnd ( int position ) { Parser parser = parser ( ) ; if ( parser == null ) return position ; Scanner scanner = parser . scanner ; if ( scanner . lineEnds == null ) return position ; int index = Util . getLineNumber ( position , scanner . lineEnds , 0 , scanner . linePtr ) ; if ( index < 2 ) return position ; int previousLineEnd = scanner . lineEnds [ index - 2 ] ; char [ ] source = scanner . source ; for ( int i = previousLineEnd + 1 ; i < position ; i ++ ) { if ( ! ( source [ i ] == ' ' || source [ i ] == '\t' ) ) return position ; } return previousLineEnd ; } public int sourceEnd ( ) { return 0 ; } protected String tabString ( int tab ) { StringBuffer result = new StringBuffer ( ) ; for ( int i = tab ; i > 0 ; i -- ) { result . append ( " " ) ; } return result . toString ( ) ; } public RecoveredElement topElement ( ) { RecoveredElement current = this ; while ( current . parent != null ) { current = current . parent ; } return current ; } public String toString ( ) { return toString ( 0 ) ; } public String toString ( int tab ) { return super . toString ( ) ; } public RecoveredType type ( ) { RecoveredElement current = this ; while ( current != null ) { if ( current instanceof RecoveredType ) { return ( RecoveredType ) current ; } current = current . parent ; } return null ; } public void updateBodyStart ( int bodyStart ) { this . foundOpeningBrace = true ; } public void updateFromParserState ( ) { } public RecoveredElement updateOnClosingBrace ( int braceStart , int braceEnd ) { if ( ( -- this . bracketBalance <= 0 ) && ( this . parent != null ) ) { this . updateSourceEndIfNecessary ( braceStart , braceEnd ) ; return this . parent ; } return this ; } public RecoveredElement updateOnOpeningBrace ( int braceStart , int braceEnd ) { if ( this . bracketBalance ++ == 0 ) { updateBodyStart ( braceEnd + 1 ) ; return this ; } return null ; } public void updateParseTree ( ) { } public void updateSourceEndIfNecessary ( int braceStart , int braceEnd ) { } public void updateSourceEndIfNecessary ( int sourceEnd ) { this . updateSourceEndIfNecessary ( sourceEnd + 1 , sourceEnd ) ; } } </s>