Ejemplo n.º 1
0
 static void reportUnknownVariablesInSettingWithoutExeRows(
     final FileValidationContext validationContext,
     final ProblemsReportingStrategy reporter,
     final List<VariableDeclaration> variablesDeclarations,
     final Set<String> variables) {
   final Set<String> definedVariables = newHashSet(variables);
   for (final VariableDeclaration variableDeclaration : variablesDeclarations) {
     if (TestCaseTableValidator.isInvalidVariableDeclaration(
         definedVariables, variableDeclaration)) {
       final String variableName = variableDeclaration.getVariableName().getText();
       final RobotProblem problem =
           RobotProblem.causedBy(VariablesProblem.UNDECLARED_VARIABLE_USE)
               .formatMessageWith(variableName);
       final int variableOffset = variableDeclaration.getStartFromFile().getOffset();
       final ProblemPosition position =
           new ProblemPosition(
               variableDeclaration.getStartFromFile().getLine(),
               Range.closed(
                   variableOffset,
                   variableOffset
                       + ((variableDeclaration.getEndFromFile().getOffset() + 1)
                           - variableOffset)));
       final Map<String, Object> additionalArguments =
           ImmutableMap.<String, Object>of(
               AdditionalMarkerAttributes.NAME, variableDeclaration.asToken().getText());
       reporter.handleProblem(problem, validationContext.getFile(), position, additionalArguments);
     }
   }
 }
Ejemplo n.º 2
0
  static void reportUnknownVariables(
      final FileValidationContext validationContext,
      final ProblemsReportingStrategy reporter,
      final List<? extends RobotExecutableRow<?>> executables,
      final Set<String> variables) {

    final Set<String> definedVariables = newHashSet(variables);

    for (final RobotExecutableRow<?> row : executables) {
      if (row.isExecutable()) {
        final IExecutableRowDescriptor<?> lineDescription = row.buildLineDescription();

        for (final VariableDeclaration variableDeclaration : lineDescription.getUsedVariables()) {
          if (isInvalidVariableDeclaration(
              validationContext, definedVariables, lineDescription, variableDeclaration)) {
            String variableName = variableDeclaration.getVariableName().getText();
            final Optional<TextPosition> extractVariableName =
                new VariableComputationHelper().extractVariableName(variableDeclaration);
            if (extractVariableName.isPresent()) {
              variableName = extractVariableName.get().getText();
            }
            final RobotProblem problem =
                RobotProblem.causedBy(VariablesProblem.UNDECLARED_VARIABLE_USE)
                    .formatMessageWith(variableName);
            final int variableOffset = variableDeclaration.getStartFromFile().getOffset();
            final ProblemPosition position =
                new ProblemPosition(
                    variableDeclaration.getStartFromFile().getLine(),
                    Range.closed(
                        variableOffset,
                        variableOffset
                            + ((variableDeclaration.getEndFromFile().getOffset() + 1)
                                - variableOffset)));
            final Map<String, Object> additionalArguments =
                ImmutableMap.<String, Object>of(
                    AdditionalMarkerAttributes.NAME, variableDeclaration.asToken().getText());
            reporter.handleProblem(
                problem, validationContext.getFile(), position, additionalArguments);
          }
        }
        definedVariables.addAll(
            VariableNamesSupport.extractUnifiedVariableNames(
                lineDescription.getCreatedVariables()));
      }
    }
  }