signature:
public class TagRepository { /** * Finds and returns the first ( including the nested tags ) matching with the
 * given attribute name and value .
 * @ param parallel
 * true to internally use parallel stream . If true
 * it will split the finding task to different
 * batches and will execute the batches in
 * different threads in parallel consuming all
 * CPUs . It will perform faster in finding from
 * extremely large number of tags but at the same
 * time it will less efficient in finding from
 * small number of tags .
 * @ param attributeName
 * the name of the attribute .
 * @ param attributeValue
 * the value of the attribute
 * @ return the first matching tag with the given attribute name and value .
 * @ throws NullValueException
 * if the { @ code attributeName } or
 * { @ code attributeValue } is null
 * @ since 3.0.0
 * @ author WFF */
public AbstractHtml findOneTagByAttribute ( final boolean parallel , final String attributeName , final String attributeValue ) throws NullValueException { } }

implementation: final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { final Stream < AbstractHtml > stream = buildAllTagsStream ( parallel ) ; final Optional < AbstractHtml > any = stream . filter ( tag -> { final AbstractAttribute attribute = tag . getAttributeByName ( attributeName ) ; return attribute != null && attributeValue . equals ( attribute . getAttributeValue ( ) ) ; } ) . findAny ( ) ; if ( any . isPresent ( ) ) { return any . get ( ) ; } return null ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds and returns the first ( including the nested tags ) matching with the
 * given tag name .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ param tagName
 * the name of the tag .
 * @ return the first matching tag with the given tag name .
 * @ throws NullValueException
 * if the { @ code tagName } is null
 * @ since 3.0.0
 * @ author WFF */
public AbstractHtml findOneTagByTagName ( final boolean parallel , final String tagName ) throws NullValueException { } }

