<s> package org . eclipse . jdt . internal . core . jdom ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IPackageFragment ; import org . eclipse . jdt . core . jdom . * ; import org . eclipse . jdt . internal . compiler . util . SuffixConstants ; import org . eclipse . jdt . internal . core . util . CharArrayBuffer ; import org . eclipse . jdt . internal . core . util . Messages ; import org . eclipse . jdt . internal . core . util . Util ; class DOMCompilationUnit extends DOMNode implements IDOMCompilationUnit , SuffixConstants { protected String fHeader ; DOMCompilationUnit ( ) { this . fHeader = "" ; } DOMCompilationUnit ( char [ ] document , int [ ] sourceRange ) { super ( document , sourceRange , null , new int [ ] { - 1 , - 1 } ) ; this . fHeader = "" ; } protected void appendFragmentedContents ( CharArrayBuffer buffer ) { buffer . append ( getHeader ( ) ) ; appendContentsOfChildren ( buffer ) ; } public boolean canHaveChildren ( ) { return true ; } public String getHeader ( ) { return this . fHeader ; } public IJavaElement getJavaElement ( IJavaElement parent ) throws IllegalArgumentException { if ( parent . getElementType ( ) == IJavaElement . PACKAGE_FRAGMENT ) { return ( ( IPackageFragment ) parent ) . getCompilationUnit ( getName ( ) ) ; } else { throw new IllegalArgumentException ( Messages . element_illegalParent ) ; } } public String getName ( ) { IDOMType topLevelType = null ; IDOMType firstType = null ; IDOMNode child = this . fFirstChild ; while ( child != null ) { if ( child . getNodeType ( ) == IDOMNode . TYPE ) { IDOMType type = ( IDOMType ) child ; if ( firstType == null ) { firstType = type ; } if ( Flags . isPublic ( type . getFlags ( ) ) ) { topLevelType = type ; break ; } } child = child . getNextNode ( ) ; } if ( topLevelType == null ) { topLevelType = firstType ; } if ( topLevelType != null ) { return topLevelType . getName ( ) + Util . defaultJavaExtension ( ) ; } else { return null ; } } public int getNodeType ( ) { return IDOMNode . COMPILATION_UNIT ; } protected void initalizeHeader ( ) { DOMNode child = ( DOMNode ) getFirstChild ( ) ; if ( child != null ) { int childStart = child . getStartPosition ( ) ; if ( childStart > 1 ) { setHeader ( new String ( this . fDocument , 0 , childStart ) ) ; } } } public boolean isAllowableChild ( IDOMNode node ) { if ( node != null ) { int type = node . getNodeType ( ) ; return type == IDOMNode . PACKAGE || type == IDOMNode . IMPORT || type == IDOMNode . TYPE ; } else { return false ; } } protected DOMNode newDOMNode ( ) { return new DOMCompilationUnit ( ) ; } void normalize ( ILineStartFinder finder ) { super . normalize ( finder ) ; initalizeHeader ( ) ; } public void setHeader ( String comment ) { this . fHeader = comment ; fragment ( ) ; } public void setName ( String name ) { } protected void shareContents ( DOMNode node ) { super . shareContents ( node ) ; this . fHeader = ( ( DOMCompilationUnit ) node ) . fHeader ; } public String toString ( ) { return "" + getName ( ) ; } } </s>