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

92.3% Statements 48/52
88.23% Branches 15/17
100% Functions 2/2
92.3% Lines 48/52

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 521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 24x 24x 24x 16x 16x 8x 8x 8x 8x 1x 1x 131x     131x 131x 131x 115x 115x 131x 131x 72x 72x 131x     59x 59x 59x 325x 67x 325x 67x 67x 325x 59x 131x 1x
import {ExpressionNode} from "../../nodes";
import * as Expressions from "../../2_statements/expressions";
import {Source} from "./source";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {AbstractType} from "../../..";
import {TableType} from "../../types/basic";
import {ComponentChain} from "./component_chain";
import {AbstractToken} from "../../1_lexer/tokens/abstract_token";
import {LanguageVersion, Release, releaseAtLeast} from "../../../version";
 
export class TableExpression {
  /** below v750 the object component selector "->" cannot follow a table expression, eg. "itab[ 1 ]-ref->meth( )",
   *  returns true and adds an issue if not allowed */
  public static checkArrowAfter(input: SyntaxInput, arrow: AbstractToken): boolean {
    if (releaseAtLeast(input.scope.getRelease(), Release.v750)
        || input.scope.getLanguageVersion() === LanguageVersion.Cloud
        || input.scope.getOpenABAP()) {
      return false;
    }
    const message = "Object component selector \"->\" after table expression not possible below v750";
    input.issues.push(syntaxIssue(input, arrow, message));
    return true;
  }
 
  public static runSyntax(node: ExpressionNode | undefined, input: SyntaxInput, rowType: AbstractType | undefined) {
    if (node === undefined) {
      return;
    }
 
    let context = rowType;
    if (context instanceof TableType) {
      context = context.getRowType();
    }
 
    if (node.getChildren().length === 3) {
      const s = node.findDirectExpression(Expressions.Source);
      Source.runSyntax(s, input, context);
    } else if (node.findDirectTokenByText("INDEX")) {
      const s = node.findDirectExpression(Expressions.Source);
      Source.runSyntax(s, input);
    } else {
      let fieldType: AbstractType | undefined = undefined;
      for (const c of node.getChildren()) {
        if (c instanceof ExpressionNode && c.get() instanceof Expressions.ComponentChainSimple) {
          fieldType = ComponentChain.runSyntax(context, c, input);
        } else if (c instanceof ExpressionNode && c.get() instanceof Expressions.Source) {
          Source.runSyntax(c, input, fieldType);
        }
      }
    }
  }
}