All files / src/abap/5_syntax _type_utils.ts

91.82% Statements 101/110
94.52% Branches 69/73
100% Functions 3/3
91.82% Lines 101/110

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 1101x 1x 1x 1x 1x 1x 36x   36x 10x 17x 3x 3x 17x 7x 36x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 21x 21x 5x 5x 1x 1x 2x   2x             2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 244x 244x 244x 244x 244x 31x 3x 3x 28x 31x 31x 31x 27x 27x 1x 244x 23x 23x 23x 23x 23x 22x 22x 1x 213x 7x 7x 7x 7x 6x 6x 1x 190x 19x   19x 19x 19x 19x 9x 19x 10x 6x 6x 4x 183x 67x 67x 67x 67x 1x 1x 66x 66x 97x 97x 97x 1x
import {AnyType, CharacterType, CLikeType, CSequenceType, DataReference, DateType, GenericObjectReferenceType, HexType, IntegerType, NumericType, ObjectReferenceType, PackedType, StringType, StructureType, TableType, TimeType, UnknownType, VoidType, XStringType} from "../types/basic";
import {AbstractType} from "../types/basic/_abstract_type";
 
export class TypeUtils {
 
  public static isCharLike(type: AbstractType | undefined): boolean {
    if (type === undefined) {
      return false;
    } else if (type instanceof StructureType) {
      for (const c of type.getComponents()) {
        if (this.isCharLike(c.type) === false) {
          return false;
        }
      }
      return true;
    } else if (type instanceof StringType
        || type instanceof VoidType
        || type instanceof AnyType
        || type instanceof UnknownType
        || type instanceof NumericType
        || type instanceof CSequenceType
        || type instanceof DateType
        || type instanceof CLikeType
        || type instanceof PackedType
        || type instanceof TimeType
        || type instanceof CharacterType) {
      return true;
    }
    return false;
  }
 
  public static isHexLike(type: AbstractType | undefined): boolean {
    if (type === undefined) {
      return false;
    } else if (type instanceof StructureType) {
      for (const c of type.getComponents()) {
        if (this.isHexLike(c.type) === false) {
          return false;
        }
      }
      return true;
    } else if (type instanceof XStringType
        || type instanceof HexType
        || type instanceof VoidType
        || type instanceof AnyType
        || type instanceof UnknownType) {
      return true;
    }
    return false;
  }
 
  public static isAssignable(source: AbstractType | undefined, target: AbstractType | undefined): boolean {
/*
    console.dir(source);
    console.dir(target);
*/
    if (target instanceof TableType) {
      if (target.isWithHeader()) {
        return this.isAssignable(source, target.getRowType());
      }
      if (source instanceof TableType
          || source instanceof VoidType
          || source instanceof AnyType
          || source instanceof UnknownType) {
        return true;
      }
      return false;
    } else if (target instanceof ObjectReferenceType || target instanceof GenericObjectReferenceType) {
      if (source instanceof ObjectReferenceType
          || source instanceof GenericObjectReferenceType
          || source instanceof VoidType
          || source instanceof AnyType
          || source instanceof UnknownType) {
        return true;
      }
      return false;
    } else if (target instanceof DataReference) {
      if (source instanceof DataReference
          || source instanceof VoidType
          || source instanceof AnyType
          || source instanceof UnknownType) {
        return true;
      }
      return false;
    } else if (target instanceof StructureType) {
      if (source instanceof TableType && source.isWithHeader()) {
        return this.isAssignable(source.getRowType(), target);
      } else if (source instanceof StructureType
          || source instanceof VoidType
          || source instanceof AnyType
          || source instanceof UnknownType) {
        return true;
      } else if (this.isCharLike(target)
          && (this.isCharLike(source) || source instanceof IntegerType)) {
        return true;
      }
      return false;
    } else if (target instanceof IntegerType) {
      if (source instanceof DataReference
          || source instanceof ObjectReferenceType
          || source instanceof GenericObjectReferenceType
          || source instanceof TableType) {
        return false;
      }
      return true;
    }
 
    return true;
  }
}