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

86.36% Statements 19/22
50% Branches 4/8
100% Functions 1/1
86.36% Lines 19/22

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    1x 1x 1x   1x 1x 1x   1x   8x   8x 8x       8x 8x 8x   8x 8x     8x       8x 8x 8x    
import {ExpressionNode, StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {TypedIdentifier, IdentifierMeta} from "../../types/_typed_identifier";
import {Source} from "./source";
import * as Expressions from "../../2_statements/expressions";
import {AbstractType} from "../../types/basic/_abstract_type";
import {BasicTypes} from "../basic_types";
import {UnknownType} from "../../types/basic/unknown_type";
import {ReferenceType} from "../_reference";
 
export class InlineFieldDefinition {
  public runSyntax(node: ExpressionNode | StatementNode, scope: CurrentScope, filename: string): void {
    let type: AbstractType | TypedIdentifier | undefined = undefined;
 
    const field = node.findDirectExpression(Expressions.Field);
    Iif (field === undefined) {
      return;
    }
 
    const source = node.findDirectExpression(Expressions.Source);
    Eif (source) {
      type = new Source().runSyntax(source, scope, filename);
    }
    const typeName = node.findDirectExpression(Expressions.TypeName);
    Iif (typeName) {
      type = new BasicTypes(filename, scope).parseType(typeName);
    }
    Iif (type === undefined) {
      type = new UnknownType("InlineFieldDefinition, fallback");
    }
 
    const identifier = new TypedIdentifier(field.getFirstToken(), filename, type, [IdentifierMeta.InlineDefinition]);
    scope.addReference(field.getFirstToken(), identifier, ReferenceType.DataWriteReference, filename);
    scope.addIdentifier(identifier);
  }
}