Skip to content

Commit

Permalink
tsconfig option strictPropertyInitialization on meta/scoper
Browse files Browse the repository at this point in the history
  • Loading branch information
annekekleppe committed Jun 27, 2024
1 parent 8437d1c commit a262553
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 67 deletions.
4 changes: 2 additions & 2 deletions packages/meta/src/commandline/FreonGenerateAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandLineAction, CommandLineStringParameter, ICommandLineActionOptions } from "@rushstack/ts-command-line";
import { GenerationStatus, FileUtil } from "../utils";
import {GenerationStatus, FileUtil, LOG2USER} from "../utils";

/**
* Generic generator action. The only option defined here is the -o flag for the output folder.
Expand Down Expand Up @@ -74,7 +74,7 @@ export abstract class FreonGenerateAction extends CommandLineAction {
} else if (filename.endsWith("id.json")) {
this.idFile = filename;
} else {
console.log("WARNING: unrecognized file: " + filename)
LOG2USER.warning("WARNING: unrecognized file: " + filename);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export class FreLangExpressionChecker extends Checker<LanguageExpressionTester>
LOGGER.log("checkLangExp " + langExp.toFreString() );
if (langExp instanceof FreInstanceExp) {
this.checkInstanceExpression(langExp);
} else
if (langExp instanceof FreLangSelfExp) {
} else if (langExp instanceof FreLangSelfExp) {
this.checkSelfExpression(langExp, enclosingConcept);
} else if (langExp instanceof FreLangConceptExp) {
this.checkConceptExpression(langExp, enclosingConcept);
Expand Down
9 changes: 4 additions & 5 deletions packages/meta/src/scoperdef/generator/ScoperGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { ScopeDef } from "../metalanguage";
import { CustomScoperTemplate } from "./templates/CustomScoperTemplate";
import { ScoperDefTemplate } from "./templates/ScoperDefTemplate";
import { ScoperTemplate } from "./templates/ScoperTemplate";
import { MetaElementReference } from "../../languagedef/metalanguage";
import { FreMetaModelDescription } from "../../languagedef/metalanguage/FreMetaLanguage";
import { MetaElementReference, FreMetaModelDescription } from "../../languagedef/metalanguage";

const LOGGER = new MetaLogger("ScoperGenerator").mute();
const LOGGER: MetaLogger = new MetaLogger("ScoperGenerator").mute();
export class ScoperGenerator {
public outputfolder: string = ".";
public language: FreMetaLanguage;
public language: FreMetaLanguage | undefined;
protected scoperGenFolder: string = '';
protected scoperFolder: string = '';

generate(scopedef: ScopeDef | undefined): void {
if (this.language === null) {
if (this.language === null || this.language === undefined) {
LOGGER.error("Cannot generate scoper because language is not set.");
return;
}
Expand Down
41 changes: 23 additions & 18 deletions packages/meta/src/scoperdef/generator/templates/ScoperTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,19 @@ export class ScoperTemplate {
private makeAdditionalNamespaceTexts(scopedef: ScopeDef, coreImports: string[]) {
for (const def of scopedef.scopeConceptDefs) {
if (!!def.namespaceAdditions) {
const myClassifier = def.conceptRef.referred;
// let isDone: boolean = false;
const comment = "// based on namespace addition for " + myClassifier.name + "\n";
ListUtil.addIfNotPresent(this.languageImports, Names.classifier(myClassifier));
if (myClassifier instanceof FreMetaInterface) {
for (const implementor of LangUtil.findImplementorsRecursive(myClassifier)) {
this.makeAdditionalNamespaceTextsForConcept(implementor, def, comment, coreImports);
ListUtil.addIfNotPresent(this.languageImports, Names.concept(implementor));
}
} else {
this.makeAdditionalNamespaceTextsForConcept(myClassifier, def, comment, coreImports);
const myClassifier: FreMetaConcept | undefined = def.conceptRef?.referred;
if (!!myClassifier) {
const comment = "// based on namespace addition for " + myClassifier.name + "\n";
ListUtil.addIfNotPresent(this.languageImports, Names.classifier(myClassifier));
if (myClassifier instanceof FreMetaInterface) {
for (const implementor of LangUtil.findImplementorsRecursive(myClassifier)) {
this.makeAdditionalNamespaceTextsForConcept(implementor, def, comment, coreImports);
ListUtil.addIfNotPresent(this.languageImports, Names.concept(implementor));
}
} else {
this.makeAdditionalNamespaceTextsForConcept(myClassifier, def, comment, coreImports);
ListUtil.addIfNotPresent(this.languageImports, Names.classifier(myClassifier));
}
}
}
}
Expand All @@ -130,18 +131,20 @@ export class ScoperTemplate {
this.getAdditionalNamespacetext = this.getAdditionalNamespacetext.concat(comment);
this.getAdditionalNamespacetext = this.getAdditionalNamespacetext.concat(
`if (element instanceof ${typeName}) {`);
for (const expression of def.namespaceAdditions.expressions) {
this.getAdditionalNamespacetext = this.getAdditionalNamespacetext.concat(this.addNamespaceExpression(expression, coreImports));
if (!!def.namespaceAdditions) {
for (const expression of def.namespaceAdditions.expressions) {
this.getAdditionalNamespacetext = this.getAdditionalNamespacetext.concat(this.addNamespaceExpression(expression, coreImports));
}
}
this.getAdditionalNamespacetext = this.getAdditionalNamespacetext.concat(
`}\n`);
}

private makeAlternativeScopeTexts(scopedef: ScopeDef) {
for (const def of scopedef.scopeConceptDefs) {
if (!!def.alternativeScope) {
const conceptName = def.conceptRef.referred.name;
// we are adding to three textstrings
if (!!def.alternativeScope && !!def.conceptRef) {
const conceptName: string = def.conceptRef.referred.name;
// we are adding to three text strings
// first, to the import statements
ListUtil.addIfNotPresent(this.languageImports, Names.classifier(def.conceptRef.referred));
// console.log("Adding 444: " + Names.classifier(def.conceptRef.referred) + ", list: [" + this.languageImports.map(n => n).join(", ") + "]");
Expand All @@ -153,11 +156,13 @@ export class ScoperTemplate {
}`);

// third, to the 'getAlternativeScope' method
this.getAlternativeScopeText = this.getAlternativeScopeText.concat(
`if (!!modelelement && modelelement instanceof ${conceptName}) {
if (!!def.alternativeScope.expression) {
this.getAlternativeScopeText = this.getAlternativeScopeText.concat(
`if (!!modelelement && modelelement instanceof ${conceptName}) {
// use alternative scope '${def.alternativeScope.expression.toFreString()}'
${this.altScopeExpToTypeScript(def.alternativeScope.expression)}
}`);
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/meta/src/scoperdef/metalanguage/FreScopeDefLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export class ScopeDef extends FreMetaDefinitionElement {
}

export class ScopeConceptDef extends FreMetaDefinitionElement {
conceptRef: MetaElementReference<FreMetaConcept>;
namespaceAdditions: FreNamespaceAddition;
alternativeScope: FreAlternativeScope;
conceptRef: MetaElementReference<FreMetaConcept> | undefined;
namespaceAdditions: FreNamespaceAddition | undefined;
alternativeScope: FreAlternativeScope | undefined;
}

export class FreNamespaceAddition extends FreMetaDefinitionElement {
expressions: FreLangExp[];
expressions: FreLangExp[] = [];
}

export class FreAlternativeScope extends FreMetaDefinitionElement {
expression: FreLangExp;
expression: FreLangExp | undefined;
}
70 changes: 35 additions & 35 deletions packages/meta/src/scoperdef/metalanguage/ScoperChecker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FreMetaUnitDescription } from "../../languagedef/metalanguage/FreMetaLanguage";
import { CheckRunner, Checker, ParseLocationUtil } from "../../utils";
import {
FreMetaConcept,
Expand All @@ -12,15 +11,15 @@ import { LangUtil, MetaLogger } from "../../utils";
// Otherwise, the run-time error 'Cannot read property 'create' of undefined' occurs.
// See: https://stackoverflow.com/questions/48123645/error-when-accessing-static-properties-when-services-include-each-other
// and: https://stackoverflow.com/questions/45986547/property-undefined-typescript
import { MetaElementReference } from "../../languagedef/metalanguage/MetaElementReference";
import { MetaElementReference, FreMetaUnitDescription } from "../../languagedef/metalanguage";
import { FreLangExpressionChecker } from "../../languagedef/checking";
import { CommonChecker } from "../../languagedef/checking/CommonChecker";
import { CommonChecker } from "../../languagedef/checking";

const LOGGER = new MetaLogger("ScoperChecker").mute();

export class ScoperChecker extends Checker<ScopeDef> {
runner = new CheckRunner(this.errors, this.warnings);
myExpressionChecker: FreLangExpressionChecker;
runner: CheckRunner = new CheckRunner(this.errors, this.warnings);
myExpressionChecker: FreLangExpressionChecker | undefined;
myNamespaces: FreMetaClassifier[] = [];

constructor(language: FreMetaLanguage) {
Expand All @@ -39,28 +38,25 @@ export class ScoperChecker extends Checker<ScopeDef> {
}
this.runner = new CheckRunner(this.errors, this.warnings);

// this.runner.nestedCheck(
// {
// check: this.language.name === definition.languageName,
// error: `Language reference ('${definition.languageName}') in scoper definition '${definition.scoperName}' ` +
// `does not match language '${this.language.name}' ${ParseLocationUtil.location(definition)}.`
// });

// check the namespaces and find any subclasses or implementors of interfaces that are mentioned in the list of namespaces in the definition
this.myNamespaces = this.findAllNamespaces(definition.namespaces);

definition.scopeConceptDefs.forEach(def => {
CommonChecker.checkClassifierReference(def.conceptRef, this.runner);
if (!!def.conceptRef.referred) {
if (!!def.namespaceAdditions) {
this.checkNamespaceAdditions(def.namespaceAdditions, def.conceptRef.referred);
}
if (!!def.alternativeScope) {
this.checkAlternativeScope(def.alternativeScope, def.conceptRef.referred);
if (!!def.conceptRef) {
CommonChecker.checkClassifierReference(def.conceptRef, this.runner);
if (!!def.conceptRef.referred) {
if (!!def.namespaceAdditions) {
this.checkNamespaceAdditions(def.namespaceAdditions, def.conceptRef.referred);
}
if (!!def.alternativeScope) {
this.checkAlternativeScope(def.alternativeScope, def.conceptRef.referred);
}
}
}
});
this.errors = this.errors.concat(this.myExpressionChecker.errors);
if (!!this.myExpressionChecker) {
this.errors = this.errors.concat(this.myExpressionChecker.errors);
}
}

private checkNamespaceAdditions(namespaceAddition: FreNamespaceAddition, enclosingConcept: FreMetaConcept) {
Expand All @@ -69,27 +65,31 @@ export class ScoperChecker extends Checker<ScopeDef> {
check: this.myNamespaces.includes(enclosingConcept),
error: `Cannot add namespaces to concept ${enclosingConcept.name} that is not a namespace itself ${ParseLocationUtil.location(namespaceAddition)}.`,
whenOk: () => {
namespaceAddition.expressions.forEach(exp => {
this.myExpressionChecker.checkLangExp(exp, enclosingConcept);
const xx: FreMetaProperty | undefined = exp.findRefOfLastAppliedFeature();
if (!!xx) {
this.runner.nestedCheck({
check: (!!xx.type && (xx.type instanceof FreMetaConcept || xx.type instanceof FreMetaUnitDescription)),
error: `A namespace addition should refer to a concept ${ParseLocationUtil.location(exp)}.`,
whenOk: () => {
this.runner.simpleCheck(this.myNamespaces.includes(xx.type),
`A namespace addition should refer to a namespace concept ${ParseLocationUtil.location(exp)}.`);
}
});
}
});
if (!!this.myExpressionChecker) {
namespaceAddition.expressions.forEach(exp => {
this.myExpressionChecker!.checkLangExp(exp, enclosingConcept);
const xx: FreMetaProperty | undefined = exp.findRefOfLastAppliedFeature();
if (!!xx) {
this.runner.nestedCheck({
check: (!!xx.type && (xx.type instanceof FreMetaConcept || xx.type instanceof FreMetaUnitDescription)),
error: `A namespace addition should refer to a concept ${ParseLocationUtil.location(exp)}.`,
whenOk: () => {
this.runner.simpleCheck(this.myNamespaces.includes(xx.type),
`A namespace addition should refer to a namespace concept ${ParseLocationUtil.location(exp)}.`);
}
});
}
});
}
}
});
}

private checkAlternativeScope(alternativeScope: FreAlternativeScope, enclosingConcept: FreMetaConcept) {
LOGGER.log("Checking alternative scope definition for " + enclosingConcept?.name);
this.myExpressionChecker.checkLangExp(alternativeScope.expression, enclosingConcept);
if (!!this.myExpressionChecker && !!alternativeScope.expression) {
this.myExpressionChecker.checkLangExp(alternativeScope.expression, enclosingConcept);
}
}

private findAllNamespaces(namespaces: MetaElementReference<FreMetaClassifier>[]): FreMetaClassifier[] {
Expand Down

0 comments on commit a262553

Please sign in to comment.