Map<String, Class< ? >> globals = context.getPackageBuilder().getGlobals();
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
returnValueRestrictionDescr,
returnValueRestrictionDescr.getContent(),
new BoundIdentifiers( declarations,
globals,
null,
thisClass ) );
if ( analysis == null ) {
// something bad happened
return null;
}
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
final List tupleDeclarations = new ArrayList();
final List factDeclarations = new ArrayList();
for ( String id : usedIdentifiers.getDeclrClasses().keySet() ) {
final Declaration decl = context.getDeclarationResolver().getDeclaration( context.getRule(),
id );
if ( decl.getPattern() == pattern ) {
factDeclarations.add( decl );
} else {
tupleDeclarations.add( decl );
}
}
this.createImplicitBindings( context,
pattern,
analysis.getNotBoundedIdentifiers(),
usedIdentifiers,
factDeclarations );
Target right = getRightTarget( extractor );
Target left = Target.FACT;
final Evaluator evaluator = getEvaluator( context,
returnValueRestrictionDescr,
extractor.getValueType(),
returnValueRestrictionDescr.getEvaluator(),
returnValueRestrictionDescr.isNegated(),
returnValueRestrictionDescr.getParameterText(),
left,
right );
if ( evaluator == null ) {
return null;
}
final Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
final Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
Arrays.sort( previousDeclarations,
SortDeclarations.instance );
Arrays.sort( localDeclarations,
SortDeclarations.instance );
final String[] requiredGlobals = usedIdentifiers.getGlobals().keySet().toArray( new String[usedIdentifiers.getGlobals().size()] );
final ReturnValueRestriction returnValueRestriction = new ReturnValueRestriction( extractor,
previousDeclarations,
localDeclarations,
requiredGlobals,
evaluator );