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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | 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 20829x 20829x 20829x 20829x 20829x 20829x 20829x 20829x 20829x 20829x 32x 32x 32x 32x 11x 11x 11x 11x 11x 32x 20829x 20829x 20829x 20829x 26x 26x 26x 26x 20829x 20829x 20829x 6x 6x 20829x 20829x 20829x 20829x 1889x 1889x 20829x 20829x 20829x 20829x 27x 27x 27x 27x 27x 9x 27x 17x 18x 1x 1x 27x 20829x 20829x 20829x 12x 12x 12x 12x 20829x 20829x 20829x 20829x 1x 1x 1x 1x 20829x 20829x 20829x 20829x 20829x 20829x 20825x 20825x 4x 20829x 20829x 4x 4x 4x 4x 1x 1x 34107x 34107x 1x 1x 1x 1x 42968x 42968x 1x 1x 1x 1x 21546x 21546x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25761x 25761x 1x 1x 90x 90x 1x 1x 1x 1x 1x 1x | import {StatementNode} from "../nodes";
import {MethodDef} from "../2_statements/statements";
import * as Expressions from "../2_statements/expressions";
import {MethodParameters} from "./method_parameters";
import {Visibility} from "../4_file_information/visibility";
import {Identifier} from "../4_file_information/_identifier";
import {IMethodDefinition} from "./_method_definition";
import {ReferenceType} from "../5_syntax/_reference";
import {SyntaxInput, syntaxIssue} from "../5_syntax/_syntax_input";
export class MethodDefinition extends Identifier implements IMethodDefinition {
private readonly visibility: Visibility;
private readonly parameters: MethodParameters;
private readonly redefinition: boolean;
private readonly eventHandler: boolean;
private readonly eventName: string | undefined;
private readonly eventClass: string | undefined;
private readonly abstract: boolean;
private readonly static: boolean;
private readonly raising: string[];
private readonly exceptions: string[];
private readonly className: string;
// todo: final flag
public constructor(node: StatementNode, visibility: Visibility, input: SyntaxInput) {
if (!(node.get() instanceof MethodDef)) {
throw new Error("MethodDefinition, expected MethodDef as part of input node");
}
const found = node.findDirectExpression(Expressions.MethodName);
if (found === undefined) {
throw new Error("MethodDefinition, expected MethodDef as part of input node");
}
super(found.getFirstToken(), input.filename);
this.className = input.scope.getName();
this.redefinition = false;
if (node.findDirectExpression(Expressions.Redefinition)) {
this.redefinition = true;
const name = found.getFirstToken().getStr();
if (name.includes("~")) {
const idef = input.scope.findInterfaceDefinition(name.split("~")[0]);
if (idef) {
input.scope.addReference(found.getFirstToken(), idef, ReferenceType.ObjectOrientedReference, input.filename);
}
}
}
this.eventHandler = false;
const handler = node.findDirectExpression(Expressions.EventHandler);
if (handler) {
this.eventHandler = true;
this.eventName = handler.findDirectExpression(Expressions.EventName)?.concatTokens().toUpperCase();
this.eventClass = handler.findDirectExpression(Expressions.ClassName)?.concatTokens().toUpperCase();
}
this.abstract = false;
if (node.findDirectExpression(Expressions.Abstract)) {
this.abstract = true;
}
this.static = false;
// checks for "CLASS-METHODS"
if (node.getFirstToken().getStr().toUpperCase().startsWith("CLASS")) {
this.static = true;
}
this.raising = [];
this.checkRaisingParameter(node, input);
for (const r of node.findDirectExpression(Expressions.MethodDefRaising)?.findAllExpressions(Expressions.ClassName) || []) {
const token = r.getFirstToken();
const name = token.getStr();
this.raising.push(name);
const clas = input.scope.findClassDefinition(name);
if (clas) {
input.scope.addReference(token, clas, ReferenceType.ObjectOrientedReference, input.filename, {ooName: name.toUpperCase(), ooType: "CLAS"});
} else if (input.scope.getDDIC().inErrorNamespace(name) === false) {
input.scope.addReference(token, clas, ReferenceType.ObjectOrientedVoidReference, input.filename, {ooName: name.toUpperCase(), ooType: "CLAS"});
} else {
input.scope.addReference(token, clas, ReferenceType.ObjectOrientedUnknownReference, input.filename, {ooName: name.toUpperCase(), ooType: "CLAS"});
}
}
this.exceptions = [];
for (const r of node.findDirectExpression(Expressions.MethodDefExceptions)?.findAllExpressions(Expressions.NamespaceSimpleName) || []) {
const token = r.getFirstToken();
const name = token.getStr();
this.exceptions.push(name);
}
this.visibility = visibility;
this.parameters = new MethodParameters(node, input, this.abstract);
}
// A system reads a parameter named RAISING as the RAISING addition, measured on 758:
// "IMPORTING a TYPE i raising TYPE i" fails with 'Type "TYPE" is unknown'
private checkRaisingParameter(node: StatementNode, input: SyntaxInput): void {
const raising = node.findDirectExpression(Expressions.MethodDefRaising);
const first = raising?.getChildren()[1];
if (raising === undefined
|| first === undefined
|| !(first.get() instanceof Expressions.ClassName)
|| ["TYPE", "LIKE"].includes(first.getFirstToken().getStr().toUpperCase()) === false) {
return;
}
if (node.findDirectExpression(Expressions.MethodDefImporting) === undefined
&& node.findDirectExpression(Expressions.MethodDefExporting) === undefined
&& node.findDirectExpression(Expressions.MethodDefChanging) === undefined) {
return;
}
const token = raising.getFirstToken();
const message = "Parameter \"" + token.getStr() + "\" is read as the RAISING addition, rename it or escape it as !" + token.getStr();
input.issues.push(syntaxIssue(input, token, message));
}
public getVisibility(): Visibility {
return this.visibility;
}
public getClassName(): string {
return this.className;
}
public isRedefinition(): boolean {
return this.redefinition;
}
public isAbstract(): boolean {
return this.abstract;
}
public isStatic(): boolean {
return this.static;
}
public isEventHandler(): boolean {
return this.eventHandler;
}
public getEventName(): string | undefined {
return this.eventName;
}
public getEventClass(): string | undefined {
return this.eventClass;
}
public getParameters(): MethodParameters {
return this.parameters;
}
public getRaising(): readonly string[] {
return this.raising;
}
public getExceptions(): readonly string[] {
return this.exceptions;
}
} |