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

76.92% Statements 20/26
50% Branches 6/12
100% Functions 1/1
76.92% Lines 20/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 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    1x 1x 1x       1x   1x               3x   3x       3x 3x 3x       3x 3x     3x 3x 3x   3x 3x     3x     3x         3x      
import {INode} from "../../nodes/_inode";
import {AbstractType} from "../../types/basic/_abstract_type";
import {VoidType} from "../../types/basic/void_type";
import {ObjectReferenceType} from "../../types/basic/object_reference_type";
import {ObjectOriented} from "../_object_oriented";
import {CurrentScope} from "../_current_scope";
import {ReferenceType} from "../_reference";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {AttributeName} from "../../2_statements/expressions";
 
export class AttributeChain {
  public runSyntax(
    inputContext: AbstractType | undefined,
    node: INode,
    scope: CurrentScope,
    filename: string,
    type?: ReferenceType | undefined): AbstractType | undefined {
 
    Iif (inputContext instanceof VoidType) {
      return inputContext;
    } else Iif (!(inputContext instanceof ObjectReferenceType)) {
      throw new Error("Not a object reference(AttributeChain)");
    }
 
    const children = node.getChildren().slice();
    const first = children[0];
    Iif (!(first.get() instanceof AttributeName)) {
      throw new Error("AttributeChain, unexpected first child");
    }
 
    const def = scope.findClassDefinition(inputContext.getIdentifierName());
    Iif (def === undefined) {
      throw new Error("Definition for \"" + inputContext.getIdentifierName() + "\" not found in scope(AttributeChain)");
    }
    const nameToken = first.getFirstToken();
    const name = nameToken.getStr();
    const helper = new ObjectOriented(scope);
 
    let context: TypedIdentifier | undefined = helper.searchAttributeName(def, name);
    Iif (context === undefined) {
      context = helper.searchConstantName(def, name);
    }
    Iif (context === undefined) {
      throw new Error("Attribute or constant \"" + name + "\" not found in \"" + def.getName() + "\"");
    }
    scope.addReference(nameToken, context, type, filename);
 
 
// todo, loop, handle ArrowOrDash, ComponentName, TableExpression
 
    return context.getType();
  }
 
}