All files / src/abap/types aliases.ts

100% Statements 31/31
90% Branches 9/10
100% Functions 4/4
100% Lines 31/31

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  1x 1x 1x 1x 1x     1x   1x         840x 840x 840x       436x           840x 840x 699x 699x 699x     840x 840x 141x         2238x 1638x     600x 600x 15x 15x 15x   15x   15x 15x 15x 10x            
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));
 
      Eif (compName.includes("~")) {
        const idef = scope.findInterfaceDefinition(compName.split("~")[0]);
        if (idef) {
          scope.addReference(compToken, idef, ReferenceType.ObjectOrientedReference, filename);
        }
      }
    }
  }
 
}