@Override public ValidationResult validateTables( OpenL openl, TableSyntaxNode[] tableSyntaxNodes, IOpenClass openClass) { ValidationResult validationResult = null; // Group methods not TableSyntaxNodes as we may have dependent modules, // and no sources for them, // represented in current module. The only information about dependency // methods contains in openClass. // Map<DimensionPropertiesMethodKey, List<TableSyntaxNode>> groupedMethods = groupExecutableMethods(tableSyntaxNodes); for (DimensionPropertiesMethodKey key : groupedMethods.keySet()) { List<TableSyntaxNode> methodsGroup = groupedMethods.get(key); List<TableSyntaxNode> activeExecutableMethodTable = new ArrayList<TableSyntaxNode>(); int activeTableFoundCount = 0; for (TableSyntaxNode executableMethodTable : methodsGroup) { if (executableMethodTable.getMember() instanceof TestSuiteMethod) { activeTableFoundCount++; break; } if (executableMethodTable.getTableProperties() != null && isActive(executableMethodTable)) { activeExecutableMethodTable.add(executableMethodTable); activeTableFoundCount++; } } if (activeTableFoundCount > 1) { if (validationResult == null) { validationResult = new ValidationResult(ValidationStatus.FAIL); } for (TableSyntaxNode executableMethodTable : activeExecutableMethodTable) { SyntaxNodeException exception = SyntaxNodeExceptionUtils.createError(ODD_ACTIVE_TABLE_MESSAGE, executableMethodTable); executableMethodTable.addError(exception); ValidationUtils.addValidationMessage(validationResult, new OpenLErrorMessage(exception)); } } if (activeTableFoundCount == 0) { if (validationResult == null) { validationResult = new ValidationResult(ValidationStatus.SUCCESS); } // warning is attached to all table syntax node for (TableSyntaxNode tsn : methodsGroup) { ValidationUtils.addValidationMessage( validationResult, new OpenLWarnMessage(NO_ACTIVE_TABLE_MESSAGE, tsn)); } } } if (validationResult != null) { return validationResult; } else { return ValidationUtils.validationSuccess(); } }
private Map<DimensionPropertiesMethodKey, List<TableSyntaxNode>> groupExecutableMethods( TableSyntaxNode[] tableSyntaxNodes) { Map<DimensionPropertiesMethodKey, List<TableSyntaxNode>> groupedMethods = new HashMap<DimensionPropertiesMethodKey, List<TableSyntaxNode>>(); for (TableSyntaxNode tsn : tableSyntaxNodes) { if (tsn.getMember() instanceof ExecutableRulesMethod) { ExecutableRulesMethod executableMethod = (ExecutableRulesMethod) tsn.getMember(); DimensionPropertiesMethodKey key = new DimensionPropertiesMethodKey(executableMethod); if (!groupedMethods.containsKey(key)) { groupedMethods.put(key, new ArrayList<TableSyntaxNode>()); } groupedMethods.get(key).add(tsn); } } return groupedMethods; }