All files / src/abap/types _typed_identifier.ts

93.33% Statements 70/75
85.71% Branches 6/7
83.33% Functions 5/6
93.33% Lines 70/75

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 761x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x     1x 1x 10125x 10125x 10125x 10125x   10125x 10125x 10125x 10125x 10125x 10125x 10125x 2338x 2338x 10125x 1x 1x 72x 72x 1x 1x 22653x 22653x 1x 1x 2167x 2167x 1x 1x 672x 672x 1x 1x  
import {AbstractToken} from "../1_lexer/tokens/abstract_token";
import {Identifier} from "../4_file_information/_identifier";
import {AbstractType} from "./basic/_abstract_type";
 
export const enum IdentifierMeta {
  MethodImporting = "importing",
  MethodExporting = "exporting",
  MethodChanging = "changing",
  MethodReturning = "returning",
  FunctionModuleImporting = "function_module_importing",
  FunctionModuleExporting = "function_module_exporting",
  FunctionModuleChanging = "function_module_changing",
  FunctionModuleTables = "function_module_tables",
  EventParameter = "event_parameter",
  FormParameter = "form_parameter",
  FormParameterStructure = "form_parameter_structure",
  ReadOnly = "read_only",
  Tables = "tables",
  Abstract = "abstract",
  PassByValue = "pass_by_value",
  InlineDefinition = "inline",
  BuiltIn = "built-in",
  DDIC = "ddic",
  Static = "static",
  Enum = "enum",
  SelectionScreenTab = "selection_screen_tab",
// todo, MethodPreferred
// todo, Optional
}
 
export class TypedIdentifier extends Identifier {
  private readonly type: AbstractType;
  private readonly meta: readonly IdentifierMeta[];
  private readonly value: string | {[index: string]: string} | undefined;
  public [Symbol.for("debug.description")](){
    return `${this.constructor.name} ${this.getName()}:${this.getType().constructor.name}`;
  }
  public static from(id: Identifier, type: TypedIdentifier | AbstractType, meta?: readonly IdentifierMeta[]): TypedIdentifier {
    return new TypedIdentifier(id.getToken(), id.getFilename(), type, meta);
  }
 
  public constructor(token: AbstractToken, filename: string, type: TypedIdentifier | AbstractType,
                     meta?: readonly IdentifierMeta[], value?: string | {[index: string]: string}) {
    super(token, filename);
 
    if (type instanceof TypedIdentifier) {
      this.type = type.getType();
    } else {
      this.type = type;
    }
 
    this.value = value;
    this.meta = [];
    if (meta) {
      this.meta = meta;
    }
  }
 
  public toText(): string {
    return "Identifier: ```" + this.getName() + "```";
  }
 
  public getType(): AbstractType {
    return this.type;
  }
 
  public getMeta(): readonly IdentifierMeta[] {
    return this.meta;
  }
 
  public getValue() {
    return this.value;
  }
 
}