idx
int64 0
41.2k
| question
stringlengths 74
4.04k
| target
stringlengths 7
750
|
|---|---|---|
37,900
|
public TimezoneOffsetFrom setTimezoneOffsetFrom ( UtcOffset offset ) { TimezoneOffsetFrom prop = new TimezoneOffsetFrom ( offset ) ; setTimezoneOffsetFrom ( prop ) ; return prop ; }
|
Sets the UTC offset that the timezone observance transitions from .
|
37,901
|
public TimezoneName addTimezoneName ( String timezoneName ) { TimezoneName prop = new TimezoneName ( timezoneName ) ; addTimezoneName ( prop ) ; return prop ; }
|
Adds a traditional non - standard name for the timezone observance .
|
37,902
|
private static String getCidUriValue ( String uri ) { int colon = uri . indexOf ( ':' ) ; if ( colon == 3 ) { String scheme = uri . substring ( 0 , colon ) ; return "cid" . equalsIgnoreCase ( scheme ) ? uri . substring ( colon + 1 ) : null ; } if ( uri . length ( ) > 0 && uri . charAt ( 0 ) == '<' && uri . charAt ( uri . length ( ) - 1 ) == '>' ) { return uri . substring ( 1 , uri . length ( ) - 1 ) ; } return null ; }
|
Gets the value of the given cid URI .
|
37,903
|
public < T extends ICalProperty > T getProperty ( Class < T > clazz ) { return clazz . cast ( properties . first ( clazz ) ) ; }
|
Gets the first property of a given class .
|
37,904
|
public List < ICalProperty > setProperty ( ICalProperty property ) { return properties . replace ( property . getClass ( ) , property ) ; }
|
Replaces all existing properties of the given property instance s class with the given property instance .
|
37,905
|
public < T extends ICalProperty > List < T > setProperty ( Class < T > clazz , T property ) { List < ICalProperty > replaced = properties . replace ( clazz , property ) ; return castList ( replaced , clazz ) ; }
|
Replaces all existing properties of the given class with a single property instance . If the property instance is null then all instances of that property will be removed .
|
37,906
|
public < T extends ICalProperty > boolean removeProperty ( T property ) { return properties . remove ( property . getClass ( ) , property ) ; }
|
Removes a specific property instance from this component .
|
37,907
|
public < T extends ICalProperty > List < T > removeProperties ( Class < T > clazz ) { List < ICalProperty > removed = properties . removeAll ( clazz ) ; return castList ( removed , clazz ) ; }
|
Removes all properties of a given class from this component .
|
37,908
|
public < T extends ICalComponent > boolean removeComponent ( T component ) { return components . remove ( component . getClass ( ) , component ) ; }
|
Removes a specific sub - component instance from this component .
|
37,909
|
public < T extends ICalComponent > List < T > removeComponents ( Class < T > clazz ) { List < ICalComponent > removed = components . removeAll ( clazz ) ; return castList ( removed , clazz ) ; }
|
Removes all sub - components of the given class from this component .
|
37,910
|
public RawProperty getExperimentalProperty ( String name ) { for ( RawProperty raw : getExperimentalProperties ( ) ) { if ( raw . getName ( ) . equalsIgnoreCase ( name ) ) { return raw ; } } return null ; }
|
Gets the first experimental property with a given name .
|
37,911
|
public List < RawProperty > getExperimentalProperties ( String name ) { List < RawProperty > toReturn = new ArrayList < RawProperty > ( ) ; for ( RawProperty property : getExperimentalProperties ( ) ) { if ( property . getName ( ) . equalsIgnoreCase ( name ) ) { toReturn . add ( property ) ; } } return Collections . unmodifiableList ( toReturn ) ; }
|
Gets all experimental properties with a given name .
|
37,912
|
public List < RawProperty > removeExperimentalProperties ( String name ) { List < RawProperty > all = getExperimentalProperties ( ) ; List < RawProperty > toRemove = new ArrayList < RawProperty > ( ) ; for ( RawProperty property : all ) { if ( property . getName ( ) . equalsIgnoreCase ( name ) ) { toRemove . add ( property ) ; } } all . removeAll ( toRemove ) ; return Collections . unmodifiableList ( toRemove ) ; }
|
Removes all experimental properties that have the given name .
|
37,913
|
public < T extends ICalComponent > T getComponent ( Class < T > clazz ) { return clazz . cast ( components . first ( clazz ) ) ; }
|
Gets the first sub - component of a given class .
|
37,914
|
public < T extends ICalComponent > List < T > getComponents ( Class < T > clazz ) { return new ICalComponentList < T > ( clazz ) ; }
|
Gets all sub - components of a given class . Changes to the returned list will update the parent component object and vice versa .
|
37,915
|
public List < ICalComponent > setComponent ( ICalComponent component ) { return components . replace ( component . getClass ( ) , component ) ; }
|
Replaces all sub - components of a given class with the given component .
|
37,916
|
public < T extends ICalComponent > List < T > setComponent ( Class < T > clazz , T component ) { List < ICalComponent > replaced = components . replace ( clazz , component ) ; return castList ( replaced , clazz ) ; }
|
Replaces all sub - components of a given class with the given component . If the component instance is null then all instances of that component will be removed .
|
37,917
|
public RawComponent getExperimentalComponent ( String name ) { for ( RawComponent component : getExperimentalComponents ( ) ) { if ( component . getName ( ) . equalsIgnoreCase ( name ) ) { return component ; } } return null ; }
|
Gets the first experimental sub - component with a given name .
|
37,918
|
public List < RawComponent > getExperimentalComponents ( String name ) { List < RawComponent > toReturn = new ArrayList < RawComponent > ( ) ; for ( RawComponent component : getExperimentalComponents ( ) ) { if ( component . getName ( ) . equalsIgnoreCase ( name ) ) { toReturn . add ( component ) ; } } return Collections . unmodifiableList ( toReturn ) ; }
|
Gets all experimental sub - component with a given name .
|
37,919
|
public RawComponent addExperimentalComponent ( String name ) { RawComponent raw = new RawComponent ( name ) ; addComponent ( raw ) ; return raw ; }
|
Adds an experimental sub - component to this component .
|
37,920
|
public List < RawComponent > removeExperimentalComponents ( String name ) { List < RawComponent > all = getExperimentalComponents ( ) ; List < RawComponent > toRemove = new ArrayList < RawComponent > ( ) ; for ( RawComponent property : all ) { if ( property . getName ( ) . equalsIgnoreCase ( name ) ) { toRemove . add ( property ) ; } } all . removeAll ( toRemove ) ; return Collections . unmodifiableList ( toRemove ) ; }
|
Removes all experimental sub - components that have the given name .
|
37,921
|
protected void checkRequiredCardinality ( List < ValidationWarning > warnings , Class < ? extends ICalProperty > ... classes ) { for ( Class < ? extends ICalProperty > clazz : classes ) { List < ? extends ICalProperty > props = getProperties ( clazz ) ; if ( props . isEmpty ( ) ) { warnings . add ( new ValidationWarning ( 2 , clazz . getSimpleName ( ) ) ) ; continue ; } if ( props . size ( ) > 1 ) { warnings . add ( new ValidationWarning ( 3 , clazz . getSimpleName ( ) ) ) ; continue ; } } }
|
Utility method for validating that there is exactly one instance of each of the given properties .
|
37,922
|
private static < T > List < T > castList ( List < ? > list , Class < T > castTo ) { List < T > casted = new ArrayList < T > ( list . size ( ) ) ; for ( Object object : list ) { casted . add ( castTo . cast ( object ) ) ; } return Collections . unmodifiableList ( casted ) ; }
|
Casts all objects in the given list to the given class adding the casted objects to a new list .
|
37,923
|
public final T parseText ( String value , ICalDataType dataType , ICalParameters parameters , ParseContext context ) { T property = _parseText ( value , dataType , parameters , context ) ; property . setParameters ( parameters ) ; return property ; }
|
Unmarshals a property from a plain - text iCalendar data stream .
|
37,924
|
private static String jcalValueToString ( JCalValue value ) { List < JsonValue > values = value . getValues ( ) ; if ( values . size ( ) > 1 ) { List < String > multi = value . asMulti ( ) ; if ( ! multi . isEmpty ( ) ) { return VObjectPropertyValues . writeList ( multi ) ; } } if ( ! values . isEmpty ( ) && values . get ( 0 ) . getArray ( ) != null ) { List < List < String > > structured = value . asStructured ( ) ; if ( ! structured . isEmpty ( ) ) { return VObjectPropertyValues . writeStructured ( structured , true ) ; } } if ( values . get ( 0 ) . getObject ( ) != null ) { ListMultimap < String , String > object = value . asObject ( ) ; if ( ! object . isEmpty ( ) ) { return VObjectPropertyValues . writeMultimap ( object . getMap ( ) ) ; } } return VObjectPropertyValues . escape ( value . asSingle ( ) ) ; }
|
Converts a jCal value to its plain - text format representation .
|
37,925
|
protected static DateWriter date ( Date date ) { return date ( ( date == null ) ? null : new ICalDate ( date ) ) ; }
|
Formats a date as a string .
|
37,926
|
protected static ICalParameters handleTzidParameter ( ICalProperty property , boolean hasTime , WriteContext context ) { ICalParameters parameters = property . getParameters ( ) ; if ( ! hasTime ) { return parameters ; } if ( context . getVersion ( ) == ICalVersion . V1_0 ) { return parameters ; } TimezoneInfo tzinfo = context . getTimezoneInfo ( ) ; boolean floating = tzinfo . isFloating ( property ) ; if ( floating ) { return parameters ; } TimezoneAssignment tz ; TimezoneAssignment globalTz = context . getGlobalTimezone ( ) ; if ( globalTz == null ) { tz = tzinfo . getTimezoneToWriteIn ( property ) ; if ( tz == null ) { return parameters ; } } else { tz = globalTz ; } String tzid = null ; VTimezone component = tz . getComponent ( ) ; String globalId = tz . getGlobalId ( ) ; if ( component != null ) { tzid = ValuedProperty . getValue ( component . getTimezoneId ( ) ) ; } else if ( globalId != null ) { tzid = '/' + globalId ; } if ( tzid == null ) { tzid = tz . getTimeZone ( ) . getID ( ) ; } parameters = new ICalParameters ( parameters ) ; parameters . setTimezoneId ( tzid ) ; return parameters ; }
|
Adds a TZID parameter to a property s parameter list if necessary .
|
37,927
|
public ICalComponentScribe < ? extends ICalComponent > getComponentScribe ( String componentName , ICalVersion version ) { componentName = componentName . toUpperCase ( ) ; ICalComponentScribe < ? extends ICalComponent > scribe = experimentalCompByName . get ( componentName ) ; if ( scribe == null ) { scribe = standardCompByName . get ( componentName ) ; } if ( scribe == null ) { return new RawComponentScribe ( componentName ) ; } if ( version != null && ! scribe . getSupportedVersions ( ) . contains ( version ) ) { return new RawComponentScribe ( componentName ) ; } return scribe ; }
|
Gets a component scribe by name .
|
37,928
|
public ICalPropertyScribe < ? extends ICalProperty > getPropertyScribe ( String propertyName , ICalVersion version ) { propertyName = propertyName . toUpperCase ( ) ; String key = propertyNameKey ( propertyName , version ) ; ICalPropertyScribe < ? extends ICalProperty > scribe = experimentalPropByName . get ( key ) ; if ( scribe == null ) { scribe = standardPropByName . get ( key ) ; } if ( scribe == null ) { return new RawPropertyScribe ( propertyName ) ; } if ( version != null && ! scribe . getSupportedVersions ( ) . contains ( version ) ) { return new RawPropertyScribe ( propertyName ) ; } return scribe ; }
|
Gets a property scribe by name .
|
37,929
|
public ICalComponentScribe < ? extends ICalComponent > getComponentScribe ( Class < ? extends ICalComponent > clazz ) { ICalComponentScribe < ? extends ICalComponent > scribe = experimentalCompByClass . get ( clazz ) ; if ( scribe != null ) { return scribe ; } return standardCompByClass . get ( clazz ) ; }
|
Gets a component scribe by class .
|
37,930
|
public ICalPropertyScribe < ? extends ICalProperty > getPropertyScribe ( Class < ? extends ICalProperty > clazz ) { ICalPropertyScribe < ? extends ICalProperty > scribe = experimentalPropByClass . get ( clazz ) ; if ( scribe != null ) { return scribe ; } return standardPropByClass . get ( clazz ) ; }
|
Gets a property scribe by class .
|
37,931
|
public ICalComponentScribe < ? extends ICalComponent > getComponentScribe ( ICalComponent component ) { if ( component instanceof RawComponent ) { RawComponent raw = ( RawComponent ) component ; return new RawComponentScribe ( raw . getName ( ) ) ; } return getComponentScribe ( component . getClass ( ) ) ; }
|
Gets the appropriate component scribe for a given component instance .
|
37,932
|
public ICalPropertyScribe < ? extends ICalProperty > getPropertyScribe ( ICalProperty property ) { if ( property instanceof RawProperty ) { RawProperty raw = ( RawProperty ) property ; return new RawPropertyScribe ( raw . getName ( ) ) ; } return getPropertyScribe ( property . getClass ( ) ) ; }
|
Gets the appropriate property scribe for a given property instance .
|
37,933
|
public ICalPropertyScribe < ? extends ICalProperty > getPropertyScribe ( QName qname ) { ICalPropertyScribe < ? extends ICalProperty > scribe = experimentalPropByQName . get ( qname ) ; if ( scribe == null ) { scribe = standardPropByQName . get ( qname ) ; } if ( scribe == null || ! scribe . getSupportedVersions ( ) . contains ( ICalVersion . V2_0 ) ) { if ( XCalNamespaceContext . XCAL_NS . equals ( qname . getNamespaceURI ( ) ) ) { return new RawPropertyScribe ( qname . getLocalPart ( ) . toUpperCase ( ) ) ; } return getPropertyScribe ( Xml . class ) ; } return scribe ; }
|
Gets a property scribe by XML local name and namespace .
|
37,934
|
public void unregister ( ICalComponentScribe < ? extends ICalComponent > scribe ) { experimentalCompByName . remove ( scribe . getComponentName ( ) . toUpperCase ( ) ) ; experimentalCompByClass . remove ( scribe . getComponentClass ( ) ) ; }
|
Unregisters a component scribe .
|
37,935
|
public void unregister ( ICalPropertyScribe < ? extends ICalProperty > scribe ) { for ( ICalVersion version : ICalVersion . values ( ) ) { experimentalPropByName . remove ( propertyNameKey ( scribe , version ) ) ; } experimentalPropByClass . remove ( scribe . getPropertyClass ( ) ) ; experimentalPropByQName . remove ( scribe . getQName ( ) ) ; }
|
Unregisters a property scribe
|
37,936
|
private static Date determineStartDate ( VAlarm valarm , ICalComponent parent ) { Trigger trigger = valarm . getTrigger ( ) ; if ( trigger == null ) { return null ; } Date triggerStart = trigger . getDate ( ) ; if ( triggerStart != null ) { return triggerStart ; } Duration triggerDuration = trigger . getDuration ( ) ; if ( triggerDuration == null ) { return null ; } if ( parent == null ) { return null ; } Related related = trigger . getRelated ( ) ; Date date = null ; if ( related == Related . START ) { date = ValuedProperty . getValue ( parent . getProperty ( DateStart . class ) ) ; } else if ( related == Related . END ) { date = ValuedProperty . getValue ( parent . getProperty ( DateEnd . class ) ) ; if ( date == null ) { Date dateStart = ValuedProperty . getValue ( parent . getProperty ( DateStart . class ) ) ; Duration duration = ValuedProperty . getValue ( parent . getProperty ( DurationProperty . class ) ) ; if ( duration != null && dateStart != null ) { date = duration . add ( dateStart ) ; } } } return ( date == null ) ? null : triggerDuration . add ( date ) ; }
|
Determines what the alarm property s start date should be .
|
37,937
|
static int [ ] uniquify ( int [ ] ints ) { IntSet iset = new IntSet ( ) ; for ( int i : ints ) { iset . add ( i ) ; } return iset . toIntArray ( ) ; }
|
Returns a sorted copy of an integer array with duplicate values removed .
|
37,938
|
static int countInPeriod ( DayOfWeek dow , DayOfWeek dow0 , int nDays ) { if ( dow . getCalendarConstant ( ) >= dow0 . getCalendarConstant ( ) ) { return 1 + ( ( nDays - ( dow . getCalendarConstant ( ) - dow0 . getCalendarConstant ( ) ) - 1 ) / 7 ) ; } else { return 1 + ( ( nDays - ( 7 - ( dow0 . getCalendarConstant ( ) - dow . getCalendarConstant ( ) ) ) - 1 ) / 7 ) ; } }
|
Counts the number of occurrences of a weekday in a given period .
|
37,939
|
private DateValue generateInstance ( ) { try { do { if ( ! instanceGenerator . generate ( builder ) ) { return null ; } DateValue dUtc = dtStart instanceof TimeValue ? TimeUtils . toUtc ( builder . toDateTime ( ) , tzid ) : builder . toDate ( ) ; if ( dUtc . compareTo ( lastUtc_ ) > 0 ) { return dUtc ; } } while ( true ) ; } catch ( Generator . IteratorShortCircuitingException ex ) { return null ; } }
|
Generates a date .
|
37,940
|
public void setTimezone ( ICalProperty property , TimezoneAssignment timezone ) { if ( timezone == null ) { TimezoneAssignment existing = propertyTimezones . remove ( property ) ; if ( existing != null && existing != defaultTimezone && ! propertyTimezones . values ( ) . contains ( existing ) ) { assignments . remove ( existing ) ; } return ; } assignments . add ( timezone ) ; propertyTimezones . put ( property , timezone ) ; }
|
Assigns a timezone to a specific property .
|
37,941
|
public boolean isFloating ( ICalProperty property ) { if ( containsIdentity ( floatingProperties , property ) ) { return true ; } if ( propertyTimezones . containsKey ( property ) ) { return false ; } return globalFloatingTime ; }
|
Determines if a property value should be formatted in floating time when written to an output stream .
|
37,942
|
private static < T > void removeIdentity ( List < T > list , T object ) { Iterator < T > it = list . iterator ( ) ; while ( it . hasNext ( ) ) { if ( object == it . next ( ) ) { it . remove ( ) ; } } }
|
Removes an object from a list using reference equality .
|
37,943
|
private static < T > boolean containsIdentity ( List < T > list , T object ) { for ( T item : list ) { if ( item == object ) { return true ; } } return false ; }
|
Searches for an item in a list using reference equality .
|
37,944
|
public ChainingXmlWriter register ( String parameterName , ICalDataType dataType ) { parameterDataTypes . put ( parameterName , dataType ) ; return this ; }
|
Registers the data type of a non - standard parameter . Non - standard parameters use the unknown data type by default .
|
37,945
|
public void setScribeIndex ( ScribeIndex index ) { this . index = index ; serializer . setScribeIndex ( index ) ; deserializer . setScribeIndex ( index ) ; }
|
Sets the scribe index for the serializer and deserializer to use .
|
37,946
|
public static JCalValue multi ( List < ? > values ) { List < JsonValue > multiValues = new ArrayList < JsonValue > ( values . size ( ) ) ; for ( Object value : values ) { multiValues . add ( new JsonValue ( value ) ) ; } return new JCalValue ( multiValues ) ; }
|
Creates a multi - valued value .
|
37,947
|
public static JCalValue structured ( List < List < ? > > values ) { List < JsonValue > array = new ArrayList < JsonValue > ( values . size ( ) ) ; for ( List < ? > list : values ) { if ( list . isEmpty ( ) ) { array . add ( new JsonValue ( "" ) ) ; continue ; } if ( list . size ( ) == 1 ) { Object value = list . get ( 0 ) ; if ( value == null ) { value = "" ; } array . add ( new JsonValue ( value ) ) ; continue ; } List < JsonValue > subArray = new ArrayList < JsonValue > ( list . size ( ) ) ; for ( Object value : list ) { if ( value == null ) { value = "" ; } subArray . add ( new JsonValue ( value ) ) ; } array . add ( new JsonValue ( subArray ) ) ; } return new JCalValue ( new JsonValue ( array ) ) ; }
|
Creates a structured value .
|
37,948
|
public static JCalValue object ( ListMultimap < String , Object > value ) { Map < String , JsonValue > object = new LinkedHashMap < String , JsonValue > ( ) ; for ( Map . Entry < String , List < Object > > entry : value ) { String key = entry . getKey ( ) ; List < Object > list = entry . getValue ( ) ; JsonValue v ; if ( list . size ( ) == 1 ) { v = new JsonValue ( list . get ( 0 ) ) ; } else { List < JsonValue > array = new ArrayList < JsonValue > ( list . size ( ) ) ; for ( Object element : list ) { array . add ( new JsonValue ( element ) ) ; } v = new JsonValue ( array ) ; } object . put ( key , v ) ; } return new JCalValue ( new JsonValue ( object ) ) ; }
|
Creates an object value .
|
37,949
|
public String asSingle ( ) { if ( values . isEmpty ( ) ) { return "" ; } JsonValue first = values . get ( 0 ) ; if ( first . isNull ( ) ) { return "" ; } Object obj = first . getValue ( ) ; if ( obj != null ) { return obj . toString ( ) ; } List < JsonValue > array = first . getArray ( ) ; if ( array != null && ! array . isEmpty ( ) ) { obj = array . get ( 0 ) . getValue ( ) ; if ( obj != null ) { return obj . toString ( ) ; } } return "" ; }
|
Parses this jCal value as a single - valued property value .
|
37,950
|
public List < List < String > > asStructured ( ) { if ( values . isEmpty ( ) ) { return Collections . emptyList ( ) ; } JsonValue first = values . get ( 0 ) ; List < JsonValue > array = first . getArray ( ) ; if ( array != null ) { List < List < String > > components = new ArrayList < List < String > > ( array . size ( ) ) ; for ( JsonValue value : array ) { if ( value . isNull ( ) ) { components . add ( Arrays . < String > asList ( ) ) ; continue ; } Object obj = value . getValue ( ) ; if ( obj != null ) { String s = obj . toString ( ) ; List < String > component = ( s . length ( ) == 0 ) ? Arrays . < String > asList ( ) : Arrays . asList ( s ) ; components . add ( component ) ; continue ; } List < JsonValue > subArray = value . getArray ( ) ; if ( subArray != null ) { List < String > component = new ArrayList < String > ( subArray . size ( ) ) ; for ( JsonValue subArrayValue : subArray ) { if ( subArrayValue . isNull ( ) ) { component . add ( "" ) ; continue ; } obj = subArrayValue . getValue ( ) ; if ( obj != null ) { component . add ( obj . toString ( ) ) ; continue ; } } if ( component . size ( ) == 1 && component . get ( 0 ) . length ( ) == 0 ) { component . clear ( ) ; } components . add ( component ) ; } } return components ; } Object obj = first . getValue ( ) ; if ( obj != null ) { List < List < String > > components = new ArrayList < List < String > > ( 1 ) ; String s = obj . toString ( ) ; List < String > component = ( s . length ( ) == 0 ) ? Arrays . < String > asList ( ) : Arrays . asList ( s ) ; components . add ( component ) ; return components ; } if ( first . isNull ( ) ) { List < List < String > > components = new ArrayList < List < String > > ( 1 ) ; components . add ( Arrays . < String > asList ( ) ) ; return components ; } return Collections . emptyList ( ) ; }
|
Parses this jCal value as a structured property value .
|
37,951
|
public List < String > asMulti ( ) { if ( values . isEmpty ( ) ) { return Collections . emptyList ( ) ; } List < String > multi = new ArrayList < String > ( values . size ( ) ) ; for ( JsonValue value : values ) { if ( value . isNull ( ) ) { multi . add ( "" ) ; continue ; } Object obj = value . getValue ( ) ; if ( obj != null ) { multi . add ( obj . toString ( ) ) ; continue ; } } return multi ; }
|
Parses this jCal value as a multi - valued property value .
|
37,952
|
public ListMultimap < String , String > asObject ( ) { if ( values . isEmpty ( ) ) { return new ListMultimap < String , String > ( 0 ) ; } Map < String , JsonValue > map = values . get ( 0 ) . getObject ( ) ; if ( map == null ) { return new ListMultimap < String , String > ( 0 ) ; } ListMultimap < String , String > values = new ListMultimap < String , String > ( ) ; for ( Map . Entry < String , JsonValue > entry : map . entrySet ( ) ) { String key = entry . getKey ( ) ; JsonValue value = entry . getValue ( ) ; if ( value . isNull ( ) ) { values . put ( key , "" ) ; continue ; } Object obj = value . getValue ( ) ; if ( obj != null ) { values . put ( key , obj . toString ( ) ) ; continue ; } List < JsonValue > array = value . getArray ( ) ; if ( array != null ) { for ( JsonValue element : array ) { if ( element . isNull ( ) ) { values . put ( key , "" ) ; continue ; } obj = element . getValue ( ) ; if ( obj != null ) { values . put ( key , obj . toString ( ) ) ; } } } } return values ; }
|
Parses this jCal value as an object property value .
|
37,953
|
public static DateTimeComponents parse ( String dateString , Boolean hasTime ) { Matcher m = regex . matcher ( dateString ) ; if ( ! m . find ( ) ) { throw Messages . INSTANCE . getIllegalArgumentException ( 19 , dateString ) ; } int i = 1 ; int year = Integer . parseInt ( m . group ( i ++ ) ) ; int month = Integer . parseInt ( m . group ( i ++ ) ) ; int date = Integer . parseInt ( m . group ( i ++ ) ) ; i ++ ; String hourStr = m . group ( i ++ ) ; if ( hasTime == null ) { hasTime = ( hourStr != null ) ; } if ( ! hasTime ) { return new DateTimeComponents ( year , month , date ) ; } int hour = ( hourStr == null ) ? 0 : Integer . parseInt ( hourStr ) ; String minuteStr = m . group ( i ++ ) ; int minute = ( minuteStr == null ) ? 0 : Integer . parseInt ( minuteStr ) ; String secondStr = m . group ( i ++ ) ; int second = ( secondStr == null ) ? 0 : Integer . parseInt ( secondStr ) ; boolean utc = "Z" . equals ( m . group ( i ++ ) ) ; return new DateTimeComponents ( year , month , date , hour , minute , second , utc ) ; }
|
Parses the components out of a date - time string .
|
37,954
|
public static RecurrenceIterator createRecurrenceIterator ( Collection < ? extends DateValue > dates ) { DateValue [ ] datesArray = dates . toArray ( new DateValue [ 0 ] ) ; return new RDateIteratorImpl ( datesArray ) ; }
|
Creates a recurrence iterator from an RDATE or EXDATE list .
|
37,955
|
public static RecurrenceIterable createRecurrenceIterable ( final Recurrence rrule , final DateValue dtStart , final TimeZone tzid ) { return new RecurrenceIterable ( ) { public RecurrenceIterator iterator ( ) { return createRecurrenceIterator ( rrule , dtStart , tzid ) ; } } ; }
|
Creates a recurrence iterable from an RRULE .
|
37,956
|
public static RecurrenceIterator join ( RecurrenceIterator first , RecurrenceIterator ... rest ) { List < RecurrenceIterator > all = new ArrayList < RecurrenceIterator > ( ) ; all . add ( first ) ; all . addAll ( Arrays . asList ( rest ) ) ; return new CompoundIteratorImpl ( all , Collections . < RecurrenceIterator > emptyList ( ) ) ; }
|
Generates a recurrence iterator that iterates over the union of the given recurrence iterators .
|
37,957
|
public static Duration parse ( String value ) { if ( value . length ( ) == 0 ) { throw parseError ( value ) ; } int index = 0 ; char first = value . charAt ( index ) ; boolean prior = ( first == '-' ) ; if ( first == '-' || first == '+' ) { index ++ ; } if ( value . charAt ( index ) != 'P' ) { throw parseError ( value ) ; } Builder builder = new Builder ( ) ; builder . prior ( prior ) ; StringBuilder buffer = new StringBuilder ( ) ; for ( int i = index + 1 ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( c == 'T' ) { continue ; } if ( c >= '0' && c <= '9' ) { buffer . append ( c ) ; continue ; } if ( buffer . length ( ) == 0 ) { throw parseError ( value ) ; } Integer num = Integer . valueOf ( buffer . toString ( ) ) ; buffer . setLength ( 0 ) ; switch ( c ) { case 'W' : builder . weeks ( num ) ; break ; case 'D' : builder . days ( num ) ; break ; case 'H' : builder . hours ( num ) ; break ; case 'M' : builder . minutes ( num ) ; break ; case 'S' : builder . seconds ( num ) ; break ; default : throw parseError ( value ) ; } } return builder . build ( ) ; }
|
Parses a duration string .
|
37,958
|
public static Duration diff ( Date start , Date end ) { return fromMillis ( end . getTime ( ) - start . getTime ( ) ) ; }
|
Builds a duration based on the difference between two dates .
|
37,959
|
public static Duration fromMillis ( long milliseconds ) { Duration . Builder builder = builder ( ) ; if ( milliseconds < 0 ) { builder . prior ( true ) ; milliseconds *= - 1 ; } int seconds = ( int ) ( milliseconds / 1000 ) ; Integer weeks = seconds / ( 60 * 60 * 24 * 7 ) ; if ( weeks > 0 ) { builder . weeks ( weeks ) ; } seconds %= 60 * 60 * 24 * 7 ; Integer days = seconds / ( 60 * 60 * 24 ) ; if ( days > 0 ) { builder . days ( days ) ; } seconds %= 60 * 60 * 24 ; Integer hours = seconds / ( 60 * 60 ) ; if ( hours > 0 ) { builder . hours ( hours ) ; } seconds %= 60 * 60 ; Integer minutes = seconds / ( 60 ) ; if ( minutes > 0 ) { builder . minutes ( minutes ) ; } seconds %= 60 ; if ( seconds > 0 ) { builder . seconds ( seconds ) ; } return builder . build ( ) ; }
|
Builds a duration from a number of milliseconds .
|
37,960
|
public long toMillis ( ) { long totalSeconds = 0 ; if ( weeks != null ) { totalSeconds += 60L * 60 * 24 * 7 * weeks ; } if ( days != null ) { totalSeconds += 60L * 60 * 24 * days ; } if ( hours != null ) { totalSeconds += 60L * 60 * hours ; } if ( minutes != null ) { totalSeconds += 60L * minutes ; } if ( seconds != null ) { totalSeconds += seconds ; } if ( prior ) { totalSeconds *= - 1 ; } return totalSeconds * 1000 ; }
|
Converts the duration value to milliseconds .
|
37,961
|
private static DateValue [ ] removeDuplicates ( DateValue [ ] dates ) { int k = 0 ; for ( int i = 1 ; i < dates . length ; ++ i ) { if ( ! dates [ i ] . equals ( dates [ k ] ) ) { dates [ ++ k ] = dates [ i ] ; } } if ( ++ k < dates . length ) { DateValue [ ] uniqueDates = new DateValue [ k ] ; System . arraycopy ( dates , 0 , uniqueDates , 0 , k ) ; return uniqueDates ; } return dates ; }
|
Removes duplicates from a list of date values .
|
37,962
|
public T emptyInstance ( ) { T component = _newInstance ( ) ; component . getProperties ( ) . clear ( ) ; component . getComponents ( ) . clear ( ) ; return component ; }
|
Creates a new instance of the component class that doesn t have any properties or sub - components .
|
37,963
|
public List < ICalComponent > getComponents ( T component ) { return new ArrayList < ICalComponent > ( component . getComponents ( ) . values ( ) ) ; }
|
Gets the sub - components to marshal . Child classes can override this for better control over which components are marshalled .
|
37,964
|
public List < ICalProperty > getProperties ( T component ) { return new ArrayList < ICalProperty > ( component . getProperties ( ) . values ( ) ) ; }
|
Gets the properties to marshal . Child classes can override this for better control over which properties are marshalled .
|
37,965
|
public void registerParameterDataType ( String parameterName , ICalDataType dataType ) { parameterName = parameterName . toLowerCase ( ) ; if ( dataType == null ) { parameterDataTypes . remove ( parameterName ) ; } else { parameterDataTypes . put ( parameterName , dataType ) ; } }
|
Registers the data type of an experimental parameter . Experimental parameters use the unknown data type by default .
|
37,966
|
public static void premain ( String agentArgs , Instrumentation inst ) { MarkerType markerType = MarkerType . NONE ; boolean debugMode = false ; boolean autoSerializable = true ; if ( agentArgs != null && ! agentArgs . isEmpty ( ) ) { String [ ] splitArgs = agentArgs . split ( "," ) ; for ( String splitArg : splitArgs ) { String [ ] keyVal = splitArg . split ( "=" , 2 ) ; if ( keyVal . length != 2 ) { throw new IllegalArgumentException ( "Unrecognized arg passed to Coroutines Java agent: " + splitArg ) ; } String key = keyVal [ 0 ] ; String val = keyVal [ 1 ] ; switch ( key ) { case "markerType" : try { markerType = MarkerType . valueOf ( val ) ; } catch ( IllegalArgumentException iae ) { throw new IllegalArgumentException ( "Unable to parse marker type -- must be one of the following: " + Arrays . toString ( MarkerType . values ( ) ) , iae ) ; } break ; case "debugMode" : if ( val . equalsIgnoreCase ( "true" ) ) { debugMode = true ; } else if ( val . equalsIgnoreCase ( "false" ) ) { debugMode = false ; } else { throw new IllegalArgumentException ( "Unable to parse debug mode -- must be true or false" ) ; } break ; case "autoSerializable" : if ( val . equalsIgnoreCase ( "true" ) ) { autoSerializable = true ; } else if ( val . equalsIgnoreCase ( "false" ) ) { autoSerializable = false ; } else { throw new IllegalArgumentException ( "Unable to parse debug mode -- must be true or false" ) ; } break ; default : throw new IllegalArgumentException ( "Unrecognized arg passed to Coroutines Java agent: " + keyVal ) ; } } } inst . addTransformer ( new CoroutinesClassFileTransformer ( markerType , debugMode , autoSerializable ) ) ; }
|
Java agent premain .
|
37,967
|
public static StorageSizes computeSizes ( Frame < BasicValue > frame , int offset , int length ) { Validate . notNull ( frame ) ; Validate . isTrue ( offset >= 0 ) ; Validate . isTrue ( length >= 0 ) ; Validate . isTrue ( offset < frame . getStackSize ( ) ) ; Validate . isTrue ( offset + length <= frame . getStackSize ( ) ) ; int intsSize = 0 ; int longsSize = 0 ; int floatsSize = 0 ; int doublesSize = 0 ; int objectsSize = 0 ; for ( int i = offset + length - 1 ; i >= offset ; i -- ) { BasicValue basicValue = frame . getStack ( i ) ; Type type = basicValue . getType ( ) ; if ( "Lnull;" . equals ( type . getDescriptor ( ) ) ) { continue ; } switch ( type . getSort ( ) ) { case Type . BOOLEAN : case Type . BYTE : case Type . SHORT : case Type . CHAR : case Type . INT : intsSize ++ ; break ; case Type . FLOAT : floatsSize ++ ; break ; case Type . LONG : longsSize ++ ; break ; case Type . DOUBLE : doublesSize ++ ; break ; case Type . ARRAY : case Type . OBJECT : objectsSize ++ ; break ; case Type . METHOD : case Type . VOID : default : throw new IllegalStateException ( ) ; } } return new StorageSizes ( intsSize , longsSize , floatsSize , doublesSize , objectsSize ) ; }
|
Compute sizes required for the storage arrays that will contain the operand stack at this frame .
|
37,968
|
public static InsnList jumpTo ( LabelNode labelNode ) { Validate . notNull ( labelNode ) ; InsnList ret = new InsnList ( ) ; ret . add ( new JumpInsnNode ( Opcodes . GOTO , labelNode ) ) ; return ret ; }
|
Generates instructions for an unconditional jump to a label .
|
37,969
|
public static InsnList addLabel ( LabelNode labelNode ) { Validate . notNull ( labelNode ) ; InsnList ret = new InsnList ( ) ; ret . add ( labelNode ) ; return ret ; }
|
Generates instructions for a label .
|
37,970
|
public static InsnList lineNumber ( int num ) { Validate . isTrue ( num >= 0 ) ; InsnList ret = new InsnList ( ) ; LabelNode labelNode = new LabelNode ( ) ; ret . add ( labelNode ) ; ret . add ( new LineNumberNode ( num , labelNode ) ) ; return ret ; }
|
Generates instructions for line numbers . This is useful for debugging . For example you can put a line number of 99999 or some other special number to denote that the code being executed is instrumented code . Then if a stacktrace happens you ll know that if instrumented code was immediately involved .
|
37,971
|
public static InsnList pop ( ) { InsnList ret = new InsnList ( ) ; ret . add ( new InsnNode ( Opcodes . POP ) ) ; return ret ; }
|
Generates instructions to pop an item off the stack .
|
37,972
|
public static InsnList monitorEnter ( ) { InsnList ret = new InsnList ( ) ; ret . add ( new InsnNode ( Opcodes . MONITORENTER ) ) ; return ret ; }
|
Generates a MONITORENTER instruction which consumes an Object from the top of the stack .
|
37,973
|
public static InsnList monitorExit ( ) { InsnList ret = new InsnList ( ) ; ret . add ( new InsnNode ( Opcodes . MONITOREXIT ) ) ; return ret ; }
|
Generates a MONITOREXIT instruction which consumes an Object from the top of the stack .
|
37,974
|
public static InsnList loadIntConst ( int i ) { InsnList ret = new InsnList ( ) ; ret . add ( new LdcInsnNode ( i ) ) ; return ret ; }
|
Generates instructions to push an integer constant on to the stack .
|
37,975
|
public static InsnList loadStringConst ( String s ) { Validate . notNull ( s ) ; InsnList ret = new InsnList ( ) ; ret . add ( new LdcInsnNode ( s ) ) ; return ret ; }
|
Generates instruction to push a string constant on to the stack .
|
37,976
|
public static InsnList loadNull ( ) { InsnList ret = new InsnList ( ) ; ret . add ( new InsnNode ( Opcodes . ACONST_NULL ) ) ; return ret ; }
|
Generates instruction to push a null on to the stack .
|
37,977
|
public static InsnList loadVar ( Variable variable ) { Validate . notNull ( variable ) ; InsnList ret = new InsnList ( ) ; switch ( variable . getType ( ) . getSort ( ) ) { case Type . BOOLEAN : case Type . BYTE : case Type . CHAR : case Type . SHORT : case Type . INT : ret . add ( new VarInsnNode ( Opcodes . ILOAD , variable . getIndex ( ) ) ) ; break ; case Type . LONG : ret . add ( new VarInsnNode ( Opcodes . LLOAD , variable . getIndex ( ) ) ) ; break ; case Type . FLOAT : ret . add ( new VarInsnNode ( Opcodes . FLOAD , variable . getIndex ( ) ) ) ; break ; case Type . DOUBLE : ret . add ( new VarInsnNode ( Opcodes . DLOAD , variable . getIndex ( ) ) ) ; break ; case Type . OBJECT : case Type . ARRAY : ret . add ( new VarInsnNode ( Opcodes . ALOAD , variable . getIndex ( ) ) ) ; break ; default : throw new IllegalStateException ( ) ; } return ret ; }
|
Copies a local variable on to the stack .
|
37,978
|
public static InsnList saveVar ( Variable variable ) { Validate . notNull ( variable ) ; InsnList ret = new InsnList ( ) ; switch ( variable . getType ( ) . getSort ( ) ) { case Type . BOOLEAN : case Type . BYTE : case Type . CHAR : case Type . SHORT : case Type . INT : ret . add ( new VarInsnNode ( Opcodes . ISTORE , variable . getIndex ( ) ) ) ; break ; case Type . LONG : ret . add ( new VarInsnNode ( Opcodes . LSTORE , variable . getIndex ( ) ) ) ; break ; case Type . FLOAT : ret . add ( new VarInsnNode ( Opcodes . FSTORE , variable . getIndex ( ) ) ) ; break ; case Type . DOUBLE : ret . add ( new VarInsnNode ( Opcodes . DSTORE , variable . getIndex ( ) ) ) ; break ; case Type . OBJECT : case Type . ARRAY : ret . add ( new VarInsnNode ( Opcodes . ASTORE , variable . getIndex ( ) ) ) ; break ; default : throw new IllegalStateException ( ) ; } return ret ; }
|
Pops the stack in to the the local variable table . You may run in to problems if the item on top of the stack isn t of the same type as the variable it s being put in to .
|
37,979
|
public static InsnList createNewObjectArray ( InsnList size ) { Validate . notNull ( size ) ; InsnList ret = new InsnList ( ) ; ret . add ( size ) ; ret . add ( new TypeInsnNode ( Opcodes . ANEWARRAY , "java/lang/Object" ) ) ; return ret ; }
|
Creates a new object array on the stack .
|
37,980
|
public static InsnList loadArrayLength ( InsnList arrayRef ) { Validate . notNull ( arrayRef ) ; InsnList ret = new InsnList ( ) ; ret . add ( arrayRef ) ; ret . add ( new InsnNode ( Opcodes . ARRAYLENGTH ) ) ; return ret ; }
|
Gets the size of an array and puts it on to the stack .
|
37,981
|
public static InsnList addIntegers ( InsnList lhs , InsnList rhs ) { Validate . notNull ( lhs ) ; Validate . notNull ( rhs ) ; InsnList ret = new InsnList ( ) ; ret . add ( lhs ) ; ret . add ( rhs ) ; ret . add ( new InsnNode ( Opcodes . IADD ) ) ; return ret ; }
|
Adds two integers together and puts the result on to the stack .
|
37,982
|
public static InsnList ifIntegersEqual ( InsnList lhs , InsnList rhs , InsnList action ) { Validate . notNull ( lhs ) ; Validate . notNull ( rhs ) ; Validate . notNull ( action ) ; InsnList ret = new InsnList ( ) ; LabelNode notEqualLabelNode = new LabelNode ( ) ; ret . add ( lhs ) ; ret . add ( rhs ) ; ret . add ( new JumpInsnNode ( Opcodes . IF_ICMPNE , notEqualLabelNode ) ) ; ret . add ( action ) ; ret . add ( notEqualLabelNode ) ; return ret ; }
|
Compares two integers and performs some action if the integers are equal .
|
37,983
|
public static InsnList forEach ( Variable counterVar , Variable arrayLenVar , InsnList array , InsnList action ) { Validate . notNull ( counterVar ) ; Validate . notNull ( arrayLenVar ) ; Validate . notNull ( array ) ; Validate . notNull ( action ) ; Validate . isTrue ( counterVar . getType ( ) . equals ( Type . INT_TYPE ) ) ; Validate . isTrue ( arrayLenVar . getType ( ) . equals ( Type . INT_TYPE ) ) ; InsnList ret = new InsnList ( ) ; LabelNode doneLabelNode = new LabelNode ( ) ; LabelNode loopLabelNode = new LabelNode ( ) ; ret . add ( new LdcInsnNode ( 0 ) ) ; ret . add ( new VarInsnNode ( Opcodes . ISTORE , counterVar . getIndex ( ) ) ) ; ret . add ( array ) ; ret . add ( new InsnNode ( Opcodes . DUP ) ) ; ret . add ( new InsnNode ( Opcodes . ARRAYLENGTH ) ) ; ret . add ( new VarInsnNode ( Opcodes . ISTORE , arrayLenVar . getIndex ( ) ) ) ; ret . add ( loopLabelNode ) ; ret . add ( new VarInsnNode ( Opcodes . ILOAD , counterVar . getIndex ( ) ) ) ; ret . add ( new VarInsnNode ( Opcodes . ILOAD , arrayLenVar . getIndex ( ) ) ) ; ret . add ( new JumpInsnNode ( Opcodes . IF_ICMPEQ , doneLabelNode ) ) ; ret . add ( new InsnNode ( Opcodes . DUP ) ) ; ret . add ( new VarInsnNode ( Opcodes . ILOAD , counterVar . getIndex ( ) ) ) ; ret . add ( new InsnNode ( Opcodes . AALOAD ) ) ; ret . add ( action ) ; ret . add ( new IincInsnNode ( counterVar . getIndex ( ) , 1 ) ) ; ret . add ( new JumpInsnNode ( Opcodes . GOTO , loopLabelNode ) ) ; ret . add ( doneLabelNode ) ; ret . add ( new InsnNode ( Opcodes . POP ) ) ; return ret ; }
|
For each element in an object array performs an action .
|
37,984
|
public static InsnList combineObjectArrays ( Variable destArrayVar , Variable firstArrayVar , Variable secondArrayVar ) { Validate . notNull ( destArrayVar ) ; Validate . notNull ( firstArrayVar ) ; Validate . notNull ( secondArrayVar ) ; Validate . isTrue ( destArrayVar . getType ( ) . equals ( Type . getType ( Object [ ] . class ) ) ) ; Validate . isTrue ( firstArrayVar . getType ( ) . equals ( Type . getType ( Object [ ] . class ) ) ) ; Validate . isTrue ( secondArrayVar . getType ( ) . equals ( Type . getType ( Object [ ] . class ) ) ) ; validateLocalIndicies ( destArrayVar . getIndex ( ) , firstArrayVar . getIndex ( ) , secondArrayVar . getIndex ( ) ) ; InsnList ret = merge ( createNewObjectArray ( addIntegers ( loadArrayLength ( loadVar ( firstArrayVar ) ) , loadArrayLength ( loadVar ( secondArrayVar ) ) ) ) , saveVar ( destArrayVar ) , call ( SYSTEM_ARRAY_COPY_METHOD , loadVar ( firstArrayVar ) , loadIntConst ( 0 ) , loadVar ( destArrayVar ) , loadIntConst ( 0 ) , loadArrayLength ( loadVar ( firstArrayVar ) ) ) , call ( SYSTEM_ARRAY_COPY_METHOD , loadVar ( secondArrayVar ) , loadIntConst ( 0 ) , loadVar ( destArrayVar ) , loadArrayLength ( loadVar ( firstArrayVar ) ) , loadArrayLength ( loadVar ( secondArrayVar ) ) ) ) ; return ret ; }
|
Concatenates two object arrays together .
|
37,985
|
public static InsnList tryCatchBlock ( TryCatchBlockNode tryCatchBlockNode , Type exceptionType , InsnList tryInsnList , InsnList catchInsnList ) { Validate . notNull ( tryInsnList ) ; Validate . notNull ( catchInsnList ) ; if ( exceptionType != null ) { Validate . isTrue ( exceptionType . getSort ( ) == Type . OBJECT ) ; } InsnList ret = new InsnList ( ) ; LabelNode tryLabelNode = new LabelNode ( ) ; LabelNode catchLabelNode = new LabelNode ( ) ; LabelNode endLabelNode = new LabelNode ( ) ; tryCatchBlockNode . start = tryLabelNode ; tryCatchBlockNode . end = catchLabelNode ; tryCatchBlockNode . handler = catchLabelNode ; tryCatchBlockNode . type = exceptionType == null ? null : exceptionType . getInternalName ( ) ; ret . add ( tryLabelNode ) ; ret . add ( tryInsnList ) ; ret . add ( new JumpInsnNode ( Opcodes . GOTO , endLabelNode ) ) ; ret . add ( catchLabelNode ) ; ret . add ( catchInsnList ) ; ret . add ( endLabelNode ) ; return ret ; }
|
Generates instructions for a try - catch block .
|
37,986
|
public static InsnList returnValue ( Type returnType , InsnList returnValueInsnList ) { Validate . notNull ( returnType ) ; Validate . isTrue ( returnType . getSort ( ) != Type . METHOD ) ; InsnList ret = new InsnList ( ) ; ret . add ( returnValueInsnList ) ; switch ( returnType . getSort ( ) ) { case Type . VOID : ret . add ( new InsnNode ( Opcodes . RETURN ) ) ; break ; case Type . BOOLEAN : case Type . BYTE : case Type . SHORT : case Type . CHAR : case Type . INT : ret . add ( new InsnNode ( Opcodes . IRETURN ) ) ; break ; case Type . LONG : ret . add ( new InsnNode ( Opcodes . LRETURN ) ) ; break ; case Type . FLOAT : ret . add ( new InsnNode ( Opcodes . FRETURN ) ) ; break ; case Type . DOUBLE : ret . add ( new InsnNode ( Opcodes . DRETURN ) ) ; break ; case Type . OBJECT : case Type . ARRAY : ret . add ( new InsnNode ( Opcodes . ARETURN ) ) ; break ; default : throw new IllegalStateException ( ) ; } return ret ; }
|
Generates instructions that returns a value .
|
37,987
|
protected final void instrumentPath ( Log log , List < String > classpath , File path ) throws MojoExecutionException { try { Instrumenter instrumenter = getInstrumenter ( log , classpath ) ; InstrumentationSettings settings = new InstrumentationSettings ( markerType , debugMode , autoSerializable ) ; PluginHelper . instrument ( instrumenter , settings , path , path , log :: info ) ; } catch ( Exception ex ) { throw new MojoExecutionException ( "Unable to get compile classpath elements" , ex ) ; } }
|
Instruments all classes in a path recursively .
|
37,988
|
private static byte [ ] dumpBytecode ( MethodNode methodNode ) { List < AbstractInsnNode > onlyInstructionsAndLabels = Arrays . stream ( methodNode . instructions . toArray ( ) ) . filter ( x -> x instanceof LabelNode || x . getOpcode ( ) != - 1 ) . collect ( Collectors . toList ( ) ) ; Map < Label , Integer > labelOffsets = onlyInstructionsAndLabels . stream ( ) . filter ( x -> x instanceof LabelNode ) . map ( x -> ( LabelNode ) x ) . collect ( Collectors . toMap ( x -> x . getLabel ( ) , x -> onlyInstructionsAndLabels . indexOf ( x ) ) ) ; try ( ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; DataOutputStream daos = new DataOutputStream ( baos ) ; ) { MethodVisitor daosDumpMethodVisitor = new DumpToDaosMethodVisitor ( daos , labelOffsets ) ; methodNode . accept ( daosDumpMethodVisitor ) ; daos . flush ( ) ; return baos . toByteArray ( ) ; } catch ( IOException ioe ) { throw new IllegalStateException ( ioe ) ; } }
|
Takes into account the instructions and operands as well as the overall structure .
|
37,989
|
public static Type getReturnTypeOfInvocation ( AbstractInsnNode invokeNode ) { Validate . notNull ( invokeNode ) ; if ( invokeNode instanceof MethodInsnNode ) { MethodInsnNode methodInsnNode = ( MethodInsnNode ) invokeNode ; Type methodType = Type . getType ( methodInsnNode . desc ) ; return methodType . getReturnType ( ) ; } else if ( invokeNode instanceof InvokeDynamicInsnNode ) { InvokeDynamicInsnNode invokeDynamicInsnNode = ( InvokeDynamicInsnNode ) invokeNode ; Type methodType = Type . getType ( invokeDynamicInsnNode . desc ) ; return methodType . getReturnType ( ) ; } else { throw new IllegalArgumentException ( ) ; } }
|
Get the return type of the method being invoked .
|
37,990
|
public void addIndividual ( String className , ClassInformation classInformation ) { Validate . notNull ( className ) ; Validate . notNull ( classInformation ) ; Validate . isTrue ( ! hierarchyMap . containsKey ( className ) ) ; hierarchyMap . put ( className , classInformation ) ; }
|
Add a custom class .
|
37,991
|
public void addClasspath ( List < File > classpath ) throws IOException { Validate . notNull ( classpath ) ; Validate . noNullElements ( classpath ) ; for ( File classpathElement : classpath ) { if ( classpathElement . isFile ( ) ) { addJar ( classpathElement ) ; } else if ( classpathElement . isDirectory ( ) ) { addDirectory ( classpathElement ) ; } else { throw new IllegalStateException ( ) ; } } }
|
Add classes contained within a list of JAR files and folders . Note that if a duplicate class is encountered the original is kept .
|
37,992
|
private static InsnList popMethodResult ( AbstractInsnNode invokeInsnNode ) { Validate . notNull ( invokeInsnNode ) ; Type returnType = getReturnTypeOfInvocation ( invokeInsnNode ) ; InsnList ret = new InsnList ( ) ; switch ( returnType . getSort ( ) ) { case Type . LONG : case Type . DOUBLE : ret . add ( new InsnNode ( Opcodes . POP2 ) ) ; break ; case Type . VOID : break ; case Type . METHOD : throw new IllegalStateException ( ) ; default : ret . add ( new InsnNode ( Opcodes . POP ) ) ; break ; } return ret ; }
|
Generates instructions to pop the result of the method off the stack . This will only generate instructions if the method being invoked generates a return value .
|
37,993
|
public void detail ( MethodNode methodNode , MethodAttributes attrs , StringBuilder output ) { Validate . notNull ( methodNode ) ; Validate . notNull ( attrs ) ; Validate . notNull ( output ) ; int methodId = attrs . getSignature ( ) . getMethodId ( ) ; output . append ( "Class Name: " ) . append ( attrs . getSignature ( ) . getClassName ( ) . replace ( '/' , '.' ) ) . append ( '\n' ) ; output . append ( "Method Name: " ) . append ( attrs . getSignature ( ) . getMethodName ( ) ) . append ( '\n' ) ; output . append ( "Method Params: " ) . append ( attrs . getSignature ( ) . getMethodDescriptor ( ) ) . append ( '\n' ) ; output . append ( "Method Return: " ) . append ( attrs . getSignature ( ) . getReturnType ( ) ) . append ( '\n' ) ; output . append ( "Method ID: " ) . append ( methodId ) . append ( '\n' ) ; output . append ( "------------------------------------\n" ) ; UnmodifiableList < ContinuationPoint > cps = attrs . getContinuationPoints ( ) ; for ( int i = 0 ; i < cps . size ( ) ; i ++ ) { ContinuationPoint cp = cps . get ( i ) ; int line = cp . getLineNumber ( ) == null ? - 1 : cp . getLineNumber ( ) ; String header = String . format ( "Continuation Point ID: %-4d Line: %-4d Type: %s" , i , line , cp . getClass ( ) . getSimpleName ( ) ) ; output . append ( header ) . append ( '\n' ) ; detailLocals ( cp , methodNode , output ) ; detailOperands ( cp , output ) ; output . append ( '\n' ) ; } output . append ( '\n' ) ; }
|
MUST BE CALLED PRIOR TO INSTRUMENTATION!!!!
|
37,994
|
protected String getCommonSuperClass ( final String type1 , final String type2 ) { Validate . notNull ( type1 ) ; Validate . notNull ( type2 ) ; infoRepo . getInformation ( type1 ) ; LinkedHashSet < String > type1Hierarchy = flattenHierarchy ( type1 ) ; LinkedHashSet < String > type2Hierarchy = flattenHierarchy ( type2 ) ; for ( String testType1 : type1Hierarchy ) { for ( String testType2 : type2Hierarchy ) { if ( testType1 . equals ( testType2 ) ) { return testType1 ; } } } return "java/lang/Object" ; }
|
Derives common super class from the super name mapping passed in to the constructor .
|
37,995
|
void validateState ( ) { if ( frames == null || coroutine == null ) { throw new IllegalStateException ( "Bad state" ) ; } for ( int i = 0 ; i < frames . length ; i ++ ) { if ( frames [ i ] == null ) { throw new IllegalStateException ( "Bad state" ) ; } frames [ i ] . validateState ( ) ; } }
|
method to do that .
|
37,996
|
public static InsnList debugMarker ( MarkerType markerType , String text ) { Validate . notNull ( markerType ) ; Validate . notNull ( text ) ; InsnList ret = new InsnList ( ) ; switch ( markerType ) { case NONE : break ; case CONSTANT : ret . add ( new LdcInsnNode ( text ) ) ; ret . add ( new InsnNode ( Opcodes . POP ) ) ; break ; case STDOUT : ret . add ( new FieldInsnNode ( Opcodes . GETSTATIC , "java/lang/System" , "out" , "Ljava/io/PrintStream;" ) ) ; ret . add ( new LdcInsnNode ( text ) ) ; ret . add ( new MethodInsnNode ( Opcodes . INVOKEVIRTUAL , "java/io/PrintStream" , "println" , "(Ljava/lang/String;)V" , false ) ) ; break ; default : throw new IllegalStateException ( ) ; } return ret ; }
|
Generates instructions for generating marker instructions . These marker instructions are meant to be is useful for debugging instrumented code . For example you can spot a specific portion of instrumented code by looking for specific markers in the assembly output .
|
37,997
|
public InstrumentationResult instrument ( byte [ ] input , InstrumentationSettings settings ) { Validate . notNull ( input ) ; Validate . notNull ( settings ) ; Validate . isTrue ( input . length > 0 ) ; ClassReader cr = new ClassReader ( input ) ; ClassNode classNode = new SimpleClassNode ( ) ; cr . accept ( classNode , 0 ) ; classNode = reconstructStackMapFrames ( classNode ) ; InstrumentationPass [ ] passes = new InstrumentationPass [ ] { new IdentifyInstrumentationPass ( ) , new AnalyzeInstrumentationPass ( ) , new SerializationPreInstrumentationPass ( ) , new PerformInstrumentationPass ( ) , new SerializationPostInstrumentationPass ( ) , new AutoSerializableInstrumentationPass ( ) } ; InstrumentationState passState = new InstrumentationState ( settings , classRepo ) ; for ( InstrumentationPass pass : passes ) { pass . pass ( classNode , passState ) ; ControlFlag controlFlag = passState . control ( ) ; switch ( controlFlag ) { case CONTINUE_INSTRUMENT : break ; case NO_INSTRUMENT : return new InstrumentationResult ( input ) ; default : throw new IllegalStateException ( ) ; } } ClassWriter cw = new SimpleClassWriter ( ClassWriter . COMPUTE_MAXS | ClassWriter . COMPUTE_FRAMES , classRepo ) ; classNode . accept ( cw ) ; byte [ ] classData = cw . toByteArray ( ) ; Map < String , byte [ ] > extraFiles = passState . extraFiles ( ) ; return new InstrumentationResult ( classData , extraFiles ) ; }
|
Instruments a class .
|
37,998
|
public static List < MethodNode > findMethodsWithName ( Collection < MethodNode > methodNodes , String name ) { Validate . notNull ( methodNodes ) ; Validate . notNull ( name ) ; Validate . noNullElements ( methodNodes ) ; List < MethodNode > ret = new ArrayList < > ( ) ; for ( MethodNode methodNode : methodNodes ) { if ( methodNode . name . equals ( name ) ) { ret . add ( methodNode ) ; } } return ret ; }
|
Find methods within a class with a specific name .
|
37,999
|
public static List < MethodNode > findStaticMethods ( Collection < MethodNode > methodNodes ) { Validate . notNull ( methodNodes ) ; Validate . noNullElements ( methodNodes ) ; List < MethodNode > ret = new ArrayList < > ( ) ; for ( MethodNode methodNode : methodNodes ) { if ( ( methodNode . access & Opcodes . ACC_STATIC ) == Opcodes . ACC_STATIC ) { ret . add ( methodNode ) ; } } return ret ; }
|
Find static methods within a class .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.