All files / src/abap/5_syntax/expressions _check_database_fields.ts

86.04% Statements 37/43
86.66% Branches 13/15
100% Functions 1/1
86.04% Lines 37/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 200x 200x 200x 200x 200x 200x 200x 10x 10x 190x 190x 200x 155x 155x 155x 35x 35x 200x     200x         35x 200x 44x 15x 15x 29x 44x 3x 3x 3x 3x 44x 32x  
import {AbstractToken} from "../../1_lexer/tokens/abstract_token";
import {StructureType, UnknownType, VoidType} from "../../types/basic";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {DatabaseTableSource} from "./database_table";
 
export function checkDatabaseFields(
  fields: readonly string[],
  dbSources: DatabaseTableSource[],
  input: SyntaxInput,
  token: AbstractToken,
): void {
  if (dbSources.length > 1) {
    return;
  }
 
  const first = dbSources[0];
  if (first === undefined) {
    // then its voided
    return;
  }
 
  const type = first.parseType(input.scope.getRegistry());
  if (type instanceof VoidType || type instanceof UnknownType) {
    return;
  }
  if (!(type instanceof StructureType)) {
    const message = "checkFields, expected structure, " + type.constructor.name;
    input.issues.push(syntaxIssue(input, token, message));
    return;
  }
 
  for (const field of fields) {
    if (field === "*") {
      continue;
    }
 
    if (/^[A-Z_]\w*$/i.test(field) && type.getComponentByName(field) === undefined) {
      const message = `checkFields, field ${field} not found`;
      input.issues.push(syntaxIssue(input, token, message));
      return;
    }
  }
}