Input: Converts an object to destination type . If type is registered it s { [CODESPLIT] @ SuppressWarnings ( { "unchecked" } ) public < T > T convertType ( final Object value , final Class < T > destinationType ) { if ( destinationType == Object . class ) { // no conversion :) return ( T ) value ; } final TypeConverter converter = lookup ( destinationType ) ; if ( converter != null ) { return ( T ) converter . convert ( value ) ; } // no converter if ( value == null ) { return null ; } // check same instances if ( ClassUtil . isInstanceOf ( value , destinationType ) ) { return ( T ) value ; } // handle destination arrays if ( destinationType . isArray ( ) ) { ArrayConverter < T > arrayConverter = new ArrayConverter ( this , destinationType . getComponentType ( ) ) ; return ( T ) arrayConverter . convert ( value ) ; } // handle enums if ( destinationType . isEnum ( ) ) { Object [ ] enums = destinationType . getEnumConstants ( ) ; String valStr = value . toString ( ) ; for ( Object e : enums ) { if ( e . toString ( ) . equals ( valStr ) ) { return ( T ) e ; } } } // collection if ( ClassUtil . isTypeOf ( destinationType , Collection . class ) ) { // component type is unknown because of Java's type-erasure CollectionConverter < T > collectionConverter = new CollectionConverter ( this , destinationType , Object . class ) ; return ( T ) collectionConverter . convert ( value ) ; } // fail throw new TypeConversionException ( "Conversion failed of input type: " + value . getClass ( ) + " into: " + destinationType . getName ( ) ) ; }


Input: Special case of { [CODESPLIT] @ SuppressWarnings ( "unchecked" ) public < C extends Collection < T > , T > C convertToCollection ( final Object value , final Class < ? extends Collection > destinationType , final Class < T > componentType ) { if ( value == null ) { return null ; } // check same instances if ( ClassUtil . isInstanceOf ( value , destinationType ) ) { return ( C ) value ; } final CollectionConverter collectionConverter ; if ( componentType == null ) { collectionConverter = new CollectionConverter ( destinationType , Object . class ) ; } else { collectionConverter = new CollectionConverter ( destinationType , componentType ) ; } return ( C ) collectionConverter . convert ( value ) ; }


Input: Selects nodes using CSS3 selector query . [CODESPLIT] public List < Node > select ( final String query ) { Collection < List < CssSelector >> selectorsCollection = CSSelly . parse ( query ) ; return select ( selectorsCollection ) ; }


Input: Selected nodes using pre - parsed CSS selectors . Take in consideration collection type for results grouping order . [CODESPLIT] public List < Node > select ( final Collection < List < CssSelector > > selectorsCollection ) { List < Node > results = new ArrayList <> ( ) ; for ( List < CssSelector > selectors : selectorsCollection ) { processSelectors ( results , selectors ) ; } return results ; }


Input: Process selectors and keep adding results . [CODESPLIT] protected void processSelectors ( final List < Node > results , final List < CssSelector > selectors ) { List < Node > selectedNodes = select ( rootNode , selectors ) ; for ( Node selectedNode : selectedNodes ) { if ( ! results . contains ( selectedNode ) ) { results . add ( selectedNode ) ; } } }


Input: Selects nodes using CSS3 selector query and returns the very first one . [CODESPLIT] public Node selectFirst ( final String query ) { List < Node > selectedNodes = select ( query ) ; if ( selectedNodes . isEmpty ( ) ) { return null ; } return selectedNodes . get ( 0 ) ; }


Input: Selects nodes using { [CODESPLIT] public List < Node > select ( final NodeFilter nodeFilter ) { List < Node > nodes = new ArrayList <> ( ) ; walk ( rootNode , nodeFilter , nodes ) ; return nodes ; }


Input: Selects nodes using { [CODESPLIT] public Node selectFirst ( final NodeFilter nodeFilter ) { List < Node > selectedNodes = select ( nodeFilter ) ; if ( selectedNodes . isEmpty ( ) ) { return null ; } return selectedNodes . get ( 0 ) ; }


Input: ---------------------------------------------------------------- internal [CODESPLIT] protected void walk ( final Node rootNode , final NodeFilter nodeFilter , final List < Node > result ) { int childCount = rootNode . getChildNodesCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { Node node = rootNode . getChild ( i ) ; if ( nodeFilter . accept ( node ) ) { result . add ( node ) ; } walk ( node , nodeFilter , result ) ; } }


Input: Walks over the child notes maintaining the tree order and not using recursion . [CODESPLIT] protected void walkDescendantsIteratively ( final LinkedList < Node > nodes , final CssSelector cssSelector , final List < Node > result ) { while ( ! nodes . isEmpty ( ) ) { Node node = nodes . removeFirst ( ) ; selectAndAdd ( node , cssSelector , result ) ; // append children in walking order to be processed right after this node int childCount = node . getChildNodesCount ( ) ; for ( int i = childCount - 1 ; i >= 0 ; i -- ) { nodes . addFirst ( node . getChild ( i ) ) ; } } }


Input: Finds nodes in the tree that matches single selector . [CODESPLIT] protected void walk ( final Node rootNode , final CssSelector cssSelector , final List < Node > result ) { // previous combinator determines the behavior CssSelector previousCssSelector = cssSelector . getPrevCssSelector ( ) ; Combinator combinator = previousCssSelector != null ? previousCssSelector . getCombinator ( ) : Combinator . DESCENDANT ; switch ( combinator ) { case DESCENDANT : LinkedList < Node > nodes = new LinkedList <> ( ) ; int childCount = rootNode . getChildNodesCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { nodes . add ( rootNode . getChild ( i ) ) ; // recursive //					selectAndAdd(node, cssSelector, result); //					walk(node, cssSelector, result); } walkDescendantsIteratively ( nodes , cssSelector , result ) ; break ; case CHILD : childCount = rootNode . getChildNodesCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { Node node = rootNode . getChild ( i ) ; selectAndAdd ( node , cssSelector , result ) ; } break ; case ADJACENT_SIBLING : Node node = rootNode . getNextSiblingElement ( ) ; if ( node != null ) { selectAndAdd ( node , cssSelector , result ) ; } break ; case GENERAL_SIBLING : node = rootNode ; while ( true ) { node = node . getNextSiblingElement ( ) ; if ( node == null ) { break ; } selectAndAdd ( node , cssSelector , result ) ; } break ; } }


Input: Selects single node for single selector and appends it to the results . [CODESPLIT] protected void selectAndAdd ( final Node node , final CssSelector cssSelector , final List < Node > result ) { // ignore all nodes that are not elements if ( node . getNodeType ( ) != Node . NodeType . ELEMENT ) { return ; } boolean matched = cssSelector . accept ( node ) ; if ( matched ) { // check for duplicates if ( result . contains ( node ) ) { return ; } // no duplicate found, add it to the results result . add ( node ) ; } }


Input: Filter nodes . [CODESPLIT] protected boolean filter ( final List < Node > currentResults , final Node node , final CssSelector cssSelector , final int index ) { return cssSelector . accept ( currentResults , node , index ) ; }


Input: Unpacks the compressed character translation table . [CODESPLIT] private static char [ ] zzUnpackCMap ( final String packed ) { char [ ] map = new char [ 0x110000 ] ; int i = 0 ; /* index in packed string  */ int j = 0 ; /* index in unpacked array */ while ( i < 128 ) { int count = packed . charAt ( i ++ ) ; char value = packed . charAt ( i ++ ) ; do map [ j ++ ] = value ; while ( -- count > 0 ) ; } return map ; }


Input: Refills the input buffer . [CODESPLIT] private boolean zzRefill ( ) { if ( zzBuffer == null ) { zzBuffer = zzChars ; zzEndRead += zzChars . length ; return false ; } return true ; }


Input: Resumes scanning until the next regular expression is matched the end of input is encountered or an I / O - Error occurs . [CODESPLIT] public int yylex ( ) throws java . io . IOException { int zzInput ; int zzAction ; // cached fields: int zzCurrentPosL ; int zzMarkedPosL ; int zzEndReadL = zzEndRead ; char [ ] zzBufferL = zzBuffer ; char [ ] zzCMapL = ZZ_CMAP ; int [ ] zzTransL = ZZ_TRANS ; int [ ] zzRowMapL = ZZ_ROWMAP ; int [ ] zzAttrL = ZZ_ATTRIBUTE ; while ( true ) { zzMarkedPosL = zzMarkedPos ; yychar += zzMarkedPosL - zzStartRead ; zzAction = - 1 ; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL ; zzState = ZZ_LEXSTATE [ zzLexicalState ] ; // set up zzAction for empty match case: int zzAttributes = zzAttrL [ zzState ] ; if ( ( zzAttributes & 1 ) == 1 ) { zzAction = zzState ; } zzForAction : { while ( true ) { if ( zzCurrentPosL < zzEndReadL ) { zzInput = Character . codePointAt ( zzBufferL , zzCurrentPosL , zzEndReadL ) ; zzCurrentPosL += Character . charCount ( zzInput ) ; } else if ( zzAtEOF ) { zzInput = YYEOF ; break zzForAction ; } else { // store back cached positions zzCurrentPos = zzCurrentPosL ; zzMarkedPos = zzMarkedPosL ; boolean eof = zzRefill ( ) ; // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos ; zzMarkedPosL = zzMarkedPos ; zzBufferL = zzBuffer ; zzEndReadL = zzEndRead ; if ( eof ) { zzInput = YYEOF ; break zzForAction ; } else { zzInput = Character . codePointAt ( zzBufferL , zzCurrentPosL , zzEndReadL ) ; zzCurrentPosL += Character . charCount ( zzInput ) ; } } int zzNext = zzTransL [ zzRowMapL [ zzState ] + zzCMapL [ zzInput ] ] ; if ( zzNext == - 1 ) break zzForAction ; zzState = zzNext ; zzAttributes = zzAttrL [ zzState ] ; if ( ( zzAttributes & 1 ) == 1 ) { zzAction = zzState ; zzMarkedPosL = zzCurrentPosL ; if ( ( zzAttributes & 8 ) == 8 ) break zzForAction ; } } } // store back cached position zzMarkedPos = zzMarkedPosL ; if ( zzInput == YYEOF && zzStartRead == zzCurrentPos ) { zzAtEOF = true ; zzDoEOF ( ) ; { return 0 ; } } else { switch ( zzAction < 0 ? zzAction : ZZ_ACTION [ zzAction ] ) { case 1 : { cssSelector . setCombinator ( Combinator . DESCENDANT ) ; stateReset ( ) ; } case 20 : break ; case 2 : { cssSelector = new CssSelector ( yytext ( ) ) ; selectors . add ( cssSelector ) ; stateSelector ( ) ; } case 21 : break ; case 3 : { cssSelector = new CssSelector ( ) ; selectors . add ( cssSelector ) ; yypushback ( 1 ) ; stateSelector ( ) ; } case 22 : break ; case 4 : { /* ignore whitespaces */ } case 23 : break ; case 5 : { cssSelector = new CssSelector ( ) ; selectors . add ( cssSelector ) ; stateSelector ( ) ; } case 24 : break ; case 6 : { throw new CSSellyException ( "Illegal character <" + yytext ( ) + ">." , yystate ( ) , line ( ) , column ( ) ) ; } case 25 : break ; case 7 : { yypushback ( 1 ) ; stateCombinator ( ) ; } case 26 : break ; case 8 : { stateAttr ( ) ; } case 27 : break ; case 9 : { cssSelector . addAttributeSelector ( yytext ( ) ) ; } case 28 : break ; case 10 : { stateSelector ( ) ; } case 29 : break ; case 11 : { throw new CSSellyException ( "Invalid combinator <" + yytext ( ) + ">." , yystate ( ) , line ( ) , column ( ) ) ; } case 30 : break ; case 12 : { cssSelector . setCombinator ( Combinator . GENERAL_SIBLING ) ; stateReset ( ) ; } case 31 : break ; case 13 : { cssSelector . setCombinator ( Combinator . CHILD ) ; stateReset ( ) ; } case 32 : break ; case 14 : { cssSelector . setCombinator ( Combinator . ADJACENT_SIBLING ) ; stateReset ( ) ; } case 33 : break ; case 15 : { cssSelector . addPseudoFunctionSelector ( pseudoFnName , yytext ( 0 , 1 ) ) ; stateSelector ( ) ; } case 34 : break ; case 16 : { cssSelector . addClassSelector ( yytext ( 1 ) ) ; } case 35 : break ; case 17 : { cssSelector . addIdSelector ( yytext ( 1 ) ) ; } case 36 : break ; case 18 : { cssSelector . addPseudoClassSelector ( yytext ( yycharat ( 1 ) == ' ' ? 2 : 1 ) ) ; } case 37 : break ; case 19 : { pseudoFnName = yytext ( yycharat ( 1 ) == ' ' ? 2 : 1 , 1 ) ; statePseudoFn ( ) ; } case 38 : break ; default : zzScanError ( ZZ_NO_MATCH ) ; } } } }


Input: Performs the pagination with given { @link jodd . joy . page . PageRequest } . [CODESPLIT] public < T > PageData < T > page ( PageRequest pageRequest , final String sql , final Map params , final String [ ] sortColumns , final Class [ ] target ) { if ( pageRequest == null ) { pageRequest = getDefaultPageRequest ( ) ; } // check sort String sortColumName = null ; boolean ascending = true ; int sort = pageRequest . getSort ( ) ; if ( sort != 0 ) { ascending = sort > 0 ; if ( ! ascending ) { sort = - sort ; } int index = sort - 1 ; if ( index >= sortColumns . length ) { index = 1 ; } sortColumName = sortColumns [ index ] ; } // page int page = pageRequest . getPage ( ) ; int pageSize = pageRequest . getSize ( ) ; PageData < T > pageData = page ( sql , params , page , pageSize , sortColumName , ascending , target ) ; // fix the out-of-bounds if ( pageData . getItems ( ) . isEmpty ( ) && pageData . currentPage != 0 ) { if ( pageData . currentPage != page ) { // out of bounds int newPage = pageData . getCurrentPage ( ) ; pageData = page ( sql , params , newPage , pageSize , sortColumName , ascending , target ) ; } } return pageData ; }


Input: Pages given page . [CODESPLIT] protected < T > PageData < T > page ( String sql , final Map params , final int page , final int pageSize , final String sortColumnName , final boolean ascending , final Class [ ] target ) { if ( sortColumnName != null ) { sql = buildOrderSql ( sql , sortColumnName , ascending ) ; } int from = ( page - 1 ) * pageSize ; String pageSql = buildPageSql ( sql , from , pageSize ) ; DbSqlBuilder dbsql = sql ( pageSql ) ; DbOomQuery query = query ( dbsql ) ; query . setMaxRows ( pageSize ) ; query . setFetchSize ( pageSize ) ; query . setMap ( params ) ; List < T > list = query . list ( pageSize , target ) ; query . close ( ) ; String countSql = buildCountSql ( sql ) ; dbsql = sql ( countSql ) ; query = query ( dbsql ) ; query . setMap ( params ) ; long count = query . executeCount ( ) ; query . close ( ) ; return new PageData <> ( page , ( int ) count , pageSize , list ) ; }


Input: Removes the first select from the sql query . [CODESPLIT] protected String removeSelect ( String sql ) { int ndx = StringUtil . indexOfIgnoreCase ( sql , "select" ) ; if ( ndx != - 1 ) { sql = sql . substring ( ndx + 6 ) ; // select.length() } return sql ; }


Input: Removes the first part of the sql up to the relevant from . Tries to detect sub - queries in the select part . [CODESPLIT] protected String removeToFrom ( String sql ) { int from = 0 ; int fromCount = 1 ; int selectCount = 0 ; int lastNdx = 0 ; while ( true ) { int ndx = StringUtil . indexOfIgnoreCase ( sql , "from" , from ) ; if ( ndx == - 1 ) { break ; } // count selects in left part String left = sql . substring ( lastNdx , ndx ) ; selectCount += StringUtil . countIgnoreCase ( left , "select" ) ; if ( fromCount >= selectCount ) { sql = sql . substring ( ndx ) ; break ; } // find next 'from' lastNdx = ndx ; from = ndx + 4 ; fromCount ++ ; } return sql ; }


Input: Removes everything from last order by . [CODESPLIT] protected String removeLastOrderBy ( String sql ) { int ndx = StringUtil . lastIndexOfIgnoreCase ( sql , "order by" ) ; if ( ndx != - 1 ) { int ndx2 = sql . lastIndexOf ( sql , ' ' ) ; if ( ndx > ndx2 ) { sql = sql . substring ( 0 , ndx ) ; } } return sql ; }


Input: Decodes HTML text . Assumes that all character references are properly closed with semi - colon . [CODESPLIT] public static String decode ( final String html ) { int ndx = html . indexOf ( ' ' ) ; if ( ndx == - 1 ) { return html ; } StringBuilder result = new StringBuilder ( html . length ( ) ) ; int lastIndex = 0 ; int len = html . length ( ) ; mainloop : while ( ndx != - 1 ) { result . append ( html . substring ( lastIndex , ndx ) ) ; lastIndex = ndx ; while ( html . charAt ( lastIndex ) != ' ' ) { lastIndex ++ ; if ( lastIndex == len ) { lastIndex = ndx ; break mainloop ; } } if ( html . charAt ( ndx + 1 ) == ' ' ) { // decimal/hex char c = html . charAt ( ndx + 2 ) ; int radix ; if ( ( c == ' ' ) || ( c == ' ' ) ) { radix = 16 ; ndx += 3 ; } else { radix = 10 ; ndx += 2 ; } String number = html . substring ( ndx , lastIndex ) ; int i = Integer . parseInt ( number , radix ) ; result . append ( ( char ) i ) ; lastIndex ++ ; } else { // token String encodeToken = html . substring ( ndx + 1 , lastIndex ) ; char [ ] replacement = ENTITY_MAP . get ( encodeToken ) ; if ( replacement == null ) { result . append ( ' ' ) ; lastIndex = ndx + 1 ; } else { result . append ( replacement ) ; lastIndex ++ ; } } ndx = html . indexOf ( ' ' , lastIndex ) ; } result . append ( html . substring ( lastIndex ) ) ; return result . toString ( ) ; }


Input: Detects the longest character reference name on given position in char array . [CODESPLIT] public static String detectName ( final char [ ] input , int ndx ) { final Ptr ptr = new Ptr ( ) ; int firstIndex = 0 ; int lastIndex = ENTITY_NAMES . length - 1 ; int len = input . length ; char [ ] lastName = null ; final BinarySearchBase binarySearch = new BinarySearchBase ( ) { @ Override protected int compare ( final int index ) { char [ ] name = ENTITY_NAMES [ index ] ; if ( ptr . offset >= name . length ) { return - 1 ; } return name [ ptr . offset ] - ptr . c ; } } ; while ( true ) { ptr . c = input [ ndx ] ; if ( ! CharUtil . isAlphaOrDigit ( ptr . c ) ) { return lastName != null ? new String ( lastName ) : null ; } firstIndex = binarySearch . findFirst ( firstIndex , lastIndex ) ; if ( firstIndex < 0 ) { return lastName != null ? new String ( lastName ) : null ; } char [ ] element = ENTITY_NAMES [ firstIndex ] ; if ( element . length == ptr . offset + 1 ) { // total match, remember position, continue for finding the longer name lastName = ENTITY_NAMES [ firstIndex ] ; } lastIndex = binarySearch . findLast ( firstIndex , lastIndex ) ; if ( firstIndex == lastIndex ) { // only one element found, check the rest for ( int i = ptr . offset ; i < element . length ; i ++ ) { if ( element [ i ] != input [ ndx ] ) { return lastName != null ? new String ( lastName ) : null ; } ndx ++ ; } return new String ( element ) ; } ptr . offset ++ ; ndx ++ ; if ( ndx == len ) { return lastName != null ? new String ( lastName ) : null ; } } }


Input: ---------------------------------------------------------------- define [CODESPLIT] @ Override protected void defineParameter ( final StringBuilder query , final String name , final Object value , DbEntityColumnDescriptor dec ) { if ( dec == null ) { dec = templateData . lastColumnDec ; } super . defineParameter ( query , name , value , dec ) ; }


Input: Appends ORDER BY keyword . [CODESPLIT] @ Override protected String buildOrderSql ( String sql , final String column , final boolean ascending ) { sql += " order by " + column ; if ( ! ascending ) { sql += " desc" ; } return sql ; }


Input: Builds page sql using LIMIT keyword after the SELECT . [CODESPLIT] @ Override protected String buildPageSql ( String sql , final int from , final int pageSize ) { sql = removeSelect ( sql ) ; return "select LIMIT " + from + ' ' + pageSize + sql ; }


Input: Builds count sql using COUNT ( * ) . [CODESPLIT] @ Override protected String buildCountSql ( String sql ) { sql = removeToFrom ( sql ) ; sql = removeLastOrderBy ( sql ) ; return "select count(*) " + sql ; }


Input: Resolves list of all columns and properties . [CODESPLIT] private void resolveColumnsAndProperties ( final Class type ) { PropertyDescriptor [ ] allProperties = ClassIntrospector . get ( ) . lookup ( type ) . getAllPropertyDescriptors ( ) ; List < DbEntityColumnDescriptor > decList = new ArrayList <> ( allProperties . length ) ; int idcount = 0 ; HashSet < String > names = new HashSet <> ( allProperties . length ) ; for ( PropertyDescriptor propertyDescriptor : allProperties ) { DbEntityColumnDescriptor dec = DbMetaUtil . resolveColumnDescriptors ( this , propertyDescriptor , isAnnotated , columnNamingStrategy ) ; if ( dec != null ) { if ( ! names . add ( dec . getColumnName ( ) ) ) { throw new DbOomException ( "Duplicate column name: " + dec . getColumnName ( ) ) ; } decList . add ( dec ) ; if ( dec . isId ) { idcount ++ ; } } } if ( decList . isEmpty ( ) ) { throw new DbOomException ( "No column mappings in entity: " + type ) ; } columnDescriptors = decList . toArray ( new DbEntityColumnDescriptor [ 0 ] ) ; Arrays . sort ( columnDescriptors ) ; // extract ids from sorted list if ( idcount > 0 ) { idColumnDescriptors = new DbEntityColumnDescriptor [ idcount ] ; idcount = 0 ; for ( DbEntityColumnDescriptor dec : columnDescriptors ) { if ( dec . isId ) { idColumnDescriptors [ idcount ++ ] = dec ; } } } }


Input: Finds column descriptor by column name . Case is ignored . [CODESPLIT] public DbEntityColumnDescriptor findByColumnName ( final String columnName ) { if ( columnName == null ) { return null ; } init ( ) ; for ( DbEntityColumnDescriptor columnDescriptor : columnDescriptors ) { if ( columnDescriptor . columnName . equalsIgnoreCase ( columnName ) ) { return columnDescriptor ; } } return null ; }


Input: Finds column descriptor by property name . [CODESPLIT] public DbEntityColumnDescriptor findByPropertyName ( final String propertyName ) { if ( propertyName == null ) { return null ; } init ( ) ; for ( DbEntityColumnDescriptor columnDescriptor : columnDescriptors ) { if ( columnDescriptor . propertyName . equals ( propertyName ) ) { return columnDescriptor ; } } return null ; }


Input: Returns property name for specified column name . [CODESPLIT] public String getPropertyName ( final String columnName ) { DbEntityColumnDescriptor dec = findByColumnName ( columnName ) ; return dec == null ? null : dec . propertyName ; }


Input: Returns column name for specified property name .. [CODESPLIT] public String getColumnName ( final String propertyName ) { DbEntityColumnDescriptor dec = findByPropertyName ( propertyName ) ; return dec == null ? null : dec . columnName ; }


Input: Returns ID value for given entity instance . [CODESPLIT] public Object getIdValue ( final E object ) { final String propertyName = getIdPropertyName ( ) ; return BeanUtil . declared . getProperty ( object , propertyName ) ; }


Input: Sets ID value for given entity . [CODESPLIT] public void setIdValue ( final E object , final Object value ) { final String propertyName = getIdPropertyName ( ) ; BeanUtil . declared . setProperty ( object , propertyName , value ) ; }


Input: Returns unique key for this entity . Returned key is built from entity class and id value . [CODESPLIT] public String getKeyValue ( final E object ) { Object idValue = getIdValue ( object ) ; String idValueString = idValue == null ? StringPool . NULL : idValue . toString ( ) ; return type . getName ( ) . concat ( StringPool . COLON ) . concat ( idValueString ) ; }


Input: Appends a string . [CODESPLIT] public StringBand append ( String s ) { if ( s == null ) { s = StringPool . NULL ; } if ( index >= array . length ) { expandCapacity ( ) ; } array [ index ++ ] = s ; length += s . length ( ) ; return this ; }


Input: Specifies the new index . [CODESPLIT] public void setIndex ( final int newIndex ) { if ( newIndex < 0 ) { throw new ArrayIndexOutOfBoundsException ( newIndex ) ; } if ( newIndex > array . length ) { String [ ] newArray = new String [ newIndex ] ; System . arraycopy ( array , 0 , newArray , 0 , index ) ; array = newArray ; } if ( newIndex > index ) { for ( int i = index ; i < newIndex ; i ++ ) { array [ i ] = StringPool . EMPTY ; } } else if ( newIndex < index ) { for ( int i = newIndex ; i < index ; i ++ ) { array [ i ] = null ; } } index = newIndex ; length = calculateLength ( ) ; }


Input: Returns char at given position . This method is <b > not< / b > fast as it calculates the right string array element and the offset! [CODESPLIT] public char charAt ( final int pos ) { int len = 0 ; for ( int i = 0 ; i < index ; i ++ ) { int newlen = len + array [ i ] . length ( ) ; if ( pos < newlen ) { return array [ i ] . charAt ( pos - len ) ; } len = newlen ; } throw new IllegalArgumentException ( "Invalid char index" ) ; }


Input: Expands internal string array by multiplying its size by 2 . [CODESPLIT] protected void expandCapacity ( ) { String [ ] newArray = new String [ array . length << 1 ] ; System . arraycopy ( array , 0 , newArray , 0 , index ) ; array = newArray ; }


Input: Calculates string length . [CODESPLIT] protected int calculateLength ( ) { int len = 0 ; for ( int i = 0 ; i < index ; i ++ ) { len += array [ i ] . length ( ) ; } return len ; }


Input: Returns scoped proxy bean if injection scopes are mixed on some injection point . May return <code > null< / code > if mixing scopes is not detected . [CODESPLIT] public Object lookupValue ( final PetiteContainer petiteContainer , final BeanDefinition targetBeanDefinition , final BeanDefinition refBeanDefinition ) { Scope targetScope = targetBeanDefinition . scope ; Scope refBeanScope = refBeanDefinition . scope ; boolean detectMixedScopes = petiteContainer . config ( ) . isDetectMixedScopes ( ) ; boolean wireScopedProxy = petiteContainer . config ( ) . isWireScopedProxy ( ) ; // when target scope is null then all beans can be injected into it // similar to prototype scope if ( targetScope != null && ! targetScope . accept ( refBeanScope ) ) { if ( ! wireScopedProxy ) { if ( detectMixedScopes ) { throw new PetiteException ( createMixingMessage ( targetBeanDefinition , refBeanDefinition ) ) ; } return null ; } if ( detectMixedScopes ) { if ( log . isWarnEnabled ( ) ) { log . warn ( createMixingMessage ( targetBeanDefinition , refBeanDefinition ) ) ; } } else { if ( log . isDebugEnabled ( ) ) { log . debug ( createMixingMessage ( targetBeanDefinition , refBeanDefinition ) ) ; } } String scopedProxyBeanName = refBeanDefinition . name ; Object proxy = proxies . get ( scopedProxyBeanName ) ; if ( proxy == null ) { proxy = createScopedProxyBean ( petiteContainer , refBeanDefinition ) ; proxies . put ( scopedProxyBeanName , proxy ) ; } return proxy ; } return null ; }


Input: Creates mixed scope message . [CODESPLIT] protected String createMixingMessage ( final BeanDefinition targetBeanDefinition , final BeanDefinition refBeanDefinition ) { return "Scopes mixing detected: " + refBeanDefinition . name + "@" + refBeanDefinition . scope . getClass ( ) . getSimpleName ( ) + " -> " + targetBeanDefinition . name + "@" + targetBeanDefinition . scope . getClass ( ) . getSimpleName ( ) ; }


Input: Creates scoped proxy bean for given bean definition . [CODESPLIT] protected Object createScopedProxyBean ( final PetiteContainer petiteContainer , final BeanDefinition refBeanDefinition ) { Class beanType = refBeanDefinition . type ; Class proxyClass = proxyClasses . get ( beanType ) ; if ( proxyClass == null ) { // create proxy class only once if ( refBeanDefinition instanceof ProxettaBeanDefinition ) { // special case, double proxy! ProxettaBeanDefinition pbd = ( ProxettaBeanDefinition ) refBeanDefinition ; ProxyProxetta proxetta = Proxetta . proxyProxetta ( ) . withAspects ( ArraysUtil . insert ( pbd . proxyAspects , aspect , 0 ) ) ; proxetta . setClassNameSuffix ( "$ScopedProxy" ) ; proxetta . setVariableClassName ( true ) ; ProxyProxettaFactory builder = proxetta . proxy ( ) . setTarget ( pbd . originalTarget ) ; proxyClass = builder . define ( ) ; proxyClasses . put ( beanType , proxyClass ) ; } else { ProxyProxetta proxetta = Proxetta . proxyProxetta ( ) . withAspect ( aspect ) ; proxetta . setClassNameSuffix ( "$ScopedProxy" ) ; proxetta . setVariableClassName ( true ) ; ProxyProxettaFactory builder = proxetta . proxy ( ) . setTarget ( beanType ) ; proxyClass = builder . define ( ) ; proxyClasses . put ( beanType , proxyClass ) ; } } Object proxy ; try { proxy = ClassUtil . newInstance ( proxyClass ) ; Field field = proxyClass . getField ( "$__petiteContainer$0" ) ; field . set ( proxy , petiteContainer ) ; field = proxyClass . getField ( "$__name$0" ) ; field . set ( proxy , refBeanDefinition . name ) ; } catch ( Exception ex ) { throw new PetiteException ( ex ) ; } return proxy ; }


Input: Prepares step value . If step is 0 it will be set to + 1 or - 1 depending on start and end value . <p > If autoDirection flag is <code > true< / code > then it is assumed that step is positive and that direction ( step sign ) should be detected from start and end value . <p > If checkDirection flag is <code > true< / code > than it checks loop direction ( step sign ) based on start and end value . Throws an exception if direction is invalid . If autoDirection is set direction checking is skipped . [CODESPLIT] protected void prepareStepDirection ( final boolean autoDirection , final boolean checkDirection ) { if ( step == 0 ) { step = ( start <= end ) ? 1 : - 1 ; return ; } if ( autoDirection ) { if ( step < 0 ) { throw new IllegalArgumentException ( "Step value can't be negative: " + step ) ; } if ( start > end ) { step = - step ; } return ; } if ( checkDirection ) { if ( start < end ) { if ( step < 0 ) { throw new IllegalArgumentException ( "Negative step value for increasing loop" ) ; } return ; } if ( start > end ) { if ( step > 0 ) { throw new IllegalArgumentException ( "Positive step value for decreasing loop" ) ; } } } }


Input: Loops body . [CODESPLIT] protected void loopBody ( ) throws JspException { JspFragment body = getJspBody ( ) ; if ( body == null ) { return ; } LoopIterator loopIterator = new LoopIterator ( start , end , step , modulus ) ; if ( status != null ) { getJspContext ( ) . setAttribute ( status , loopIterator ) ; } while ( loopIterator . next ( ) ) { TagUtil . invokeBody ( body ) ; } if ( status != null ) { getJspContext ( ) . removeAttribute ( status ) ; } }


Input: Initializes dir watcher by reading all files from watched folder . [CODESPLIT] protected void init ( ) { File [ ] filesArray = dir . listFiles ( ) ; filesCount = 0 ; if ( filesArray != null ) { filesCount = filesArray . length ; for ( File file : filesArray ) { if ( ! acceptFile ( file ) ) { continue ; } map . put ( file , new MutableLong ( file . lastModified ( ) ) ) ; } } }


Input: Accepts if a file is going to be watched . [CODESPLIT] protected boolean acceptFile ( final File file ) { if ( ! file . isFile ( ) ) { return false ; // ignore non-files } String fileName = file . getName ( ) ; if ( ignoreDotFiles ) { if ( fileName . startsWith ( StringPool . DOT ) ) { return false ; // ignore hidden files } } if ( patterns == null ) { return true ; } return Wildcard . matchOne ( fileName , patterns ) != - 1 ; }


Input: Enables usage of provided watch file . [CODESPLIT] public DirWatcher useWatchFile ( final String name ) { watchFile = new File ( dir , name ) ; if ( ! watchFile . isFile ( ) || ! watchFile . exists ( ) ) { try { FileUtil . touch ( watchFile ) ; } catch ( IOException ioex ) { throw new DirWatcherException ( "Invalid watch file: " + name , ioex ) ; } } watchFileLastAccessTime = watchFile . lastModified ( ) ; return this ; }


Input: Starts the watcher . [CODESPLIT] public void start ( final long pollingInterval ) { if ( timer == null ) { if ( ! startBlank ) { init ( ) ; } timer = new Timer ( true ) ; timer . schedule ( new WatchTask ( ) , 0 , pollingInterval ) ; } }


Input: Triggers listeners on file change . [CODESPLIT] protected void onChange ( final DirWatcherEvent . Type type , final File file ) { listeners . accept ( new DirWatcherEvent ( type , file ) ) ; }


Input: Adds an enumeration to this composite . [CODESPLIT] public void add ( final Enumeration < T > enumeration ) { if ( allEnumerations . contains ( enumeration ) ) { throw new IllegalArgumentException ( "Duplicate enumeration" ) ; } allEnumerations . add ( enumeration ) ; }


Input: Returns <code > true< / code > if composite has more elements . [CODESPLIT] public boolean hasMoreElements ( ) { if ( currentEnumeration == - 1 ) { currentEnumeration = 0 ; } for ( int i = currentEnumeration ; i < allEnumerations . size ( ) ; i ++ ) { Enumeration enumeration = allEnumerations . get ( i ) ; if ( enumeration . hasMoreElements ( ) ) { currentEnumeration = i ; return true ; } } return false ; }


Input: Converts non - array value to array . Detects various collection types and iterates them to make conversion and to create target array . [CODESPLIT] protected double [ ] convertValueToArray ( final Object value ) { if ( value instanceof Collection ) { final Collection collection = ( Collection ) value ; final double [ ] target = new double [ collection . size ( ) ] ; int i = 0 ; for ( final Object element : collection ) { target [ i ] = convertType ( element ) ; i ++ ; } return target ; } if ( value instanceof Iterable ) { final Iterable iterable = ( Iterable ) value ; final ArrayList < Double > doubleArrayList = new ArrayList <> ( ) ; for ( final Object element : iterable ) { final double convertedValue = convertType ( element ) ; doubleArrayList . add ( Double . valueOf ( convertedValue ) ) ; } final double [ ] array = new double [ doubleArrayList . size ( ) ] ; for ( int i = 0 ; i < doubleArrayList . size ( ) ; i ++ ) { final Double d = doubleArrayList . get ( i ) ; array [ i ] = d . doubleValue ( ) ; } return array ; } if ( value instanceof CharSequence ) { final String [ ] strings = StringUtil . splitc ( value . toString ( ) , ArrayConverter . NUMBER_DELIMITERS ) ; return convertArrayToArray ( strings ) ; } // everything else: return convertToSingleElementArray ( value ) ; }


Input: Returns the size of the field_info JVMS structure generated by this FieldWriter . Also adds the names of the attributes of this field in the constant pool . [CODESPLIT] int computeFieldInfoSize ( ) { // The access_flags, name_index, descriptor_index and attributes_count fields use 8 bytes. int size = 8 ; // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS. if ( constantValueIndex != 0 ) { // ConstantValue attributes always use 8 bytes. symbolTable . addConstantUtf8 ( Constants . CONSTANT_VALUE ) ; size += 8 ; } // Before Java 1.5, synthetic fields are represented with a Synthetic attribute. if ( ( accessFlags & Opcodes . ACC_SYNTHETIC ) != 0 && symbolTable . getMajorVersion ( ) < Opcodes . V1_5 ) { // Synthetic attributes always use 6 bytes. symbolTable . addConstantUtf8 ( Constants . SYNTHETIC ) ; size += 6 ; } if ( signatureIndex != 0 ) { // Signature attributes always use 8 bytes. symbolTable . addConstantUtf8 ( Constants . SIGNATURE ) ; size += 8 ; } // ACC_DEPRECATED is ASM specific, the ClassFile format uses a Deprecated attribute instead. if ( ( accessFlags & Opcodes . ACC_DEPRECATED ) != 0 ) { // Deprecated attributes always use 6 bytes. symbolTable . addConstantUtf8 ( Constants . DEPRECATED ) ; size += 6 ; } if ( lastRuntimeVisibleAnnotation != null ) { size += lastRuntimeVisibleAnnotation . computeAnnotationsSize ( Constants . RUNTIME_VISIBLE_ANNOTATIONS ) ; } if ( lastRuntimeInvisibleAnnotation != null ) { size += lastRuntimeInvisibleAnnotation . computeAnnotationsSize ( Constants . RUNTIME_INVISIBLE_ANNOTATIONS ) ; } if ( lastRuntimeVisibleTypeAnnotation != null ) { size += lastRuntimeVisibleTypeAnnotation . computeAnnotationsSize ( Constants . RUNTIME_VISIBLE_TYPE_ANNOTATIONS ) ; } if ( lastRuntimeInvisibleTypeAnnotation != null ) { size += lastRuntimeInvisibleTypeAnnotation . computeAnnotationsSize ( Constants . RUNTIME_INVISIBLE_TYPE_ANNOTATIONS ) ; } if ( firstAttribute != null ) { size += firstAttribute . computeAttributesSize ( symbolTable ) ; } return size ; }


Input: Puts the content of the field_info JVMS structure generated by this FieldWriter into the given ByteVector . [CODESPLIT] void putFieldInfo ( final ByteVector output ) { boolean useSyntheticAttribute = symbolTable . getMajorVersion ( ) < Opcodes . V1_5 ; // Put the access_flags, name_index and descriptor_index fields. int mask = useSyntheticAttribute ? Opcodes . ACC_SYNTHETIC : 0 ; output . putShort ( accessFlags & ~ mask ) . putShort ( nameIndex ) . putShort ( descriptorIndex ) ; // Compute and put the attributes_count field. // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS. int attributesCount = 0 ; if ( constantValueIndex != 0 ) { ++ attributesCount ; } if ( ( accessFlags & Opcodes . ACC_SYNTHETIC ) != 0 && useSyntheticAttribute ) { ++ attributesCount ; } if ( signatureIndex != 0 ) { ++ attributesCount ; } if ( ( accessFlags & Opcodes . ACC_DEPRECATED ) != 0 ) { ++ attributesCount ; } if ( lastRuntimeVisibleAnnotation != null ) { ++ attributesCount ; } if ( lastRuntimeInvisibleAnnotation != null ) { ++ attributesCount ; } if ( lastRuntimeVisibleTypeAnnotation != null ) { ++ attributesCount ; } if ( lastRuntimeInvisibleTypeAnnotation != null ) { ++ attributesCount ; } if ( firstAttribute != null ) { attributesCount += firstAttribute . getAttributeCount ( ) ; } output . putShort ( attributesCount ) ; // Put the field_info attributes. // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS. if ( constantValueIndex != 0 ) { output . putShort ( symbolTable . addConstantUtf8 ( Constants . CONSTANT_VALUE ) ) . putInt ( 2 ) . putShort ( constantValueIndex ) ; } if ( ( accessFlags & Opcodes . ACC_SYNTHETIC ) != 0 && useSyntheticAttribute ) { output . putShort ( symbolTable . addConstantUtf8 ( Constants . SYNTHETIC ) ) . putInt ( 0 ) ; } if ( signatureIndex != 0 ) { output . putShort ( symbolTable . addConstantUtf8 ( Constants . SIGNATURE ) ) . putInt ( 2 ) . putShort ( signatureIndex ) ; } if ( ( accessFlags & Opcodes . ACC_DEPRECATED ) != 0 ) { output . putShort ( symbolTable . addConstantUtf8 ( Constants . DEPRECATED ) ) . putInt ( 0 ) ; } if ( lastRuntimeVisibleAnnotation != null ) { lastRuntimeVisibleAnnotation . putAnnotations ( symbolTable . addConstantUtf8 ( Constants . RUNTIME_VISIBLE_ANNOTATIONS ) , output ) ; } if ( lastRuntimeInvisibleAnnotation != null ) { lastRuntimeInvisibleAnnotation . putAnnotations ( symbolTable . addConstantUtf8 ( Constants . RUNTIME_INVISIBLE_ANNOTATIONS ) , output ) ; } if ( lastRuntimeVisibleTypeAnnotation != null ) { lastRuntimeVisibleTypeAnnotation . putAnnotations ( symbolTable . addConstantUtf8 ( Constants . RUNTIME_VISIBLE_TYPE_ANNOTATIONS ) , output ) ; } if ( lastRuntimeInvisibleTypeAnnotation != null ) { lastRuntimeInvisibleTypeAnnotation . putAnnotations ( symbolTable . addConstantUtf8 ( Constants . RUNTIME_INVISIBLE_TYPE_ANNOTATIONS ) , output ) ; } if ( firstAttribute != null ) { firstAttribute . putAttributes ( symbolTable , output ) ; } }


Input: Matches conditional comment expression with current mode . Returns <code > true< / code > it conditional comment expression is positive otherwise returns <code > false< / code > . [CODESPLIT] public boolean match ( final float ieVersion , String expression ) { expression = StringUtil . removeChars ( expression , "()" ) ; expression = expression . substring ( 3 ) ; String [ ] andChunks = StringUtil . splitc ( expression , ' ' ) ; boolean valid = true ; for ( String andChunk : andChunks ) { String [ ] orChunks = StringUtil . splitc ( andChunk , ' ' ) ; boolean innerValid = false ; for ( String orChunk : orChunks ) { orChunk = orChunk . trim ( ) ; if ( orChunk . startsWith ( "IE " ) ) { String value = orChunk . substring ( 3 ) ; float number = Float . parseFloat ( value ) ; if ( versionToCompare ( ieVersion , number ) == number ) { innerValid = true ; break ; } continue ; } if ( orChunk . startsWith ( "!IE " ) ) { String value = orChunk . substring ( 4 ) ; float number = Float . parseFloat ( value ) ; if ( versionToCompare ( ieVersion , number ) != number ) { innerValid = true ; break ; } continue ; } if ( orChunk . startsWith ( "lt IE " ) ) { String value = orChunk . substring ( 6 ) ; float number = Float . parseFloat ( value ) ; if ( ieVersion < number ) { innerValid = true ; break ; } continue ; } if ( orChunk . startsWith ( "lte IE " ) ) { String value = orChunk . substring ( 7 ) ; float number = Float . parseFloat ( value ) ; if ( versionToCompare ( ieVersion , number ) <= number ) { innerValid = true ; break ; } continue ; } if ( orChunk . startsWith ( "gt IE " ) ) { String value = orChunk . substring ( 6 ) ; float number = Float . parseFloat ( value ) ; if ( versionToCompare ( ieVersion , number ) > number ) { innerValid = true ; break ; } continue ; } if ( orChunk . startsWith ( "gte IE " ) ) { String value = orChunk . substring ( 7 ) ; float number = Float . parseFloat ( value ) ; if ( ieVersion >= number ) { innerValid = true ; break ; } continue ; } } valid = valid && innerValid ; } return valid ; }


Input: Appends another fast buffer to this one . [CODESPLIT] public FastByteBuffer append ( final FastByteBuffer buff ) { if ( buff . offset == 0 ) { return this ; } append ( buff . buffer , 0 , buff . offset ) ; return this ; }


Input: Creates a common target over a value with known scope data . [CODESPLIT] public static Target ofValue ( final Object value , final ScopeData scopeData ) { return new Target ( value , null , scopeData , null , VALUE_INSTANCE_CREATOR ) ; }


Input: Creates a common target over a method param . [CODESPLIT] public static Target ofMethodParam ( final MethodParam methodParam , final Object object ) { return new Target ( object , methodParam . type ( ) , methodParam . scopeData ( ) , methodParam . mapperFunction ( ) , VALUE_INSTANCE_CREATOR ) ; }


Input: Creates a common target over a method param . [CODESPLIT] public static Target ofMethodParam ( final MethodParam methodParam , final Function < Class , Object > valueInstanceCreator ) { return new Target ( null , methodParam . type ( ) , methodParam . scopeData ( ) , methodParam . mapperFunction ( ) , valueInstanceCreator ) ; }


Input: Writes value to this target . Depending on a flag writing the value can be completely silent when no exception is thrown and with top performances . Otherwise an exception is thrown on a failure . [CODESPLIT] public void writeValue ( final InjectionPoint injectionPoint , final Object propertyValue , final boolean silent ) { writeValue ( injectionPoint . targetName ( ) , propertyValue , silent ) ; }


Input: Decorates page content with decorator template and outputs the result . [CODESPLIT] public void decorate ( final Writer writer , final char [ ] pageContent , final char [ ] decoraContent ) throws IOException { DecoraTag [ ] decoraTags = parseDecorator ( decoraContent ) ; parsePage ( pageContent , decoraTags ) ; writeDecoratedPage ( writer , decoraContent , pageContent , decoraTags ) ; }


Input: Parses decorator file and collects { [CODESPLIT] protected DecoraTag [ ] parseDecorator ( final char [ ] decoraContent ) { LagartoParser lagartoParser = new LagartoParser ( decoraContent ) ; lagartoParser . getConfig ( ) . setEnableRawTextModes ( false ) ; DecoratorTagVisitor visitor = new DecoratorTagVisitor ( ) ; lagartoParser . parse ( visitor ) ; return visitor . getDecoraTags ( ) ; }


Input: Parses target page and extracts Decora regions for replacements . [CODESPLIT] protected void parsePage ( final char [ ] pageContent , final DecoraTag [ ] decoraTags ) { LagartoParser lagartoParser = new LagartoParser ( pageContent ) ; PageRegionExtractor writer = new PageRegionExtractor ( decoraTags ) ; lagartoParser . parse ( writer ) ; }


Input: Writes decorated content . [CODESPLIT] protected void writeDecoratedPage ( final Writer out , final char [ ] decoratorContent , final char [ ] pageContent , final DecoraTag [ ] decoraTags ) throws IOException { int ndx = 0 ; for ( DecoraTag decoraTag : decoraTags ) { // [1] just copy content before the Decora tag int decoratorLen = decoraTag . getStartIndex ( ) - ndx ; if ( decoratorLen <= 0 ) { continue ; } out . write ( decoratorContent , ndx , decoratorLen ) ; ndx = decoraTag . getEndIndex ( ) ; // [2] now write region at the place of Decora tag int regionLen = decoraTag . getRegionLength ( ) ; if ( regionLen == 0 ) { if ( decoraTag . hasDefaultValue ( ) ) { out . write ( decoratorContent , decoraTag . getDefaultValueStart ( ) , decoraTag . getDefaultValueLength ( ) ) ; } } else { writeRegion ( out , pageContent , decoraTag , decoraTags ) ; } } // write remaining content out . write ( decoratorContent , ndx , decoratorContent . length - ndx ) ; }


Input: Writes region to output but extracts all inner regions . [CODESPLIT] protected void writeRegion ( final Writer out , final char [ ] pageContent , final DecoraTag decoraTag , final DecoraTag [ ] decoraTags ) throws IOException { int regionStart = decoraTag . getRegionStart ( ) ; int regionLen = decoraTag . getRegionLength ( ) ; int regionEnd = regionStart + regionLen ; for ( DecoraTag innerDecoraTag : decoraTags ) { if ( decoraTag == innerDecoraTag ) { continue ; } if ( decoraTag . isRegionUndefined ( ) ) { continue ; } if ( innerDecoraTag . isInsideOtherTagRegion ( decoraTag ) ) { // write everything from region start to the inner Decora tag out . write ( pageContent , regionStart , innerDecoraTag . getRegionTagStart ( ) - regionStart ) ; regionStart = innerDecoraTag . getRegionTagEnd ( ) ; } } // write remaining content of the region out . write ( pageContent , regionStart , regionEnd - regionStart ) ; }


Input: Returns <code > true< / code > if text content is blank . [CODESPLIT] public boolean isBlank ( ) { if ( blank == null ) { blank = Boolean . valueOf ( StringUtil . isBlank ( nodeValue ) ) ; } return blank . booleanValue ( ) ; }


Input: Starts HTTP tunnel . Method ends when the tunnel is stopped . [CODESPLIT] public void start ( ) throws IOException { serverSocket = new ServerSocket ( listenPort , socketBacklog ) ; serverSocket . setReuseAddress ( true ) ; executorService = Executors . newFixedThreadPool ( threadPoolSize ) ; running = true ; while ( running ) { Socket socket = serverSocket . accept ( ) ; socket . setKeepAlive ( false ) ; executorService . execute ( onSocketConnection ( socket ) ) ; } executorService . shutdown ( ) ; }


Input: Converts non - array value to array . Detects various collection types and iterates them to make conversion and to create target array . [CODESPLIT] protected int [ ] convertValueToArray ( final Object value ) { if ( value instanceof Collection ) { final Collection collection = ( Collection ) value ; final int [ ] target = new int [ collection . size ( ) ] ; int i = 0 ; for ( final Object element : collection ) { target [ i ] = convertType ( element ) ; i ++ ; } return target ; } if ( value instanceof Iterable ) { final Iterable iterable = ( Iterable ) value ; final FastIntBuffer fastIntBuffer = new FastIntBuffer ( ) ; for ( final Object element : iterable ) { final int convertedValue = convertType ( element ) ; fastIntBuffer . append ( convertedValue ) ; } return fastIntBuffer . toArray ( ) ; } if ( value instanceof CharSequence ) { final String [ ] strings = StringUtil . splitc ( value . toString ( ) , ArrayConverter . NUMBER_DELIMITERS ) ; return convertArrayToArray ( strings ) ; } // everything else: return convertToSingleElementArray ( value ) ; }


Input: Executes a process and returns the process output and exit code . [CODESPLIT] public static ProcessResult run ( final Process process ) throws InterruptedException { final ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; final StreamGobbler outputGobbler = new StreamGobbler ( process . getInputStream ( ) , baos , OUTPUT_PREFIX ) ; final StreamGobbler errorGobbler = new StreamGobbler ( process . getErrorStream ( ) , baos , ERROR_PREFIX ) ; outputGobbler . start ( ) ; errorGobbler . start ( ) ; final int result = process . waitFor ( ) ; outputGobbler . waitFor ( ) ; errorGobbler . waitFor ( ) ; return new ProcessResult ( result , baos . toString ( ) ) ; }


Input: Returns email store . [CODESPLIT] @ Override protected IMAPSSLStore getStore ( final Session session ) { SimpleAuthenticator simpleAuthenticator = ( SimpleAuthenticator ) authenticator ; final URLName url ; if ( simpleAuthenticator == null ) { url = new URLName ( PROTOCOL_IMAP , host , port , StringPool . EMPTY , null , null ) ; } else { final PasswordAuthentication pa = simpleAuthenticator . getPasswordAuthentication ( ) ; url = new URLName ( PROTOCOL_IMAP , host , port , StringPool . EMPTY , pa . getUserName ( ) , pa . getPassword ( ) ) ; } return new IMAPSSLStore ( session , url ) ; }


Input: Returns <code > true< / code > if path matches the query . [CODESPLIT] public boolean matches ( final Path path ) { int exprNdx = 0 ; int pathNdx = 0 ; int pathLen = path . length ( ) ; int exprLen = expression . length ; while ( pathNdx < pathLen ) { CharSequence current = path . get ( pathNdx ) ; if ( exprNdx < exprLen && expression [ exprNdx ] . equals ( STAR ) ) { exprNdx ++ ; } else if ( exprNdx < exprLen && expression [ exprNdx ] . contentEquals ( current ) ) { pathNdx ++ ; exprNdx ++ ; } else if ( exprNdx - 1 >= 0 && expression [ exprNdx - 1 ] . equals ( STAR ) ) { pathNdx ++ ; } else { return false ; } } if ( exprNdx > 0 && expression [ exprNdx - 1 ] . equals ( STAR ) ) { return pathNdx >= pathLen && exprNdx >= exprLen ; } else { return pathLen != 0 && pathNdx >= pathLen && ( included || exprNdx >= exprLen ) ; } }


Input: Creates and returns a ServletOutputStream to write the content associated with this Response . [CODESPLIT] public ServletOutputStream createOutputStream ( ) throws IOException { GzipResponseStream gzstream = new GzipResponseStream ( origResponse ) ; gzstream . setBuffer ( threshold ) ; return gzstream ; }


Input: Invokes validation on inner context . Always returns <code > true< / code > since inner context violations will be appended to provided validator . [CODESPLIT] @ Override public boolean isValid ( final ValidationConstraintContext vcc , final Object value ) { if ( value == null ) { return true ; } vcc . validateWithin ( targetValidationContext , value ) ; return true ; }


Input: { [CODESPLIT] @ Override public URL get ( final ResultSet rs , final int index , final int dbSqlType ) throws SQLException { return rs . getURL ( index ) ; }


Input: { [CODESPLIT] @ Override public void set ( final PreparedStatement st , final int index , final URL value , final int dbSqlType ) throws SQLException { st . setURL ( index , value ) ; }


Input: ---------------------------------------------------------------- process [CODESPLIT] @ Override public void process ( final StringBuilder out ) { final DbEntityDescriptor ded ; if ( tableRef != null ) { ded = lookupTableRef ( tableRef ) ; final String tableName = resolveTable ( tableRef , ded ) ; out . append ( tableName ) ; } else { ded = findColumnRef ( columnRef ) ; } if ( onlyId ) { if ( tableRef != null ) { out . append ( ' ' ) ; } out . append ( ded . getIdColumnName ( ) ) ; } else if ( columnRef != null ) { DbEntityColumnDescriptor dec = ded . findByPropertyName ( columnRef ) ; templateData . lastColumnDec = dec ; if ( dec == null ) { throw new DbSqlBuilderException ( "Invalid column reference: [" + tableRef + ' ' + columnRef + "]" ) ; } if ( tableRef != null ) { out . append ( ' ' ) ; } out . append ( dec . getColumnNameForQuery ( ) ) ; } }


Input: Counts actual real hints . [CODESPLIT] @ Override public void init ( final TemplateData templateData ) { super . init ( templateData ) ; if ( hint != null ) { templateData . incrementHintsCount ( ) ; } }


Input: Appends alias . [CODESPLIT] protected void appendAlias ( final StringBuilder query , final DbEntityDescriptor ded , final DbEntityColumnDescriptor dec ) { final ColumnAliasType columnAliasType = templateData . getColumnAliasType ( ) ; if ( columnAliasType == null || columnAliasType == ColumnAliasType . TABLE_REFERENCE ) { final String tableName = ded . getTableName ( ) ; final String columnName = dec . getColumnNameForQuery ( ) ; templateData . registerColumnDataForTableRef ( tableRef , tableName ) ; query . append ( tableRef ) . append ( columnAliasSeparator ) . append ( columnName ) ; } else if ( columnAliasType == ColumnAliasType . COLUMN_CODE ) { final String tableName = ded . getTableName ( ) ; final String columnName = dec . getColumnName ( ) ; final String code = templateData . registerColumnDataForColumnCode ( tableName , columnName ) ; query . append ( code ) ; } else if ( columnAliasType == ColumnAliasType . TABLE_NAME ) { final String tableName = ded . getTableNameForQuery ( ) ; final String columnName = dec . getColumnNameForQuery ( ) ; query . append ( tableName ) . append ( columnAliasSeparator ) . append ( columnName ) ; } }


Input: Simply appends column name with optional table reference and alias . [CODESPLIT] protected void appendColumnName ( final StringBuilder query , final DbEntityDescriptor ded , final DbEntityColumnDescriptor dec ) { query . append ( resolveTable ( tableRef , ded ) ) . append ( ' ' ) . append ( dec . getColumnName ( ) ) ; if ( templateData . getColumnAliasType ( ) != null ) { // create column aliases query . append ( AS ) ; switch ( templateData . getColumnAliasType ( ) ) { case TABLE_NAME : { final String tableName = ded . getTableNameForQuery ( ) ; query . append ( tableName ) . append ( columnAliasSeparator ) . append ( dec . getColumnNameForQuery ( ) ) ; break ; } case TABLE_REFERENCE : { final String tableName = ded . getTableName ( ) ; templateData . registerColumnDataForTableRef ( tableRef , tableName ) ; query . append ( tableRef ) . append ( columnAliasSeparator ) . append ( dec . getColumnNameForQuery ( ) ) ; break ; } case COLUMN_CODE : { final String tableName = ded . getTableName ( ) ; final String code = templateData . registerColumnDataForColumnCode ( tableName , dec . getColumnName ( ) ) ; query . append ( code ) ; break ; } } } }


Input: Adds a rule . Duplicates are not allowed and will be ignored . [CODESPLIT] protected void addRule ( final D ruleDefinition , final boolean include ) { if ( rules == null ) { rules = new ArrayList <> ( ) ; } if ( include ) { includesCount ++ ; } else { excludesCount ++ ; } Rule < R > newRule = new Rule <> ( makeRule ( ruleDefinition ) , include ) ; if ( rules . contains ( newRule ) ) { return ; } rules . add ( newRule ) ; }


Input: Matches value against the set of rules using provided white / black list mode . [CODESPLIT] public boolean match ( final V value , final boolean blacklist ) { if ( rules == null ) { return blacklist ; } boolean include = blacklist ; if ( include ) { include = processExcludes ( value , true ) ; include = processIncludes ( value , include ) ; } else { include = processIncludes ( value , false ) ; include = processExcludes ( value , include ) ; } return include ; }


Input: Applies rules on given flag . Flag is only changed if at least one rule matched . Otherwise the same value is returned . This way you can chain several rules and have the rule engine change the flag only when a rule is matched . [CODESPLIT] public boolean apply ( final V value , final boolean blacklist , boolean flag ) { if ( rules == null ) { return flag ; } if ( blacklist ) { flag = processExcludes ( value , flag ) ; flag = processIncludes ( value , flag ) ; } else { flag = processIncludes ( value , flag ) ; flag = processExcludes ( value , flag ) ; } return flag ; }


Input: Process includes rules . [CODESPLIT] protected boolean processIncludes ( final V value , boolean include ) { if ( includesCount > 0 ) { if ( ! include ) { for ( Rule < R > rule : rules ) { if ( ! rule . include ) { continue ; } if ( inExRuleMatcher . accept ( value , rule . value , true ) ) { include = true ; break ; } } } } return include ; }


Input: Process excludes rules . [CODESPLIT] protected boolean processExcludes ( final V value , boolean include ) { if ( excludesCount > 0 ) { if ( include ) { for ( Rule < R > rule : rules ) { if ( rule . include ) { continue ; } if ( inExRuleMatcher . accept ( value , rule . value , false ) ) { include = false ; break ; } } } } return include ; }


Input: Matches value against single rule . By default performs <code > equals< / code > on value against the rule . [CODESPLIT] @ Override public boolean accept ( final V value , final R rule , final boolean include ) { return value . equals ( rule ) ; }


Input: Returns pseudo - class name from simple class name . [CODESPLIT] public String getPseudoClassName ( ) { String name = getClass ( ) . getSimpleName ( ) . toLowerCase ( ) ; name = name . replace ( ' ' , ' ' ) ; return name ; }


Input: Adds an Object to sorted list . Object is inserted at correct place found using binary search . If the same item exist it will be put to the end of the range . <p > This method breaks original list contract since objects are not added at the list end but in sorted manner . [CODESPLIT] @ Override public boolean add ( final E o ) { int idx = 0 ; if ( ! isEmpty ( ) ) { idx = findInsertionPoint ( o ) ; } super . add ( idx , o ) ; return true ; }


Input: Add all of the elements in the given collection to this list . [CODESPLIT] @ Override public boolean addAll ( final Collection < ? extends E > c ) { Iterator < ? extends E > i = c . iterator ( ) ; boolean changed = false ; while ( i . hasNext ( ) ) { boolean ret = add ( i . next ( ) ) ; if ( ! changed ) { changed = ret ; } } return changed ; }


Input: Conducts a binary search to find the index where Object should be inserted . [CODESPLIT] protected int findInsertionPoint ( final E o , int low , int high ) { while ( low <= high ) { int mid = ( low + high ) >>> 1 ; int delta = compare ( get ( mid ) , o ) ; if ( delta > 0 ) { high = mid - 1 ; } else { low = mid + 1 ; } } return low ; }


Input: Converts Jodd logging level to JDK . [CODESPLIT] private org . apache . logging . log4j . Level jodd2log4j2 ( final Logger . Level level ) { switch ( level ) { case TRACE : return org . apache . logging . log4j . Level . TRACE ; case DEBUG : return org . apache . logging . log4j . Level . DEBUG ; case INFO : return org . apache . logging . log4j . Level . INFO ; case WARN : return org . apache . logging . log4j . Level . WARN ; case ERROR : return org . apache . logging . log4j . Level . ERROR ; default : throw new IllegalArgumentException ( ) ; } }


Input: ---------------------------------------------------------------- match [CODESPLIT] public boolean accept ( final Node node ) { if ( ! node . hasAttribute ( name ) ) { return false ; } if ( value == null ) { // just detect if attribute exist return true ; } String nodeValue = node . getAttribute ( name ) ; if ( nodeValue == null ) { return false ; } return match . compare ( nodeValue , value ) ; }


Input: Registers action configuration for given annotation . New { [CODESPLIT] public void registerAnnotation ( final Class < ? extends Annotation > annotationType ) { final ActionConfiguredBy actionConfiguredBy = annotationType . getAnnotation ( ActionConfiguredBy . class ) ; if ( actionConfiguredBy == null ) { throw new MadvocException ( "Action annotation is missing it's " + ActionConfiguredBy . class . getSimpleName ( ) + " configuration." ) ; } bindAnnotationConfig ( annotationType , actionConfiguredBy . value ( ) ) ; }


Input: Binds action annotation and the action config . This can overwrite the default annotation configuration of an annotation . [CODESPLIT] public void bindAnnotationConfig ( final Class < ? extends Annotation > annotationType , final Class < ? extends ActionConfig > actionConfigClass ) { final ActionConfig actionConfig = registerNewActionConfiguration ( actionConfigClass ) ; actionConfigs . put ( annotationType , actionConfig ) ; for ( final AnnotationParser annotationParser : annotationParsers ) { if ( annotationType . equals ( annotationParser . getAnnotationType ( ) ) ) { // parser already exists return ; } } annotationParsers = ArraysUtil . append ( annotationParsers , new AnnotationParser ( annotationType , Action . class ) ) ; }


Input: Registers action configuration for given type . [CODESPLIT] protected ActionConfig registerNewActionConfiguration ( final Class < ? extends ActionConfig > actionConfigClass ) { final ActionConfig newActionConfig = createActionConfig ( actionConfigClass ) ; actionConfigs . put ( actionConfigClass , newActionConfig ) ; return newActionConfig ; }


Input: Lookup for the action configuration . Typically the input argument is either the action type or annotation type . [CODESPLIT] public ActionConfig lookup ( final Class actionTypeOrAnnotationType ) { final ActionConfig actionConfig = actionConfigs . get ( actionTypeOrAnnotationType ) ; if ( actionConfig == null ) { throw new MadvocException ( "ActionConfiguration not registered:" + actionTypeOrAnnotationType . getName ( ) ) ; } return actionConfig ; }


Input: Fetch some action config and consumes it . [CODESPLIT] public < T extends ActionConfig > void with ( final Class < T > actionConfigType , final Consumer < T > actionConfigConsumer ) { final T actionConfig = ( T ) lookup ( actionConfigType ) ; actionConfigConsumer . accept ( actionConfig ) ; }


Input: Returns { [CODESPLIT] public boolean hasActionAnnotationOn ( final AnnotatedElement annotatedElement ) { for ( final AnnotationParser annotationParser : annotationParsers ) { if ( annotationParser . hasAnnotationOn ( annotatedElement ) ) { return true ; } } return false ; }


Input: Setups the system email properties . [CODESPLIT] protected static void setupSystemMailProperties ( ) { System . setProperty ( "mail.mime.encodefilename" , Boolean . valueOf ( Defaults . mailMimeEncodefilename ) . toString ( ) ) ; System . setProperty ( "mail.mime.decodefilename" , Boolean . valueOf ( Defaults . mailMimeDecodefilename ) . toString ( ) ) ; }


Input: Validates provided context and value withing this constraint content . [CODESPLIT] public void validateWithin ( final ValidationContext vctx , final Object value ) { vtor . validate ( vctx , value , name ) ; }


Input: Returns <code > true< / code > if provided element is one of the table - related elements . [CODESPLIT] protected boolean isOneOfTableElements ( final Element element ) { String elementName = element . getNodeName ( ) . toLowerCase ( ) ; return StringUtil . equalsOne ( elementName , TABLE_ELEMENTS ) != - 1 ; }


Input: Returns <code > true< / code > if given node is a table element . [CODESPLIT] protected boolean isTableElement ( final Node node ) { if ( node . getNodeType ( ) != Node . NodeType . ELEMENT ) { return false ; } String elementName = node . getNodeName ( ) . toLowerCase ( ) ; return elementName . equals ( "table" ) ; }


Input: Returns <code > true< / code > if parent node is one of the table elements . [CODESPLIT] protected boolean isParentNodeOneOfFosterTableElements ( final Node parentNode ) { if ( parentNode == null ) { return false ; } if ( parentNode . getNodeName ( ) == null ) { return false ; } String nodeName = parentNode . getNodeName ( ) . toLowerCase ( ) ; return StringUtil . equalsOne ( nodeName , FOSTER_TABLE_ELEMENTS ) != - 1 ; }


Input: Finds the last table in stack of open elements . [CODESPLIT] protected Element findLastTable ( final Node node ) { Node tableNode = node ; while ( tableNode != null ) { if ( tableNode . getNodeType ( ) == Node . NodeType . ELEMENT ) { String tableNodeName = tableNode . getNodeName ( ) . toLowerCase ( ) ; if ( tableNodeName . equals ( "table" ) ) { break ; } } tableNode = tableNode . getParentNode ( ) ; } return ( Element ) tableNode ; }


Input: Finds foster elements . Returns <code > true< / code > if there was no change in DOM tree of the parent element . Otherwise returns <code > false< / code > meaning that parent will scan its childs again . [CODESPLIT] protected boolean findFosterNodes ( final Node node ) { boolean isTable = false ; if ( ! lastTables . isEmpty ( ) ) { // if inside table if ( node . getNodeType ( ) == Node . NodeType . TEXT ) { String value = node . getNodeValue ( ) ; if ( ! StringUtil . isBlank ( value ) ) { if ( isParentNodeOneOfFosterTableElements ( node . getParentNode ( ) ) ) { fosterTexts . add ( ( Text ) node ) ; } } } } if ( node . getNodeType ( ) == Node . NodeType . ELEMENT ) { Element element = ( Element ) node ; isTable = isTableElement ( node ) ; if ( isTable ) { // if node is a table, add it to the stack-of-last-tables lastTables . add ( element ) ; } else { // otherwise... // ...if inside the table if ( ! lastTables . isEmpty ( ) ) { // check this and parent Node parentNode = node . getParentNode ( ) ; if ( isParentNodeOneOfFosterTableElements ( parentNode ) && ! isOneOfTableElements ( element ) ) { String elementNodeName = element . getNodeName ( ) . toLowerCase ( ) ; if ( elementNodeName . equals ( "form" ) ) { if ( element . getChildNodesCount ( ) > 0 ) { // if form element, take all its child nodes // and add after the from element Node [ ] formChildNodes = element . getChildNodes ( ) ; parentNode . insertAfter ( formChildNodes , element ) ; return false ; } else { // empty form element, leave it where it is return true ; } } if ( elementNodeName . equals ( "input" ) ) { String inputType = element . getAttribute ( "type" ) ; if ( inputType . equals ( "hidden" ) ) { // input hidden elements remains as they are return true ; } } // foster element found, remember it to process it later fosterElements . add ( element ) ; } } else { // ...if not inside the table, just keep going } } } allchilds : while ( true ) { int childs = node . getChildNodesCount ( ) ; for ( int i = 0 ; i < childs ; i ++ ) { Node childNode = node . getChild ( i ) ; boolean done = findFosterNodes ( childNode ) ; if ( ! done ) { continue allchilds ; } } break ; } if ( isTable ) { // remove last element int size = lastTables . size ( ) ; if ( size > 0 ) { lastTables . remove ( size - 1 ) ; // no array copy occurs when the last element is removed } } return true ; }


Input: Performs the fix for elements . [CODESPLIT] protected void fixElements ( ) { for ( Element fosterElement : fosterElements ) { // find parent table Element lastTable = findLastTable ( fosterElement ) ; Node fosterElementParent = fosterElement . getParentNode ( ) ; // filter our foster element Node [ ] fosterChilds = fosterElement . getChildNodes ( ) ; for ( Node fosterChild : fosterChilds ) { if ( fosterChild . getNodeType ( ) == Node . NodeType . ELEMENT ) { if ( isOneOfTableElements ( ( Element ) fosterChild ) ) { // move all child table elements outside // the foster element fosterChild . detachFromParent ( ) ; fosterElementParent . insertBefore ( fosterChild , fosterElement ) ; } } } // finally, move foster element above the table fosterElement . detachFromParent ( ) ; lastTable . getParentNode ( ) . insertBefore ( fosterElement , lastTable ) ; } }


Input: Prune only expired objects <code > LinkedHashMap< / code > will take care of LRU if needed . [CODESPLIT] @ Override protected int pruneCache ( ) { if ( ! isPruneExpiredActive ( ) ) { return 0 ; } int count = 0 ; Iterator < CacheObject < K , V > > values = cacheMap . values ( ) . iterator ( ) ; while ( values . hasNext ( ) ) { CacheObject < K , V > co = values . next ( ) ; if ( co . isExpired ( ) ) { values . remove ( ) ; onRemove ( co . key , co . cachedObject ) ; count ++ ; } } return count ; }


Input: Registers new session destroy callback if not already registered . [CODESPLIT] protected Map < String , BeanData > registerSessionBeans ( final HttpSession httpSession ) { SessionBeans sessionBeans = new SessionBeans ( ) ; httpSession . setAttribute ( SESSION_BEANS_NAME , sessionBeans ) ; return sessionBeans . getBeanMap ( ) ; }


Input: Returns instance map from http session . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) protected Map < String , BeanData > getSessionMap ( final HttpSession session ) { SessionBeans sessionBeans = ( SessionBeans ) session . getAttribute ( SESSION_BEANS_NAME ) ; if ( sessionBeans == null ) { return null ; } return sessionBeans . getBeanMap ( ) ; }


Input: Returns request from current thread . [CODESPLIT] protected HttpSession getCurrentHttpSession ( ) { HttpServletRequest request = RequestContextListener . getRequest ( ) ; if ( request == null ) { throw new PetiteException ( "No HTTP request bound to the current thread. Is RequestContextListener registered?" ) ; } return request . getSession ( ) ; }


Input: Work data initialization . [CODESPLIT] public void init ( String name , final String superName , final String suffix , final String reqProxyClassName ) { int lastSlash = name . lastIndexOf ( ' ' ) ; this . targetPackage = lastSlash == - 1 ? StringPool . EMPTY : name . substring ( 0 , lastSlash ) . replace ( ' ' , ' ' ) ; this . targetClassname = name . substring ( lastSlash + 1 ) ; this . nextSupername = superName ; this . superName = name ; // create proxy name if ( reqProxyClassName != null ) { if ( reqProxyClassName . startsWith ( DOT ) ) { name = name . substring ( 0 , lastSlash ) + ' ' + reqProxyClassName . substring ( 1 ) ; } else if ( reqProxyClassName . endsWith ( DOT ) ) { name = reqProxyClassName . replace ( ' ' , ' ' ) + this . targetClassname ; } else { name = reqProxyClassName . replace ( ' ' , ' ' ) ; } } // add optional suffix if ( suffix != null ) { name += suffix ; } this . thisReference = name ; this . superReference = this . superName ; }


Input: Saves used static initialization blocks ( clinit ) of advices . [CODESPLIT] void addAdviceClinitMethod ( final String name ) { if ( adviceClinits == null ) { adviceClinits = new ArrayList <> ( ) ; } adviceClinits . add ( name ) ; }


Input: Saves used constructors of advices . [CODESPLIT] void addAdviceInitMethod ( final String name ) { if ( adviceInits == null ) { adviceInits = new ArrayList <> ( ) ; } adviceInits . add ( name ) ; }


Input: { [CODESPLIT] @ Override public Byte get ( final ResultSet rs , final int index , final int dbSqlType ) throws SQLException { return Byte . valueOf ( rs . getByte ( index ) ) ; }


Input: { [CODESPLIT] @ Override public void set ( final PreparedStatement st , final int index , final Byte value , final int dbSqlType ) throws SQLException { st . setByte ( index , value . byteValue ( ) ) ; }


Input: Process links . Returns bundle link if this is the first resource of the same type . Otherwise returns <code > null< / code > indicating that collection is going on and the original link should be removed . [CODESPLIT] public String processLink ( final String src ) { if ( newAction ) { if ( bundleId == null ) { bundleId = bundlesManager . registerNewBundleId ( ) ; bundleId += ' ' + bundleContentType ; } sources . add ( src ) ; } if ( firstScriptTag ) { // this is the first tag, change the url to point to the bundle firstScriptTag = false ; return buildStaplerUrl ( ) ; } else { // ignore all other script tags return null ; } }


Input: Called on end of parsing . [CODESPLIT] public void end ( ) { if ( newAction ) { bundleId = bundlesManager . registerBundle ( contextPath , actionPath , bundleId , bundleContentType , sources ) ; } }


Input: Replaces bundle marker with calculated bundle id . Used for <code > RESOURCE_ONLY< / code > strategy . [CODESPLIT] public char [ ] replaceBundleId ( final char [ ] content ) { if ( strategy == ACTION_MANAGED || bundleId == null ) { return content ; } int index = ArraysUtil . indexOf ( content , bundleIdMark ) ; if ( index == - 1 ) { return content ; } char [ ] bundleIdChars = bundleId . toCharArray ( ) ; char [ ] result = new char [ content . length - bundleIdMark . length + bundleIdChars . length ] ; System . arraycopy ( content , 0 , result , 0 , index ) ; System . arraycopy ( bundleIdChars , 0 , result , index , bundleIdChars . length ) ; System . arraycopy ( content , index + bundleIdMark . length , result , index + bundleIdChars . length , content . length - bundleIdMark . length - index ) ; return result ; }


Input: Convert Java Properties to Jodd Props format . [CODESPLIT] public static void convert ( final Writer writer , final Properties properties ) throws IOException { convert ( writer , properties , Collections . emptyMap ( ) ) ; }


Input: Convert Java Properties to Jodd Props format . [CODESPLIT] public static void convert ( final Writer writer , final Properties properties , final Map < String , Properties > profiles ) throws IOException { final PropertiesToProps toProps = new PropertiesToProps ( ) ; toProps . convertToWriter ( writer , properties , profiles ) ; }


Input: Loads properties . [CODESPLIT] public void parse ( final String in ) { ParseState state = ParseState . TEXT ; ParseState stateOnEscape = null ; boolean insideSection = false ; String currentSection = null ; String key = null ; Operator operator = Operator . ASSIGN ; final StringBuilder sb = new StringBuilder ( ) ; final int len = in . length ( ) ; int ndx = 0 ; while ( ndx < len ) { final char c = in . charAt ( ndx ) ; ndx ++ ; if ( state == ParseState . COMMENT ) { // comment, skip to the end of the line if ( c == ' ' ) { if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } state = ParseState . TEXT ; } else if ( c == ' ' ) { state = ParseState . TEXT ; } } else if ( state == ParseState . ESCAPE ) { state = stateOnEscape ; //ParseState.VALUE; switch ( c ) { case ' ' : if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } case ' ' : // need to go 1 step back in order to escape // the current line ending in the follow-up state ndx -- ; state = ParseState . ESCAPE_NEWLINE ; break ; // encode UTF character case ' ' : int value = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { final char hexChar = in . charAt ( ndx ++ ) ; if ( CharUtil . isDigit ( hexChar ) ) { value = ( value << 4 ) + hexChar - ' ' ; } else if ( hexChar >= ' ' && hexChar <= ' ' ) { value = ( value << 4 ) + 10 + hexChar - ' ' ; } else if ( hexChar >= ' ' && hexChar <= ' ' ) { value = ( value << 4 ) + 10 + hexChar - ' ' ; } else { throw new IllegalArgumentException ( "Malformed \\uXXXX encoding." ) ; } } sb . append ( ( char ) value ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; default : sb . append ( c ) ; } } else if ( state == ParseState . TEXT ) { switch ( c ) { case ' ' : // escape char, take the next char as is stateOnEscape = state ; state = ParseState . ESCAPE ; break ; // start section case ' ' : if ( sb . length ( ) > 0 ) { if ( StringUtil . isNotBlank ( sb ) ) { sb . append ( c ) ; // previous string is not blank, hence it's not the section break ; } } sb . setLength ( 0 ) ; insideSection = true ; break ; // end section case ' ' : if ( insideSection ) { currentSection = sb . toString ( ) . trim ( ) ; sb . setLength ( 0 ) ; insideSection = false ; if ( currentSection . length ( ) == 0 ) { currentSection = null ; } } else { sb . append ( c ) ; } break ; case ' ' : case ' ' : state = ParseState . COMMENT ; break ; // copy operator case ' ' : if ( ndx == len || in . charAt ( ndx ) != ' ' ) { sb . append ( c ) ; break ; } operator = Operator . COPY ; //ndx++; continue ; // assignment operator case ' ' : if ( ndx == len || in . charAt ( ndx ) != ' ' ) { sb . append ( c ) ; break ; } operator = Operator . QUICK_APPEND ; //ndx++; continue ; case ' ' : case ' ' : if ( key == null ) { key = sb . toString ( ) . trim ( ) ; sb . setLength ( 0 ) ; } else { sb . append ( c ) ; } state = ParseState . VALUE ; break ; case ' ' : case ' ' : add ( currentSection , key , sb , true , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; break ; case ' ' : case ' ' : // ignore whitespaces break ; default : sb . append ( c ) ; } } else { switch ( c ) { case ' ' : // escape char, take the next char as is stateOnEscape = state ; state = ParseState . ESCAPE ; break ; case ' ' : if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } case ' ' : if ( state == ParseState . ESCAPE_NEWLINE ) { sb . append ( escapeNewLineValue ) ; if ( ! ignorePrefixWhitespacesOnNewLine ) { state = ParseState . VALUE ; } } else { add ( currentSection , key , sb , true , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; // end of value, continue to text state = ParseState . TEXT ; } break ; case ' ' : case ' ' : if ( state == ParseState . ESCAPE_NEWLINE ) { break ; } default : sb . append ( c ) ; state = ParseState . VALUE ; if ( multilineValues ) { if ( sb . length ( ) == 3 ) { // check for ''' beginning if ( sb . toString ( ) . equals ( "'''" ) ) { sb . setLength ( 0 ) ; int endIndex = in . indexOf ( "'''" , ndx ) ; if ( endIndex == - 1 ) { endIndex = in . length ( ) ; } sb . append ( in , ndx , endIndex ) ; // append add ( currentSection , key , sb , false , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; // end of value, continue to text state = ParseState . TEXT ; ndx = endIndex + 3 ; } } } } } } if ( key != null ) { add ( currentSection , key , sb , true , operator ) ; } }


Input: Adds accumulated value to key and current section . [CODESPLIT] protected void add ( final String section , final String key , final StringBuilder value , final boolean trim , final Operator operator ) { // ignore lines without : or = if ( key == null ) { return ; } String fullKey = key ; if ( section != null ) { if ( fullKey . length ( ) != 0 ) { fullKey = section + ' ' + fullKey ; } else { fullKey = section ; } } String v = value . toString ( ) ; if ( trim ) { if ( valueTrimLeft && valueTrimRight ) { v = v . trim ( ) ; } else if ( valueTrimLeft ) { v = StringUtil . trimLeft ( v ) ; } else { v = StringUtil . trimRight ( v ) ; } } if ( v . length ( ) == 0 && skipEmptyProps ) { return ; } extractProfilesAndAdd ( fullKey , v , operator ) ; }


Input: Extracts profiles from the key name and adds key - value to them . [CODESPLIT] protected void extractProfilesAndAdd ( final String key , final String value , final Operator operator ) { String fullKey = key ; int ndx = fullKey . indexOf ( PROFILE_LEFT ) ; if ( ndx == - 1 ) { justAdd ( fullKey , value , null , operator ) ; return ; } // extract profiles ArrayList < String > keyProfiles = new ArrayList <> ( ) ; while ( true ) { ndx = fullKey . indexOf ( PROFILE_LEFT ) ; if ( ndx == - 1 ) { break ; } final int len = fullKey . length ( ) ; int ndx2 = fullKey . indexOf ( PROFILE_RIGHT , ndx + 1 ) ; if ( ndx2 == - 1 ) { ndx2 = len ; } // remember profile final String profile = fullKey . substring ( ndx + 1 , ndx2 ) ; keyProfiles . add ( profile ) ; // extract profile from key ndx2 ++ ; final String right = ( ndx2 == len ) ? StringPool . EMPTY : fullKey . substring ( ndx2 ) ; fullKey = fullKey . substring ( 0 , ndx ) + right ; } if ( fullKey . startsWith ( StringPool . DOT ) ) { // check for special case when only profile is defined in section fullKey = fullKey . substring ( 1 ) ; } // add value to extracted profiles justAdd ( fullKey , value , keyProfiles , operator ) ; }


Input: Core key - value addition . [CODESPLIT] protected void justAdd ( final String key , final String value , final ArrayList < String > keyProfiles , final Operator operator ) { if ( operator == Operator . COPY ) { HashMap < String , Object > target = new HashMap <> ( ) ; String [ ] profiles = null ; if ( keyProfiles != null ) { profiles = keyProfiles . toArray ( new String [ 0 ] ) ; } String [ ] sources = StringUtil . splitc ( value , ' ' ) ; for ( String source : sources ) { source = source . trim ( ) ; // try to extract profile for parsing String [ ] lookupProfiles = profiles ; String lookupProfilesString = null ; int leftIndex = source . indexOf ( ' ' ) ; if ( leftIndex != - 1 ) { int rightIndex = source . indexOf ( ' ' ) ; lookupProfilesString = source . substring ( leftIndex + 1 , rightIndex ) ; source = source . substring ( 0 , leftIndex ) . concat ( source . substring ( rightIndex + 1 ) ) ; lookupProfiles = StringUtil . splitc ( lookupProfilesString , ' ' ) ; StringUtil . trimAll ( lookupProfiles ) ; } String [ ] wildcards = new String [ ] { source + ".*" } ; propsData . extract ( target , lookupProfiles , wildcards , null ) ; for ( Map . Entry < String , Object > entry : target . entrySet ( ) ) { String entryKey = entry . getKey ( ) ; String suffix = entryKey . substring ( source . length ( ) ) ; String newKey = key + suffix ; String newValue = "${" + entryKey ; if ( lookupProfilesString != null ) { newValue += "<" + lookupProfilesString + ">" ; } newValue += "}" ; if ( profiles == null ) { propsData . putBaseProperty ( newKey , newValue , false ) ; } else { for ( final String p : profiles ) { propsData . putProfileProperty ( newKey , newValue , p , false ) ; } } } } return ; } boolean append = operator == Operator . QUICK_APPEND ; if ( keyProfiles == null ) { propsData . putBaseProperty ( key , value , append ) ; return ; } for ( final String p : keyProfiles ) { propsData . putProfileProperty ( key , value , p , append ) ; } }


Input: Compares value of two same instances . [CODESPLIT] @ Override public int compareTo ( final MutableShort other ) { return value < other . value ? - 1 : ( value == other . value ? 0 : 1 ) ; }


Input: Converts bytecode - like description to java class name that can be loaded with a classloader . Uses less - known feature of class loaders for loading array classes . [CODESPLIT] public static String typedesc2ClassName ( final String desc ) { String className = desc ; switch ( desc . charAt ( 0 ) ) { case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : if ( desc . length ( ) != 1 ) { throw new IllegalArgumentException ( INVALID_BASE_TYPE + desc ) ; } break ; case ' ' : className = className . substring ( 1 , className . length ( ) - 1 ) ; break ; case ' ' : // uses less-known feature of class loaders for loading array types // using bytecode-like signatures. className = className . replace ( ' ' , ' ' ) ; break ; default : throw new IllegalArgumentException ( INVALID_TYPE_DESCRIPTION + desc ) ; } return className ; }


Input: Converts type reference to java - name . [CODESPLIT] public static String typeref2Name ( final String desc ) { if ( desc . charAt ( 0 ) != TYPE_REFERENCE ) { throw new IllegalArgumentException ( INVALID_TYPE_DESCRIPTION + desc ) ; } String name = desc . substring ( 1 , desc . length ( ) - 1 ) ; return name . replace ( ' ' , ' ' ) ; }


Input: Returns java - like signature of a bytecode - like description . Only first description is parsed . [CODESPLIT] public static String typedescToSignature ( final String desc , final MutableInteger from ) { int fromIndex = from . get ( ) ; from . value ++ ; // default usage for most cases switch ( desc . charAt ( fromIndex ) ) { case ' ' : return "byte" ; case ' ' : return "char" ; case ' ' : return "double" ; case ' ' : return "float" ; case ' ' : return "int" ; case ' ' : return "long" ; case ' ' : return "short" ; case ' ' : return "boolean" ; case ' ' : return "void" ; case ' ' : int index = desc . indexOf ( ' ' , fromIndex ) ; if ( index < 0 ) { throw new IllegalArgumentException ( INVALID_TYPE_DESCRIPTION + desc ) ; } from . set ( index + 1 ) ; String str = desc . substring ( fromIndex + 1 , index ) ; return str . replace ( ' ' , ' ' ) ; case ' ' : return desc . substring ( from . value ) ; case ' ' : StringBuilder brackets = new StringBuilder ( ) ; int n = fromIndex ; while ( desc . charAt ( n ) == ' ' ) { // count opening brackets brackets . append ( "[]" ) ; n ++ ; } from . value = n ; String type = typedescToSignature ( desc , from ) ; // the rest of the string denotes a `<field_type>' return type + brackets ; default : if ( from . value == 0 ) { throw new IllegalArgumentException ( INVALID_TYPE_DESCRIPTION + desc ) ; } // generics! return desc . substring ( from . value ) ; } }


Input: Converts type to byteccode type ref . [CODESPLIT] public static String typeToTyperef ( final Class type ) { if ( ! type . isArray ( ) ) { if ( ! type . isPrimitive ( ) ) { return ' ' + typeToSignature ( type ) + ' ' ; } if ( type == int . class ) { return "I" ; } if ( type == long . class ) { return "J" ; } if ( type == boolean . class ) { return "Z" ; } if ( type == double . class ) { return "D" ; } if ( type == float . class ) { return "F" ; } if ( type == short . class ) { return "S" ; } if ( type == void . class ) { return "V" ; } if ( type == byte . class ) { return "B" ; } if ( type == char . class ) { return "C" ; } } return type . getName ( ) ; }


Input: Converts <code > Integer< / code > object to an <code > int< / code > . [CODESPLIT] public static void intValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_INTEGER ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_INTEGER , "intValue" , "()I" , false ) ; }


Input: Converts <code > Long< / code > object to a <code > long< / code > . [CODESPLIT] public static void longValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_LONG ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_LONG , "longValue" , "()J" , false ) ; }


Input: Converts <code > Float< / code > object to a <code > float< / code > . [CODESPLIT] public static void floatValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_FLOAT ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_FLOAT , "floatValue" , "()F" , false ) ; }


Input: Converts <code > Double< / code > object to a <code > double< / code > . [CODESPLIT] public static void doubleValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_DOUBLE ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_DOUBLE , "doubleValue" , "()D" , false ) ; }


Input: Converts <code > Byte< / code > object to a <code > byte< / code > . [CODESPLIT] public static void byteValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_BYTE ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_BYTE , "byteValue" , "()B" , false ) ; }


Input: Converts <code > Short< / code > object to a <code > short< / code > . [CODESPLIT] public static void shortValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_SHORT ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_SHORT , "shortValue" , "()S" , false ) ; }


Input: Converts <code > Boolean< / code > object to a <code > boolean< / code > . [CODESPLIT] public static void booleanValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_BOOLEAN ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_BOOLEAN , "booleanValue" , "()Z" , false ) ; }


Input: Converts <code > Character< / code > object to a <code > char< / code > . [CODESPLIT] public static void charValue ( final MethodVisitor mv ) { mv . visitTypeInsn ( CHECKCAST , SIGNATURE_JAVA_LANG_CHARACTER ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , SIGNATURE_JAVA_LANG_CHARACTER , "charValue" , "()C" , false ) ; }


Input: Registers additional consumers . [CODESPLIT] public Consumers < T > addAll ( final Consumer < T > ... consumers ) { Collections . addAll ( consumerList , consumers ) ; return this ; }


Input: Consumes all registered consumers . The are executed sequentially in order of registration . If { [CODESPLIT] @ Override public void accept ( final T t ) { if ( parallel ) { consumerList . parallelStream ( ) . forEach ( consumer -> consumer . accept ( t ) ) ; } else { consumerList . forEach ( consumer -> consumer . accept ( t ) ) ; } }


Input: Creates new collection of target component type . Default implementation uses reflection to create an collection of target type . Override it for better performances . [CODESPLIT] @ SuppressWarnings ( "unchecked" ) protected Collection < T > createCollection ( final int length ) { if ( collectionType . isInterface ( ) ) { if ( collectionType == List . class ) { if ( length > 0 ) { return new ArrayList <> ( length ) ; } else { return new ArrayList <> ( ) ; } } if ( collectionType == Set . class ) { if ( length > 0 ) { return new HashSet <> ( length ) ; } else { return new HashSet <> ( ) ; } } throw new TypeConversionException ( "Unknown collection: " + collectionType . getName ( ) ) ; } if ( length > 0 ) { try { Constructor < Collection < T >> ctor = ( Constructor < Collection < T > > ) collectionType . getConstructor ( int . class ) ; return ctor . newInstance ( Integer . valueOf ( length ) ) ; } catch ( Exception ex ) { // ignore exception } } try { return collectionType . getDeclaredConstructor ( ) . newInstance ( ) ; } catch ( Exception ex ) { throw new TypeConversionException ( ex ) ; } }


Input: Creates a collection with single element . [CODESPLIT] protected Collection < T > convertToSingleElementCollection ( final Object value ) { Collection < T > collection = createCollection ( 0 ) ; //noinspection unchecked collection . add ( ( T ) value ) ; return collection ; }


Input: Converts non - collection value to collection . [CODESPLIT] protected Collection < T > convertValueToCollection ( Object value ) { if ( value instanceof Iterable ) { Iterable iterable = ( Iterable ) value ; Collection < T > collection = createCollection ( 0 ) ; for ( Object element : iterable ) { collection . add ( convertType ( element ) ) ; } return collection ; } if ( value instanceof CharSequence ) { value = CsvUtil . toStringArray ( value . toString ( ) ) ; } Class type = value . getClass ( ) ; if ( type . isArray ( ) ) { // convert arrays Class componentType = type . getComponentType ( ) ; if ( componentType . isPrimitive ( ) ) { return convertPrimitiveArrayToCollection ( value , componentType ) ; } else { Object [ ] array = ( Object [ ] ) value ; Collection < T > result = createCollection ( array . length ) ; for ( Object a : array ) { result . add ( convertType ( a ) ) ; } return result ; } } // everything else: return convertToSingleElementCollection ( value ) ; }


Input: Converts collection value to target collection . Each element is converted to target component type . [CODESPLIT] protected Collection < T > convertCollectionToCollection ( final Collection value ) { Collection < T > collection = createCollection ( value . size ( ) ) ; for ( Object v : value ) { collection . add ( convertType ( v ) ) ; } return collection ; }


Input: Converts primitive array to target collection . [CODESPLIT] @ SuppressWarnings ( "AutoBoxing" ) protected Collection < T > convertPrimitiveArrayToCollection ( final Object value , final Class primitiveComponentType ) { Collection < T > result = null ; if ( primitiveComponentType == int . class ) { int [ ] array = ( int [ ] ) value ; result = createCollection ( array . length ) ; for ( int a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == long . class ) { long [ ] array = ( long [ ] ) value ; result = createCollection ( array . length ) ; for ( long a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == float . class ) { float [ ] array = ( float [ ] ) value ; result = createCollection ( array . length ) ; for ( float a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == double . class ) { double [ ] array = ( double [ ] ) value ; result = createCollection ( array . length ) ; for ( double a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == short . class ) { short [ ] array = ( short [ ] ) value ; result = createCollection ( array . length ) ; for ( short a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == byte . class ) { byte [ ] array = ( byte [ ] ) value ; result = createCollection ( array . length ) ; for ( byte a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == char . class ) { char [ ] array = ( char [ ] ) value ; result = createCollection ( array . length ) ; for ( char a : array ) { result . add ( convertType ( a ) ) ; } } else if ( primitiveComponentType == boolean . class ) { boolean [ ] array = ( boolean [ ] ) value ; result = createCollection ( array . length ) ; for ( boolean a : array ) { result . add ( convertType ( a ) ) ; } } return result ; }


Input: { [CODESPLIT] @ Override protected WorkData process ( final ClassReader cr , final TargetClassInfoReader targetClassInfoReader ) { ProxettaClassBuilder pcb = new ProxettaClassBuilder ( destClassWriter , proxetta . getAspects ( new ProxyAspect [ 0 ] ) , resolveClassNameSuffix ( ) , requestedProxyClassName , targetClassInfoReader ) ; cr . accept ( pcb , 0 ) ; return pcb . getWorkData ( ) ; }


Input: Adds a source line number corresponding to this label . [CODESPLIT] final void addLineNumber ( final int lineNumber ) { if ( this . lineNumber == 0 ) { this . lineNumber = ( short ) lineNumber ; } else { if ( otherLineNumbers == null ) { otherLineNumbers = new int [ LINE_NUMBERS_CAPACITY_INCREMENT ] ; } int otherLineNumberIndex = ++ otherLineNumbers [ 0 ] ; if ( otherLineNumberIndex >= otherLineNumbers . length ) { int [ ] newLineNumbers = new int [ otherLineNumbers . length + LINE_NUMBERS_CAPACITY_INCREMENT ] ; System . arraycopy ( otherLineNumbers , 0 , newLineNumbers , 0 , otherLineNumbers . length ) ; otherLineNumbers = newLineNumbers ; } otherLineNumbers [ otherLineNumberIndex ] = lineNumber ; } }


Input: Makes the given visitor visit this label and its source line numbers if applicable . [CODESPLIT] final void accept ( final MethodVisitor methodVisitor , final boolean visitLineNumbers ) { methodVisitor . visitLabel ( this ) ; if ( visitLineNumbers && lineNumber != 0 ) { methodVisitor . visitLineNumber ( lineNumber & 0xFFFF , this ) ; if ( otherLineNumbers != null ) { for ( int i = 1 ; i <= otherLineNumbers [ 0 ] ; ++ i ) { methodVisitor . visitLineNumber ( otherLineNumbers [ i ] , this ) ; } } } }


Input: Puts a reference to this label in the bytecode of a method . If the bytecode offset of the label is known the relative bytecode offset between the label and the instruction referencing it is computed and written directly . Otherwise a null relative offset is written and a new forward reference is declared for this label . [CODESPLIT] final void put ( final ByteVector code , final int sourceInsnBytecodeOffset , final boolean wideReference ) { if ( ( flags & FLAG_RESOLVED ) == 0 ) { if ( wideReference ) { addForwardReference ( sourceInsnBytecodeOffset , FORWARD_REFERENCE_TYPE_WIDE , code . length ) ; code . putInt ( - 1 ) ; } else { addForwardReference ( sourceInsnBytecodeOffset , FORWARD_REFERENCE_TYPE_SHORT , code . length ) ; code . putShort ( - 1 ) ; } } else { if ( wideReference ) { code . putInt ( bytecodeOffset - sourceInsnBytecodeOffset ) ; } else { code . putShort ( bytecodeOffset - sourceInsnBytecodeOffset ) ; } } }


Input: Adds a forward reference to this label . This method must be called only for a true forward reference i . e . only if this label is not resolved yet . For backward references the relative bytecode offset of the reference can be and must be computed and stored directly . [CODESPLIT] private void addForwardReference ( final int sourceInsnBytecodeOffset , final int referenceType , final int referenceHandle ) { if ( forwardReferences == null ) { forwardReferences = new int [ FORWARD_REFERENCES_CAPACITY_INCREMENT ] ; } int lastElementIndex = forwardReferences [ 0 ] ; if ( lastElementIndex + 2 >= forwardReferences . length ) { int [ ] newValues = new int [ forwardReferences . length + FORWARD_REFERENCES_CAPACITY_INCREMENT ] ; System . arraycopy ( forwardReferences , 0 , newValues , 0 , forwardReferences . length ) ; forwardReferences = newValues ; } forwardReferences [ ++ lastElementIndex ] = sourceInsnBytecodeOffset ; forwardReferences [ ++ lastElementIndex ] = referenceType | referenceHandle ; forwardReferences [ 0 ] = lastElementIndex ; }


Input: Sets the bytecode offset of this label to the given value and resolves the forward references to this label if any . This method must be called when this label is added to the bytecode of the method i . e . when its bytecode offset becomes known . This method fills in the blanks that where left in the bytecode by each forward reference previously added to this label . [CODESPLIT] final boolean resolve ( final byte [ ] code , final int bytecodeOffset ) { this . flags |= FLAG_RESOLVED ; this . bytecodeOffset = bytecodeOffset ; if ( forwardReferences == null ) { return false ; } boolean hasAsmInstructions = false ; for ( int i = forwardReferences [ 0 ] ; i > 0 ; i -= 2 ) { final int sourceInsnBytecodeOffset = forwardReferences [ i - 1 ] ; final int reference = forwardReferences [ i ] ; final int relativeOffset = bytecodeOffset - sourceInsnBytecodeOffset ; int handle = reference & FORWARD_REFERENCE_HANDLE_MASK ; if ( ( reference & FORWARD_REFERENCE_TYPE_MASK ) == FORWARD_REFERENCE_TYPE_SHORT ) { if ( relativeOffset < Short . MIN_VALUE || relativeOffset > Short . MAX_VALUE ) { // Change the opcode of the jump instruction, in order to be able to find it later in // ClassReader. These ASM specific opcodes are similar to jump instruction opcodes, except // that the 2 bytes offset is unsigned (and can therefore represent values from 0 to // 65535, which is sufficient since the size of a method is limited to 65535 bytes). int opcode = code [ sourceInsnBytecodeOffset ] & 0xFF ; if ( opcode < Opcodes . IFNULL ) { // Change IFEQ ... JSR to ASM_IFEQ ... ASM_JSR. code [ sourceInsnBytecodeOffset ] = ( byte ) ( opcode + Constants . ASM_OPCODE_DELTA ) ; } else { // Change IFNULL and IFNONNULL to ASM_IFNULL and ASM_IFNONNULL. code [ sourceInsnBytecodeOffset ] = ( byte ) ( opcode + Constants . ASM_IFNULL_OPCODE_DELTA ) ; } hasAsmInstructions = true ; } code [ handle ++ ] = ( byte ) ( relativeOffset >>> 8 ) ; code [ handle ] = ( byte ) relativeOffset ; } else { code [ handle ++ ] = ( byte ) ( relativeOffset >>> 24 ) ; code [ handle ++ ] = ( byte ) ( relativeOffset >>> 16 ) ; code [ handle ++ ] = ( byte ) ( relativeOffset >>> 8 ) ; code [ handle ] = ( byte ) relativeOffset ; } } return hasAsmInstructions ; }


Input: Finds the basic blocks that belong to the subroutine starting with the basic block corresponding to this label and marks these blocks as belonging to this subroutine . This method follows the control flow graph to find all the blocks that are reachable from the current basic block WITHOUT following any jsr target . [CODESPLIT] final void markSubroutine ( final short subroutineId ) { // Data flow algorithm: put this basic block in a list of blocks to process (which are blocks // belonging to subroutine subroutineId) and, while there are blocks to process, remove one from // the list, mark it as belonging to the subroutine, and add its successor basic blocks in the // control flow graph to the list of blocks to process (if not already done). Label listOfBlocksToProcess = this ; listOfBlocksToProcess . nextListElement = EMPTY_LIST ; while ( listOfBlocksToProcess != EMPTY_LIST ) { // Remove a basic block from the list of blocks to process. Label basicBlock = listOfBlocksToProcess ; listOfBlocksToProcess = listOfBlocksToProcess . nextListElement ; basicBlock . nextListElement = null ; // If it is not already marked as belonging to a subroutine, mark it as belonging to // subroutineId and add its successors to the list of blocks to process (unless already done). if ( basicBlock . subroutineId == 0 ) { basicBlock . subroutineId = subroutineId ; listOfBlocksToProcess = basicBlock . pushSuccessors ( listOfBlocksToProcess ) ; } } }