idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
7,600
public static Backbone computeNegative ( final Formula formula , final Collection < Variable > variables ) { return compute ( formula , variables , BackboneType . ONLY_NEGATIVE ) ; }
Computes the negative backbone variables for a given formula w . r . t . a collection of variables .
7,601
public static Backbone computeNegative ( final Formula formula ) { return compute ( formula , formula . variables ( ) , BackboneType . ONLY_NEGATIVE ) ; }
Computes the negative backbone variables for a given formula .
7,602
public void push ( final T element ) { int newSize = this . size + 1 ; this . ensure ( newSize ) ; this . elements [ this . size ++ ] = element ; }
Pushes an element at the end of the vector .
7,603
public void shrinkTo ( int newSize ) { if ( newSize < this . size ) { for ( int i = this . size ; i > newSize ; i -- ) this . elements [ i - 1 ] = null ; this . size = newSize ; } }
Shrinks the vector to a given size if the new size is less then the current size . Otherwise the size remains the same .
7,604
@ SuppressWarnings ( "unchecked" ) public void replaceInplace ( final LNGVector < ? extends T > other ) { if ( this == other ) throw new IllegalArgumentException ( "cannot replace a vector in-place with itself" ) ; this . elements = ( T [ ] ) new Object [ other . size ( ) ] ; for ( int i = 0 ; i < other . size ( ) ; i ++ ) this . elements [ i ] = other . get ( i ) ; this . size = other . size ; }
Replaces the contents of this vector with the contents of another vector in - place .
7,605
private void selectionSort ( final T [ ] array , int start , int end , Comparator < T > lt ) { int i ; int j ; int bestI ; T tmp ; for ( i = start ; i < end ; i ++ ) { bestI = i ; for ( j = i + 1 ; j < end ; j ++ ) { if ( lt . compare ( array [ j ] , array [ bestI ] ) < 0 ) bestI = j ; } tmp = array [ i ] ; array [ i ] = array [ bestI ] ; array [ bestI ] = tmp ; } }
Selection sort implementation for a given array .
7,606
private void sort ( final T [ ] array , int start , int end , Comparator < T > lt ) { if ( start == end ) return ; if ( ( end - start ) <= 15 ) this . selectionSort ( array , start , end , lt ) ; else { final T pivot = array [ start + ( ( end - start ) / 2 ) ] ; T tmp ; int i = start - 1 ; int j = end ; while ( true ) { do i ++ ; while ( lt . compare ( array [ i ] , pivot ) < 0 ) ; do j -- ; while ( lt . compare ( pivot , array [ j ] ) < 0 ) ; if ( i >= j ) break ; tmp = array [ i ] ; array [ i ] = array [ j ] ; array [ j ] = tmp ; } this . sort ( array , start , i , lt ) ; this . sort ( array , i , end , lt ) ; } }
Merge sort implementation for a given array .
7,607
public void growTo ( int size , boolean pad ) { if ( this . size >= size ) return ; this . ensure ( size ) ; for ( int i = this . size ; i < size ; i ++ ) this . elements [ i ] = pad ; this . size = size ; }
Grows the vector to a new size and initializes the new elements with a given value .
7,608
public void reverseInplace ( ) { for ( int i = 0 ; i < this . size / 2 ; i ++ ) { boolean temp = this . elements [ i ] ; this . elements [ i ] = this . elements [ this . size - i - 1 ] ; this . elements [ this . size ( ) - i - 1 ] = temp ; } }
Reverses the content of this vector in - place .
7,609
public EmbeddedMongoDB withVersion ( Version . Main version ) { Objects . requireNonNull ( version , "version can not be null" ) ; this . version = version ; return this ; }
Sets the version for the EmbeddedMongoDB instance
7,610
public EmbeddedMongoDB start ( ) { if ( ! this . active ) { try { this . mongodProcess = MongodStarter . getDefaultInstance ( ) . prepare ( new MongodConfigBuilder ( ) . version ( this . version ) . net ( new Net ( this . host , this . port , false ) ) . build ( ) ) . start ( ) ; this . active = true ; LOG . info ( "Successfully started EmbeddedMongoDB @ {}:{}" , this . host , this . port ) ; } catch ( final IOException e ) { LOG . error ( "Failed to start EmbeddedMongoDB @ {}:{}" , this . host , this . port , e ) ; } } return this ; }
Starts the EmbeddedMongoDB instance
7,611
public void stop ( ) { if ( this . active ) { this . mongodProcess . stop ( ) ; this . active = false ; LOG . info ( "Successfully stopped EmbeddedMongoDB @ {}:{}" , this . host , this . port ) ; } }
Stops the EmbeddedMongoDB instance
7,612
public String encrypt ( String toEncrypt ) { byte [ ] encryptedBytes = encryptInternal ( dataEncryptionSecretKeySpec , toEncrypt ) ; return new String ( base64Encoder . encode ( encryptedBytes ) ) ; }
Encrypt and base64 - encode a String .
7,613
private byte [ ] encryptInternal ( SecretKeySpec key , String toEncrypt ) { try { Cipher cipher = Cipher . getInstance ( ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER ) ; cipher . init ( Cipher . ENCRYPT_MODE , key ) ; return cipher . doFinal ( toEncrypt . getBytes ( ENCODING ) ) ; } catch ( GeneralSecurityException e ) { throw new RuntimeException ( "Exception during decryptInternal: " + e , e ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( "Exception during encryptInternal: " + e , e ) ; } }
Internal Encryption method .
7,614
public String decrypt ( String toDecrypt ) { byte [ ] encryptedBytes = base64Decoder . decode ( toDecrypt ) ; return decryptInternal ( dataEncryptionSecretKeySpec , encryptedBytes ) ; }
Decrypt an encrypted and base64 - encoded String
7,615
private String decryptInternal ( SecretKeySpec key , byte [ ] encryptedBytes ) { try { Cipher cipher = Cipher . getInstance ( ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER ) ; cipher . init ( Cipher . DECRYPT_MODE , key ) ; byte [ ] decryptedBytes = cipher . doFinal ( encryptedBytes ) ; return new String ( decryptedBytes , ENCODING ) ; } catch ( GeneralSecurityException e ) { throw new RuntimeException ( "Exception during decryptInternal: " + e , e ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( "Exception during encryptInternal: " + e , e ) ; } }
Internal decryption method .
7,616
public void process ( final Exchange exchange ) throws Exception { final Message in = exchange . getIn ( ) ; final String contentType = in . getHeader ( CONTENT_TYPE , "" , String . class ) ; final String body = in . getBody ( String . class ) ; final Set < String > endpoints = new HashSet < > ( ) ; for ( final String s : in . getHeader ( REINDEXING_RECIPIENTS , "" , String . class ) . split ( "," ) ) { endpoints . add ( s . trim ( ) ) ; } if ( contentType . equals ( "application/json" ) && body != null && ! body . trim ( ) . isEmpty ( ) ) { try { final JsonNode root = MAPPER . readTree ( body ) ; final Iterator < JsonNode > ite = root . elements ( ) ; while ( ite . hasNext ( ) ) { final JsonNode n = ite . next ( ) ; endpoints . add ( n . asText ( ) ) ; } } catch ( JsonProcessingException e ) { LOGGER . debug ( "Invalid JSON" , e ) ; in . setHeader ( HTTP_RESPONSE_CODE , BAD_REQUEST ) ; in . setBody ( "Invalid JSON" ) ; } } in . setHeader ( REINDEXING_RECIPIENTS , join ( "," , endpoints ) ) ; }
Convert the incoming REST request into the correct Fcrepo header fields .
7,617
public void process ( final Exchange exchange ) throws Exception { final Message in = exchange . getIn ( ) ; final String eventURIBase = in . getHeader ( AuditHeaders . EVENT_BASE_URI , String . class ) ; final String eventID = in . getHeader ( FCREPO_EVENT_ID , String . class ) ; final Resource eventURI = createResource ( eventURIBase + "/" + eventID ) ; final StringBuilder query = new StringBuilder ( "update=" ) ; query . append ( ProcessorUtils . insertData ( serializedGraphForMessage ( in , eventURI ) , "" ) ) ; in . setBody ( query . toString ( ) ) ; in . setHeader ( AuditHeaders . EVENT_URI , eventURI . toString ( ) ) ; in . setHeader ( Exchange . CONTENT_TYPE , "application/x-www-form-urlencoded" ) ; in . setHeader ( Exchange . HTTP_METHOD , "POST" ) ; }
Define how a message should be processed .
7,618
private static String serializedGraphForMessage ( final Message message , final Resource subject ) throws IOException { final ByteArrayOutputStream serializedGraph = new ByteArrayOutputStream ( ) ; final Model model = createDefaultModel ( ) ; @ SuppressWarnings ( "unchecked" ) final List < String > eventType = message . getHeader ( FCREPO_EVENT_TYPE , emptyList ( ) , List . class ) ; final String dateTime = message . getHeader ( FCREPO_DATE_TIME , EMPTY_STRING , String . class ) ; @ SuppressWarnings ( "unchecked" ) final List < String > agents = message . getHeader ( FCREPO_AGENT , emptyList ( ) , List . class ) ; @ SuppressWarnings ( "unchecked" ) final List < String > resourceTypes = message . getHeader ( FCREPO_RESOURCE_TYPE , emptyList ( ) , List . class ) ; final String identifier = message . getHeader ( FCREPO_URI , EMPTY_STRING , String . class ) ; final Optional < String > premisType = getAuditEventType ( eventType , resourceTypes ) ; model . add ( model . createStatement ( subject , type , INTERNAL_EVENT ) ) ; model . add ( model . createStatement ( subject , type , PREMIS_EVENT ) ) ; model . add ( model . createStatement ( subject , type , PROV_EVENT ) ) ; model . add ( model . createStatement ( subject , PREMIS_TIME , createTypedLiteral ( dateTime , XSDdateTime ) ) ) ; model . add ( model . createStatement ( subject , PREMIS_OBJ , createResource ( identifier ) ) ) ; agents . forEach ( agent -> { model . add ( model . createStatement ( subject , PREMIS_AGENT , createTypedLiteral ( agent , XSDstring ) ) ) ; } ) ; premisType . ifPresent ( rdfType -> { model . add ( model . createStatement ( subject , PREMIS_TYPE , createResource ( rdfType ) ) ) ; } ) ; write ( serializedGraph , model , NTRIPLES ) ; return serializedGraph . toString ( "UTF-8" ) ; }
Convert a Camel message to audit event description .
7,619
private static Optional < String > getAuditEventType ( final List < String > eventType , final List < String > resourceType ) { if ( eventType . contains ( EVENT_NAMESPACE + "ResourceCreation" ) || eventType . contains ( AS_NAMESPACE + "Create" ) ) { if ( resourceType . contains ( REPOSITORY + "Binary" ) ) { return of ( CONTENT_ADD ) ; } else { return of ( OBJECT_ADD ) ; } } else if ( eventType . contains ( EVENT_NAMESPACE + "ResourceDeletion" ) || eventType . contains ( AS_NAMESPACE + "Delete" ) ) { if ( resourceType . contains ( REPOSITORY + "Binary" ) ) { return of ( CONTENT_REM ) ; } else { return of ( OBJECT_REM ) ; } } else if ( eventType . contains ( EVENT_NAMESPACE + "ResourceModification" ) || eventType . contains ( AS_NAMESPACE + "Update" ) ) { if ( resourceType . contains ( REPOSITORY + "Binary" ) ) { return of ( CONTENT_MOD ) ; } else { return of ( METADATA_MOD ) ; } } return empty ( ) ; }
Returns the Audit event type based on fedora event type and properties .
7,620
public List < Map < String , Collection < ? > > > programQuery ( final String uri , final InputStream program ) throws LDPathParseException { return singletonList ( ldpath . programQuery ( new URIImpl ( uri ) , new InputStreamReader ( program ) ) ) ; }
Execute an LDPath query
7,621
public static ClientConfiguration createClient ( final AuthScope authScope , final Credentials credentials , final List < Endpoint > endpoints , final List < DataProvider > providers ) { final ClientConfiguration client = new ClientConfiguration ( ) ; if ( credentials != null && authScope != null ) { final CredentialsProvider credsProvider = new BasicCredentialsProvider ( ) ; credsProvider . setCredentials ( authScope , credentials ) ; client . setHttpClient ( HttpClients . custom ( ) . setDefaultCredentialsProvider ( credsProvider ) . useSystemProperties ( ) . build ( ) ) ; } client . addProvider ( new LinkedDataProvider ( ) ) ; client . addProvider ( new CacheProvider ( ) ) ; client . addProvider ( new RegexUriProvider ( ) ) ; client . addProvider ( new SPARQLProvider ( ) ) ; client . addEndpoint ( new LinkedDataEndpoint ( ) ) ; endpoints . forEach ( client :: addEndpoint ) ; providers . forEach ( client :: addProvider ) ; return client ; }
Create a linked data client suitable for use with a Fedora Repository .
7,622
public void configure ( ) throws Exception { final Namespaces ns = new Namespaces ( "rdf" , "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ) . add ( "fedora" , REPOSITORY ) ; onException ( Exception . class ) . maximumRedeliveries ( "{{error.maxRedeliveries}}" ) . log ( "Index Routing Error: ${routeId}" ) ; from ( "{{input.stream}}" ) . routeId ( "FcrepoSerialization" ) . process ( new EventProcessor ( ) ) . process ( exchange -> { final String uri = exchange . getIn ( ) . getHeader ( FCREPO_URI , "" , String . class ) ; exchange . getIn ( ) . setHeader ( SERIALIZATION_PATH , create ( uri ) . getPath ( ) ) ; } ) . filter ( not ( in ( uriFilter ) ) ) . choice ( ) . when ( or ( header ( FCREPO_EVENT_TYPE ) . contains ( RESOURCE_DELETION ) , header ( FCREPO_EVENT_TYPE ) . contains ( DELETE ) ) ) . to ( "direct:delete" ) . otherwise ( ) . multicast ( ) . to ( "direct:metadata" , "direct:binary" ) ; from ( "{{serialization.stream}}" ) . routeId ( "FcrepoReSerialization" ) . filter ( not ( in ( uriFilter ) ) ) . process ( exchange -> { final String uri = exchange . getIn ( ) . getHeader ( FCREPO_URI , "" , String . class ) ; exchange . getIn ( ) . setHeader ( SERIALIZATION_PATH , create ( uri ) . getPath ( ) ) ; } ) . multicast ( ) . to ( "direct:metadata" , "direct:binary" ) ; from ( "direct:metadata" ) . routeId ( "FcrepoSerializationMetadataUpdater" ) . to ( "fcrepo:localhost?accept={{serialization.mimeType}}" ) . log ( INFO , LOGGER , "Serializing object ${headers[CamelFcrepoUri]}" ) . setHeader ( FILE_NAME ) . simple ( "${headers[CamelSerializationPath]}.{{serialization.extension}}" ) . log ( DEBUG , LOGGER , "filename is ${headers[CamelFileName]}" ) . to ( "file://{{serialization.descriptions}}" ) ; from ( "direct:binary" ) . routeId ( "FcrepoSerializationBinaryUpdater" ) . filter ( ) . simple ( "{{serialization.includeBinaries}} == 'true'" ) . to ( "fcrepo:localhost?preferInclude=PreferMinimalContainer" + "&accept=application/rdf+xml" ) . filter ( ) . xpath ( isBinaryResourceXPath , ns ) . log ( INFO , LOGGER , "Writing binary ${headers[CamelSerializationPath]}" ) . to ( "fcrepo:localhost?metadata=false" ) . setHeader ( FILE_NAME ) . header ( SERIALIZATION_PATH ) . log ( DEBUG , LOGGER , "header filename is: ${headers[CamelFileName]}" ) . to ( "file://{{serialization.binaries}}" ) ; from ( "direct:delete" ) . routeId ( "FcrepoSerializationDeleter" ) . setHeader ( EXEC_COMMAND_ARGS ) . simple ( "-rf {{serialization.descriptions}}${headers[CamelSerializationPath]}.{{serialization.extension}} " + "{{serialization.descriptions}}${headers[CamelSerializationPath]} " + "{{serialization.binaries}}${headers[CamelSerializationPath]}" ) . to ( "exec:rm" ) ; }
Configure the message route workflow
7,623
public JsonPropertyBuilder < T , P > name ( String name ) { return new JsonPropertyBuilder < T , P > ( coderClass , name , null , null ) ; }
Gets a new instance of property builder for the given key name .
7,624
public JsonPropertyBuilder < T , P > coder ( JsonModelCoder < P > coder ) { return new JsonPropertyBuilder < T , P > ( coderClass , name , coder , null ) ; }
Gets a new instance of property builder for the given value coder .
7,625
public JsonPropertyBuilder < T , P > router ( JsonCoderRouter < P > router ) { return new JsonPropertyBuilder < T , P > ( coderClass , name , null , router ) ; }
Gets a new instance of property builder for the given coder router .
7,626
public Object put ( String key , Object value , State state ) { return put ( key , value , Type . from ( state ) ) ; }
put with State .
7,627
public void write ( ) throws IOException { { Filer filer = processingEnv . getFiler ( ) ; String generateClassName = jsonModel . getPackageName ( ) + "." + jsonModel . getTarget ( ) + postfix ; JavaFileObject fileObject = filer . createSourceFile ( generateClassName , classElement ) ; Template . writeGen ( fileObject , jsonModel ) ; } if ( jsonModel . isBuilder ( ) ) { Filer filer = processingEnv . getFiler ( ) ; String generateClassName = jsonModel . getPackageName ( ) + "." + jsonModel . getTarget ( ) + "JsonMeta" ; JavaFileObject fileObject = filer . createSourceFile ( generateClassName , classElement ) ; Template . writeJsonMeta ( fileObject , jsonModel ) ; } }
Generates the source code .
7,628
String getElementKeyString ( Element element ) { JsonKey key = element . getAnnotation ( JsonKey . class ) ; JsonModel model = element . getEnclosingElement ( ) . getAnnotation ( JsonModel . class ) ; if ( ! "" . equals ( key . value ( ) ) ) { return key . value ( ) ; } else if ( "" . equals ( key . value ( ) ) && key . decamelize ( ) ) { return decamelize ( element . toString ( ) ) ; } else if ( "" . equals ( key . value ( ) ) && model . decamelize ( ) ) { return decamelize ( element . toString ( ) ) ; } else { return element . toString ( ) ; } }
Get JSON key string .
7,629
public T pop ( ) { final int max = stack . size ( ) - 1 ; if ( max < 0 ) { throw new NoSuchElementException ( ) ; } return stack . remove ( max ) ; }
Pops the value from the top of stack and returns it .
7,630
public T peek ( ) { final int top = stack . size ( ) - 1 ; if ( top < 0 ) { throw new NoSuchElementException ( ) ; } return stack . get ( top ) ; }
Returns the value currently on the top of the stack .
7,631
public static Integer parserInteger ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_LONG ) { return ( int ) parser . getValueLong ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_LONG, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as an integer .
7,632
public static Long parserLong ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_LONG ) { return parser . getValueLong ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_LONG, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a long .
7,633
public static Byte parserByte ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_LONG ) { return ( byte ) parser . getValueLong ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_LONG, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a byte .
7,634
public static Short parserShort ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_LONG ) { return ( short ) parser . getValueLong ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_LONG, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a short .
7,635
public static Boolean parserBoolean ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_BOOLEAN ) { return parser . getValueBoolean ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_BOOLEAN, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a boolean .
7,636
public static Character parserCharacter ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_STRING ) { String str = parser . getValueString ( ) ; if ( str . length ( ) != 1 ) { throw new IllegalStateException ( "unexpected value. expecte string size is 1. but get=" + str ) ; } return str . charAt ( 0 ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_STRING, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a character .
7,637
public static Double parserDouble ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_DOUBLE ) { return parser . getValueDouble ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_DOUBLE, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a double - precision floating point value .
7,638
public static Float parserFloat ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } else if ( eventType == State . VALUE_DOUBLE ) { return ( float ) parser . getValueDouble ( ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_DOUBLE, but get=" + eventType . toString ( ) ) ; } }
Parses the current token as a single - precision floating point value .
7,639
public static List < Integer > parserIntegerList ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < Integer > list = new ArrayList < Integer > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_LONG ) { list . add ( ( int ) parser . getValueLong ( ) ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_LONG, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of integers .
7,640
public static List < Boolean > parserBooleanList ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < Boolean > list = new ArrayList < Boolean > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_BOOLEAN ) { list . add ( parser . getValueBoolean ( ) ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_BOOLEAN, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of booleans .
7,641
public static List < Character > parserCharacterList ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < Character > list = new ArrayList < Character > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_STRING ) { String str = parser . getValueString ( ) ; if ( str . length ( ) != 1 ) { throw new IllegalStateException ( "unexpected value. expecte string size is 1. but get=" + str ) ; } list . add ( str . charAt ( 0 ) ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_STRING, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of characters .
7,642
public static List < Double > parserDoubleList ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < Double > list = new ArrayList < Double > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_DOUBLE ) { list . add ( parser . getValueDouble ( ) ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_DOUBLE, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of double - precision floating point numbers .
7,643
public static List < String > parserStringList ( JsonPullParser parser ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < String > list = new ArrayList < String > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_STRING ) { list . add ( parser . getValueString ( ) ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_STRING, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of strings .
7,644
public static < T extends Enum < T > > List < T > parserEnumList ( JsonPullParser parser , Class < T > clazz ) throws IOException , JsonFormatException { State eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { return null ; } if ( eventType != State . START_ARRAY ) { throw new IllegalStateException ( "not started brace!" ) ; } List < T > list = new ArrayList < T > ( ) ; while ( parser . lookAhead ( ) != State . END_ARRAY ) { eventType = parser . getEventType ( ) ; if ( eventType == State . VALUE_NULL ) { list . add ( null ) ; } else if ( eventType == State . VALUE_STRING ) { T obj = Enum . valueOf ( clazz , parser . getValueString ( ) ) ; list . add ( obj ) ; } else { throw new IllegalStateException ( "unexpected state. expected=VALUE_STRING, but get=" + eventType . toString ( ) ) ; } } parser . getEventType ( ) ; return list ; }
Parses the current token as a list of Enums .
7,645
public JsonModelBuilder < T > rm ( String ... names ) { for ( String name : names ) { rmSub ( name ) ; } return this ; }
Detaches property builder for the given names .
7,646
public static JsonArray fromParser ( JsonPullParser parser ) throws IOException , JsonFormatException { State state = parser . getEventType ( ) ; if ( state == State . VALUE_NULL ) { return null ; } else if ( state != State . START_ARRAY ) { throw new JsonFormatException ( "unexpected token. token=" + state , parser ) ; } JsonArray jsonArray = new JsonArray ( ) ; while ( ( state = parser . lookAhead ( ) ) != State . END_ARRAY ) { jsonArray . add ( getValue ( parser ) , state ) ; } parser . getEventType ( ) ; return jsonArray ; }
Parses the given JSON data as an array .
7,647
public static void e ( String msg , Element element ) { messager . printMessage ( Diagnostic . Kind . ERROR , msg , element ) ; }
Logs error message about the given element .
7,648
public static void e ( Throwable e ) { messager . printMessage ( Diagnostic . Kind . ERROR , "exception thrown! " + e . getMessage ( ) ) ; }
Logs error message about the given exception .
7,649
public static boolean isPrimitiveWrapper ( Element element ) { if ( element == null ) { return false ; } else if ( element . toString ( ) . equals ( Boolean . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Integer . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Long . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Byte . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Short . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Character . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Double . class . getCanonicalName ( ) ) ) { return true ; } else if ( element . toString ( ) . equals ( Float . class . getCanonicalName ( ) ) ) { return true ; } else { return false ; } }
Tests if the given element is a primitive wrapper .
7,650
public static boolean isInternalType ( Types typeUtils , TypeMirror type ) { Element element = ( ( TypeElement ) typeUtils . asElement ( type ) ) . getEnclosingElement ( ) ; return element . getKind ( ) != ElementKind . PACKAGE ; }
Test if the given type is an internal type .
7,651
public static boolean isPackagePrivate ( Element element ) { if ( isPublic ( element ) ) { return false ; } else if ( isProtected ( element ) ) { return false ; } else if ( isPrivate ( element ) ) { return false ; } return true ; }
Tests if the given element has the package - private visibility .
7,652
public static String getElementSetter ( Element element ) { String setterName = null ; if ( isPrimitiveBoolean ( element ) ) { Pattern pattern = Pattern . compile ( "^is[^a-z].*$" ) ; Matcher matcher = pattern . matcher ( element . getSimpleName ( ) . toString ( ) ) ; if ( matcher . matches ( ) ) { setterName = "set" + element . getSimpleName ( ) . toString ( ) . substring ( 2 ) ; } } if ( setterName == null ) { setterName = "set" + element . getSimpleName ( ) . toString ( ) ; } Element setter = null ; for ( Element method : ElementFilter . methodsIn ( element . getEnclosingElement ( ) . getEnclosedElements ( ) ) ) { String methodName = method . getSimpleName ( ) . toString ( ) ; if ( setterName . equalsIgnoreCase ( methodName ) ) { if ( isStatic ( method ) == false && isPublic ( method ) || isPackagePrivate ( method ) ) { setter = method ; break ; } } } if ( setter != null ) { return setter . getSimpleName ( ) . toString ( ) ; } else { return null ; } }
Returns the name of corresponding setter .
7,653
public static String getElementGetter ( Element element ) { String getterName1 = "get" + element . getSimpleName ( ) . toString ( ) ; String getterName2 = "is" + element . getSimpleName ( ) . toString ( ) ; String getterName3 = element . getSimpleName ( ) . toString ( ) ; Element getter = null ; for ( Element method : ElementFilter . methodsIn ( element . getEnclosingElement ( ) . getEnclosedElements ( ) ) ) { String methodName = method . getSimpleName ( ) . toString ( ) ; if ( getterName1 . equalsIgnoreCase ( methodName ) ) { if ( isStatic ( method ) == false && isPublic ( method ) || isPackagePrivate ( method ) ) { getter = method ; break ; } } else if ( getterName2 . equalsIgnoreCase ( methodName ) ) { if ( isStatic ( method ) == false && isPublic ( method ) || isPackagePrivate ( method ) ) { getter = method ; break ; } } else if ( getterName3 . equalsIgnoreCase ( methodName ) ) { if ( isStatic ( method ) == false && isPublic ( method ) || isPackagePrivate ( method ) ) { getter = method ; break ; } } } if ( getter != null ) { return getter . getSimpleName ( ) . toString ( ) ; } else { return null ; } }
Returns the name of corresponding getter .
7,654
public void setInputFile ( final File value ) { if ( value != null && ! value . isAbsolute ( ) ) { throw new IllegalArgumentException ( "path is not absolute: " + value ) ; } this . inputFile = value ; }
Sets the absolute path to the grammar file to pass into JTB for preprocessing .
7,655
public void setOutputDirectory ( final File value ) { if ( value != null && ! value . isAbsolute ( ) ) { throw new IllegalArgumentException ( "path is not absolute: " + value ) ; } this . outputDirectory = value ; }
Sets the absolute path to the output directory for the generated grammar file .
7,656
public File getOutputFile ( ) { File outputFile = null ; if ( this . outputDirectory != null && this . inputFile != null ) { final String fileName = FileUtils . removeExtension ( this . inputFile . getName ( ) ) + ".jj" ; outputFile = new File ( this . outputDirectory , fileName ) ; } return outputFile ; }
Gets the absolute path to the enhanced grammar file generated by JTB .
7,657
public void setNodeDirectory ( final File value ) { if ( value != null && ! value . isAbsolute ( ) ) { throw new IllegalArgumentException ( "path is not absolute: " + value ) ; } this . nodeDirectory = value ; }
Sets the absolute path to the output directory for the syntax tree files .
7,658
private File getEffectiveNodeDirectory ( ) { if ( this . nodeDirectory != null ) return this . nodeDirectory ; if ( this . outputDirectory != null ) return new File ( this . outputDirectory , getLastPackageName ( getEffectiveNodePackageName ( ) ) ) ; return null ; }
Gets the absolute path to the output directory for the syntax tree files .
7,659
public void setVisitorDirectory ( final File value ) { if ( value != null && ! value . isAbsolute ( ) ) { throw new IllegalArgumentException ( "path is not absolute: " + value ) ; } this . visitorDirectory = value ; }
Sets the absolute path to the output directory for the visitor files .
7,660
private File getEffectiveVisitorDirectory ( ) { if ( this . visitorDirectory != null ) return this . visitorDirectory ; if ( this . outputDirectory != null ) return new File ( this . outputDirectory , getLastPackageName ( getEffectiveVisitorPackageName ( ) ) ) ; return null ; }
Gets the absolute path to the output directory for the visitor files .
7,661
private String getEffectiveNodePackageName ( ) { if ( this . packageName != null ) return this . packageName . length ( ) <= 0 ? SYNTAX_TREE : this . packageName + '.' + SYNTAX_TREE ; if ( this . nodePackageName != null ) return this . nodePackageName ; return SYNTAX_TREE ; }
Gets the effective package name for the syntax tree files .
7,662
private String getEffectiveVisitorPackageName ( ) { if ( this . packageName != null ) return this . packageName . length ( ) <= 0 ? VISITOR : this . packageName + '.' + VISITOR ; if ( this . visitorPackageName != null ) return this . visitorPackageName ; return VISITOR ; }
Gets the effective package name for the visitor files .
7,663
private String [ ] generateArguments ( ) { final List < String > argsList = new ArrayList < > ( ) ; argsList . add ( "-np" ) ; argsList . add ( getEffectiveNodePackageName ( ) ) ; argsList . add ( "-vp" ) ; argsList . add ( getEffectiveVisitorPackageName ( ) ) ; if ( this . supressErrorChecking != null && this . supressErrorChecking . booleanValue ( ) ) { argsList . add ( "-e" ) ; } if ( this . javadocFriendlyComments != null && this . javadocFriendlyComments . booleanValue ( ) ) { argsList . add ( "-jd" ) ; } if ( this . descriptiveFieldNames != null && this . descriptiveFieldNames . booleanValue ( ) ) { argsList . add ( "-f" ) ; } if ( this . nodeParentClass != null ) { argsList . add ( "-ns" ) ; argsList . add ( this . nodeParentClass ) ; } if ( this . parentPointers != null && this . parentPointers . booleanValue ( ) ) { argsList . add ( "-pp" ) ; } if ( this . specialTokens != null && this . specialTokens . booleanValue ( ) ) { argsList . add ( "-tk" ) ; } if ( this . scheme != null && this . scheme . booleanValue ( ) ) { argsList . add ( "-scheme" ) ; } if ( this . printer != null && this . printer . booleanValue ( ) ) { argsList . add ( "-printer" ) ; } final File outputFile = getOutputFile ( ) ; if ( outputFile != null ) { argsList . add ( "-o" ) ; argsList . add ( outputFile . getAbsolutePath ( ) ) ; } if ( this . inputFile != null ) { argsList . add ( this . inputFile . getAbsolutePath ( ) ) ; } return argsList . toArray ( new String [ argsList . size ( ) ] ) ; }
Assembles the command line arguments for the invocation of JTB according to the configuration .
7,664
private String getLastPackageName ( final String name ) { if ( name != null ) { return name . substring ( name . lastIndexOf ( '.' ) + 1 ) ; } return null ; }
Gets the last identifier from the specified package name . For example returns apache upon input of org . apache . JTB uses this approach to derive the output directories for the visitor and syntax tree files .
7,665
protected JJTree newJJTree ( ) { final JJTree jjtree = new JJTree ( ) ; jjtree . setLog ( getLog ( ) ) ; jjtree . setGrammarEncoding ( getGrammarEncoding ( ) ) ; jjtree . setOutputEncoding ( getOutputEncoding ( ) ) ; jjtree . setJdkVersion ( getJdkVersion ( ) ) ; jjtree . setBuildNodeFiles ( this . buildNodeFiles ) ; jjtree . setMulti ( this . multi ) ; jjtree . setNodeDefaultVoid ( this . nodeDefaultVoid ) ; jjtree . setNodeClass ( this . nodeClass ) ; jjtree . setNodeFactory ( this . nodeFactory ) ; jjtree . setNodePrefix ( this . nodePrefix ) ; jjtree . setNodeScopeHook ( this . nodeScopeHook ) ; jjtree . setNodeUsesParser ( this . nodeUsesParser ) ; jjtree . setTrackTokens ( this . trackTokens ) ; jjtree . setVisitor ( this . visitor ) ; jjtree . setVisitorDataType ( this . visitorDataType ) ; jjtree . setVisitorReturnType ( this . visitorReturnType ) ; jjtree . setVisitorException ( this . visitorException ) ; jjtree . setJavaTemplateType ( this . getJavaTemplateType ( ) ) ; return jjtree ; }
Creates a new facade to invoke JJTree . Most options for the invocation are derived from the current values of the corresponding mojo parameters . The caller is responsible to set the input file output directory and package on the returned facade .
7,666
public final void addClassPathEntry ( final File path ) { if ( path != null ) m_aClassPathEntries . add ( path . getAbsolutePath ( ) ) ; }
Adds the specified path to the class path of the forked JVM .
7,667
private static File _getResourceSource ( final String resource , final ClassLoader loader ) { if ( resource != null ) { URL url ; if ( loader != null ) { url = loader . getResource ( resource ) ; } else { url = ClassLoader . getSystemResource ( resource ) ; } return UrlUtils . getResourceRoot ( url , resource ) ; } return null ; }
Gets the JAR file or directory that contains the specified resource .
7,668
private Commandline _createCommandLine ( ) { final Commandline cli = new Commandline ( ) ; cli . setExecutable ( this . executable ) ; if ( this . workingDirectory != null ) { cli . setWorkingDirectory ( this . workingDirectory . getAbsolutePath ( ) ) ; } final String classPath = _getClassPath ( ) ; if ( classPath != null && classPath . length ( ) > 0 ) { cli . addArguments ( new String [ ] { "-cp" , classPath } ) ; } if ( this . mainClass != null && this . mainClass . length ( ) > 0 ) { cli . addArguments ( new String [ ] { this . mainClass } ) ; } cli . addArguments ( _getArguments ( ) ) ; return cli ; }
Creates the command line for the new JVM based on the current configuration .
7,669
private File [ ] getSourceDirectories ( ) { final Set < File > directories = new LinkedHashSet < > ( ) ; if ( this . sourceDirectories != null && this . sourceDirectories . length > 0 ) { directories . addAll ( Arrays . asList ( this . sourceDirectories ) ) ; } else { if ( this . defaultGrammarDirectoryJavaCC != null ) { directories . add ( this . defaultGrammarDirectoryJavaCC ) ; } if ( this . defaultGrammarDirectoryJJTree != null ) { directories . add ( this . defaultGrammarDirectoryJJTree ) ; } if ( this . defaultGrammarDirectoryJTB != null ) { directories . add ( this . defaultGrammarDirectoryJTB ) ; } } return directories . toArray ( new File [ directories . size ( ) ] ) ; }
Get the source directories that should be scanned for grammar files .
7,670
public void executeReport ( final Locale locale ) throws MavenReportException { final Sink sink = getSink ( ) ; createReportHeader ( getBundle ( locale ) , sink ) ; final File [ ] sourceDirs = getSourceDirectories ( ) ; for ( final File sourceDir : sourceDirs ) { final GrammarInfo [ ] grammarInfos = scanForGrammars ( sourceDir ) ; if ( grammarInfos == null ) { getLog ( ) . debug ( "Skipping non-existing source directory: " + sourceDir ) ; } else { Arrays . sort ( grammarInfos , GrammarInfoComparator . getInstance ( ) ) ; for ( final GrammarInfo grammarInfo : grammarInfos ) { final File grammarFile = grammarInfo . getGrammarFile ( ) ; String relativeOutputFileName = grammarInfo . getRelativeGrammarFile ( ) ; relativeOutputFileName = relativeOutputFileName . replaceAll ( "(?i)\\.(jj|jjt|jtb)$" , getOutputFileExtension ( ) ) ; final File jjdocOutputFile = new File ( getJJDocOutputDirectory ( ) , relativeOutputFileName ) ; final JJDoc jjdoc = newJJDoc ( ) ; jjdoc . setInputFile ( grammarFile ) ; jjdoc . setOutputFile ( jjdocOutputFile ) ; try { jjdoc . run ( ) ; } catch ( final Exception e ) { throw new MavenReportException ( "Failed to create BNF documentation: " + grammarFile , e ) ; } createReportLink ( sink , sourceDir , grammarFile , relativeOutputFileName ) ; } } } createReportFooter ( sink ) ; sink . flush ( ) ; sink . close ( ) ; }
Run the actual report .
7,671
private void createReportHeader ( final ResourceBundle bundle , final Sink sink ) { sink . head ( ) ; sink . title ( ) ; sink . text ( bundle . getString ( "report.jjdoc.title" ) ) ; sink . title_ ( ) ; sink . head_ ( ) ; sink . body ( ) ; sink . section1 ( ) ; sink . sectionTitle1 ( ) ; sink . text ( bundle . getString ( "report.jjdoc.title" ) ) ; sink . sectionTitle1_ ( ) ; sink . text ( bundle . getString ( "report.jjdoc.description" ) ) ; sink . section1_ ( ) ; sink . lineBreak ( ) ; sink . table ( ) ; sink . tableRow ( ) ; sink . tableHeaderCell ( ) ; sink . text ( bundle . getString ( "report.jjdoc.table.heading" ) ) ; sink . tableHeaderCell_ ( ) ; sink . tableRow_ ( ) ; }
Create the header and title for the HTML report page .
7,672
private void createReportLink ( final Sink sink , final File sourceDirectory , final File grammarFile , String linkPath ) { sink . tableRow ( ) ; sink . tableCell ( ) ; if ( linkPath . startsWith ( "/" ) ) { linkPath = linkPath . substring ( 1 ) ; } sink . link ( linkPath ) ; String grammarFileRelativePath = sourceDirectory . toURI ( ) . relativize ( grammarFile . toURI ( ) ) . toString ( ) ; if ( grammarFileRelativePath . startsWith ( "/" ) ) { grammarFileRelativePath = grammarFileRelativePath . substring ( 1 ) ; } sink . text ( grammarFileRelativePath ) ; sink . link_ ( ) ; sink . tableCell_ ( ) ; sink . tableRow_ ( ) ; }
Create a table row containing a link to the JJDoc report for a grammar file .
7,673
private JJDoc newJJDoc ( ) { final JJDoc jjdoc = new JJDoc ( ) ; jjdoc . setLog ( getLog ( ) ) ; jjdoc . setGrammarEncoding ( this . grammarEncoding ) ; jjdoc . setOutputEncoding ( this . outputEncoding ) ; jjdoc . setCssHref ( this . cssHref ) ; jjdoc . setText ( this . text ) ; jjdoc . setBnf ( this . bnf ) ; jjdoc . setOneTable ( Boolean . valueOf ( this . oneTable ) ) ; return jjdoc ; }
Creates a new facade to invoke JJDoc . Most options for the invocation are derived from the current values of the corresponding mojo parameters . The caller is responsible to set the input file and output file on the returned facade .
7,674
private GrammarInfo [ ] scanForGrammars ( final File sourceDirectory ) throws MavenReportException { if ( ! sourceDirectory . isDirectory ( ) ) { return null ; } GrammarInfo [ ] grammarInfos ; getLog ( ) . debug ( "Scanning for grammars: " + sourceDirectory ) ; try { final String [ ] includes = { "**/*.jj" , "**/*.JJ" , "**/*.jjt" , "**/*.JJT" , "**/*.jtb" , "**/*.JTB" } ; final GrammarDirectoryScanner scanner = new GrammarDirectoryScanner ( ) ; scanner . setSourceDirectory ( sourceDirectory ) ; scanner . setIncludes ( includes ) ; scanner . scan ( ) ; grammarInfos = scanner . getIncludedGrammars ( ) ; } catch ( final Exception e ) { throw new MavenReportException ( "Failed to scan for grammars: " + sourceDirectory , e ) ; } getLog ( ) . debug ( "Found grammars: " + Arrays . asList ( grammarInfos ) ) ; return grammarInfos ; }
Searches the specified source directory to find grammar files that can be documented .
7,675
public void execute ( ) throws MojoExecutionException , MojoFailureException { final GrammarInfo [ ] grammarInfos = scanForGrammars ( ) ; if ( grammarInfos == null ) { getLog ( ) . info ( "Skipping non-existing source directory: " + getSourceDirectory ( ) ) ; return ; } else if ( grammarInfos . length <= 0 ) { getLog ( ) . info ( "Skipping - all parsers are up to date" ) ; } else { determineNonGeneratedSourceRoots ( ) ; if ( StringUtils . isEmpty ( grammarEncoding ) ) { getLog ( ) . warn ( "File encoding for grammars has not been configured, using platform default encoding, i.e. build is platform dependent!" ) ; } if ( StringUtils . isEmpty ( outputEncoding ) ) { getLog ( ) . warn ( "File encoding for output has not been configured, defaulting to UTF-8!" ) ; } for ( final GrammarInfo grammarInfo : grammarInfos ) { processGrammar ( grammarInfo ) ; } getLog ( ) . info ( "Processed " + grammarInfos . length + " grammar" + ( grammarInfos . length != 1 ? "s" : "" ) ) ; } final Collection < File > compileSourceRoots = new LinkedHashSet < > ( Arrays . asList ( getCompileSourceRoots ( ) ) ) ; for ( final File file : compileSourceRoots ) { addSourceRoot ( file ) ; } }
Execute the tool .
7,676
private GrammarInfo [ ] scanForGrammars ( ) throws MojoExecutionException { if ( ! getSourceDirectory ( ) . isDirectory ( ) ) { return null ; } GrammarInfo [ ] grammarInfos ; getLog ( ) . debug ( "Scanning for grammars: " + getSourceDirectory ( ) ) ; try { final GrammarDirectoryScanner scanner = new GrammarDirectoryScanner ( ) ; scanner . setSourceDirectory ( getSourceDirectory ( ) ) ; scanner . setIncludes ( getIncludes ( ) ) ; scanner . setExcludes ( getExcludes ( ) ) ; scanner . setOutputDirectory ( getOutputDirectory ( ) ) ; scanner . setParserPackage ( getParserPackage ( ) ) ; scanner . setStaleMillis ( getStaleMillis ( ) ) ; scanner . scan ( ) ; grammarInfos = scanner . getIncludedGrammars ( ) ; } catch ( final Exception e ) { throw new MojoExecutionException ( "Failed to scan for grammars: " + getSourceDirectory ( ) , e ) ; } getLog ( ) . debug ( "Found grammars: " + Arrays . asList ( grammarInfos ) ) ; return grammarInfos ; }
Scans the configured source directory for grammar files which need processing .
7,677
protected void deleteTempDirectory ( final File tempDirectory ) { try { FileUtils . deleteDirectory ( tempDirectory ) ; } catch ( final IOException e ) { getLog ( ) . warn ( "Failed to delete temporary directory: " + tempDirectory , e ) ; } }
Deletes the specified temporary directory .
7,678
private File findSourceFile ( final String filename ) { final Collection < File > sourceRoots = this . nonGeneratedSourceRoots ; for ( final File sourceRoot : sourceRoots ) { final File sourceFile = new File ( sourceRoot , filename ) ; if ( sourceFile . exists ( ) ) { return sourceFile ; } } return null ; }
Determines whether the specified source file is already present in any of the compile source roots registered with the current Maven project .
7,679
private void addSourceRoot ( final File directory ) { if ( this . project != null ) { getLog ( ) . debug ( "Adding compile source root: " + directory ) ; this . project . addCompileSourceRoot ( directory . getAbsolutePath ( ) ) ; } }
Registers the specified directory as a compile source root for the current project .
7,680
protected JavaCC newJavaCC ( ) { final JavaCC javacc = new JavaCC ( ) ; javacc . setLog ( getLog ( ) ) ; javacc . setGrammarEncoding ( this . grammarEncoding ) ; javacc . setOutputEncoding ( this . outputEncoding ) ; javacc . setJdkVersion ( this . jdkVersion ) ; javacc . setBuildParser ( this . buildParser ) ; javacc . setBuildTokenManager ( this . buildTokenManager ) ; javacc . setCacheTokens ( this . cacheTokens ) ; javacc . setChoiceAmbiguityCheck ( this . choiceAmbiguityCheck ) ; javacc . setCommonTokenAction ( this . commonTokenAction ) ; javacc . setDebugLookAhead ( this . debugLookAhead ) ; javacc . setDebugParser ( this . debugParser ) ; javacc . setDebugTokenManager ( this . debugTokenManager ) ; javacc . setErrorReporting ( this . errorReporting ) ; javacc . setForceLaCheck ( this . forceLaCheck ) ; javacc . setIgnoreCase ( this . ignoreCase ) ; javacc . setJavaUnicodeEscape ( this . javaUnicodeEscape ) ; javacc . setKeepLineColumn ( this . keepLineColumn ) ; javacc . setLookAhead ( this . lookAhead ) ; javacc . setOtherAmbiguityCheck ( this . otherAmbiguityCheck ) ; javacc . setSanityCheck ( this . sanityCheck ) ; javacc . setTokenManagerUsesParser ( this . tokenManagerUsesParser ) ; javacc . setTokenExtends ( this . tokenExtends ) ; javacc . setTokenFactory ( this . tokenFactory ) ; javacc . setUnicodeInput ( this . unicodeInput ) ; javacc . setUserCharStream ( this . userCharStream ) ; javacc . setUserTokenManager ( this . userTokenManager ) ; javacc . setSupportClassVisibilityPublic ( this . supportClassVisibilityPublic ) ; javacc . setJavaTemplateType ( this . javaTemplateType ) ; return javacc ; }
Creates a new facade to invoke JavaCC . Most options for the invocation are derived from the current values of the corresponding mojo parameters . The caller is responsible to set the input file and output directory on the returned facade .
7,681
public static File getResourceRoot ( final URL url , final String resource ) { String path = null ; if ( url != null ) { final String spec = url . toExternalForm ( ) ; if ( ( JAR_FILE ) . regionMatches ( true , 0 , spec , 0 , JAR_FILE . length ( ) ) ) { URL jar ; try { jar = new URL ( spec . substring ( JAR . length ( ) , spec . lastIndexOf ( "!/" ) ) ) ; } catch ( final MalformedURLException e ) { throw new IllegalArgumentException ( "Invalid JAR URL: " + url + ", " + e . getMessage ( ) ) ; } path = decodeUrl ( jar . getPath ( ) ) ; } else if ( FILE . regionMatches ( true , 0 , spec , 0 , FILE . length ( ) ) ) { path = decodeUrl ( url . getPath ( ) ) ; path = path . substring ( 0 , path . length ( ) - resource . length ( ) ) ; } else { throw new IllegalArgumentException ( "Invalid class path URL: " + url ) ; } } return path != null ? new File ( path ) : null ; }
Gets the absolute filesystem path to the class path root for the specified resource . The root is either a JAR file or a directory with loose class files . If the URL does not use a supported protocol an exception will be thrown .
7,682
private JTB newJTB ( ) { final JTB jtb = new JTB ( ) ; jtb . setLog ( getLog ( ) ) ; jtb . setDescriptiveFieldNames ( this . descriptiveFieldNames ) ; jtb . setJavadocFriendlyComments ( this . javadocFriendlyComments ) ; jtb . setNodeParentClass ( this . nodeParentClass ) ; jtb . setParentPointers ( this . parentPointers ) ; jtb . setPrinter ( this . printer ) ; jtb . setScheme ( this . scheme ) ; jtb . setSpecialTokens ( this . specialTokens ) ; jtb . setSupressErrorChecking ( this . supressErrorChecking ) ; return jtb ; }
Creates a new facade to invoke JTB . Most options for the invocation are derived from the current values of the corresponding mojo parameters . The caller is responsible to set the input file output directories and packages on the returned facade .
7,683
public void setSourceDirectory ( final File directory ) { if ( ! directory . isAbsolute ( ) ) { throw new IllegalArgumentException ( "source directory is not absolute: " + directory ) ; } this . scanner . setBasedir ( directory ) ; }
Sets the absolute path to the source directory to scan for grammar files . This directory must exist or the scanner will report an error .
7,684
public void setOutputDirectory ( final File directory ) { if ( directory != null && ! directory . isAbsolute ( ) ) { throw new IllegalArgumentException ( "output directory is not absolute: " + directory ) ; } this . outputDirectory = directory ; }
Sets the absolute path to the output directory used to detect stale target files .
7,685
public void scan ( ) throws IOException { this . includedGrammars . clear ( ) ; this . scanner . scan ( ) ; final String [ ] includedFiles = this . scanner . getIncludedFiles ( ) ; for ( final String includedFile : includedFiles ) { final GrammarInfo grammarInfo = new GrammarInfo ( this . scanner . getBasedir ( ) , includedFile , this . parserPackage ) ; if ( this . outputDirectory != null ) { final File sourceFile = grammarInfo . getGrammarFile ( ) ; final File [ ] targetFiles = getTargetFiles ( this . outputDirectory , includedFile , grammarInfo ) ; for ( final File targetFile2 : targetFiles ) { final File targetFile = targetFile2 ; if ( ! targetFile . exists ( ) || targetFile . lastModified ( ) + this . staleMillis < sourceFile . lastModified ( ) ) { this . includedGrammars . add ( grammarInfo ) ; break ; } } } else { this . includedGrammars . add ( grammarInfo ) ; } } }
Scans the source directory for grammar files that match at least one inclusion pattern but no exclusion pattern optionally performing timestamp checking to exclude grammars whose corresponding parser files are up to date .
7,686
protected File [ ] getTargetFiles ( final File targetDirectory , final String grammarFile , final GrammarInfo grammarInfo ) { final File parserFile = new File ( targetDirectory , grammarInfo . getParserFile ( ) ) ; return new File [ ] { parserFile } ; }
Determines the output files corresponding to the specified grammar file .
7,687
private String findPackageName ( final String grammar ) { final String packageDeclaration = "package\\s+([^\\s.;]+(\\.[^\\s.;]+)*)\\s*;" ; final Matcher matcher = Pattern . compile ( packageDeclaration ) . matcher ( grammar ) ; if ( matcher . find ( ) ) { return matcher . group ( 1 ) ; } return "" ; }
Extracts the declared package name from the specified grammar file .
7,688
private String findParserName ( final String grammar ) { final String parserBegin = "PARSER_BEGIN\\s*\\(\\s*([^\\s\\)]+)\\s*\\)" ; final Matcher matcher = Pattern . compile ( parserBegin ) . matcher ( grammar ) ; if ( matcher . find ( ) ) { return matcher . group ( 1 ) ; } return "" ; }
Extracts the simple parser name from the specified grammar file .
7,689
protected String getToolName ( ) { final String name = getClass ( ) . getName ( ) ; return name . substring ( name . lastIndexOf ( '.' ) + 1 ) ; }
Gets the name of the tool .
7,690
public void run ( ) throws MojoExecutionException , MojoFailureException { ESuccess exitCode ; try { if ( getLog ( ) . isDebugEnabled ( ) ) { getLog ( ) . debug ( "Running " + getToolName ( ) + ": " + this ) ; } exitCode = execute ( ) ; } catch ( final Exception e ) { throw new MojoExecutionException ( "Failed to execute " + getToolName ( ) , e ) ; } if ( exitCode . isFailure ( ) ) { throw new MojoFailureException ( getToolName ( ) + " reported failure: " + this ) ; } }
Runs the tool using the previously set parameters .
7,691
public void setOutputFile ( final File value ) { if ( value != null && ! value . isAbsolute ( ) ) { throw new IllegalArgumentException ( "path is not absolute: " + value ) ; } this . outputFile = value ; }
Sets the absolute path to the output file .
7,692
private String [ ] _generateArguments ( ) { final List < String > argsList = new ArrayList < > ( ) ; if ( StringUtils . isNotEmpty ( this . grammarEncoding ) ) { argsList . add ( "-GRAMMAR_ENCODING=" + this . grammarEncoding ) ; } if ( StringUtils . isNotEmpty ( this . outputEncoding ) ) { argsList . add ( "-OUTPUT_ENCODING=" + this . outputEncoding ) ; } if ( this . text != null ) { argsList . add ( "-TEXT=" + this . text ) ; } if ( this . bnf != null ) { argsList . add ( "-BNF=" + this . bnf ) ; } if ( this . oneTable != null ) { argsList . add ( "-ONE_TABLE=" + this . oneTable ) ; } if ( this . outputFile != null ) { argsList . add ( "-OUTPUT_FILE=" + this . outputFile . getAbsolutePath ( ) ) ; } if ( StringUtils . isNotEmpty ( this . cssHref ) ) { argsList . add ( "-CSS=" + this . cssHref ) ; } if ( this . inputFile != null ) { argsList . add ( this . inputFile . getAbsolutePath ( ) ) ; } return argsList . toArray ( new String [ argsList . size ( ) ] ) ; }
Assembles the command line arguments for the invocation of JJDoc according to the configuration .
7,693
public final PowerAdapter offset ( int offset ) { if ( offset <= 0 ) { return this ; } if ( offset == Integer . MAX_VALUE ) { return EMPTY ; } return new OffsetAdapter ( this , offset ) ; }
Returns a new adapter that presents all items of this adapter starting at the specified offset .
7,694
public final PowerAdapter limit ( int limit ) { if ( limit == Integer . MAX_VALUE ) { return this ; } if ( limit <= 0 ) { return EMPTY ; } return new LimitAdapter ( this , limit ) ; }
Returns a new adapter that presents all items of this adapter up until the specified limit .
7,695
private boolean shouldAnimate ( ) { if ( ! mAnimationEnabled ) { return false ; } Display display = currentDisplay ( ) ; if ( display == null ) { return false ; } if ( mVisibleStartTime <= 0 ) { return false ; } long threshold = ( long ) ( 1000 / display . getRefreshRate ( ) ) ; long millisVisible = elapsedRealtime ( ) - mVisibleStartTime ; return millisVisible > threshold ; }
Returns whether now is an appropriate time to perform animations .
7,696
protected final void notifyChanged ( ) { for ( int i = mObservers . size ( ) - 1 ; i >= 0 ; i -- ) { mObservers . get ( i ) . onChanged ( ) ; } }
Notify observers that the condition has changed .
7,697
protected final void notifyError ( final Throwable e ) { checkNotNull ( e , "e" ) ; runOnUiThread ( new Runnable ( ) { public void run ( ) { mErrorObservable . notifyError ( e ) ; } } ) ; }
Dispatch an error notification on the UI thread .
7,698
public final < O > Data < O > filter ( final Class < O > type ) { return ( Data < O > ) new FilterData < > ( this , new Predicate < Object > ( ) { public boolean apply ( Object o ) { return type . isInstance ( o ) ; } } ) ; }
Filter this data by class . The resulting elements are guaranteed to be of the given type .
7,699
private void loadLoop ( ) throws InterruptedException { boolean firstItem = true ; boolean moreAvailable = true ; while ( moreAvailable ) { if ( currentThread ( ) . isInterrupted ( ) ) { throw new InterruptedException ( ) ; } try { setLoading ( true ) ; final Result < ? extends T > result = load ( ) ; moreAvailable = result != null && result . getRemaining ( ) > 0 ; setAvailable ( result != null ? result . getRemaining ( ) : 0 ) ; final boolean needToClear = firstItem ; firstItem = false ; runOnUiThread ( new Runnable ( ) { public void run ( ) { List < ? extends T > elements = result != null ? result . getElements ( ) : Collections . < T > emptyList ( ) ; if ( needToClear ) { overwriteResult ( elements ) ; } else { appendResult ( elements ) ; } setLoading ( false ) ; } } ) ; } catch ( InterruptedException e ) { throw e ; } catch ( InterruptedIOException e ) { InterruptedException interruptedException = new InterruptedException ( ) ; interruptedException . initCause ( e ) ; throw interruptedException ; } catch ( final Throwable e ) { runOnUiThread ( new Runnable ( ) { public void run ( ) { notifyError ( e ) ; } } ) ; mError = true ; setLoading ( false ) ; } block ( ) ; } }
Loads each increment until full range has been loading halting in between increment until instructed to proceed .