implementation: if ( tagName == null ) { throw new NullValueException ( "The tagName should not be null" ) ; } final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { final Optional < AbstractHtml > any = buildAllTagsStream ( parallel ) . filter ( tag -> { return tagName . equals ( tag . getTagName ( ) ) ; } ) . findAny ( ) ; if ( any . isPresent ( ) ) { return any . get ( ) ; } return null ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds and returns the first matching ( including from nested tags ) tag
 * ( which is assignable to the given tag class ) . < br >
 * < br >
 * < pre >
 * < code >
 * Html html = new Html ( null ) { {
 * new Head ( this ) { {
 * new TitleTag ( this ) { {
 * new NoTag ( this , " some title " ) ;
 * new Body ( this , new Id ( " one " ) ) { {
 * new Div ( this ) ;
 * TitleTag titleTag = TagRepository . findOneTagAssignableToTagClass ( TitleTag . class , html ) ;
 * System . out . println ( titleTag . getTagName ( ) ) ;
 * System . out . println ( titleTag . toHtmlString ( ) ) ;
 * / / prints
 * title
 * & lt ; title & gt ; some title & lt ; / title & gt ;
 * < / code >
 * < / pre >
 * @ param tagClass
 * the class of the tag .
 * @ return the first matching tag which is assignable to the given tag
 * class .
 * @ throws NullValueException
 * if the { @ code tagClass } is null
 * @ since 2.1.11
 * @ author WFF */
public < T extends AbstractHtml > T findOneTagAssignableToTag ( final Class < T > tagClass ) throws NullValueException { } }

implementation: return findOneTagAssignableToTag ( false , tagClass ) ;


signature:
public class TagRepository { /** * Finds and returns the first matching ( including from nested tags ) tag
 * ( which is assignable to the given tag class ) . < br >
 * < br >
 * < pre >
 * < code >
 * Html html = new Html ( null ) { {
 * new Head ( this ) { {
 * new TitleTag ( this ) { {
 * new NoTag ( this , " some title " ) ;
 * new Body ( this , new Id ( " one " ) ) { {
 * new Div ( this ) ;
 * TitleTag titleTag = TagRepository . findOneTagAssignableToTagClass ( TitleTag . class , html ) ;
 * System . out . println ( titleTag . getTagName ( ) ) ;
 * System . out . println ( titleTag . toHtmlString ( ) ) ;
 * / / prints
 * title
 * & lt ; title & gt ; some title & lt ; / title & gt ;
 * < / code >
 * < / pre >
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ param tagClass
 * the class of the tag .
 * @ return the first matching tag which is assignable to the given tag
 * class .
 * @ throws NullValueException
 * if the { @ code tagClass } is null
 * @ since 3.0.0
 * @ author WFF */
@ SuppressWarnings ( "unchecked" ) public < T extends AbstractHtml > T findOneTagAssignableToTag ( final boolean parallel , final Class < T > tagClass ) throws NullValueException { } }

implementation: final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { final Stream < AbstractHtml > stream = buildAllTagsStream ( parallel ) ; final Optional < AbstractHtml > any = stream . filter ( tag -> { return tagClass . isAssignableFrom ( tag . getClass ( ) ) && ! NoTag . class . isAssignableFrom ( tag . getClass ( ) ) ; } ) . findAny ( ) ; if ( any . isPresent ( ) ) { return ( T ) any . get ( ) ; } return null ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds and returns the first ( including the nested tags ) matching with the
 * given attribute name .
 * @ param parallel
 * true to internally use parallel stream . If true
 * it will split the finding task to different
 * batches and will execute the batches in
 * different threads in parallel consuming all
 * CPUs . It will perform faster in finding from
 * extremely large number of tags but at the same
 * time it will less efficient in finding from
 * small number of tags .
 * @ param attributeName
 * the name of the attribute .
 * @ return the first matching tag with the given attribute name and value .
 * @ throws NullValueException
 * if the { @ code attributeName } is null
 * @ since 3.0.0
 * @ author WFF */
public AbstractHtml findOneTagByAttributeName ( final boolean parallel , final String attributeName ) throws NullValueException { } }

implementation: if ( attributeName == null ) { throw new NullValueException ( "The attributeName should not be null" ) ; } final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { final Stream < AbstractHtml > stream = buildAllTagsStream ( parallel ) ; final Optional < AbstractHtml > any = stream . filter ( tag -> { return tag . getAttributeByName ( attributeName ) != null ; } ) . findAny ( ) ; if ( any . isPresent ( ) ) { return any . get ( ) ; } return null ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds tags by attribute instance .
 * @ param attribute
 * @ return all tags which are consuming the given attribute instance . It
 * returns the only tags consuming the given attribute object which
 * are available in browserPage .
 * @ throws NullValueException
 * if the { @ code attribute } is null
 * @ since 2.1.8
 * @ author WFF */
public Collection < AbstractHtml > findTagsByAttribute ( final AbstractAttribute attribute ) throws NullValueException { } }

implementation: if ( attribute == null ) { throw new NullValueException ( "attribute cannot be null" ) ; } final Collection < AbstractHtml > tags = new HashSet < > ( ) ; for ( final AbstractHtml ownerTag : attribute . getOwnerTags ( ) ) { if ( browserPage . contains ( ownerTag ) ) { tags . add ( ownerTag ) ; } } return tags ;


signature:
public class TagRepository { /** * Finds one tag by attribute instance .
 * @ param attribute
 * @ return the first matching tag consuming the given attribute instance .
 * There must be a consuming tag which is available in the
 * browserPage instance otherwise returns null .
 * @ throws NullValueException
 * if the { @ code attribute } is null
 * @ since 2.1.8
 * @ author WFF */
public AbstractHtml findOneTagByAttribute ( final AbstractAttribute attribute ) { } }

implementation: if ( attribute == null ) { throw new NullValueException ( "attribute cannot be null" ) ; } for ( final AbstractHtml ownerTag : attribute . getOwnerTags ( ) ) { if ( browserPage . contains ( ownerTag ) ) { return ownerTag ; } } return null ;


signature:
public class TagRepository { /** * Inserts or replaces ( if already exists ) the key bmObject pair in the
 * wffObjects property of tag . The conventional JavaScript object of
 * { @ code WffBMObject } will be set to the { @ code wffObjects } property of the
 * given tag at client side .
 * @ param tag
 * the tag object on which the given bmObject to be set .
 * @ param key
 * key to set in wffObjects property of the tag .
 * @ param bmObject
 * @ throws InvalidTagException
 * if the given instance is of NoTag / Blank
 * @ throws NullValueException
 * if tag , key or bmObject is null
 * @ since 2.1.8
 * @ author WFF */
public void upsert ( final AbstractHtml tag , final String key , final WffBMObject bmObject ) throws InvalidTagException , NullValueException { } }

implementation: if ( tag == null ) { throw new NullValueException ( "tag cannot be null" ) ; } if ( tag instanceof NoTag ) { throw new InvalidTagException ( "NoTag and Blank tag are not allowed to use" ) ; } if ( key == null ) { throw new NullValueException ( "key cannot be null" ) ; } if ( bmObject == null ) { throw new NullValueException ( "bmObject cannot be null" ) ; } if ( ! browserPage . contains ( tag ) ) { throw new InvalidTagException ( "The given tag is not available in the corresponding browserPage instance." ) ; } AbstractHtmlRepository . addWffData ( tag , key , bmObject ) ;


signature:
public class TagRepository { /** * Inserts or replaces ( if already exists ) the key bmArray pair in the
 * wffObjects property of tag . The conventional JavaScript array of
 * { @ code WffBMArray } will be set to the { @ code wffObjects } property of the
 * given tag at client side .
 * @ param tag
 * the tag object on which the given bmArray to be set .
 * @ param key
 * key to set in wffObjects property of the tag .
 * @ param bmArray
 * @ throws InvalidTagException
 * if the given instance is of NoTag / Blank
 * @ throws NullValueException
 * if tag , key or bmArray is null
 * @ since 2.1.8
 * @ author WFF */
public void upsert ( final AbstractHtml tag , final String key , final WffBMArray bmArray ) throws InvalidTagException , NullValueException { } }

implementation: if ( tag == null ) { throw new NullValueException ( "tag cannot be null" ) ; } if ( tag instanceof NoTag ) { throw new InvalidTagException ( "NoTag and Blank tag are not allowed to use" ) ; } if ( key == null ) { throw new NullValueException ( "key cannot be null" ) ; } if ( bmArray == null ) { throw new NullValueException ( "bmArray cannot be null" ) ; } if ( ! browserPage . contains ( tag ) ) { throw new InvalidTagException ( "The given tag is not available in the corresponding browserPage instance." ) ; } AbstractHtmlRepository . addWffData ( tag , key , bmArray ) ;


signature:
public class TagRepository { /** * Deletes the key - WffBMObject / WffBMArray pair from the { @ code wffObjects }
 * property of tag .
 * @ param tag
 * @ param key
 * @ throws InvalidTagException
 * if the given instance is of NoTag / Blank
 * @ throws NullValueException
 * if tag or key is null
 * @ since 2.1.8
 * @ author WFF */
public void delete ( final AbstractHtml tag , final String key ) throws InvalidTagException , NullValueException { } }

implementation: if ( tag == null ) { throw new NullValueException ( "tag cannot be null" ) ; } if ( tag instanceof NoTag ) { throw new InvalidTagException ( "NoTag and Blank tag are not allowed to use" ) ; } if ( key == null ) { throw new NullValueException ( "key cannot be null" ) ; } if ( ! browserPage . contains ( tag ) ) { throw new InvalidTagException ( "The given tag is not available in the corresponding browserPage instance." ) ; } AbstractHtmlRepository . removeWffData ( tag , key ) ;


signature:
public class TagRepository { /** * gets the WffBMObject / WffBMArray from the { @ code wffObjects } property of
 * tag in the form of WffBMData .
 * @ param tag
 * @ param key
 * @ return WffBMData which may be type casted to either WffBMObject or
 * WffBMArray .
 * @ throws InvalidTagException
 * if the given instance is of NoTag / Blank
 * @ throws NullValueException
 * if tag or key is null
 * @ since 3.0.1
 * @ author WFF */
public WffBMData getWffBMData ( final AbstractHtml tag , final String key ) throws InvalidTagException , NullValueException { } }

implementation: if ( tag == null ) { throw new NullValueException ( "tag cannot be null" ) ; } if ( tag instanceof NoTag ) { throw new InvalidTagException ( "NoTag and Blank tag are not allowed to use" ) ; } if ( key == null ) { throw new NullValueException ( "key cannot be null" ) ; } if ( ! browserPage . contains ( tag ) ) { throw new InvalidTagException ( "The given tag is not available in the corresponding browserPage instance." ) ; } return AbstractHtmlRepository . getWffData ( tag , key ) ;


signature:
public class TagRepository { /** * Finds all tags excluding { @ code NoTag } . To get { @ code NoTag } included
 * collection use static method
 * { @ code TagRepository . findAllTags ( boolean parallel , AbstractHtml . . . fromTags ) } .
 * This method may perform better than the static method .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ return the collection of all tags
 * @ since 3.0.0
 * @ author WFF */
public Collection < AbstractHtml > findAllTags ( final boolean parallel ) { } }

implementation: final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { return buildAllTagsStream ( parallel ) . collect ( Collectors . toSet ( ) ) ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds all tags excluding { @ code NoTag } .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ return the stream of all tags
 * @ since 3.0.0
 * @ author WFF */
public Stream < AbstractHtml > buildAllTagsStream ( final boolean parallel ) { } }

implementation: return parallel ? tagByWffId . values ( ) . parallelStream ( ) : tagByWffId . values ( ) . stream ( ) ;


signature:
public class TagRepository { /** * Finds all tags including the nested tags ( and including { @ code NoTag } )
 * from the given tags .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ param fromTags
 * to find all tags from these tags
 * @ return all tags including the nested tags from the given tags .
 * @ throws NullValueException
 * if { @ code fromTags } is null
 * @ since 3.0.0
 * @ author WFF */
public static Collection < AbstractHtml > findAllTags ( final boolean parallel , final AbstractHtml ... fromTags ) throws NullValueException { } }

implementation: if ( fromTags == null ) { throw new NullValueException ( "fromTags cannot be null" ) ; } final Collection < Lock > locks = getReadLocks ( fromTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { return getAllNestedChildrenIncludingParent ( parallel , fromTags ) . collect ( Collectors . toSet ( ) ) ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds all attributes from all tags .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ return the collection of all attributes
 * @ since 3.0.0
 * @ author WFF */
public Collection < AbstractAttribute > findAllAttributes ( final boolean parallel ) { } }

implementation: final Collection < Lock > locks = getReadLocks ( rootTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { return buildAllAttributesStream ( parallel ) . collect ( Collectors . toSet ( ) ) ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Finds all attributes as stream from all tags .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ return the stream of all attributes
 * @ since 3.0.0
 * @ author WFF */
public Stream < AbstractAttribute > buildAllAttributesStream ( final boolean parallel ) { } }

implementation: final Stream < AbstractAttribute > attributesStream = buildAllTagsStream ( parallel ) . filter ( tag -> tag . getAttributes ( ) != null ) . map ( tag -> { return tag . getAttributes ( ) ; } ) . flatMap ( attributes -> attributes . stream ( ) ) ; return attributesStream ;


signature:
public class TagRepository { /** * Finds all attributes from the given tags
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ param fromTags
 * the tags to find the attributes from .
 * @ return the all attributes from the given tags including the nested tags .
 * @ throws NullValueException
 * if { @ code fromTags } is null
 * @ since 3.0.0
 * @ author WFF */
public static Collection < AbstractAttribute > findAllAttributes ( final boolean parallel , final AbstractHtml ... fromTags ) throws NullValueException { } }

implementation: if ( fromTags == null ) { throw new NullValueException ( "fromTags cannot be null" ) ; } final Collection < Lock > locks = getReadLocks ( fromTags ) ; for ( final Lock lock : locks ) { lock . lock ( ) ; } try { return getAllNestedChildrenIncludingParent ( parallel , fromTags ) . filter ( tag -> tag . getAttributes ( ) != null ) . map ( tag -> { return tag . getAttributes ( ) ; } ) . flatMap ( attributes -> attributes . stream ( ) ) . collect ( Collectors . toSet ( ) ) ; } finally { for ( final Lock lock : locks ) { lock . unlock ( ) ; } }


signature:
public class TagRepository { /** * Checks the existence of a tag instance .
 * @ param tag
 * @ return true if the given tag instance exists anywhere in the browser
 * page .
 * @ throws NullValueException
 * if the tag is null
 * @ throws InvalidTagException
 * if the given tag is { @ code NoTag } .
 * @ since 2.1.8
 * @ author WFF */
public boolean exists ( final AbstractHtml tag ) throws NullValueException , InvalidTagException { } }

implementation: if ( tag == null ) { throw new NullValueException ( "tag cannot be null" ) ; } if ( NoTag . class . isAssignableFrom ( tag . getClass ( ) ) ) { throw new InvalidTagException ( "classes like NoTag.class cannot be used to find tags as it's not a logical tag in behaviour." ) ; } return browserPage . contains ( tag ) ;


signature:
public class TagRepository { /** * Checks the existence of an attribute instance .
 * @ param attribute
 * @ return true if the given attribute instance exists anywhere in the
 * browser page .
 * @ throws NullValueException
 * if the { @ code attribute } is null
 * @ since 2.1.8
 * @ author WFF */
public boolean exists ( final AbstractAttribute attribute ) throws NullValueException { } }

implementation: if ( attribute == null ) { throw new NullValueException ( "attribute cannot be null" ) ; } for ( final AbstractHtml ownerTag : attribute . getOwnerTags ( ) ) { if ( browserPage . contains ( ownerTag ) ) { return true ; } } return false ;


signature:
public class TagRepository { /** * Executes the JavaScript at the client browser page . This method is
 * equalent to calling < br >
 * < pre >
 * < code >
 * try {
 * browserPage . performBrowserPageAction (
 * BrowserPageAction . getActionByteBufferForExecuteJS ( js ) ) ;
 * return true ;
 * } catch ( final UnsupportedEncodingException e ) {
 * e . printStackTrace ( ) ;
 * < / code >
 * < / pre >
 * Eg : -
 * < pre >
 * < code >
 * tagRepository . executeJs ( " alert ( ' This is an alert ' ) ; " ) ;
 * < / code >
 * < / pre >
 * This shows an alert in the browser : < b > < i > This is an alert < / i > < / b > .
 * @ param js
 * the JavaScript to be executed at the client browser page .
 * @ return true if the given js string is in a supported encoding otherwise
 * false . Returning true DOESN ' T mean the given js string is valid ,
 * successfully sent to the client browser to execute or executed
 * successfully .
 * @ since 2.1.11
 * @ author WFF */
public boolean executeJs ( final String js ) { } }

implementation:
try { browserPage . performBrowserPageAction ( BrowserPageAction . getActionByteBufferForExecuteJS ( js ) ) ; return true ; } catch ( final UnsupportedEncodingException e ) { // NOP
} return false ;


signature:
public class TagRepository { /** * Builds all attributes stream from the given tags .
 * @ param parallel
 * true to internally use parallel stream . If true it
 * will split the finding task to different batches and
 * will execute the batches in different threads in
 * parallel consuming all CPUs . It will perform faster
 * in finding from extremely large number of tags but at
 * the same time it will less efficient in finding from
 * small number of tags .
 * @ param fromTags
 * the tags to build stream of nested children ' s
 * attributes from .
 * @ return { @ code Stream < AbstractAttribute > }
 * @ since 3.0.0
 * @ author WFF */
public static Stream < AbstractAttribute > buildAllAttributesStream ( final boolean parallel , final AbstractHtml ... fromTags ) { } }

implementation: final Stream < AbstractAttribute > attributesStream = getAllNestedChildrenIncludingParent ( parallel , fromTags ) . filter ( tag -> tag . getAttributes ( ) != null ) . map ( tag -> { return tag . getAttributes ( ) ; } ) . flatMap ( attributes -> attributes . stream ( ) ) ; return attributesStream ;


signature:
public class BorderLeft { /** * checks the given css value is valid for this class . It does ' t do a strict
 * validation .
 * @ param cssValue
 * @ return
 * @ since 1.0.0
 * @ author WFF */
public static boolean isValid ( final String cssValue ) { } }

implementation:
// TODO modify to make a strict validation
if ( cssValue == null || StringUtil . isBlank ( cssValue ) ) { return false ; } final List < String > cssValueParts = CssValueUtil . split ( cssValue ) ; BorderLeftWidth borderLeftWidth = null ; BorderLeftStyle borderLeftStyle = null ; BorderLeftColor borderLeftColor = null ; for ( final String eachPart : cssValueParts ) { boolean invalid = true ; if ( borderLeftWidth == null && BorderLeftWidth . isValid ( eachPart ) ) { borderLeftWidth = new BorderLeftWidth ( eachPart ) ; invalid = false ; } else if ( borderLeftStyle == null && BorderLeftStyle . isValid ( eachPart ) ) { borderLeftStyle = BorderLeftStyle . getThis ( eachPart ) ; invalid = false ; } else if ( borderLeftColor == null && BorderLeftColor . isValid ( eachPart ) ) { borderLeftColor = new BorderLeftColor ( eachPart ) ; invalid = false ; } if ( invalid ) { return false ; } } return borderLeftWidth != null || borderLeftStyle != null || borderLeftColor != null ;


signature:
public class CssEnumUtil { /** * checks whether the given { @ code cssValues } contains the given
 * { @ code cssValue } .
 * @ param cssValue
 * the value to be checked .
 * @ param cssValues
 * the { @ code cssValue } will be checked in this
 * { @ code cssValues } .
 * @ param lowestLength
 * the lowest length of the string contained in the
 * given { @ code cssValues } .
 * @ param highestLength
 * the highest length of the string contained in
 * the given { @ code cssValues } .
 * @ return true if the given { @ code cssValues } contains the given
 * { @ code cssValue } , and the length of { @ code cssValue } is not less
 * than { @ code lowestLength } and not greater than
 * { @ code highestLength } .
 * @ since 1.0.0
 * @ author WFF */
public static boolean contains ( final String cssValue , final Collection < String > cssValues , final int lowestLength , final int highestLength ) { } }

implementation: if ( cssValue == null || cssValue . length ( ) < lowestLength || cssValue . length ( ) > highestLength ) { return false ; } final boolean contains = cssValues . contains ( TagStringUtil . toUpperCase ( cssValue ) ) ; return contains ;


signature:
public class ListStyleImage { /** * To check whether the given { @ code cssValue } is valid for this class .
 * @ param cssValue
 * @ return true if the given { @ code cssValue } is valid for this class .
 * @ since 1.0.0
 * @ author WFF */
public static boolean isValid ( final String cssValue ) { } }

implementation: String trimmedCssValue = null ; if ( cssValue == null ) { return false ; } else if ( ( trimmedCssValue = StringUtil . strip ( cssValue ) ) . equalsIgnoreCase ( INITIAL ) || trimmedCssValue . equalsIgnoreCase ( INHERIT ) || trimmedCssValue . equalsIgnoreCase ( NONE ) ) { return true ; } else if ( trimmedCssValue . toLowerCase ( ) . startsWith ( "url(" ) && trimmedCssValue . endsWith ( ")" ) ) { return true ; } return false ;


signature:
public class TextArea { /** * sets the child text for this tag .
 * @ param text
 * String which needs to be shown as a child of this tag .
 * @ since 2.1.4 */
public void setChildText ( final String text ) { } }

implementation: if ( text == null || text . isEmpty ( ) ) { removeAllChildren ( ) ; } else { addInnerHtml ( new NoTag ( null , text ) ) ; }


signature:
public class TextArea { /** * sets the child text for this tag .
 * @ param updateClient
 * true to update client browser page if it is
 * available . The default value is true but it will
 * be ignored if there is no client browser page .
 * @ param text
 * String which needs to be shown as a child of this
 * tag .
 * @ since 2.1.15 */
public void setChildText ( final boolean updateClient , final String text ) { } }

implementation: if ( text == null || text . isEmpty ( ) ) { removeAllChildren ( ) ; } else { addInnerHtmls ( updateClient , new NoTag ( null , text ) ) ; }


signature:
public class TextArea { /** * gets the child text set for this tag .
 * @ return the child text set for this tag in string format . If there is no
 * children / child text then will return empty string .
 * @ since 2.1.4 */
public String getChildText ( ) { } }

implementation: final List < AbstractHtml > children = getChildren ( ) ; if ( children . size ( ) > 0 ) { final StringBuilder builder = new StringBuilder ( ) ; for ( final AbstractHtml child : children ) { builder . append ( child . toHtmlString ( ) ) ; } return builder . toString ( ) ; } return "" ;


signature:
public class BorderColor { /** * ( non - Javadoc )
 * @ see
 * com . webfirmframework . wffweb . informer . StateChangeInformer # stateChanged (
 * java . lang . Object ) */
@ Override public void stateChanged ( final CssProperty stateChangedObject ) { } }

implementation: if ( stateChangedObject instanceof BorderTopColor ) { final BorderTopColor borderTopColor = ( BorderTopColor ) stateChangedObject ; if ( BorderTopColor . INITIAL . equals ( borderTopColor . getCssValue ( ) ) || BorderTopColor . INHERIT . equals ( borderTopColor . getCssValue ( ) ) ) { throw new InvalidValueException ( "borderTopColor cannot have initial/inherit as its cssValue" ) ; } } else if ( stateChangedObject instanceof BorderRightColor ) { final BorderRightColor borderRightColor = ( BorderRightColor ) stateChangedObject ; if ( BorderRightColor . INITIAL . equals ( borderRightColor . getCssValue ( ) ) || BorderRightColor . INHERIT . equals ( borderRightColor . getCssValue ( ) ) ) { throw new InvalidValueException ( "borderRightColor cannot have initial/inherit as its cssValue" ) ; } } else if ( stateChangedObject instanceof BorderBottomColor ) { final BorderBottomColor borderBottomColor = ( BorderBottomColor ) stateChangedObject ; if ( BorderBottomColor . INITIAL . equals ( borderBottomColor . getCssValue ( ) ) || BorderBottomColor . INHERIT . equals ( borderBottomColor . getCssValue ( ) ) ) { throw new InvalidValueException ( "borderBottomColor cannot have initial/inherit as its cssValue" ) ; } } else if ( stateChangedObject instanceof BorderLeftColor ) { final BorderLeftColor borderLeftColor = ( BorderLeftColor ) stateChangedObject ; if ( BorderLeftColor . INITIAL . equals ( borderLeftColor . getCssValue ( ) ) || BorderLeftColor . INHERIT . equals ( borderLeftColor . getCssValue ( ) ) ) { throw new InvalidValueException ( "borderLeftColor cannot have initial/inherit as its cssValue" ) ; } } assignProducedCssValue ( borderTopColor , borderRightColor , borderBottomColor , borderLeftColor ) ;


signature:
public class WebkitFlexGrow { /** * validates if the given cssValue is valid for this class .
 * @ param cssValue
 * the value to check .
 * @ return true if valid and false if invalid .
 * @ author WFF
 * @ since 1.0.0 */
public static boolean isValid ( final String cssValue ) { } }

implementation: final String trimmedCssValue = TagStringUtil . toLowerCase ( StringUtil . strip ( cssValue ) ) ; if ( StringUtil . containsSpace ( trimmedCssValue ) ) { return false ; } try { Float . parseFloat ( trimmedCssValue ) ; return true ; } catch ( final NumberFormatException e ) { } return PREDEFINED_CONSTANTS . contains ( trimmedCssValue ) ;


signature:
public class WffBinaryMessageOutputStreamer { /** * writes maximum bytes at chuckSize
 * @ param bytes
 * @ throws IOException
 * @ since 1.1.2
 * @ author WFF */
private void writeByChunk ( final byte [ ] bytes ) throws IOException { } }

implementation: final int chunkSize = this . chunkSize ; if ( bytes . length == 0 ) { return ; } if ( chunkSize < bytes . length && chunkSize > 0 ) { int remaining = bytes . length ; int offset = 0 ; while ( remaining > 0 ) { if ( chunkSize < remaining ) { os . write ( bytes , offset , chunkSize ) ; remaining -= chunkSize ; offset += chunkSize ; } else { os . write ( bytes , offset , remaining ) ; remaining = 0 ; } } } else { os . write ( bytes ) ; }


signature:
public class DocType { /** * ( non - Javadoc )
 * @ see com . webfirmframework . wffweb . tag . html . AbstractHtml # toHtmlString ( ) */
@ Override public String toHtmlString ( ) { } }

implementation: if ( prependDocType ) { return new String ( ( docTypeTag + "\n" + super . toHtmlString ( ) ) . getBytes ( getCharset ( ) ) , getCharset ( ) ) ; } return super . toHtmlString ( ) ;


signature:
public class DocType { /** * ( non - Javadoc )
 * @ see com . webfirmframework . wffweb . tag . html . AbstractHtml # toBigHtmlString ( ) */
@ Override public String toBigHtmlString ( ) { } }

implementation: if ( prependDocType ) { return new String ( ( docTypeTag + "\n" + super . toBigHtmlString ( ) ) . getBytes ( getCharset ( ) ) , getCharset ( ) ) ; } return super . toBigHtmlString ( ) ;


signature:
public class DocType { /** * ( non - Javadoc )
 * @ see
 * com . webfirmframework . wffweb . tag . html . AbstractHtml # toHtmlString ( java . nio .
 * charset . Charset ) */
@ Override public String toHtmlString ( final Charset charset ) { } }

implementation:
final Charset previousCharset = super . getCharset ( ) ; try { super . setCharset ( charset ) ; if ( prependDocType ) { // assigning it to new variable is very important here as this
// line of code should invoke before finally block
final String htmlString = new String ( ( super . toHtmlString ( super . getCharset ( ) ) ) . getBytes ( super . getCharset ( ) ) , getCharset ( ) ) ; return htmlString ; } // assigning it to new variable is very important here as this line
// of code should invoke before finally block
final String htmlString = super . toHtmlString ( super . getCharset ( ) ) ; return htmlString ; } finally { super . setCharset ( previousCharset ) ; }


signature:
public class DocType { /** * ( non - Javadoc )
 * @ see
 * com . webfirmframework . wffweb . tag . html . AbstractHtml # toOutputStream ( java . io .
 * OutputStream ) */
@ Override public int toOutputStream ( final OutputStream os ) throws IOException { } }

implementation: int docTypeTagLength = 0 ; if ( prependDocType ) { final byte [ ] docTypeTagBytes = ( docTypeTag + "\n" ) . getBytes ( getCharset ( ) ) ; os . write ( docTypeTagBytes ) ; docTypeTagLength = docTypeTagBytes . length ; } return docTypeTagLength + super . toOutputStream ( os ) ;


signature:
public class OutlineWidth { /** * validates if the given cssValue is valid for this class .
 * @ param cssValue
 * the value to check .
 * @ return true if valid and false if invalid .
 * @ author WFF
 * @ since 1.0.0 */
public static boolean isValid ( final String cssValue ) { } }

implementation: final String trimmedCssValue = TagStringUtil . toLowerCase ( StringUtil . strip ( cssValue ) ) ; if ( StringUtil . containsSpace ( trimmedCssValue ) ) { return false ; } if ( CssLengthUtil . getLengthValueAsPremitiveAndUnit ( trimmedCssValue ) . length == 2 ) { return true ; } return PREDEFINED_CONSTANTS . contains ( trimmedCssValue ) ;


signature:
public class WebkitFlex { /** * checks the given css value is valid for this class . It does ' t do a strict
 * validation .
 * @ param cssValue
 * @ return
 * @ since 1.0.0
 * @ author WFF */
public static boolean isValid ( final String cssValue ) { } }

implementation:
// TODO modify to make a strict validation
if ( cssValue == null || StringUtil . isBlank ( cssValue ) ) { return false ; } final String [ ] cssValueParts = StringUtil . splitBySpace ( cssValue ) ; WebkitFlexGrow webkitFlexGrow = null ; WebkitFlexShrink webkitFlexShrink = null ; WebkitFlexBasis webkitFlexBasis = null ; for ( final String eachPart : cssValueParts ) { boolean invalid = true ; if ( webkitFlexGrow == null && WebkitFlexGrow . isValid ( eachPart ) ) { webkitFlexGrow = new WebkitFlexGrow ( eachPart ) ; invalid = false ; } else if ( webkitFlexShrink == null && WebkitFlexShrink . isValid ( eachPart ) ) { webkitFlexShrink = new WebkitFlexShrink ( eachPart ) ; invalid = false ; } else if ( webkitFlexBasis == null && WebkitFlexBasis . isValid ( eachPart ) ) { webkitFlexBasis = new WebkitFlexBasis ( eachPart ) ; invalid = false ; } if ( invalid ) { return false ; } } return webkitFlexGrow != null || webkitFlexShrink != null || webkitFlexBasis != null ;


signature:
public class EmbeddedTomcat { /** * Sets the contextPath for the webapplication
 * @ param contextPath The new contextPath . Has to start with / or is the empty " "
 * string
 * @ return The embedded Tomcat */
public EmbeddedTomcat setContextPath ( String contextPath ) { } }

implementation: if ( contextPath == null || ! contextPath . equals ( "" ) && ! contextPath . startsWith ( "/" ) ) { throw new IllegalArgumentException ( "contextPath must be the empty string \"\" or a path starting with /" ) ; } this . contextPath = contextPath ; return this ;


signature:
public class EmbeddedTomcat { /** * Convenient method for adding a context environment to the embedded Tomcat . Creates
 * a < code > ContextEnvironment < / code > object and adds it to the list of the context
 * environments .
 * Example : < br >
 * Tomcat context xml file
 * < pre >
 * & lt ; Environment name = " aparam "
 * value = " test "
 * type = " java . lang . String "
 * override = " false " / & gt ;
 * < / pre >
 * Programmatic way :
 * < pre >
 * embeddedTomcat . addContextEnvironment ( & quot ; aparam & quot ; , & quot ; test & quot ; , & quot ; java . lang . String & quot ; ) ;
 * < / pre >
 * @ param name name of the context environment
 * @ param value value of the context environment
 * @ param type type of the context environment
 * @ return The embedded Tomcat
 * @ see ContextEnvironment
 * @ see NamingResources # addEnvironment ( ContextEnvironment )
 * @ see EmbeddedTomcat # addContextEnvironment ( ContextEnvironment )
 * @ see EmbeddedTomcat # addContextEnvironmentString ( String , String ) */
public EmbeddedTomcat addContextEnvironment ( String name , String value , String type ) { } }

implementation: final ContextEnvironment env = new ContextEnvironment ( ) ; env . setType ( type ) ; env . setName ( name ) ; env . setValue ( value ) ; addContextEnvironment ( env ) ; return this ;


signature:
public class EmbeddedTomcat { /** * Sets the location of the context file that configures this web application
 * @ param contextFile Location of the context file
 * @ return The embedded Tomcat instance */
public EmbeddedTomcat setContextFile ( String contextFile ) { } }

implementation: try { this . contextFileURL = new File ( contextFile ) . toURI ( ) . toURL ( ) ; } catch ( MalformedURLException e ) { throw new RuntimeException ( e ) ; } return this ;


signature:
public class EmbeddedTomcat { /** * Read ContextEnvironment and ContextResource definition from a text file .
 * @ param contextFile Location to a context file
 * @ return The embedded Tomcat
 * @ deprecated use { @ link # setContextFile ( String ) } */
@ Deprecated public EmbeddedTomcat addContextEnvironmentAndResourceFromFile ( String contextFile ) { } }

implementation: try { setContextFile ( new File ( contextFile ) . toURI ( ) . toURL ( ) ) ; } catch ( MalformedURLException e ) { throw new RuntimeException ( e ) ; } return this ;


signature:
public class Content { /** * Construct a content filter from a path filter and a content type .
 * @ param filter - - - path filter
 * @ param contentType
 * @ return */
public static < T > Filter < T > filter ( final Path . Filter filter , final Content . Type < T > contentType ) { } }

implementation: return new Filter < T > ( ) { @ Override public boolean matches ( Path . ID id , Content . Type < T > ct ) { return ct == contentType && filter . matches ( id ) ; } @ Override public boolean matchesSubpath ( Path . ID id ) { return filter . matchesSubpath ( id ) ; } @ Override public String toString ( ) { return filter . toString ( ) ; } } ;


signature:
public class Content { /** * Combine two filters together produce one filter whose items must be
 * matched by at least one of the original filters .
 * @ param f1
 * @ param f2
 * @ return */
public static < T > Filter < T > or ( final Filter < T > f1 , final Filter < T > f2 ) { } }

implementation: return new Filter < T > ( ) { @ Override public boolean matches ( Path . ID id , Content . Type < T > ct ) { return f1 . matches ( id , ct ) || f2 . matches ( id , ct ) ; } @ Override public boolean matchesSubpath ( Path . ID id ) { return f1 . matchesSubpath ( id ) || f2 . matchesSubpath ( id ) ; } @ Override public String toString ( ) { return f1 . toString ( ) + "|" + f2 . toString ( ) ; } } ;


signature:
public class ConfigFileParser { /** * Read a < code > ConfigFile < / code > from the token stream . If the stream is
 * invalid in some way ( e . g . contains a syntax error , etc ) then a
 * < code > SyntaxError < / code > is thrown .
 * @ return */
public ConfigFile read ( ) { } }

implementation:
List < Declaration > declarations = new ArrayList < > ( ) ; skipWhiteSpace ( ) ; while ( index < tokens . size ( ) ) { Token lookahead = tokens . get ( index ) ; if ( lookahead . kind == LeftSquare ) { declarations . add ( parseSection ( ) ) ; } else { declarations . add ( parseKeyValuePair ( ) ) ; } skipWhiteSpace ( ) ; } // FIXME : why do we need this ?
file . setDeclarations ( new Tuple < > ( declarations ) ) ; return file ;


signature:
public class ConfigFileParser { /** * Check that the End - Of - File has not been reached . This method should be
 * called from contexts where we are expecting something to follow . */
private void checkNotEof ( ) { } }

implementation:
skipWhiteSpace ( ) ; if ( index >= tokens . size ( ) ) { if ( index > 0 ) { syntaxError ( "unexpected end-of-file" , tokens . get ( index - 1 ) ) ; } else { // I believe this is actually dead - code , since checkNotEof ( )
// won ' t be called before at least one token is matched .
throw new SyntacticException ( "unexpected end-of-file" , file . getEntry ( ) , null ) ; } }


signature:
public class ConfigFileParser { /** * Define what is considered to be linespace .
 * @ param token
 * @ return */
private boolean isLineSpace ( Token token ) { } }

implementation: return token . kind == Token . Kind . Indent || token . kind == Token . Kind . LineComment ;


signature:
public class ConfigFileParser { /** * Parse a string constant whilst interpreting all escape characters .
 * @ param v
 * @ return */
protected String parseString ( String v ) { } }

implementation:
/* * Parsing a string requires several steps to be taken . First , we need
 * to strip quotes from the ends of the string . */
v = v . substring ( 1 , v . length ( ) - 1 ) ; StringBuffer result = new StringBuffer ( ) ; // Second , step through the string and replace escaped characters
for ( int i = 0 ; i < v . length ( ) ; i ++ ) { if ( v . charAt ( i ) == '\\' ) { if ( v . length ( ) <= i + 1 ) { throw new RuntimeException ( "unexpected end-of-string" ) ; } else { char replace = 0 ; int len = 2 ; switch ( v . charAt ( i + 1 ) ) { case 'b' : replace = '\b' ; break ; case 't' : replace = '\t' ; break ; case 'n' : replace = '\n' ; break ; case 'f' : replace = '\f' ; break ; case 'r' : replace = '\r' ; break ; case '"' : replace = '\"' ; break ; case '\'' : replace = '\'' ; break ; case '\\' : replace = '\\' ; break ; case 'u' : len = 6 ; // unicode escapes are six digits long ,
// including " slash u "
String unicode = v . substring ( i + 2 , i + 6 ) ; replace = ( char ) Integer . parseInt ( unicode , 16 ) ; // unicode
i = i + 5 ; break ; default : throw new RuntimeException ( "unknown escape character" ) ; } result = result . append ( replace ) ; i = i + 1 ; } } else { result = result . append ( v . charAt ( i ) ) ; } } return result . toString ( ) ;


signature:
public class AbstractLexer { /** * Scan the given input stream and produce a list of tokens , or an error .
 * @ return */
public List < Token > scan ( ) throws Error { } }

implementation:
ArrayList < Token > tokens = new ArrayList < > ( ) ; int pos = 0 ; while ( pos < input . length ( ) ) { int start = pos ; for ( int i = 0 ; i != rules . length ; ++ i ) { Rule rule = rules [ i ] ; int left = input . length ( ) - pos ; if ( left >= rule . lookahead ( ) ) { Token t = rule . match ( input , pos ) ; if ( t != null ) { tokens . add ( t ) ; pos = pos + t . text . length ( ) ; break ; // restart rule application loop
} } } if ( pos == start ) { throw new Error ( "unrecognised token encountered (" + input . charAt ( pos ) + ")" , pos ) ; } } return tokens ;


signature: public class AbstractLexer { private static boolean matchString ( StringBuffer input , int pos , java . lang . String syntax ) { } }

implementation: int diff = input . length ( ) - pos ; if ( syntax . length ( ) > diff ) { return false ; } else { for ( int i = 0 ; i != syntax . length ( ) ; ++ i ) { if ( syntax . charAt ( i ) != input . charAt ( pos + i ) ) { return false ; } } return true ; }


signature:
public class CommandParser { /** * Parse a given set of command - line arguments starting from a given index
 * position to produce an appropriate command template .
 * @ param args
 * @ param index */
protected Command . Template parse ( Command . Descriptor root , String [ ] args , int index ) { } }

implementation: ArrayList < Command . Option > options = new ArrayList < > ( ) ; ArrayList < String > arguments = new ArrayList < > ( ) ; Command . Template sub = null ; while ( index < args . length ) { String arg = args [ index ] ; if ( isLongOption ( arg ) ) { options . add ( parseLongOption ( root , args [ index ] ) ) ; } else if ( isCommand ( arg , root . getCommands ( ) ) ) { Command . Descriptor cmd = getCommandDescriptor ( arg , root . getCommands ( ) ) ; sub = parse ( cmd , args , index + 1 ) ; break ; } else { arguments . add ( arg ) ; } index = index + 1 ; } Command . Options optionMap = new OptionsMap ( options , root . getOptionDescriptors ( ) ) ; return new ConcreteTemplate ( root , optionMap , arguments , sub ) ;


signature:
public class CommandParser { /** * Parse an option which is either a string of the form " - - name " or
 * " - - name = data " . Here , name is an arbitrary string and data is a string
 * representing a data value .
 * @ param arg
 * The option argument to be parsed .
 * @ return */
private static Pair < String , Object > parseOption ( String arg ) { } }

implementation: arg = arg . substring ( 2 ) ; String [ ] split = arg . split ( "=" ) ; Object data = null ; if ( split . length > 1 ) { data = parseData ( split [ 1 ] ) ; } return new Pair < > ( split [ 0 ] , data ) ;


signature:
public class CommandParser { /** * Parse a given string representing a data value into an instance of Data .
 * @ param str
 * The string to be parsed .
 * @ return */
private static Object parseData ( String str ) { } }

implementation:
if ( str . equals ( "true" ) ) { return true ; } else if ( str . equals ( "false" ) ) { return false ; } else if ( Character . isDigit ( str . charAt ( 0 ) ) ) { // number
return Integer . parseInt ( str ) ; } else { return str ; }


signature:
public class Help { /** * Print usage information to the console . */
protected void printUsage ( ) { } }

implementation: List < Command . Descriptor > descriptors = project . getParent ( ) . getCommandDescriptors ( ) ; out . println ( "usage: wy [--verbose] command [<options>] [<args>]" ) ; out . println ( ) ; int maxWidth = determineCommandNameWidth ( descriptors ) ; out . println ( "Commands:" ) ; for ( Command . Descriptor d : descriptors ) { out . print ( "  " ) ; out . print ( rightPad ( d . getName ( ) , maxWidth ) ) ; out . println ( "   " + d . getDescription ( ) ) ; } out . println ( ) ; out . println ( "Run `wy help COMMAND` for more information on a command" ) ;


signature:
public class Help { /** * Determine the maximum width of any configured command name
 * @ param descriptors
 * @ return */
private static int determineCommandNameWidth ( List < Command . Descriptor > descriptors ) { } }

implementation: int max = 0 ; for ( Command . Descriptor d : descriptors ) { max = Math . max ( max , d . getName ( ) . length ( ) ) ; } return max ;


signature:
public class Install { /** * Identify which files are to be included in the package . This is determined by
 * the build / includes attribute in the package manifest .
 * @ return
 * @ throws IOException */
private List < Path . Entry < ? > > determinePackageContents ( ) throws IOException { } }

implementation:
// Determine includes filter
ArrayList < Path . Entry < ? > > files = new ArrayList < > ( ) ; // Determine local root of project
Path . Root root = project . getParent ( ) . getLocalRoot ( ) ; // Add all files from the includes filter
for ( int i = 0 ; i != includes . length ; ++ i ) { // Construct a filter from the attribute itself
Content . Filter filter = createFilter ( includes [ i ] . toString ( ) ) ; // Add all files matching the attribute
files . addAll ( root . get ( filter ) ) ; } // Done
return files ;


signature:
public class Install { /** * Given a list of files construct a corresponding ZipFile containing them .
 * @ param files
 * @ return
 * @ throws IOException */
private ZipFile createZipFile ( List < Path . Entry < ? > > files ) throws IOException { } }

implementation:
// The set of known paths
HashSet < Path . ID > paths = new HashSet < > ( ) ; // The zip file we ' re creating
ZipFile zf = new ZipFile ( ) ; // Add each file to zip file
for ( int i = 0 ; i != files . size ( ) ; ++ i ) { Path . Entry < ? > file = files . get ( i ) ; // Extract path
addPaths ( file . id ( ) . parent ( ) , paths , zf ) ; // Construct filename for given entry
String filename = file . id ( ) . toString ( ) + "." + file . contentType ( ) . getSuffix ( ) ; // Extract bytes representing entry
byte [ ] contents = readFileContents ( file ) ; zf . add ( new ZipEntry ( filename ) , contents ) ; } return zf ;


signature:
public class Install { /** * This is a slightly strange method . Basically , it recursively adds directory
 * entries into the ZipFile . Technically such entries should not be needed .
 * However , due to a quirk in the way that ZipFileRoot works ( in fact ,
 * AbstractFolder to be more precise ) these entries are required for now .
 * @ param path
 * @ param paths
 * @ param zf */
private void addPaths ( Path . ID path , HashSet < Path . ID > paths , ZipFile zf ) { } }

implementation:
if ( path . size ( ) > 0 && ! paths . contains ( path ) ) { addPaths ( path . parent ( ) , paths , zf ) ; // A new path encountered
String directory = path . toString ( ) + "/" ; System . out . println ( "ADDING DIRECTORY: " + directory ) ; zf . add ( new ZipEntry ( directory ) , new byte [ 0 ] ) ; paths . add ( path ) ; }


signature:
public class Install { /** * Read the contents of a given file into a byte array .
 * @ param file
 * @ return
 * @ throws IOException */
private byte [ ] readFileContents ( Path . Entry < ? > file ) throws IOException { } }

implementation:
InputStream in = file . inputStream ( ) ; ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; int nRead ; // Read bytes in max 1024 chunks
byte [ ] data = new byte [ 1024 ] ; // Read all bytes from the input stream
while ( ( nRead = in . read ( data , 0 , data . length ) ) != - 1 ) { buffer . write ( data , 0 , nRead ) ; } // Done
buffer . flush ( ) ; return buffer . toByteArray ( ) ;


signature:
public class Install { /** * Construct an entry for the target package ( zip ) file .
 * @ return
 * @ throws IOException */
private Path . Entry < ZipFile > getPackageFile ( ) throws IOException { } }

implementation:
// Extract package name from configuration
Value . UTF8 name = configuration . get ( Value . UTF8 . class , Trie . fromString ( "package/name" ) ) ; // Extract package version from
Value . UTF8 version = configuration . get ( Value . UTF8 . class , Trie . fromString ( "package/version" ) ) ; // Determine fully qualified package name
Trie pkg = Trie . fromString ( name + "-v" + version ) ; // Dig out the file !
return project . getRepositoryRoot ( ) . create ( pkg , ZipFile . ContentType ) ;


signature:
public class Install { /** * Create a content filter from the string representation .
 * @ param filter
 * @ return */
private Content . Filter createFilter ( String filter ) { } }

implementation: String [ ] split = filter . split ( "\\." ) ; Content . Type contentType = getContentType ( split [ 1 ] ) ; return Content . filter ( split [ 0 ] , contentType ) ;


signature:
public class Install { /** * Determine the content type from the suffix of a given build / includes
 * attribute entry .
 * @ param suffix
 * @ return */
private Content . Type getContentType ( String suffix ) { } }

implementation:
List < Content . Type < ? > > cts = project . getParent ( ) . getContentTypes ( ) ; for ( int i = 0 ; i != cts . size ( ) ; ++ i ) { Content . Type < ? > ct = cts . get ( i ) ; if ( ct . getSuffix ( ) . equals ( suffix ) ) { // hit
return ct ; } } // miss
throw new IllegalArgumentException ( "unknown content-type: " + suffix ) ;


signature:
public class BinaryOutputStream { /** * Write an unsigned integer value using 8bits using a big - endian encoding .
 * @ param w
 * @ throws IOException */
@ Override public void write ( int i ) throws IOException { } }

implementation: if ( count == 0 ) { output . write ( i & 0xFF ) ; } else { write_un ( i & 0xFF , 8 ) ; }


signature:
public class BinaryOutputStream { /** * Write an unsigned integer value using 32bits using a big - endian encoding .
 * @ param w
 * @ throws IOException */
public void write_u32 ( int w ) throws IOException { } }


signature:
public class BinaryOutputStream { /** * Write an unsigned integer value using a variable amount of space . The
 * value is split into 4 bit ( big - endian ) chunks , where the msb of each
 * chunk is a flag indicating whether there are more chunks . Therefore ,
 * values between 0 and 7 fit into 4 bits . Similarly , values between 8 and
 * 63 fit into 8 bits , etc
 * @ param w
 * - - - number to convert ( which cannot be negative )
 * @ throws IOException */
public void write_uv ( int w ) throws IOException { } }

implementation: if ( w < 0 ) { throw new IllegalArgumentException ( "cannot write negative number in a variable amount of space" ) ; } do { int t = w & 7 ; w = w >> 3 ; if ( w != 0 ) { write_un ( 8 | t , 4 ) ; } else { write_un ( t , 4 ) ; } } while ( w != 0 ) ;


signature:
public class BinaryOutputStream { /** * Write an unsigned integer value using n bits using a big - endian encoding .
 * @ param w
 * @ throws IOException */
public void write_un ( int bits , int n ) throws IOException { } }

implementation: int mask = 1 ; for ( int i = 0 ; i < n ; ++ i ) { boolean bit = ( bits & mask ) != 0 ; write_bit ( bit ) ; mask = mask << 1 ; }


signature:
public class Build { /** * Print out syntactic markers for all entries in the build graph . This requires
 * going through all entries , extracting the markers and then printing them .
 * @ param executor
 * @ throws IOException */
public static void printSyntacticMarkers ( PrintStream output , Collection < Path . Entry < ? > > sources , Path . Entry < ? > target ) throws IOException { } }

implementation:
// Extract all syntactic markers from entries in the build graph
List < SyntacticItem . Marker > items = extractSyntacticMarkers ( target ) ; // For each marker , print out error messages appropriately
for ( int i = 0 ; i != items . size ( ) ; ++ i ) { // Log the error message
printSyntacticMarkers ( output , sources , items . get ( i ) ) ; }


signature:
public class Build { /** * Print out an individual syntactic markers .
 * @ param marker */
private static void printSyntacticMarkers ( PrintStream output , Collection < Path . Entry < ? > > sources , SyntacticItem . Marker marker ) { } }

implementation:
Path . Entry < ? > source = getSourceEntry ( sources , marker . getSource ( ) ) ; Span span = marker . getTarget ( ) . getAncestor ( AbstractCompilationUnit . Attribute . Span . class ) ; // Read the enclosing line so we can print it
EnclosingLine line = readEnclosingLine ( source , span ) ; // Sanity check we found it
if ( line != null ) { // print the error message
output . println ( source . location ( ) + ":" + line . lineNumber + ": " + marker . getMessage ( ) ) ; // Finally print the line highlight
printLineHighlight ( output , line ) ; } else { output . println ( source . location ( ) + ":?: " + marker . getMessage ( ) ) ; }


signature:
public class Build { /** * Traverse the various binaries which have been generated looking for error
 * messages .
 * @ param binaries
 * @ return
 * @ throws IOException */
private static List < SyntacticItem . Marker > extractSyntacticMarkers ( Path . Entry < ? > ... binaries ) throws IOException { } }

implementation:
List < SyntacticItem . Marker > annotated = new ArrayList < > ( ) ; for ( Path . Entry < ? > binary : binaries ) { Object o = binary . read ( ) ; // If the object in question can be decoded as a syntactic heap then we can look
// for syntactic messages .
if ( o instanceof SyntacticHeap ) { SyntacticHeap h = ( SyntacticHeap ) o ; extractSyntacticMarkers ( h . getRootItem ( ) , annotated , new BitSet ( ) ) ; } } return annotated ;


signature:
public class LocalPackageResolver { /** * Determine the package root . This is relative to the registry root and
 * determines where the package will be stored . By default , this is given by
 * the path < code > name / version / < / code > .
 * @ return
 * @ throws IOException */
public Path . Root getPackageRoot ( String name , SemanticVersion version ) throws IOException { } }

implementation: Path . ID path = Trie . ROOT . append ( name ) . append ( version . toString ( ) ) ; return root . createRelativeRoot ( path ) ;


signature:
public class AbstractSyntacticItem { /** * Get the first syntactic item of a given kind which refers to this item .
 * @ param kind
 * @ return */
@ Override public < T extends SyntacticItem > T getParent ( Class < T > kind ) { } }

implementation: return parent . getParent ( this , kind ) ;


signature:
public class AbstractSyntacticItem { /** * Get all syntactic items of a given kind which refer to this item .
 * @ param kind
 * @ return */
@ Override public < T extends SyntacticItem > List < T > getParents ( Class < T > kind ) { } }

implementation: return parent . getParents ( this , kind ) ;


signature:
public class AbstractSyntacticItem { /** * Get the first syntactic item of a given kind which refers to this item either
 * indirectly or directly .
 * @ param kind
 * @ return */
@ Override public < T extends SyntacticItem > T getAncestor ( Class < T > kind ) { } }

implementation: return parent . getAncestor ( this , kind ) ;


signature:
public class AbstractSyntacticItem { /** * Compare the data object associated with a given syntactic item . An
 * important question here is what kinds of data are actually permitted . At
 * this stage , it ' s not completely clear . However , at least :
 * < code > Boolean < / code > , < code > BigInteger < / code > , < code > String < / code > and
 * < code > byte [ ] < / code > . For simplicity , we ' ll order them according to this sequence .
 * @ param leftData
 * @ param rightData
 * @ return */
private int compareData ( Object leftData , Object rightData ) { } }

implementation:
if ( leftData == null || rightData == null ) { if ( leftData == rightData ) { return 0 ; } else if ( leftData == null ) { return - 1 ; } else { return 1 ; } } // At this point , we have two non - null data items . Therefore , we need to
// determine whether they refer to the same kind of item or to different
// kinds . In the latter case , we need to determine the relative ordering
// of kinds .
int leftKind = getDataKind ( leftData ) ; int rightKind = getDataKind ( rightData ) ; if ( leftKind != rightKind ) { return leftKind - rightKind ; } else { switch ( leftKind ) { case 0 : // Boolean
return ( ( Boolean ) leftData ) . compareTo ( ( Boolean ) rightData ) ; case 1 : // BigInteger
return ( ( BigInteger ) leftData ) . compareTo ( ( BigInteger ) rightData ) ; case 2 : // String
return ( ( String ) leftData ) . compareTo ( ( String ) rightData ) ; default : // byte [ ]
byte [ ] leftBytes = ( byte [ ] ) leftData ; byte [ ] rightBytes = ( byte [ ] ) rightData ; if ( leftBytes . length != rightBytes . length ) { return leftBytes . length - rightBytes . length ; } else { for ( int i = 0 ; i != leftBytes . length ; ++ i ) { int c = Byte . compare ( leftBytes [ i ] , rightBytes [ i ] ) ; if ( c != 0 ) { return c ; } } return 0 ; } } }


signature:
public class ArrayUtils { /** * Return an integer array containing consecutive integers from a given
 * start value upto ( but not including ) a given end value .
 * @ param start
 * The start value from which the range begins . This value is
 * always the first element of the final array ( assuming it ' s not
 * empty ) .
 * @ param end
 * The value up to which ( exclusively ) the range extends . This
 * value is not in the final array . If this value equals or is
 * less than the start value , then the empty array is returned .
 * @ return */
public static int [ ] range ( int start , int end ) { } }

implementation: if ( end <= start ) { return new int [ 0 ] ; } else { int [ ] rs = new int [ Math . abs ( end - start ) ] ; for ( int i = start ; i < end ; ++ i ) { rs [ i - start ] = i ; } return rs ; }


signature:
public class ArrayUtils { /** * Append an integer item to the front of an array of integer type together ,
 * producing a fresh array whose length equals that the second plus one .
 * @ param lhs
 * The left - hand side . Elements of this array will be copied
 * first into the resulting array .
 * @ param rhs
 * The right - hand side . Elements of this array will be copied
 * last into the resulting array .
 * @ return */
public static int [ ] append ( int lhs , int [ ] rhs ) { } }

implementation: int [ ] rs = new int [ rhs . length + 1 ] ; rs [ 0 ] = lhs ; System . arraycopy ( rhs , 0 , rs , 1 , rhs . length ) ; return rs ;


signature:
public class ArrayUtils { /** * Append two integer items to the front of an array of integer type
 * together , producing a fresh array whose length equals that of the third
 * plus two .
 * @ param lhs
 * The left - hand side . Elements of this array will be copied
 * first into the resulting array .
 * @ param rhs
 * The right - hand side . Elements of this array will be copied
 * last into the resulting array .
 * @ return */
public static int [ ] append ( int first , int second , int [ ] rhs ) { } }

implementation: int [ ] rs = new int [ rhs . length + 2 ] ; rs [ 0 ] = first ; rs [ 1 ] = second ; System . arraycopy ( rhs , 0 , rs , 2 , rhs . length ) ; return rs ;


signature:
public class ArrayUtils { /** * Append two arrays of integer type together , producing a fresh array whose
 * length equals that of the first and second added together .
 * @ param lhs
 * The left - hand side . Elements of this array will be copied
 * first into the resulting array .
 * @ param rhs
 * The right - hand side . Elements of this array will be copied
 * last into the resulting array .
 * @ return */
public static int [ ] append ( int [ ] lhs , int [ ] rhs ) { } }

implementation: int [ ] rs = java . util . Arrays . copyOf ( lhs , lhs . length + rhs . length ) ; System . arraycopy ( rhs , 0 , rs , lhs . length , rhs . length ) ; return rs ;


signature:
public class ArrayUtils { /** * Append an element onto an array of unknown type together , producing a
 * fresh array whose length equals that of the second plus one .
 * @ param lhs
 * The left - hand side . This element will be copied
 * first into the resulting array .
 * @ param rhs
 * The right - hand side . Elements of this array will be copied
 * last into the resulting array .
 * @ return */
public static < T > T [ ] append ( Class < T > type , T lhs , T ... rhs ) { } }

implementation: T [ ] rs = ( T [ ] ) Array . newInstance ( type , rhs . length + 1 ) ; System . arraycopy ( rhs , 0 , rs , 1 , rhs . length ) ; rs [ 0 ] = lhs ; return rs ;


signature:
public class ArrayUtils { /** * Add all elements from an array into a given collection of the same type .
 * @ param lhs
 * The left - hand side . Elements of this array will be added to
 * the collection .
 * @ param rhs
 * The right - hand side . Elements from the left - hand side will be
 * added to this collection . */
public static < T > void addAll ( T [ ] lhs , Collection < T > rhs ) { } }

implementation: for ( int i = 0 ; i != lhs . length ; ++ i ) { rhs . add ( lhs [ i ] ) ; }


signature:
public class ArrayUtils { /** * Convert a collection of strings into a string array .
 * @ param items
 * @ return */
public static String [ ] toStringArray ( Collection < String > items ) { } }

implementation: String [ ] result = new String [ items . size ( ) ] ; int i = 0 ; for ( String s : items ) { result [ i ++ ] = s ; } return result ;


signature:
public class ArrayUtils { /** * Convert a collection of Integers into an int array .
 * @ param items
 * @ return */
public static int [ ] toIntArray ( Collection < Integer > items ) { } }

implementation: int [ ] result = new int [ items . size ( ) ] ; int i = 0 ; for ( Integer v : items ) { result [ i ++ ] = v ; } return result ;


signature:
public class ArrayUtils { /** * Convert from an array of one kind to an array of another kind .
 * @ param type
 * @ param src
 * @ return */
public static < T , S > T [ ] toArray ( Class < T > type , S [ ] src ) { } }

implementation: @ SuppressWarnings ( "unchecked" ) T [ ] dest = ( T [ ] ) Array . newInstance ( type , src . length ) ; System . arraycopy ( src , 0 , dest , 0 , src . length ) ; return dest ;


signature:
public class ArrayUtils { /** * Convert from an array of one kind to an array of another kind .
 * @ param type
 * @ param src
 * @ return */
@ SuppressWarnings ( "unchecked" ) public static < T , S > T [ ] toArray ( Class < T > type , Collection < S > src ) { } }

implementation: T [ ] dest = ( T [ ] ) Array . newInstance ( type , src . size ( ) ) ; int i = 0 ; for ( S s : src ) { dest [ i ++ ] = ( T ) s ; } return dest ;


signature:
public class ArrayUtils { /** * Remove duplicate types from an unsorted array . This produces a potentially
 * smaller array with all duplicates removed . Null is permitted in the array
 * and will be preserved , though duplicates of it will not be . Items in the
 * array are compared using < code > Object . equals ( ) < / code > .
 * @ param items
 * The array for which duplicates are to be removed
 * @ return */
public static < T > T [ ] removeDuplicates ( T [ ] items ) { } }

implementation:
int count = 0 ; // First , identify duplicates and store this information in a bitset .
BitSet duplicates = new BitSet ( items . length ) ; for ( int i = 0 ; i != items . length ; ++ i ) { T ith = items [ i ] ; for ( int j = i + 1 ; j < items . length ; ++ j ) { T jth = items [ j ] ; if ( ith == null ) { if ( jth == null ) { duplicates . set ( i ) ; count = count + 1 ; break ; } } else if ( ith . equals ( jth ) ) { duplicates . set ( i ) ; count = count + 1 ; break ; } } } // Second , eliminate duplicates ( if any )
if ( count == 0 ) { // nothing actually needs to be removed
return items ; } else { T [ ] nItems = Arrays . copyOf ( items , items . length - count ) ; for ( int i = 0 , j = 0 ; i != items . length ; ++ i ) { if ( duplicates . get ( i ) ) { // this is a duplicate , ignore
} else { nItems [ j ++ ] = items [ i ] ; } } return nItems ; }


signature:
public class ArrayUtils { /** * Sort and remove duplicate items from a given array .
 * @ param children
 * @ return */
public static < T extends S , S extends Comparable < S > > T [ ] sortAndRemoveDuplicates ( T [ ] children ) { } }

implementation:
int r = isSortedAndUnique ( children ) ; switch ( r ) { case 0 : // In this case , the array is already sorted and no duplicates were
// found .
return children ; case 1 : // In this case , the array is already sorted , but duplicates were
// found
return ArrayUtils . sortedRemoveDuplicates ( children ) ; default : // In this case , the array is not sorted and may or may not
// contain duplicates .
children = Arrays . copyOf ( children , children . length ) ; Arrays . sort ( children ) ; return ArrayUtils . sortedRemoveDuplicates ( children ) ; }


signature:
public class ArrayUtils { /** * Check whether or not the children of this array are sorted according to
 * their underlying order . And , if so , whether or not there are any
 * duplicate elements encountered .
 * @ param children
 * @ return */
public static < T extends Comparable < T > > int isSortedAndUnique ( T [ ] children ) { } }

implementation:
int r = 0 ; for ( int i = 1 ; i < children . length ; ++ i ) { int c = children [ i - 1 ] . compareTo ( children [ i ] ) ; if ( c == 0 ) { // Duplicate found , though still could be in sorted order .
r = 1 ; } else if ( c > 0 ) { // NOT in sorted order
return - 1 ; } } // All good
return r ;


signature:
public class ArrayUtils { /** * Remove any occurrence of a given value from an array . The resulting array
 * may be shorter in length , but the relative position of all other items
 * will remain unchanged . This algorithm is robust to < code > null < / code > . The
 * < code > items < / code > array may contain < code > null < / code > values and the
 * < code > item < / code > may itself be < code > null < / code > ( in which case , all
 * < code > null < / code > values are removed ) .
 * @ param items
 * @ return */
public static < T > T [ ] removeAll ( T [ ] items , T item ) { } }

implementation:
int count = 0 ; // First , determine the number of elements which will be removed
for ( int i = 0 ; i != items . length ; ++ i ) { T ith = items [ i ] ; if ( ith == item || ( item != null && item . equals ( ith ) ) ) { count ++ ; } } // Second , eliminate duplicates ( if any )
if ( count == 0 ) { // nothing actually needs to be removed
return items ; } else { T [ ] nItems = Arrays . copyOf ( items , items . length - count ) ; for ( int i = 0 , j = 0 ; i != items . length ; ++ i ) { T ith = items [ i ] ; if ( ith == item || ( item != null && item . equals ( ith ) ) ) { // skip item
} else { nItems [ j ++ ] = ith ; } } return nItems ; }


signature:
public class ArrayUtils { /** * A default operator for comparing arrays
 * @ param lhs
 * @ param rhs
 * @ return */
public static < S , T extends Comparable < S > > int compareTo ( T [ ] lhs , T [ ] rhs ) { } }

implementation: if ( lhs . length != rhs . length ) { return lhs . length - rhs . length ; } else { for ( int i = 0 ; i != lhs . length ; ++ i ) { int r = lhs [ i ] . compareTo ( ( S ) rhs [ i ] ) ; if ( r != 0 ) { return r ; } } return 0 ; }


signature:
public class ArrayUtils { /** * Determine the first index of a given item in an array of items , or return
 * - 1 otherwise . Items are compared using the method
 * < code > Object . equals ( ) < / code > . The < code > items < / code > array may contain
 * < code > null < / code > values ; likewise , < code > item < / code > may be
 * < code > null < / code > and will match against other < code > null < / code > values .
 * @ param items
 * @ param item
 * @ return */
public static < T > int firstIndexOf ( T [ ] items , T item ) { } }

implementation: for ( int i = 0 ; i != items . length ; ++ i ) { T ith = items [ i ] ; if ( ith == item || ( ith != null && ith . equals ( item ) ) ) { return i ; } } return - 1 ;


signature:
public class WyMain { /** * Get the appropriate configuration schema for a project . This defines what
 * keys are permitted .
 * @ return */
public Configuration . Schema getBuildSchema ( ) { } }

implementation: Configuration . Schema [ ] schemas = new Configuration . Schema [ buildPlatforms . size ( ) + 1 ] ; schemas [ 0 ] = LOCAL_CONFIG_SCHEMA ; for ( int i = 0 ; i != buildPlatforms . size ( ) ; ++ i ) { wybs . lang . Build . Platform platform = buildPlatforms . get ( i ) ; schemas [ i + 1 ] = platform . getConfigurationSchema ( ) ; } return Configuration . toCombinedSchema ( schemas ) ;


signature:
public class WyMain { /** * Create the Build . Template extension point . This is where plugins register
 * their primary functionality for constructing a specific build project .
 * @ param context
 * @ param templates */
private void createTemplateExtensionPoint ( ) { } }

implementation: context . create ( Command . Descriptor . class , new Module . ExtensionPoint < Command . Descriptor > ( ) { @ Override public void register ( Command . Descriptor command ) { commandDescriptors . add ( command ) ; } } ) ;


signature:
public class WyMain { /** * Create the Content . Type extension point .
 * @ param context
 * @ param templates */
private void createContentTypeExtensionPoint ( ) { } }

implementation: context . create ( Content . Type . class , new Module . ExtensionPoint < Content . Type > ( ) { @ Override public void register ( Content . Type contentType ) { contentTypes . add ( contentType ) ; } } ) ;


signature:
public class WyMain { /** * Create the Content . Type extension point .
 * @ param context
 * @ param templates */
private void createBuildPlatformExtensionPoint ( ) { } }

implementation: context . create ( wybs . lang . Build . Platform . class , new Module . ExtensionPoint < wybs . lang . Build . Platform > ( ) { @ Override public void register ( wybs . lang . Build . Platform platform ) { buildPlatforms . add ( platform ) ; } } ) ;


signature:
public class WyMain { /** * Activate the default set of plugins which the tool uses . Currently this list
 * is statically determined , but eventually it will be possible to dynamically
 * add plugins to the system .
 * @ param verbose
 * @ param locations
 * @ return */
private void activateDefaultPlugins ( Configuration global ) { } }

implementation:
// Determine the set of install plugins
List < Path . ID > plugins = global . matchAll ( Trie . fromString ( "plugins/*" ) ) ; // start modules
for ( Path . ID id : plugins ) { UTF8 activator = global . get ( UTF8 . class , id ) ; try { Class < ? > c = Class . forName ( activator . toString ( ) ) ; Module . Activator instance = ( Module . Activator ) c . newInstance ( ) ; instance . start ( context ) ; } catch ( ClassNotFoundException e ) { e . printStackTrace ( ) ; } catch ( InstantiationException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } }


signature: public class WyMain { public static void main ( String [ ] args ) throws Exception { } }

implementation:
// Determine system - wide directory
String systemDir = determineSystemRoot ( ) ; // Determine user - wide directory
String globalDir = determineGlobalRoot ( ) ; // Determine project directory
String localDir = determineLocalRoot ( ) ; // Construct environment and execute arguments
new WyMain ( systemDir , globalDir , localDir ) . execute ( args ) ; // Done
System . exit ( 0 ) ;


signature:
public class WyMain { /** * Determine the system root . That is , the installation directory for the
 * compiler itself .
 * @ param tool
 * @ return
 * @ throws IOException */
private static String determineSystemRoot ( ) throws IOException { } }

implementation: String whileyhome = System . getenv ( "WHILEYHOME" ) ; if ( whileyhome == null ) { System . err . println ( "error: WHILEYHOME environment variable not set" ) ; System . exit ( - 1 ) ; } return whileyhome ;


signature:
public class WyMain { /** * Determine the global root . That is , the hidden whiley directory in the user ' s
 * home directory ( e . g . ~ / . whiley ) .
 * @ param tool
 * @ return
 * @ throws IOException */
private static String determineGlobalRoot ( ) throws IOException { } }

implementation: String userhome = System . getProperty ( "user.home" ) ; String whileydir = userhome + File . separator + ".whiley" ; return whileydir ;


signature:
public class WyMain { /** * Determine where the root of this project is . This is the nearest enclosing
 * directory containing a " wy . toml " file . The point is that we may be operating
 * in some subdirectory of the project and want the tool to automatically search
 * out the real root for us .
 * @ return
 * @ throws IOException */
private static String determineLocalRoot ( ) throws IOException { } }

implementation:
// Determine current working directory
File dir = new File ( "." ) ; // Traverse up the directory hierarchy
while ( dir != null && dir . exists ( ) && dir . isDirectory ( ) ) { File wyf = new File ( dir + File . separator + "wy.toml" ) ; if ( wyf . exists ( ) ) { return dir . getPath ( ) ; } // Traverse back up the directory hierarchy looking for a suitable directory .
dir = dir . getParentFile ( ) ; } // If we get here then it means we didn ' t find a root , therefore just use
// current directory .
return "." ;


signature:
public class WyMain { /** * Attempt to read a configuration file from a given root .
 * @ param name
 * @ param root
 * @ return
 * @ throws IOException */
private static Configuration readConfigFile ( String name , String dir , Configuration . Schema ... schemas ) throws IOException { } }

implementation:
DirectoryRoot root = new DirectoryRoot ( dir , BOOT_REGISTRY ) ; Path . Entry < ConfigFile > config = root . get ( Trie . fromString ( name ) , ConfigFile . ContentType ) ; if ( config == null ) { return Configuration . EMPTY ; } try { // Read the configuration file
ConfigFile cf = config . read ( ) ; // Construct configuration according to given schema
return cf . toConfiguration ( Configuration . toCombinedSchema ( schemas ) ) ; } catch ( SyntacticException e ) { e . outputSourceError ( System . out , false ) ; System . exit ( - 1 ) ; return null ; }


signature:
public class WyMain { /** * Print a complete stack trace . This differs from Throwable . printStackTrace ( )
 * in that it always prints all of the trace .
 * @ param out
 * @ param err */
private static void printStackTrace ( PrintStream out , Throwable err ) { } }

implementation: out . println ( err . getClass ( ) . getName ( ) + ": " + err . getMessage ( ) ) ; for ( StackTraceElement ste : err . getStackTrace ( ) ) { out . println ( "\tat " + ste . toString ( ) ) ; } if ( err . getCause ( ) != null ) { out . print ( "Caused by: " ) ; printStackTrace ( out , err . getCause ( ) ) ; }


signature:
public class StdModuleManager { /** * Get instance of given module within this context , or null if no
 * instance available .
 * @ param module
 * @ return */
public < T extends Module > T getInstance ( Class < T > module ) { } }

implementation: return ( T ) instances . get ( module ) ;


signature:
public class StdModuleManager { /** * Scan and activate all modules on the search path . As part of this , all
 * module dependencies will be checked . */
public void start ( ) { } }

implementation:
// Construct the URLClassLoader which will be used to load
// classes within the modules .
URL [ ] urls = new URL [ modules . size ( ) ] ; for ( int i = 0 ; i != modules . size ( ) ; ++ i ) { urls [ i ] = modules . get ( i ) . getLocation ( ) ; } URLClassLoader loader = new URLClassLoader ( urls ) ; // Third , active the modules . This will give them the opportunity to
// register whatever extensions they like .
activateModules ( loader ) ;


signature:
public class StdModuleManager { /** * Activate all modules in the order of occurrence in the given list . It is
 * assumed that all dependencies are already resolved prior to this and all
 * modules are topologically sorted . */
private void activateModules ( URLClassLoader loader ) { } }

implementation: for ( int i = 0 ; i != modules . size ( ) ; ++ i ) { Descriptor module = modules . get ( i ) ; try { Class c = loader . loadClass ( module . getActivator ( ) ) ; Module . Activator self = ( Module . Activator ) c . newInstance ( ) ; Module instance = self . start ( context ) ; instances . put ( c , instance ) ; logger . logTimedMessage ( "Activated module " + module . getId ( ) + " (v" + module . getVersion ( ) + ")" , 0 , 0 ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }


signature:
public class SyntacticException { /** * Output the syntax error to a given output stream in either full or brief
 * form . Brief form is intended to be used by 3rd party tools and is easier
 * to parse . In full form , contextual information from the originating
 * source file is included . */
public void outputSourceError ( PrintStream output , boolean brief ) { } }

implementation: Attribute . Span span ; if ( entry == null || element == null ) { output . println ( "syntax error: " + getMessage ( ) ) ; return ; } else if ( element instanceof Attribute . Span ) { span = ( Attribute . Span ) element ; } else { SyntacticHeap parent = element . getHeap ( ) ; span = parent . getParent ( element , Attribute . Span . class ) ; } EnclosingLine enclosing = ( span == null ) ? null : readEnclosingLine ( entry , span ) ; if ( enclosing == null ) { output . println ( "syntax error: " + getMessage ( ) ) ; } else if ( brief ) { printBriefError ( output , entry , enclosing , getMessage ( ) ) ; } else { printFullError ( output , entry , enclosing , getMessage ( ) ) ; }


signature:
public class SequentialBuildExecutor { /** * Check whether a given task is ready to be built . This is currently determined
 * by having at least one source whose timestamp is in front of the target .
 * @ param task
 * @ return */
private boolean ready ( Build . Task task ) { } }

implementation:
// FIXME : this is not a great solution in the long run for several reasons .
// Firstly , its possible that a given source will be rebuilt in the near future
// as a result of some other task and we should be waiting for that .
Path . Entry < ? > target = task . getTarget ( ) ; for ( Path . Entry < ? > s : task . getSources ( ) ) { if ( s . lastModified ( ) > target . lastModified ( ) ) { return true ; } } return false ;


signature:
public class OptArg { /** * Parse options from the list of arguments , removing those which are
 * recognised . Anything which is not recognised is left as is .
 * @ param args
 * - - - the list of argument strings . This is modified by removing
 * those which are processed .
 * @ param options
 * - - - the list of OptArg defining which options should be
 * processed
 * @ throws - - - a < code > RuntimeException < / code > if an unrecognised option is
 * encountered ( that is , a token starting with ' - ' ) . . */
public static Map < String , Object > parseOptions ( List < String > args , OptArg ... options ) { } }

implementation:
HashMap < String , Object > result = new HashMap < > ( ) ; HashMap < String , OptArg > optmap = new HashMap < > ( ) ; for ( OptArg opt : options ) { if ( opt . defaultValue != null ) { result . put ( opt . option , opt . defaultValue ) ; } optmap . put ( opt . option , opt ) ; optmap . put ( opt . shortForm , opt ) ; } Iterator < String > iter = args . iterator ( ) ; while ( iter . hasNext ( ) ) { String arg = iter . next ( ) ; if ( arg . startsWith ( "-" ) ) { arg = arg . substring ( 1 , arg . length ( ) ) ; OptArg opt = optmap . get ( arg ) ; if ( opt != null ) { // matched
iter . remove ( ) ; // remove option from args list
Kind k = opt . argument ; if ( k != null ) { String param = iter . next ( ) ; iter . remove ( ) ; k . process ( opt . option , param , result ) ; } else { result . put ( opt . option , null ) ; } } else { throw new RuntimeException ( "unknown command-line option: -" + arg ) ; } } } return result ;


signature:
public class OptArg { /** * This splits strings of the form " x = y , v = w " into distinct components and
 * puts them into a map . In the case of a string like " x , y = z " then x is
 * loaded with the empty string .
 * @ param str
 * @ return */
private static Map < String , Object > splitConfig ( String str ) { } }

implementation: HashMap < String , Object > options = new HashMap < > ( ) ; String [ ] splits = str . split ( "," ) ; for ( String s : splits ) { String [ ] p = s . split ( "=" ) ; options . put ( p [ 0 ] , parseValue ( p [ 1 ] ) ) ; } return options ;


signature:
public class StdProject { /** * Force root to refresh entries from permanent storage ( where appropriate ) . For
 * items which have been modified , this operation has no effect ( i . e . the new
 * contents are retained ) . */
public void refresh ( ) throws IOException { } }

implementation: root . refresh ( ) ; for ( Build . Rule rule : rules ) { rule . apply ( executor ) ; }


signature:
public class AbstractSyntacticHeap { /** * Get first parent of a syntactic item matching the given kind . If no item
 * was found , then null is returned .
 * @ param child
 * @ param kind
 * @ return */
@ Override public < T extends SyntacticItem > T getParent ( SyntacticItem child , Class < T > kind ) { } }

implementation:
// FIXME : this could be optimised a * lot *
for ( int i = 0 ; i != syntacticItems . size ( ) ; ++ i ) { SyntacticItem parent = syntacticItems . get ( i ) ; if ( kind . isInstance ( parent ) ) { for ( int j = 0 ; j != parent . size ( ) ; ++ j ) { if ( parent . get ( j ) == child ) { return ( T ) parent ; } } } } // no match
return null ;


signature:
public class AbstractSyntacticHeap { /** * Get first ancestor of a syntactic item matching the given kind . If no item
 * was found , then null is returned .
 * @ param child
 * @ param kind
 * @ return */
@ Override public < T extends SyntacticItem > T getAncestor ( SyntacticItem child , Class < T > kind ) { } }

implementation:
// FIXME : this could be optimised a * lot *
if ( kind . isInstance ( child ) ) { return ( T ) child ; } else { for ( int i = 0 ; i != syntacticItems . size ( ) ; ++ i ) { SyntacticItem parent = syntacticItems . get ( i ) ; for ( int j = 0 ; j != parent . size ( ) ; ++ j ) { // Don ' t follow cross - references
if ( parent . get ( j ) == child && ! ( parent instanceof AbstractCompilationUnit . Ref ) ) { // FIXME : this is not specifically efficient . It would
// be helpful if SyntacticItems actually contained
// references to their parent items .
T tmp = getAncestor ( parent , kind ) ; if ( tmp != null ) { return tmp ; } } } } // no match
return null ; }


signature:
public class AbstractSyntacticHeap { /** * Create a new syntactic item by replacing all occurrences of one item
 * ( < code > from < / code > ) with another ( < code > to < / code > ) . In the case that
 * there is no change to the item ( or any of its children ) then the original
 * item is returned untouched . Specifically , the exact same reference will
 * be returned .
 * Any new items created during this process are allocated into the heap of
 * the item they are replacing . This is necessary since otherwise a mix of
 * allocated and unallocated items would be returned , making it difficult to
 * then allocate them all .
 * This method preserves the underlying aliasing structure of the object
 * being cloned . However , aliasing information is not preserved across calls
 * to this method . Furthermore , it is not currently capable of handling
 * cyclic structures .
 * @ param item
 * The syntactic item we are currently substituting into
 * @ param from
 * The syntactic item we are looking to replace
 * @ param to
 * The syntactic item that will replace all occurrences of from
 * @ return */
public static SyntacticItem substitute ( SyntacticItem item , SyntacticItem from , SyntacticItem to ) { } }

implementation: SyntacticItem nItem = substitute ( item , from , to , new IdentityHashMap < > ( ) ) ; if ( nItem != item ) { item . getHeap ( ) . allocate ( nItem ) ; } return nItem ;


signature:
public class AbstractSyntacticHeap { /** * Helper method for above .
 * @ param mapping
 * A mapping from the original syntactic items to the cloned
 * syntactic items . This is necessary to preserve the aliasing
 * structure in the resulting cloned item . */
private static SyntacticItem substitute ( SyntacticItem item , SyntacticItem from , SyntacticItem to , Map < SyntacticItem , SyntacticItem > mapping ) { } }

implementation:
SyntacticItem sItem = mapping . get ( item ) ; if ( sItem != null ) { // We ' ve previously substituted this item already to produce a
// potentially updated item . Therefore , simply return that item to
// ensure the original aliasing structure of the ancestor ( s ) is
// properly preserved .
return sItem ; } else if ( item == from ) { // We ' ve matched the item being replaced , therefore return the item
// to which it is being replaced .
return to ; } else { SyntacticItem nItem = item ; // We need to recursively descend into children of this item looking
// for the item to replace . The challenge here is that we need to
// ensure the original item is preserved as is if there is no
// change .
SyntacticItem [ ] children = item . getAll ( ) ; // Initially , this will alias children . In the event of a child
// which is actually updated , then this will refer to a new array .
// That will be the signal that we need to create a new item to
// return .
SyntacticItem [ ] nChildren = children ; if ( children != null ) { for ( int i = 0 ; i != children . length ; ++ i ) { SyntacticItem child = children [ i ] ; // Check for null , since we don ' t want to try and substitute
// into null .
if ( child != null ) { // Perform the substitution in the given child
SyntacticItem nChild = substitute ( child , from , to , mapping ) ; // Check whether anything was actually changed by the
// substitution .
if ( nChild != child && children == nChildren ) { // Yes , the child changed and we haven ' t already
// cloned the children array . Hence , we ' d better
// clone it now to make sure that the original item
// is preserved .
nChildren = Arrays . copyOf ( children , children . length ) ; } nChildren [ i ] = nChild ; } } // Now , clone the original item if necessary . This is only
// necessary if the children array as been updated in some way .
if ( children != nChildren ) { // Create the new item which , at this point , will be
// detached .
nItem = item . clone ( nChildren ) ; } } mapping . put ( item , nItem ) ; return nItem ; }


signature:
public class Inspect { /** * Determine the content type for this file .
 * @ param file
 * @ return */
private Content . Type < ? > getContentType ( String file ) { } }

implementation:
List < Content . Type < ? > > cts = project . getParent ( ) . getContentTypes ( ) ; for ( int i = 0 ; i != cts . size ( ) ; ++ i ) { Content . Type < ? > ct = cts . get ( i ) ; String suffix = "." + ct . getSuffix ( ) ; if ( file . endsWith ( suffix ) ) { return ct ; } } // Default is just a binary file
return Content . BinaryFile ;


signature:
public class Inspect { /** * Get the entry associated with this file .
 * @ param file
 * @ param ct
 * @ return
 * @ throws IOException */
public Path . Entry < ? > getEntry ( String file , Content . Type < ? > ct ) throws IOException { } }

implementation:
// Strip suffix
file = file . replace ( "." + ct . getSuffix ( ) , "" ) ; // Determine path id
Path . ID id = Trie . fromString ( file ) ; // Get the file from the repository root
return project . getParent ( ) . getLocalRoot ( ) . get ( id , ct ) ;


signature:
public class Inspect { /** * Inspect a given path entry .
 * @ param entry
 * @ param ct
 * @ throws IOException */
private void inspect ( Path . Entry < ? > entry , Content . Type < ? > ct , boolean garbage ) throws IOException { } }

implementation: Object o = entry . read ( ) ; if ( o instanceof SyntacticHeap ) { new SyntacticHeapPrinter ( new PrintWriter ( out ) , garbage ) . print ( ( SyntacticHeap ) o ) ; } else { inspectBinaryFile ( readAllBytes ( entry . inputStream ( ) ) ) ; }


signature:
public class Inspect { /** * Inspect a given binary file . That is a file for which we don ' t have a better
 * inspector .
 * @ param bytes */
private void inspectBinaryFile ( byte [ ] bytes ) { } }

implementation:
for ( int i = 0 ; i < bytes . length ; i += width ) { out . print ( String . format ( "0x%04X " , i ) ) ; // Print out databytes
for ( int j = 0 ; j < width ; ++ j ) { if ( j + i < bytes . length ) { out . print ( String . format ( "%02X " , bytes [ i + j ] ) ) ; } else { out . print ( "   " ) ; } } for ( int j = 0 ; j < width ; ++ j ) { if ( j + i < bytes . length ) { char c = ( char ) bytes [ i + j ] ; if ( c >= 32 && c < 128 ) { out . print ( c ) ; } else { out . print ( "." ) ; } } } out . println ( ) ; }


signature:
public class SyntacticHeapReader { /** * Read all the items in this heap , returning the identified root item and an
 * array of all items contained therein .
 * @ return
 * @ throws IOException */
protected Pair < Integer , SyntacticItem [ ] > readItems ( ) throws IOException { } }

implementation:
// first , write magic number
checkHeader ( ) ; // second , determine number of items
int size = in . read_uv ( ) ; // third , determine the root item
int root = in . read_uv ( ) ; Bytecode [ ] items = new Bytecode [ size ] ; // third , read abstract syntactic items
for ( int i = 0 ; i != items . length ; ++ i ) { items [ i ] = readItem ( ) ; } return new Pair < > ( root , constructItems ( items ) ) ;


signature:
public class Trie { /** * Construct a Trie from a string , where ' / ' is the separator .
 * @ param str
 * @ return */
public static Trie fromString ( String str ) { } }

implementation: String [ ] components = str . split ( "/" ) ; Trie r = ROOT ; for ( int i = 0 ; i != components . length ; ++ i ) { r = r . append ( components [ i ] ) ; } return r ;


signature:
public class Trie { /** * Construct a Trie from a Path ID .
 * @ param str
 * @ return */
public static Trie fromString ( Path . ID id ) { } }

implementation: if ( id instanceof Trie ) { return ( ( Trie ) id ) ; } Trie r = ROOT ; for ( int i = 0 ; i != id . size ( ) ; ++ i ) { r = r . append ( id . get ( i ) ) ; } return r ;


signature: public class Trie { private boolean match ( Path . ID id , int idIndex , int myIndex , boolean submatch ) { } }

implementation: int mySize = depth + 1 ; if ( myIndex == mySize && idIndex == id . size ( ) ) { return true ; } else if ( idIndex == id . size ( ) ) { return submatch ; } else if ( myIndex == mySize ) { return false ; } String myComponent = get ( myIndex ) ; if ( myComponent . equals ( "*" ) ) { return match ( id , idIndex + 1 , myIndex + 1 , submatch ) ; } else if ( myComponent . equals ( "**" ) ) { myIndex ++ ; for ( int i = idIndex ; i <= id . size ( ) ; ++ i ) { if ( match ( id , i , myIndex , submatch ) ) { return true ; } } return false ; } else { return myComponent . equals ( id . get ( idIndex ) ) && match ( id , idIndex + 1 , myIndex + 1 , submatch ) ; }


signature:
public class WyProject { /** * The descriptor for this command .
 * @ author David J . Pearce */
public static Command . Descriptor DESCRIPTOR ( List < Command . Descriptor > descriptors ) { } }

implementation:
return new Command . Descriptor ( ) { @ Override public Schema getConfigurationSchema ( ) { // TODO Auto - generated method stub
return null ; } @ Override public List < Option . Descriptor > getOptionDescriptors ( ) { return Arrays . asList ( Command . OPTION_FLAG ( "verbose" , "generate verbose information about the build" , false ) , Command . OPTION_FLAG ( "brief" , "generate brief output for syntax errors" , false ) ) ; } @ Override public Command initialise ( Command environment , Configuration configuration ) { return new WyProject ( ( WyMain ) environment , configuration , System . out , System . err ) ; } @ Override public String getName ( ) { return "wy" ; } @ Override public String getDescription ( ) { return "Command-line interface for the Whiley Compiler Collection" ; } @ Override public List < Command . Descriptor > getCommands ( ) { return descriptors ; } } ;


signature:
public class WyProject { /** * Get the list of declared target platforms for this project . This is
 * determined by the attribute " build . platforms " in the project ( wy . toml ) build
 * file .
 * @ return */
public List < wybs . lang . Build . Platform > getTargetPlatforms ( ) { } }

implementation:
ArrayList < Build . Platform > targetPlatforms = new ArrayList < > ( ) ; // Ensure target platforms are specified
if ( configuration . hasKey ( BUILD_PLATFORMS ) ) { Value . UTF8 [ ] targetPlatformNames = configuration . get ( Value . Array . class , BUILD_PLATFORMS ) . toArray ( Value . UTF8 . class ) ; // Get list of all build platforms .
List < wybs . lang . Build . Platform > platforms = environment . getBuildPlatforms ( ) ; // Check each platform for inclusion
for ( int i = 0 ; i != platforms . size ( ) ; ++ i ) { Build . Platform platform = platforms . get ( i ) ; // Convert name to UTF8 value ( ugh )
Value . UTF8 name = new Value . UTF8 ( platform . getName ( ) . getBytes ( ) ) ; // Determine whether is a target platform or not
if ( ArrayUtils . firstIndexOf ( targetPlatformNames , name ) >= 0 ) { targetPlatforms . add ( platform ) ; } } } // Done
return targetPlatforms ;


signature:
public class WyProject { /** * Get the root of the package repository . This is the global directory in which
 * all installed packages are found .
 * @ return
 * @ throws IOException */
public Path . Root getRepositoryRoot ( ) throws IOException { } }

implementation:
Path . Root root = environment . getGlobalRoot ( ) . createRelativeRoot ( REPOSITORY_PATH ) ; // TODO : create repository if it doesn ' t exist .
return root ;


signature:
public class WyProject { /** * Setup the various roots based on the target platform ( s ) . This requires going
 * through and adding roots for all source and intermediate files .
 * @ throws IOException */
private void initialisePlatforms ( ) throws IOException { } }

implementation:
List < Build . Platform > platforms = getTargetPlatforms ( ) ; for ( int i = 0 ; i != platforms . size ( ) ; ++ i ) { Build . Platform platform = platforms . get ( i ) ; // Apply current configuration
platform . initialise ( configuration , project ) ; }


signature:
public class DirectoryRoot { /** * Given a list of physical files on the file system , determine their
 * corresponding < code > Path . Entry < / code > instances in this root ( if there
 * are any ) .
 * @ param files
 * - - - list of files on the physical file system .
 * @ param contentType
 * - - - content type of files to match .
 * @ return - - - list of path entries where each entry matches the
 * corresponding entry in files , or is null ( if there is no match ) .
 * @ throws IOException */
public < T > List < Path . Entry < T > > find ( List < File > files , Content . Type < T > contentType ) throws IOException { } }

implementation: ArrayList < Path . Entry < T > > sources = new ArrayList < > ( ) ; String suffix = "." + contentTypes . suffix ( contentType ) ; String location = location ( ) . getCanonicalPath ( ) ; for ( File file : files ) { String filePath = file . getCanonicalPath ( ) ; if ( filePath . startsWith ( location ) ) { int end = location . length ( ) ; if ( end > 1 ) { end ++ ; } String module = filePath . substring ( end ) . replace ( File . separatorChar , '/' ) ; if ( module . endsWith ( suffix ) ) { module = module . substring ( 0 , module . length ( ) - suffix . length ( ) ) ; Path . ID mid = Trie . fromString ( module ) ; Path . Entry < T > entry = this . get ( mid , contentType ) ; if ( entry != null ) { sources . add ( entry ) ; continue ; } } } } return sources ;