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

100% Statements 29/29
100% Branches 10/10
100% Functions 1/1
100% Lines 29/29

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 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 347x 347x 347x 347x 347x 347x 314x 314x 33x 33x 347x 347x 31x 31x 2x 2x 2x 2x 2x  
import {ExpressionNode} from "../../nodes";
import * as Expressions from "../../2_statements/expressions";
import {StringType} from "../../types/basic";
import {AbstractType} from "../../types/basic/_abstract_type";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
 
 
// A text symbol, 'text'(001), is a character literal of type C. Unlike a plain
// literal it does not convert when passed to a method parameter typed STRING,
// the system reports it as not type-compatible. Returns true if an issue was reported.
export function checkTextSymbol(
  source: ExpressionNode | undefined,
  parameterType: AbstractType | undefined,
  input: SyntaxInput): boolean {
 
  if (source === undefined || !(parameterType instanceof StringType)) {
    return false;
  }
 
  const children = source.getChildren();
  const constant = children.length === 1 ? source.findDirectExpression(Expressions.Constant) : undefined;
  if (constant?.findDirectExpression(Expressions.TextElementString) === undefined) {
    return false;
  }
 
  const message = `Text symbol "${source.concatTokens()}" is a character literal, not type-compatible with a STRING parameter`;
  input.issues.push(syntaxIssue(input, source.getFirstToken(), message));
  return true;
}