Skip to content

Commit

Permalink
refactor: Move matches & extensions into map
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Sep 20, 2024
1 parent 76e7366 commit d7a30e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
16 changes: 15 additions & 1 deletion packages/zowe-explorer-api/src/fs/types/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ interface DsEntryProps {
stats: Types.DatasetStats;
}

export const DS_EXTENSION_MAP: Map<string, string[]> = new Map([
[".c", ["C"]],
[".jcl", ["JCL", "JCLLIB", "CNTL", "PROC", "PROCLIB"]],
[".cbl", ["COBOL", "CBL", "COB", "SCBL"]],
[".cpy", ["COPYBOOK", "COPY", "CPY", "COBCOPY"]],
[".inc", ["INC", "INCLUDE", "PLINC"]],
[".pli", ["PLI", "PL1", "PLX", "PCX"]],
[".sh", ["SH", "SHELL"]],
[".rexx", ["REXX", "REXEC", "EXEC"]],
[".xml", ["XML"]],
[".asm", ["ASM", "ASSEMBL"]],
[".log", ["LOG", "SPFLOG"]],
]);

export class DsEntry extends FileEntry implements DsEntryProps {
public metadata: DsEntryMetadata;

Expand Down Expand Up @@ -51,7 +65,7 @@ export class DsEntryMetadata implements EntryMetadata {
* @returns the data set's file system path without the extension
*/
public extensionRemovedFromPath(): string {
for (const ext of [".c", ".jcl", ".cbl", ".cpy", ".inc", ".pli", ".sh", ".rexx", ".xml", ".asm", ".log"]) {
for (const ext of DS_EXTENSION_MAP.keys()) {
if (this.path.endsWith(ext)) {
return this.path.replace(ext, "");
}
Expand Down
52 changes: 19 additions & 33 deletions packages/zowe-explorer/src/trees/dataset/DatasetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as vscode from "vscode";
import { Types } from "@zowe/zowe-explorer-api";
import { DS_EXTENSION_MAP, Types } from "@zowe/zowe-explorer-api";
import { Constants } from "../../configuration/Constants";
import { ZoweLogger } from "../../tools/ZoweLogger";

Expand Down Expand Up @@ -74,38 +74,24 @@ export class DatasetUtils {
const bracket = label.indexOf("(");
const split = bracket > -1 ? label.substring(0, bracket).split(".", limit) : label.split(".", limit);
for (let i = split.length - 1; i > 0; i--) {
if (split[i] === "C") {
return ".c";
}
if (["JCL", "JCLLIB", "CNTL", "PROC", "PROCLIB"].includes(split[i])) {
return ".jcl";
}
if (["COBOL", "CBL", "COB", "SCBL"].includes(split[i])) {
return ".cbl";
}
if (["COPYBOOK", "COPY", "CPY", "COBCOPY"].includes(split[i])) {
return ".cpy";
}
if (["INC", "INCLUDE", "PLINC"].includes(split[i])) {
return ".inc";
}
if (["PLI", "PL1", "PLX", "PCX"].includes(split[i])) {
return ".pli";
}
if (["SH", "SHELL"].includes(split[i])) {
return ".sh";
}
if (["REXX", "REXEC", "EXEC"].includes(split[i])) {
return ".rexx";
}
if (split[i] === "XML") {
return ".xml";
}
if (split[i] === "ASM" || split[i].indexOf("ASSEMBL") > -1) {
return ".asm";
}
if (split[i] === "LOG" || split[i].indexOf("SPFLOG") > -1) {
return ".log";
for (const [ext, matches] of DS_EXTENSION_MAP.entries()) {
switch (ext) {
case ".asm":
if (split[i] === matches[0] || split[i].indexOf("ASSEMBL") > -1) {
return ext;
}
break;
case ".log":
if (split[i] === matches[0] || split[i].indexOf("SPFLOG") > -1) {
return ext;
}
break;
default:
if (matches.includes(split[i])) {
return ext;
}
break;
}
}
}
return null;
Expand Down

0 comments on commit d7a30e4

Please sign in to comment.