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 923x 923x 923x 923x 1x 1x 659x 659x 1x 1x 1x 1x 923x 923x 754x 754x 754x 754x 923x 923x 923x 169x 169x 923x 1x 1x 2431x 1747x 1747x 684x 684x 2431x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 11x 11x 16x 16x 684x 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"});
        }
      }
    }
  }
 
}