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

92.3% Statements 24/26
85.71% Branches 6/7
100% Functions 1/1
92.3% Lines 24/26

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 261x 1x 1x 1x 1x 1x 1x 1107x 1107x 678x 678x 429x 429x 1107x 421x 421x 6x 6x 421x 1107x 8x 8x     1107x 1x
import {ExpressionNode} from "../../nodes";
import {CharacterType, IntegerType, StringType} from "../../types/basic";
import {AbstractType} from "../../types/basic/_abstract_type";
import {Integer} from "../../2_statements/expressions";
 
export class Constant {
  public runSyntax(node: ExpressionNode): AbstractType {
    // todo: ConcatenatedConstant is not used?
    if (node.findDirectExpression(Integer)) {
      return IntegerType.get({derivedFromConstant: true});
    }
 
    const first = node.getFirstToken().getStr();
    if (first.startsWith("'")) {
      let len = first.length - 2;
      if (len <= 0) {
        len = 1;
      }
      return new CharacterType(len, {derivedFromConstant: true});
    } else if (first.startsWith("`")) {
      return StringType.get({derivedFromConstant: true});
    } else {
      return StringType.get();
    }
  }
}