All files / src/abap/types interface_definition.ts

94% Statements 47/50
75% Branches 12/16
81.82% Functions 9/11
94% Lines 47/50

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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 1171x   1x 1x 1x         1x 1x 1x   1x   1x   1x 1x   1x                   146x       146x 146x 146x   146x 146x 146x   146x 146x 141x       8x       126x       12x       4x       350x       153x                       112x           146x 142x   142x   142x 142x 5x     142x 19x 19x 19x 19x   19x 19x 14x 5x 4x   1x         141x      
import {Identifier} from "../4_file_information/_identifier";
import {StructureNode} from "../nodes";
import * as Structures from "../3_structures/structures";
import * as Statements from "../2_statements/statements";
import * as Expressions from "../2_statements/expressions";
import {CurrentScope} from "../5_syntax/_current_scope";
import {IInterfaceDefinition, IImplementing} from "./_interface_definition";
import {IAttributes} from "./_class_attributes";
import {ITypeDefinitions} from "./_type_definitions";
import {Attributes} from "./class_attributes";
import {Visibility} from "../4_file_information/visibility";
import {ScopeType} from "../5_syntax/_scope_type";
import {IEventDefinition} from "./_event_definition";
import {EventDefinition} from "./event_definition";
import {IMethodDefinitions} from "./_method_definitions";
import {MethodDefinitions} from "./method_definitions";
import {IAliases} from "./_aliases";
import {Aliases} from "./aliases";
import {ReferenceType} from "../5_syntax/_reference";
 
export class InterfaceDefinition extends Identifier implements IInterfaceDefinition {
  private readonly node: StructureNode;
  private attributes: IAttributes;
  private readonly implementing: IImplementing[];
  private typeDefinitions: ITypeDefinitions;
  private methodDefinitions: IMethodDefinitions;
  private readonly events: IEventDefinition[];
  private aliases: IAliases;
 
  public constructor(node: StructureNode, filename: string, scope: CurrentScope) {
    Iif (!(node.get() instanceof Structures.Interface)) {
      throw new Error("InterfaceDefinition, unexpected node type");
    }
 
    const name = node.findFirstStatement(Statements.Interface)!.findFirstExpression(Expressions.InterfaceName)!.getFirstToken();
    super(name, filename);
    scope.addInterfaceDefinition(this);
 
    this.node = node;
    this.events = [];
    this.implementing = [];
 
    scope.push(ScopeType.Interface, name.getStr(), node.getFirstToken().getStart(), filename);
    this.parse(scope);
    scope.pop(node.getLastToken().getEnd());
  }
 
  public getSuperClass(): undefined {
    return undefined;
  }
 
  public getImplementing(): readonly IImplementing[] {
    return this.implementing;
  }
 
  public getAliases(): IAliases {
    return this.aliases;
  }
 
  public getEvents() {
    return this.events;
  }
 
  public getAttributes() {
    return this.attributes;
  }
 
  public getTypeDefinitions() {
    return this.typeDefinitions;
  }
 
  public isLocal(): boolean {
    return !this.isGlobal();
  }
 
  public isGlobal(): boolean {
    return this.node.findFirstExpression(Expressions.ClassGlobal) !== undefined;
  }
 
  public getMethodDefinitions(): IMethodDefinitions {
    return this.methodDefinitions;
  }
 
/////////////////
 
  private parse(scope: CurrentScope) {
    this.attributes = new Attributes(this.node, this.filename, scope);
    this.typeDefinitions = this.attributes.getTypes();
 
    this.methodDefinitions = new MethodDefinitions(this.node, this.filename, scope);
 
    const events = this.node.findAllStatements(Statements.Events);
    for (const e of events) {
      this.events.push(new EventDefinition(e, Visibility.Public, this.filename, scope));
    }
 
    for (const i of this.node.findAllStatements(Statements.InterfaceDef)) {
      const token = i.findDirectExpression(Expressions.InterfaceName)?.getFirstToken();
      const name = token?.getStr();
      Eif (name) {
        this.implementing.push({name, partial: false});
 
        const idef = scope.findInterfaceDefinition(name);
        if (idef) {
          scope.addReference(token, idef, ReferenceType.ObjectOrientedReference, this.filename);
        } else if (scope.getDDIC().inErrorNamespace(name) === false) {
          scope.addReference(token, undefined, ReferenceType.ObjectOrientedVoidReference, this.filename);
        } else {
          throw new Error("Interface " + name + " unknown");
        }
      }
    }
 
    this.aliases = new Aliases(this.node, this.filename, scope);
  }
 
}