<s> package org . eclipse . jdt . internal . formatter ; import org . eclipse . jdt . internal . formatter . comment . IJavaDocTagConstants ; public class FormatJavadocText extends FormatJavadocNode implements IJavaDocTagConstants { long [ ] separators ; int separatorsPtr = - 1 ; private int htmlTagIndex = - 1 ; boolean immutable = false ; FormatJavadocNode [ ] htmlNodes ; int [ ] htmlIndexes ; int htmlNodesPtr = - 1 ; int depth = 0 ; public FormatJavadocText ( int start , int end , int line , int htmlIndex , int htmlDepth ) { super ( start , end , line ) ; this . htmlTagIndex = htmlIndex ; this . depth = htmlDepth ; } void appendText ( FormatJavadocText text ) { text . immutable = this . immutable ; if ( this . depth == text . depth ) { addSeparator ( text ) ; this . sourceEnd = text . sourceEnd ; if ( text . isClosingHtmlTag ( ) ) { this . htmlTagIndex = text . htmlTagIndex ; } } else { appendNode ( text ) ; } if ( text . isHtmlTag ( ) ) { switch ( text . htmlTagIndex & JAVADOC_TAGS_ID_MASK ) { case JAVADOC_CODE_TAGS_ID : text . linesBefore = this . htmlNodesPtr == - 1 ? 0 : 2 ; break ; case JAVADOC_SEPARATOR_TAGS_ID : text . linesBefore = 1 ; break ; case JAVADOC_SINGLE_BREAK_TAG_ID : if ( ! text . isClosingHtmlTag ( ) ) text . linesBefore = 1 ; break ; case JAVADOC_BREAK_TAGS_ID : if ( ! text . isClosingHtmlTag ( ) ) text . linesBefore = 1 ; } } } void appendNode ( FormatJavadocNode node ) { if ( ++ this . htmlNodesPtr == 0 ) { this . htmlNodes = new FormatJavadocNode [ DEFAULT_ARRAY_SIZE ] ; } else { if ( this . htmlNodesPtr == this . htmlNodes . length ) { int size = this . htmlNodesPtr + DEFAULT_ARRAY_SIZE ; System . arraycopy ( this . htmlNodes , 0 , ( this . htmlNodes = new FormatJavadocNode [ size ] ) , 0 , this . htmlNodesPtr ) ; } } addSeparator ( node ) ; this . htmlNodes [ this . htmlNodesPtr ] = node ; this . sourceEnd = node . sourceEnd ; } private void addSeparator ( FormatJavadocNode node ) { if ( ++ this . separatorsPtr == 0 ) { this . separators = new long [ DEFAULT_ARRAY_SIZE ] ; this . htmlIndexes = new int [ DEFAULT_ARRAY_SIZE ] ; } else { if ( this . separatorsPtr == this . separators . length ) { int size = this . separatorsPtr + DEFAULT_ARRAY_SIZE ; System . arraycopy ( this . separators , 0 , ( this . separators = new long [ size ] ) , 0 , this . separatorsPtr ) ; System . arraycopy ( this . htmlIndexes , 0 , ( this . htmlIndexes = new int [ size ] ) , 0 , this . separatorsPtr ) ; } } this . separators [ this . separatorsPtr ] = ( ( ( long ) this . sourceEnd ) << 32 ) + node . sourceStart ; this . htmlIndexes [ this . separatorsPtr ] = node . isText ( ) ? ( ( FormatJavadocText ) node ) . htmlTagIndex : - 1 ; } void clean ( ) { int length = this . separators == null ? 0 : this . separators . length ; if ( this . separatorsPtr != ( length - 1 ) ) { System . arraycopy ( this . separators , 0 , this . separators = new long [ this . separatorsPtr + 1 ] , 0 , this . separatorsPtr + 1 ) ; System . arraycopy ( this . htmlIndexes , 0 , this . htmlIndexes = new int [ this . separatorsPtr + 1 ] , 0 , this . separatorsPtr + 1 ) ; } length = this . htmlNodes == null ? 0 : this . htmlNodes . length ; if ( this . htmlNodesPtr != ( length - 1 ) ) { System . arraycopy ( this . htmlNodes , 0 , this . htmlNodes = new FormatJavadocNode [ this . htmlNodesPtr + 1 ] , 0 , this . htmlNodesPtr + 1 ) ; for ( int i = 0 ; i <= this . htmlNodesPtr ; i ++ ) { this . htmlNodes [ i ] . clean ( ) ; } } } void closeTag ( ) { this . htmlTagIndex |= JAVADOC_CLOSED_TAG ; } int getHtmlTagIndex ( ) { return this . htmlTagIndex & JAVADOC_TAGS_INDEX_MASK ; } int getHtmlTagID ( ) { return this . htmlTagIndex & JAVADOC_TAGS_ID_MASK ; } FormatJavadocNode getLastNode ( ) { if ( this . htmlNodes != null ) { return this . htmlNodes [ this . htmlNodesPtr ] ; } return null ; } public boolean isClosingHtmlTag ( ) { return this . htmlTagIndex != - 1 && ( this . htmlTagIndex & JAVADOC_CLOSED_TAG ) != 0 ; } public boolean isHtmlTag ( ) { return this . htmlTagIndex != - 1 ; } public boolean isImmutableHtmlTag ( ) { return this . htmlTagIndex != - 1 && ( this . htmlTagIndex & JAVADOC_TAGS_ID_MASK ) == JAVADOC_IMMUTABLE_TAGS_ID ; } public boolean isImmutable ( ) { return this . immutable || ( this . htmlTagIndex != - 1 && ( this . htmlTagIndex & JAVADOC_TAGS_ID_MASK ) == JAVADOC_IMMUTABLE_TAGS_ID ) ; } public boolean isTextAfterHtmlSeparatorTag ( int separatorIndex ) { int ptr = separatorIndex ; if ( ptr > this . separatorsPtr ) return false ; int tagIndex = this . htmlIndexes [ ptr ] & JAVADOC_TAGS_ID_MASK ; return tagIndex != - 1 && tagIndex == JAVADOC_SEPARATOR_TAGS_ID ; } public boolean isText ( ) { return true ; } void setHeaderLine ( int javadocLineStart ) { for ( int i = 0 ; i < this . htmlNodesPtr ; i ++ ) { FormatJavadocNode node = this . htmlNodes [ i ] ; if ( ! node . isText ( ) ) { ( ( FormatJavadocBlock ) node ) . setHeaderLine ( javadocLineStart ) ; } } } protected void toString ( StringBuffer buffer ) { StringBuffer indentation = new StringBuffer ( ) ; for ( int t = 0 ; t <= this . depth ; t ++ ) indentation . append ( '\t' ) ; buffer . append ( indentation ) ; if ( isImmutable ( ) ) { buffer . append ( "immutable " ) ; } buffer . append ( "text" ) ; super . toString ( buffer ) ; buffer . append ( " (" ) ; buffer . append ( this . separatorsPtr + 1 ) . append ( " sections, " ) ; buffer . append ( this . htmlNodesPtr + 1 ) . append ( " html tags, " ) ; buffer . append ( this . depth ) . append ( " depth, " ) ; buffer . append ( this . linesBefore ) . append ( " before, " ) ; String tagID = "no" ; switch ( getHtmlTagID ( ) ) { case JAVADOC_TAGS_ID_MASK : tagID = "mask" ; break ; case JAVADOC_SINGLE_BREAK_TAG_ID : tagID = "single break" ; break ; case JAVADOC_CODE_TAGS_ID : tagID = "code" ; break ; case JAVADOC_BREAK_TAGS_ID : tagID = "break" ; break ; case JAVADOC_IMMUTABLE_TAGS_ID : tagID = "immutable" ; break ; case JAVADOC_SEPARATOR_TAGS_ID : tagID = "separator" ; break ; } buffer . append ( tagID ) . append ( " tag id)" ) ; buffer . append ( '\n' ) ; } public void toStringDebug ( StringBuffer buffer , char [ ] source ) { if ( buffer . length ( ) > 0 ) { for ( int l = 0 ; l < this . linesBefore ; l ++ ) { buffer . append ( '\n' ) ; for ( int t = 0 ; t < this . depth ; t ++ ) buffer . append ( '\t' ) ; } } if ( this . separatorsPtr == - 1 ) { super . toStringDebug ( buffer , source ) ; return ; } int ptr = 0 ; int nextStart = this . sourceStart ; int idx = 0 ; while ( idx <= this . separatorsPtr || ( this . htmlNodesPtr != - 1 && ptr <= this . htmlNodesPtr ) ) { if ( idx > this . separatorsPtr ) { FormatJavadocNode node = this . htmlNodes [ ptr ++ ] ; node . toStringDebug ( buffer , source ) ; return ; } int end = ( int ) ( this . separators [ idx ] >>> 32 ) ; if ( this . htmlNodesPtr >= 0 && ptr <= this . htmlNodesPtr && end > this . htmlNodes [ ptr ] . sourceStart ) { FormatJavadocNode node = this . htmlNodes [ ptr ++ ] ; node . toStringDebug ( buffer , source ) ; } else { if ( idx > 1 && source [ nextStart ] != '<' ) { buffer . append ( '\n' ) ; for ( int t = 0 ; t < this . depth ; t ++ ) buffer . append ( '\t' ) ; } buffer . append ( source , nextStart , end - nextStart + 1 ) ; } nextStart = ( int ) this . separators [ idx ++ ] ; } if ( source [ nextStart ] == '<' ) { switch ( getHtmlTagID ( ) ) { case JAVADOC_CODE_TAGS_ID : buffer . append ( '\n' ) ; for ( int t = 0 ; t < this . depth ; t ++ ) buffer . append ( '\t' ) ; break ; } } buffer . append ( source , nextStart , this . sourceEnd - nextStart + 1 ) ; buffer . append ( ' ' ) ; } } </s>