private void addDuplicatedMethodError(
      String message, IOpenMethod method, IOpenMethod existedMethod) {
    ISyntaxNode newMethodSyntaxNode = method.getInfo().getSyntaxNode();
    if (newMethodSyntaxNode instanceof TableSyntaxNode) {
      SyntaxNodeException error =
          SyntaxNodeExceptionUtils.createError(message, newMethodSyntaxNode);
      ((TableSyntaxNode) newMethodSyntaxNode).addError(error);

      try {
        TableSyntaxNode existedMethodSyntaxNode =
            (TableSyntaxNode) existedMethod.getInfo().getSyntaxNode();
        if (existedMethodSyntaxNode != null) {
          existedMethodSyntaxNode.addError(
              SyntaxNodeExceptionUtils.createError(message, existedMethodSyntaxNode));
        }
      } catch (Exception ex) {
        log.warn(
            "Cannot get a syntax node for the method: {}",
            MethodUtil.printMethod(existedMethod, new StringBuilder()),
            ex);
      }

      addError(error);
    } else {
      addError(new DuplicatedMethodException(message, method));
    }
  }
  @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();
    }
  }
Exemplo n.º 3
0
  protected void processError(
      SyntaxNodeException error,
      TableSyntaxNode tableSyntaxNode,
      RulesModuleBindingContext moduleContext) {

    tableSyntaxNode.addError(error);
    BindHelper.processError(error, moduleContext);
  }