All files / src/abap/types aliases.ts

100% Statements 64/64
100% Branches 11/11
100% Functions 4/4
100% Lines 64/64

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 641x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1087x 1087x 1087x 1087x 1x 1x 1780x 1780x 1x 1x 1x 1x 1087x 1087x 871x 871x 871x 871x 1087x 1087x 1087x 216x 216x 1087x 1x 1x 2829x 2004x 2004x 825x 825x 2829x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 14x 14x 19x 19x 825x 1x 1x
import {StructureNode} from "../nodes";
import {Alias} from "./alias";
import * as Structures from "../3_structures/structures";
import * as Statements from "../2_statements/statements";
import * as Expressions from "../2_statements/expressions";
import {Visibility} from "../4_file_information/visibility";
import {IAliases} from "./_aliases";
import {CurrentScope} from "../5_syntax/_current_scope";
import {ReferenceType} from "../5_syntax/_reference";
 
export class Aliases implements IAliases {
  private readonly aliases: Alias[];
  private readonly filename: string;
 
  public constructor(node: StructureNode, filename: string, scope: CurrentScope) {
    this.aliases = [];
    this.filename = filename;
    this.parse(node, scope, filename);
  }
 
  public getAll(): readonly Alias[] {
    return this.aliases;
  }
 
/////////////////////////
 
  private parse(node: StructureNode, scope: CurrentScope, filename: string): void {
    const cdef = node.findFirstStructure(Structures.ClassDefinition);
    if (cdef) {
      this.parseSection(cdef.findFirstStructure(Structures.PublicSection), Visibility.Public, scope, filename);
      this.parseSection(cdef.findFirstStructure(Structures.PrivateSection), Visibility.Private, scope, filename);
      this.parseSection(cdef.findFirstStructure(Structures.ProtectedSection), Visibility.Protected, scope, filename);
    }
 
    const idef = node.findFirstStructure(Structures.Interface);
    if (idef) {
      this.parseSection(idef, Visibility.Public, scope, filename);
    }
  }
 
  private parseSection(node: StructureNode | undefined, visibility: Visibility, scope: CurrentScope, filename: string): void {
    if (!node) {
      return;
    }
 
    const list = node.findAllStatements(Statements.Aliases);
    for (const a of list) {
      const name = a.findFirstExpression(Expressions.SimpleName)!.getFirstToken();
      const compToken = a.findFirstExpression(Expressions.Field)!.getFirstToken();
      const compName = compToken.getStr();
 
      this.aliases.push(new Alias(name, visibility, compName, this.filename));
 
      if (compName.includes("~")) {
        const name = compName.split("~")[0];
        const idef = scope.findInterfaceDefinition(name);
        if (idef) {
          scope.addReference(compToken, idef, ReferenceType.ObjectOrientedReference, filename, {ooName: name.toUpperCase(), ooType: "INTF"});
        }
      }
    }
  }
 
}