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

100% Statements 33/33
100% Branches 5/5
100% Functions 1/1
100% Lines 33/33

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 331x 1x 1x 1x 1x 1x 1x 1x 1822x 1822x 1822x 1822x 1822x 1822x 158x 158x 158x 158x 158x 158x 1664x 1664x 1664x 1664x 1822x 4x 4x 4x 4x 4x 1664x 1664x 1x
import {ExpressionNode} from "../../nodes";
import {VoidType} from "../../types/basic";
import {AbstractType} from "../../types/basic/_abstract_type";
import {ReferenceType} from "../_reference";
import {CheckSyntaxKey, SyntaxInput, syntaxIssue} from "../_syntax_input";
 
export class SourceField {
  public runSyntax(node: ExpressionNode, input: SyntaxInput, type?: ReferenceType | ReferenceType[],
                   error = true): AbstractType | undefined {
    const token = node.getFirstToken();
    const name = token.getStr();
 
    const found = input.scope.findVariable(name);
    if (found === undefined) {
      const message = "\"" + name + "\" not found, findTop";
      if (error === true) {
        input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
      }
      return new VoidType(CheckSyntaxKey);
    }
 
    if (type) {
      input.scope.addReference(token, found, type, input.filename);
    }
    if (name.includes("~")) {
      const idef = input.scope.findInterfaceDefinition(name.split("~")[0]);
      if (idef) {
        input.scope.addReference(token, idef, ReferenceType.ObjectOrientedReference, input.filename);
      }
    }
    return found.getType();
  }
}