All files / src/abap/5_syntax/statements class_implementation.ts

100% Statements 44/44
100% Branches 7/7
100% Functions 1/1
100% Lines 44/44

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 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 421x 421x 421x 421x 421x 421x 421x 3x 3x 418x 418x 421x 49x 49x 418x 418x 421x 96x 96x 418x 418x 418x 418x 418x 418x 418x 418x 418x 418x 418x 1x
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {ObjectOriented} from "../_object_oriented";
import {ObjectReferenceType} from "../../types/basic";
import {Identifier} from "../../1_lexer/tokens";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {Position} from "../../../position";
import {BuiltIn} from "../_builtin";
import {ScopeType} from "../_scope_type";
import {StatementSyntax} from "../_statement_syntax";
 
export class ClassImplementation implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
    const helper = new ObjectOriented(scope);
 
    const className = helper.findClassName(node);
    scope.push(ScopeType.ClassImplementation, className, node.getFirstToken().getStart(), filename);
 
    const classDefinition = scope.findClassDefinition(className);
    if (classDefinition === undefined) {
      throw new Error("Class definition for \"" + className + "\" not found");
    }
    const classAttributes = classDefinition.getAttributes();
 
    for (const t of classDefinition.getTypeDefinitions().getAll()) {
      scope.addType(t.type);
    }
 
    const sup = scope.findClassDefinition(classDefinition.getSuperClass());
    if (sup) {
      scope.addIdentifier(new TypedIdentifier(new Identifier(new Position(1, 1), "super"), BuiltIn.filename, new ObjectReferenceType(sup)));
    }
    scope.addIdentifier(new TypedIdentifier(new Identifier(new Position(1, 1), "me"), BuiltIn.filename, new ObjectReferenceType(classDefinition)));
 
    helper.addAliasedAttributes(classDefinition); // todo, this is not correct, take care of instance vs static
 
    scope.addList(classAttributes.getConstants());
    scope.addList(classAttributes.getInstance()); // todo, this is not correct, take care of instance vs static
    scope.addList(classAttributes.getStatic()); // todo, this is not correct, take care of instance vs static
 
    const implemented = helper.fromSuperClass(classDefinition);
    helper.fromInterfaces(classDefinition, implemented);
  }
}