/** * Creates {@link XlsModuleOpenClass} * * @param moduleDependencies set of dependent modules for creating module. */ protected XlsModuleOpenClass createModuleOpenClass( XlsModuleSyntaxNode moduleNode, OpenL openl, IDataBase dbase, Set<CompiledDependency> moduleDependencies, IBindingContext bindingContext) { return new XlsModuleOpenClass( XlsHelper.getModuleName(moduleNode), new XlsMetaInfo(moduleNode), openl, dbase, moduleDependencies, Thread.currentThread().getContextClassLoader(), OpenLSystemProperties.isDTDispatchingMode(bindingContext.getExternalParams()), OpenLSystemProperties.isDispatchingValidationEnabled(bindingContext.getExternalParams())); }
public IBoundCode bind(IParsedCode parsedCode, IBindingContextDelegator bindingContextDelegator) { XlsModuleSyntaxNode moduleNode = (XlsModuleSyntaxNode) parsedCode.getTopNode(); OpenL openl = null; try { openl = makeOpenL(moduleNode); } catch (OpenConfigurationException ex) { OpenlSyntaxNode syntaxNode = moduleNode.getOpenlNode(); SyntaxNodeException error = SyntaxNodeExceptionUtils.createError("Error Creating OpenL", ex, syntaxNode); BindHelper.processError(error); return BindHelper.makeInvalidCode(parsedCode, syntaxNode, new SyntaxNodeException[] {error}); } IOpenBinder openlBinder = openl.getBinder(); IBindingContext bindingContext = openlBinder.makeBindingContext(); bindingContext = BindHelper.delegateContext(bindingContext, bindingContextDelegator); if (parsedCode.getExternalParams() != null) { bindingContext.setExternalParams(parsedCode.getExternalParams()); } IBoundNode topNode = null; if (!parsedCode.getCompiledDependencies().isEmpty()) { topNode = bindWithDependencies( moduleNode, openl, bindingContext, parsedCode.getCompiledDependencies()); } else { topNode = bind(moduleNode, openl, bindingContext); } return new BoundCode(parsedCode, topNode, bindingContext.getErrors(), 0); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { int childrenCount = node.getNumberOfChildren(); if (childrenCount < 1) { BindHelper.processError( "Method node should have at least one subnode", node, bindingContext, false); return new ErrorBoundNode(node); } ISyntaxNode lastNode = node.getChild(childrenCount - 1); String methodName = ((IdentifierNode) lastNode).getIdentifier(); IBoundNode[] children = bindChildren(node, bindingContext, 0, childrenCount - 1); IOpenClass[] parameterTypes = getTypes(children); IMethodCaller methodCaller = bindingContext.findMethodCaller( ISyntaxConstants.THIS_NAMESPACE, methodName, parameterTypes); methodCaller = autoCastReturnTypeWrap(bindingContext, methodCaller, parameterTypes); // can`t find directly the method with given name and parameters. so, // try to bind it some additional ways // if (methodCaller == null) { return bindWithAdditionalBinders( node, bindingContext, methodName, parameterTypes, children, childrenCount); } String bindingType = APPROPRIATE_BY_SIGNATURE_METHOD; log(methodName, parameterTypes, bindingType); return new MethodBoundNode(node, children, methodCaller); }
private void processModuleContextErrors(IBindingContext bindingContext) { for (SyntaxNodeException e : syntaxNodeExceptions) { bindingContext.addError(e); } syntaxNodeExceptions.clear(); }
/** * Common binding cycle. * * @param moduleNode * @param openl * @param moduleContext * @param moduleOpenClass * @param bindingContext * @return */ private IBoundNode processBinding( XlsModuleSyntaxNode moduleNode, OpenL openl, RulesModuleBindingContext moduleContext, XlsModuleOpenClass moduleOpenClass, IBindingContext bindingContext) { IVocabulary vocabulary = makeVocabulary(moduleNode); if (vocabulary != null) { processVocabulary(vocabulary, moduleContext); } // // Selectors // ASelector<ISyntaxNode> propertiesSelector = getSelector(XlsNodeTypes.XLS_PROPERTIES); ASelector<ISyntaxNode> dataTypeSelector = getSelector(XlsNodeTypes.XLS_DATATYPE); ISelector<ISyntaxNode> notPropertiesAndNotDatatypeSelector = propertiesSelector.not().and(dataTypeSelector.not()); ISelector<ISyntaxNode> spreadsheetSelector = getSelector(XlsNodeTypes.XLS_SPREADSHEET); ISelector<ISyntaxNode> testMethodSelector = getSelector(XlsNodeTypes.XLS_TEST_METHOD); ISelector<ISyntaxNode> runMethodSelector = getSelector(XlsNodeTypes.XLS_RUN_METHOD); ISelector<ISyntaxNode> commonTablesSelector = notPropertiesAndNotDatatypeSelector.and( spreadsheetSelector.not().and(testMethodSelector.not().and(runMethodSelector.not()))); // Bind property node at first. // TableSyntaxNode[] propertiesNodes = selectNodes(moduleNode, propertiesSelector); bindInternal(moduleNode, moduleOpenClass, propertiesNodes, openl, moduleContext); bindPropertiesForAllTables(moduleNode, moduleOpenClass, openl, moduleContext); IBoundNode topNode = null; // Bind datatype nodes. TableSyntaxNode[] datatypeNodes = selectNodes(moduleNode, dataTypeSelector); /* * Processes datatype table nodes before the bind operation. Checks type * declarations and finds invalid using of inheritance feature at this * step. */ TableSyntaxNode[] processedDatatypeNodes = new DatatypesSorter() .sort( datatypeNodes, moduleContext); // Rewrite this sorter with TableSyntaxNodeRelationsUtils bindInternal(moduleNode, moduleOpenClass, processedDatatypeNodes, openl, moduleContext); // Select nodes excluding Properties, Datatype, Spreadsheet, Test, // RunMethod tables TableSyntaxNode[] commonTables = selectNodes(moduleNode, commonTablesSelector); // Select and sort Spreadsheet tables TableSyntaxNode[] spreadsheets = selectSpreadsheetNodes(moduleNode, spreadsheetSelector); if (OpenLSystemProperties.isCustomSpreadsheetType(bindingContext.getExternalParams())) { try { spreadsheets = TableSyntaxNodeRelationsUtils.sort( spreadsheets, new SpreadsheetTableSyntaxNodeRelationsDeterminer()); } catch (TableSyntaxNodeCircularDependencyException e) { for (TableSyntaxNode tsn : e.getTableSyntaxNodes()) { SyntaxNodeException error = SyntaxNodeExceptionUtils.createError(e, tsn); processError(error, tsn, moduleContext); } } } TableSyntaxNode[] commonAndSpreadsheetTables = ArrayUtils.addAll(commonTables, spreadsheets); bindInternal(moduleNode, moduleOpenClass, commonAndSpreadsheetTables, openl, moduleContext); // Select Test and RunMethod tables TableSyntaxNode[] runTables = selectNodes(moduleNode, runMethodSelector); bindInternal(moduleNode, moduleOpenClass, runTables, openl, moduleContext); TableSyntaxNode[] testTables = selectNodes(moduleNode, testMethodSelector); topNode = bindInternal(moduleNode, moduleOpenClass, testTables, openl, moduleContext); if (moduleOpenClass.isUseDescisionTableDispatcher()) { DispatcherTablesBuilder dispTableBuilder = new DispatcherTablesBuilder((XlsModuleOpenClass) topNode.getType(), moduleContext); dispTableBuilder.build(); } ((XlsModuleOpenClass) topNode.getType()).setRulesModuleBindingContext(moduleContext); ((XlsModuleOpenClass) topNode.getType()).completeOpenClassBuilding(); processErrors(moduleOpenClass.getErrors(), bindingContext); return topNode; }
@SuppressWarnings("unchecked") public static IConditionEvaluator makeEvaluator( ICondition condition, IOpenClass methodType, IBindingContext bindingContext) throws SyntaxNodeException { IParameterDeclaration[] params = condition.getParams(); switch (params.length) { case 1: IOpenClass paramType = params[0].getType(); IOpenCast openCast = bindingContext.getCast(paramType, methodType); if (openCast != null) { return new EqualsIndexedEvaluator(openCast); } IAggregateInfo aggregateInfo = paramType.getAggregateInfo(); if (aggregateInfo.isAggregate(paramType) && aggregateInfo.getComponentType(paramType).isAssignableFrom(methodType)) { return new ContainsInArrayIndexedEvaluator(); } IRangeAdaptor<? extends Object, ? extends Comparable<?>> rangeAdaptor = getRangeAdaptor(methodType, paramType); if (rangeAdaptor != null) { return new RangeIndexedEvaluator( (IRangeAdaptor<Object, ? extends Comparable<Object>>) rangeAdaptor, 1); } if (JavaOpenClass.BOOLEAN.equals(methodType) || JavaOpenClass.getOpenClass(Boolean.class).equals(methodType)) { return new DefaultConditionEvaluator(); } break; case 2: IOpenClass paramType0 = params[0].getType(); IOpenClass paramType1 = params[1].getType(); if (methodType == paramType0 && methodType == paramType1) { Class<?> clazz = methodType.getInstanceClass(); if (clazz != short.class && clazz != byte.class && clazz != int.class && clazz != long.class && clazz != double.class && clazz != float.class && !Comparable.class.isAssignableFrom(clazz)) { String message = String.format("Type '%s' is not Comparable", methodType.getName()); throw SyntaxNodeExceptionUtils.createError( message, null, null, condition.getSourceCodeModule()); } return new RangeIndexedEvaluator(null, 2); } aggregateInfo = paramType1.getAggregateInfo(); if (aggregateInfo.isAggregate(paramType1) && aggregateInfo.getComponentType(paramType1) == methodType) { BooleanTypeAdaptor booleanTypeAdaptor = BooleanAdaptorFactory.getAdaptor(paramType0); if (booleanTypeAdaptor != null) { return new ContainsInOrNotInArrayIndexedEvaluator(booleanTypeAdaptor); } } if (JavaOpenClass.BOOLEAN.equals(methodType) || JavaOpenClass.getOpenClass(Boolean.class).equals(methodType)) { return new DefaultConditionEvaluator(); } break; } List<String> names = new ArrayList<String>(); for (IParameterDeclaration parameterDeclaration : params) { String name = parameterDeclaration.getType().getName(); names.add(name); } String parametersString = StringUtils.join(names, ","); String message = String.format( "Can not make a Condition Evaluator for parameter %s and [%s]", methodType.getName(), parametersString); throw SyntaxNodeExceptionUtils.createError( message, null, null, condition.getSourceCodeModule()); }