private void populateDSLSentences(final List<DSLTokenizedMappingFile> dsls) { for ( DSLTokenizedMappingFile file : dsls ) { for ( DSLMappingEntry entry : file.getMapping().getEntries() ) { if ( entry.getSection() == DSLMappingEntry.CONDITION ) { builder.addDSLConditionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) { builder.addDSLActionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) { builder.addDSLMapping( entry ); } else if ( entry.getSection() == DSLMappingEntry.ANY ) { builder.addDSLConditionSentence( entry.getMappingKey() ); builder.addDSLActionSentence( entry.getMappingKey() ); } } } }
@Test public void testAddDSLSentence() { final String input = "{This} is a {pattern} considered pretty \\{{easy}\\} by most \\{people\\}. What do you {say}?"; this.builder.addDSLActionSentence( input ); this.builder.addDSLConditionSentence( "foo bar" ); final SuggestionCompletionEngine engine = this.builder.getInstance(); assertEquals( 1, engine.actionDSLSentences.length ); assertEquals( 1, engine.conditionDSLSentences.length ); }
private void populateDateEnums(List<String> dataEnums) { for ( String enumFile : dataEnums ) { DataEnumLoader enumLoader = new DataEnumLoader( enumFile ); if ( enumLoader.hasErrors() ) { errors.addAll( enumLoader.getErrors() ); } else { builder.addAllDataEnumsList( enumLoader.getData() ); } } }
this.builder.addFieldType( declaredType + "." + SuggestionCompletionEngine.TYPE_THIS, declaredType, null ); this.builder.addFactType( declaredType, FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS ); this.builder.addFieldType( declaredType + "." + fieldName, fieldClass, try { Class< ? > clz = resolver.resolveType( fieldClass ); this.builder.addFieldType( declaredType + "." + fieldName, translateClassToGenericType( clz ), clz ); this.builder.addAnnotationsForType( declaredType, annotations ); this.builder.addFieldsForType( declaredType, fieldNames.toArray( new String[fieldNames.size()] ) ); this.builder.addFieldAccessorsAndMutatorsForField( accessorsAndMutators );
final Class< ? > returnType = m.returnType; final String genericType = translateClassToGenericType( returnType ); this.builder.addFieldType( qualifiedName, genericType, returnType ); final FieldInfo fi = new FieldInfo( m.genericType, m.returnType ); this.builder.addFieldTypeField( qualifiedName, fi ); this.builder.addFieldType( shortTypeName + "." + field, genericType, returnType ); final FieldInfo fi = new FieldInfo( f.getGenericType(), f.getType() ); this.builder.addFieldTypeField( shortTypeName + "." + field, fi ); clazz.getGenericSuperclass(), clazz ) ); this.builder.addFieldType( shortTypeName + "." + SuggestionCompletionEngine.TYPE_THIS, shortTypeName, clazz ); this.builder.addFieldAccessorsAndMutatorsForField( extractFieldAccessorsAndMutators( methodSignatures ) ); this.builder.addFieldsForType( shortTypeName, fields.toArray( new String[fields.size()] ) );
/** * This will validate, and generate a new engine, ready to go. If there are * errors, you can get them by doing getMissingClasses(); * * @param header * The package configuration file content. * @param jars * a list of jars to look inside (pass in empty array if not * needed) this is a list of {@link JarInputStream} * @param dsls * any dsl files. This is a list of {@link DSLMappingFile}. * @param dataEnums * this is a list of String's which hold data enum definitions. * (normally will be just one, but for completeness can load * multiple). * @return A SuggestionCompletionEngine ready to be used in anger. */ public SuggestionCompletionEngine getSuggestionEngine(final String header, final List<JarInputStream> jars, final List<DSLTokenizedMappingFile> dsls, final List<String> dataEnums) { builder.newCompletionEngine(); if ( headerNotEmpty( header ) ) { processPackageHeader( header, jars ); } populateDSLSentences( dsls ); populateDateEnums( dataEnums ); return builder.getInstance(); }
when(mapping4.getMappingKey()).thenReturn("key"); this.builder.addDSLMapping(mapping1); this.builder.addDSLMapping(mapping2); this.builder.addDSLMapping(mapping3); this.builder.addDSLMapping(mapping4); final SuggestionCompletionEngine engine = this.builder.getInstance();
@Before public void setUp() throws Exception { this.builder.newCompletionEngine(); }
private void addFactType(List jars, String className) { final Class clazz = loadClass( className, jars ); if ( clazz != null ) { try { final String shortTypeName = getShortNameOfClass( clazz.getName() ); this.builder.addFactType( shortTypeName, FIELD_CLASS_TYPE.REGULAR_CLASS ); loadClassFields( clazz, shortTypeName ); } catch ( final IOException e ) { this.errors.add( String.format( "Error while inspecting the class: %s. The error was: %s", className, e.getMessage() ) ); } catch ( NoClassDefFoundError e ) { this.errors.add( String.format( "Unable to find the class: %s which is required by: %s. You may need to add more classes to the model.", e.getMessage().replace( '/', '.' ), className ) ); } } }
final Class< ? > returnType = m.returnType; final String genericType = translateClassToGenericType( returnType ); this.builder.addFieldType( qualifiedName, genericType, returnType ); final FieldInfo fi = new FieldInfo( m.genericType, m.returnType ); this.builder.addFieldTypeField( qualifiedName, fi ); this.builder.addFieldType( shortTypeName + "." + field, genericType, returnType ); final FieldInfo fi = new FieldInfo( f.getGenericType(), f.getType() ); this.builder.addFieldTypeField( shortTypeName + "." + field, fi ); clazz.getGenericSuperclass(), clazz ) ); this.builder.addFieldType( shortTypeName + "." + SuggestionCompletionEngine.TYPE_THIS, shortTypeName, clazz ); this.builder.addFieldAccessorsAndMutatorsForField( extractFieldAccessorsAndMutators( methodSignatures ) ); this.builder.addFieldsForType( shortTypeName, fields.toArray( new String[fields.size()] ) );
this.builder.addFieldType( declaredType + "." + SuggestionCompletionEngine.TYPE_THIS, declaredType, null ); this.builder.addFactType( declaredType, FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS ); this.builder.addFieldType( declaredType + "." + fieldName, fieldClass, try { Class< ? > clz = resolver.resolveType( fieldClass ); this.builder.addFieldType( declaredType + "." + fieldName, translateClassToGenericType( clz ), clz ); this.builder.addAnnotationsForType( declaredType, annotations ); this.builder.addFieldsForType( declaredType, fieldNames.toArray( new String[fieldNames.size()] ) ); this.builder.addFieldAccessorsAndMutatorsForField( accessorsAndMutators );
/** * This will validate, and generate a new engine, ready to go. If there are * errors, you can get them by doing getMissingClasses(); * * @param header * The package configuration file content. * @param jars * a list of jars to look inside (pass in empty array if not * needed) this is a list of {@link JarInputStream} * @param dsls * any dsl files. This is a list of {@link DSLMappingFile}. * @param dataEnums * this is a list of String's which hold data enum definitions. * (normally will be just one, but for completeness can load * multiple). * @return A SuggestionCompletionEngine ready to be used in anger. */ public SuggestionCompletionEngine getSuggestionEngine(final String header, final List<JarInputStream> jars, final List<DSLTokenizedMappingFile> dsls, final List<String> dataEnums) { builder.newCompletionEngine(); if ( headerNotEmpty( header ) ) { processPackageHeader( header, jars ); } populateDSLSentences( dsls ); populateDateEnums( dataEnums ); return builder.getInstance(); }
private void addFactType(List jars, String className) { final Class clazz = loadClass( className, jars ); if ( clazz != null ) { try { final String shortTypeName = getShortNameOfClass( clazz.getName() ); this.builder.addFactType( shortTypeName, FIELD_CLASS_TYPE.REGULAR_CLASS ); loadClassFields( clazz, shortTypeName ); } catch ( final IOException e ) { this.errors.add( String.format( "Error while inspecting the class: %s. The error was: %s", className, e.getMessage() ) ); } catch ( NoClassDefFoundError e ) { this.errors.add( String.format( "Unable to find the class: %s which is required by: %s. You may need to add more classes to the model.", e.getMessage().replace( '/', '.' ), className ) ); } } }
private void populateDSLSentences(final List<DSLTokenizedMappingFile> dsls) { for ( DSLTokenizedMappingFile file : dsls ) { for ( DSLMappingEntry entry : file.getMapping().getEntries() ) { if ( entry.getSection() == DSLMappingEntry.CONDITION ) { builder.addDSLConditionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) { builder.addDSLActionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) { builder.addDSLMapping( entry ); } else if ( entry.getSection() == DSLMappingEntry.ANY ) { builder.addDSLConditionSentence( entry.getMappingKey() ); builder.addDSLActionSentence( entry.getMappingKey() ); } } } }
private void populateDateEnums(List<String> dataEnums) { for ( String enumFile : dataEnums ) { DataEnumLoader enumLoader = new DataEnumLoader( enumFile ); if ( enumLoader.hasErrors() ) { errors.addAll( enumLoader.getErrors() ); } else { builder.addAllDataEnumsList( enumLoader.getData() ); } } }