All files / src/abap/4_file_information _identifier.ts

100% Statements 45/45
100% Branches 9/9
100% Functions 7/7
100% Lines 45/45

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 451x 1x 1x 1x 1x 1x 1x 1x 494756x 494756x 494756x 1x 1x 1677306x 1677306x 1677306x 1677306x 129x 129x 1677306x 1677306x 1677306x 1x 1x 7045x 7045x 7045x 7045x 1x 1x 169848x 169848x 1x 1x 116616x 116616x 1x 1x 115683x 115683x 1x 1x 1738x 1738x 1x
import {Position} from "../../position";
import {AbstractToken} from "../1_lexer/tokens/abstract_token";
 
export class Identifier {
  private readonly token: AbstractToken;
  protected readonly filename: string;
 
  public constructor(token: AbstractToken, filename: string) {
    this.token = token;
    this.filename = filename;
  }
 
  public getName() {
    let name = this.token.getStr();
 
    // todo, should this be handled in the parser instead?
    if (name.startsWith("!")) {
      name = name.substring(1);
    }
 
    return name;
  }
 
  public equals(id: Identifier): boolean {
    // note how the boolean condition is evalulated lazily
    return id.getStart().equals(this.getStart())
      && id.getFilename() === this.getFilename();
  }
 
  public getToken(): AbstractToken {
    return this.token;
  }
 
  public getFilename(): string {
    return this.filename;
  }
 
  public getStart(): Position {
    return this.token.getStart();
  }
 
  public getEnd(): Position {
    return this.token.getEnd();
  }
}