use of org.drools.compiler.lang.descr.ReturnValueRestrictionDescr in project drools by kiegroup.
the class PatternBuilder method getDeclarationsForReturnValue.
private Declaration[] getDeclarationsForReturnValue(RuleBuildContext context, RelationalExprDescr relDescr, String operator, String value2) {
Pattern pattern = (Pattern) context.getDeclarationResolver().peekBuildStack();
ReturnValueRestrictionDescr returnValueRestrictionDescr = new ReturnValueRestrictionDescr(operator, relDescr, value2);
AnalysisResult analysis = context.getDialect().analyzeExpression(context, returnValueRestrictionDescr, returnValueRestrictionDescr.getContent(), new BoundIdentifiers(pattern, context, null, pattern.getObjectType().getClassType()));
if (analysis == null) {
// something bad happened
return null;
}
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
final List<Declaration> tupleDeclarations = new ArrayList<Declaration>();
final List<Declaration> factDeclarations = new ArrayList<Declaration>();
for (String id : usedIdentifiers.getDeclrClasses().keySet()) {
Declaration decl = context.getDeclarationResolver().getDeclaration(id);
if (decl.getPattern() == pattern) {
factDeclarations.add(decl);
} else {
tupleDeclarations.add(decl);
}
}
createImplicitBindings(context, pattern, analysis.getNotBoundedIdentifiers(), usedIdentifiers, factDeclarations);
final Declaration[] previousDeclarations = tupleDeclarations.toArray(new Declaration[tupleDeclarations.size()]);
final Declaration[] localDeclarations = 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()]);
Declaration[] requiredDeclarations = new Declaration[previousDeclarations.length + localDeclarations.length];
System.arraycopy(previousDeclarations, 0, requiredDeclarations, 0, previousDeclarations.length);
System.arraycopy(localDeclarations, 0, requiredDeclarations, previousDeclarations.length, localDeclarations.length);
Declaration[] declarations = new Declaration[requiredDeclarations.length + requiredGlobals.length];
int i = 0;
for (Declaration requiredDeclaration : requiredDeclarations) {
declarations[i++] = requiredDeclaration;
}
for (String requiredGlobal : requiredGlobals) {
declarations[i++] = context.getDeclarationResolver().getDeclaration(requiredGlobal);
}
return declarations;
}
Aggregations