From a02cb14002e5a2a66e7c1aa66d10d8462737dc22 Mon Sep 17 00:00:00 2001 From: GideonKoenig Date: Fri, 8 Jul 2022 15:48:17 +0200 Subject: [PATCH 1/4] feat: added addUnusedParametes function --- .../features/usages/model/UsageCountStore.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api-editor/gui/src/features/usages/model/UsageCountStore.ts b/api-editor/gui/src/features/usages/model/UsageCountStore.ts index bc2e58f88..d2ab2f831 100644 --- a/api-editor/gui/src/features/usages/model/UsageCountStore.ts +++ b/api-editor/gui/src/features/usages/model/UsageCountStore.ts @@ -61,6 +61,7 @@ export class UsageCountStore { api?: PythonPackage, ) { if (api) { + this.addUnusedParameters(api); this.addImplicitUsagesOfDefaultValues(api); this.computeModuleUsages(api); } @@ -122,6 +123,25 @@ export class UsageCountStore { }; } + /** + * Adds the implicit usages of a parameters default value. When a function is called and a parameter is used with + * its default value, that usage of a value is not part of the UsageStore, so we need to add it. + * + * @param api Description of the API + * @private + */ + private addUnusedParameters(api: PythonPackage) { + for (const parameter of api.getParameters()) { + + const parameterUsage = this.parameterUsages.get(parameter.id); + if (parameterUsage) { + continue; + } + + this.parameterUsages.set(parameter.id, 0) + } + } + /** * Adds the implicit usages of a parameters default value. When a function is called and a parameter is used with * its default value, that usage of a value is not part of the UsageStore, so we need to add it. From f1ed71b6b18e37cfc4bb3d82851c0ab36fe8fbab Mon Sep 17 00:00:00 2001 From: GideonKoenig Date: Fri, 8 Jul 2022 13:55:23 +0000 Subject: [PATCH 2/4] style: apply automatic fixes of linters --- api-editor/gui/src/features/usages/model/UsageCountStore.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api-editor/gui/src/features/usages/model/UsageCountStore.ts b/api-editor/gui/src/features/usages/model/UsageCountStore.ts index d2ab2f831..58fc3573d 100644 --- a/api-editor/gui/src/features/usages/model/UsageCountStore.ts +++ b/api-editor/gui/src/features/usages/model/UsageCountStore.ts @@ -132,13 +132,12 @@ export class UsageCountStore { */ private addUnusedParameters(api: PythonPackage) { for (const parameter of api.getParameters()) { - - const parameterUsage = this.parameterUsages.get(parameter.id); + const parameterUsage = this.parameterUsages.get(parameter.id); if (parameterUsage) { continue; } - this.parameterUsages.set(parameter.id, 0) + this.parameterUsages.set(parameter.id, 0); } } From f695acd16ff9d7cde2c7d029856dea29ff36c7ff Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 8 Jul 2022 20:17:36 +0200 Subject: [PATCH 3/4] refactor(gui): loop over parameters in API instead of parameters in usage store --- .../features/usages/model/UsageCountStore.ts | 42 ++++--------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/api-editor/gui/src/features/usages/model/UsageCountStore.ts b/api-editor/gui/src/features/usages/model/UsageCountStore.ts index 58fc3573d..ce7ffe7f5 100644 --- a/api-editor/gui/src/features/usages/model/UsageCountStore.ts +++ b/api-editor/gui/src/features/usages/model/UsageCountStore.ts @@ -61,7 +61,6 @@ export class UsageCountStore { api?: PythonPackage, ) { if (api) { - this.addUnusedParameters(api); this.addImplicitUsagesOfDefaultValues(api); this.computeModuleUsages(api); } @@ -128,33 +127,9 @@ export class UsageCountStore { * its default value, that usage of a value is not part of the UsageStore, so we need to add it. * * @param api Description of the API - * @private - */ - private addUnusedParameters(api: PythonPackage) { - for (const parameter of api.getParameters()) { - const parameterUsage = this.parameterUsages.get(parameter.id); - if (parameterUsage) { - continue; - } - - this.parameterUsages.set(parameter.id, 0); - } - } - - /** - * Adds the implicit usages of a parameters default value. When a function is called and a parameter is used with - * its default value, that usage of a value is not part of the UsageStore, so we need to add it. - * - * @param api Description of the API - * @private */ private addImplicitUsagesOfDefaultValues(api: PythonPackage) { - for (const [parameterId, parameterUsageCount] of this.parameterUsages.entries()) { - const parameter = api.getDeclarationById(parameterId); - if (!(parameter instanceof PythonParameter)) { - continue; - } - + for (const parameter of api.getParameters()) { const defaultValue = parameter.defaultValue; if (defaultValue === undefined || defaultValue === null) { // defaultValue could be an empty string @@ -166,21 +141,22 @@ export class UsageCountStore { continue; } - const functionUsageCount = this.functionUsages.get(containingFunction.id) ?? 0; + const parameterUsageCount = this.getUsageCount(parameter); + const functionUsageCount = this.getUsageCount(containingFunction); const nImplicitUsages = functionUsageCount - parameterUsageCount; if (nImplicitUsages === 0) { continue; } - const nExplicitUsage = this.valueUsages.get(parameterId)?.get(defaultValue) ?? 0; + const nExplicitUsages = this.valueUsages.get(parameter.id)?.get(defaultValue) ?? 0; - if (!this.valueUsages.has(parameterId)) { - this.valueUsages.set(parameterId, new Map()); + if (!this.valueUsages.has(parameter.id)) { + this.valueUsages.set(parameter.id, new Map()); } - if (!this.valueUsages.get(parameterId)!.has(defaultValue)) { - this.valueUsages.get(parameterId)!.set(defaultValue, 0); + if (!this.valueUsages.get(parameter.id)!.has(defaultValue)) { + this.valueUsages.get(parameter.id)!.set(defaultValue, 0); } - this.valueUsages.get(parameterId)!.set(defaultValue, nImplicitUsages + nExplicitUsage); + this.valueUsages.get(parameter.id)!.set(defaultValue, nImplicitUsages + nExplicitUsages); } } From b6b43f9cd764aa81e981ca28b65f82376403c57b Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 8 Jul 2022 20:20:28 +0200 Subject: [PATCH 4/4] refactor(gui): remove useless code --- api-editor/gui/src/features/usages/model/UsageCountStore.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/api-editor/gui/src/features/usages/model/UsageCountStore.ts b/api-editor/gui/src/features/usages/model/UsageCountStore.ts index ce7ffe7f5..cef7ddab5 100644 --- a/api-editor/gui/src/features/usages/model/UsageCountStore.ts +++ b/api-editor/gui/src/features/usages/model/UsageCountStore.ts @@ -153,9 +153,6 @@ export class UsageCountStore { if (!this.valueUsages.has(parameter.id)) { this.valueUsages.set(parameter.id, new Map()); } - if (!this.valueUsages.get(parameter.id)!.has(defaultValue)) { - this.valueUsages.get(parameter.id)!.set(defaultValue, 0); - } this.valueUsages.get(parameter.id)!.set(defaultValue, nImplicitUsages + nExplicitUsages); } }