Skip to content

Commit

Permalink
[DROOLS-371] Init arguments for abduced facts
Browse files Browse the repository at this point in the history
  • Loading branch information
sotty committed Feb 15, 2015
1 parent 851a110 commit 7d49688
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 68 deletions.
Expand Up @@ -53,31 +53,20 @@ public Pattern build(final RuleBuildContext context,

Declaration[] declarations = new Declaration[ params.length ];

Class<?> abductionReturnKlass = null;
if ( query.isAbductive() ) {
AnnotationDescr ann = queryDescr.getAnnotation( Abductive.class );
String returnName = ann.getValueAsString( "target" );
try {
Class<?> returnKlass = context.getPkg().getTypeResolver().resolveType( returnName.replace( ".class", "" ) );
ClassObjectType objectType = new ClassObjectType( returnKlass, false );
objectType = context.getPkg().getClassFieldAccessorStore().getClassObjectType( objectType,
(AbductiveQuery) query );
abductionReturnKlass = context.getPkg().getTypeResolver().resolveType( returnName.replace( ".class", "" ) );
params[ numParams ] = "";
types[ numParams ] = returnKlass.getName();

((AbductiveQuery) query).setReturnType( objectType, params );
types[ numParams ] = abductionReturnKlass.getName();

} catch ( ClassNotFoundException e ) {
context.addError( new DescrBuildError( context.getParentDescr(),
queryDescr,
e,
"Unable to resolve abducible type : " + returnName ) );
} catch ( NoSuchMethodException e ) {
context.addError( new DescrBuildError( context.getParentDescr(),
queryDescr,
e,
"Unable to resolve abducible constructor for type : " + returnName +
" with types " + Arrays.toString( types ) ) );

}
}

Expand Down Expand Up @@ -107,7 +96,34 @@ public Pattern build(final RuleBuildContext context,
}
context.setPrefixPattern( pattern );

if ( query.isAbductive() ) {
String returnName = "";
try {
AnnotationDescr ann = queryDescr.getAnnotation( Abductive.class );
Object[] argsVal = ((Object[]) ann.getValue( "args" ));
String[] args = argsVal != null ? Arrays.copyOf( argsVal, argsVal.length, String[].class ) : null;

returnName = types[ numParams ];
ClassObjectType objectType = new ClassObjectType( abductionReturnKlass, false );
objectType = context.getPkg().getClassFieldAccessorStore().getClassObjectType( objectType,
(AbductiveQuery) query );

( (AbductiveQuery) query ).setReturnType( objectType, params, args, declarations );
} catch ( NoSuchMethodException e ) {
context.addError( new DescrBuildError( context.getParentDescr(),
queryDescr,
e,
"Unable to resolve abducible constructor for type : " + returnName +
" with types " + Arrays.toString( types ) ) );

} catch ( IllegalArgumentException e ) {
context.addError( new DescrBuildError( context.getParentDescr(),
queryDescr,
e,
e.getMessage() ) );

}
}

return pattern;
}
Expand Down

0 comments on commit 7d49688

Please sign in to comment.