From 13d1ed2a393e16466c122f37b312e1d3c191a934 Mon Sep 17 00:00:00 2001 From: gimantha Date: Tue, 10 Sep 2024 11:05:37 +0530 Subject: [PATCH] Improve code readability --- .../core/options/FormattingOptions.java | 31 +++++++--------- .../semver/checker/util/DiffUtils.java | 36 +++++++++---------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/options/FormattingOptions.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/options/FormattingOptions.java index 8fa23bb9ee8e..c984a3497636 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/options/FormattingOptions.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/options/FormattingOptions.java @@ -179,6 +179,7 @@ public FormattingOptions build() { spacingFormattingOptions, forceFormattingOptions, importFormattingOptions, queryFormattingOptions); } + @SuppressWarnings("unchecked") public FormattingOptions build(Path root, Object formatSection) throws FormatterException { Optional path = getFormattingFilePath(formatSection, root.toString()); if (path.isEmpty()) { @@ -187,33 +188,25 @@ public FormattingOptions build(Path root, Object formatSection) throws Formatter Map configurations = getFormattingConfigurations(root, path.get()); for (Map.Entry entry : configurations.entrySet()) { Object value = entry.getValue(); - if (!(value instanceof Map configs)) { + if (!(value instanceof Map)) { continue; } + Map configs = (Map) value; String key = entry.getKey(); FormatSection section = FormatSection.fromString(key); switch (section) { - case INDENT -> indentFormattingOptions = IndentFormattingOptions.builder().build( - (Map) configs); - case WRAPPING -> wrappingFormattingOptions = WrappingFormattingOptions.builder().build( - (Map) configs); - case BRACES -> braceFormattingOptions = BraceFormattingOptions.builder().build( - (Map) configs); + case INDENT -> indentFormattingOptions = IndentFormattingOptions.builder().build(configs); + case WRAPPING -> wrappingFormattingOptions = WrappingFormattingOptions.builder().build(configs); + case BRACES -> braceFormattingOptions = BraceFormattingOptions.builder().build(configs); case FUNCTION_DEFINITION -> - functionDefFormattingOptions = FunctionDefFormattingOptions.builder().build( - (Map) configs); + functionDefFormattingOptions = FunctionDefFormattingOptions.builder().build(configs); case FUNCTION_CALL -> - functionCallFormattingOptions = FunctionCallFormattingOptions.builder().build( - (Map) configs); + functionCallFormattingOptions = FunctionCallFormattingOptions.builder().build(configs); case IF_STATEMENT -> - ifStatementFormattingOptions = IfStatementFormattingOptions.builder().build( - (Map) configs); - case QUERY -> queryFormattingOptions = QueryFormattingOptions.builder().build( - (Map) configs); - case SPACING -> spacingFormattingOptions = SpacingFormattingOptions.builder().build( - (Map) configs); - case IMPORT -> importFormattingOptions = ImportFormattingOptions.builder().build( - (Map) configs); + ifStatementFormattingOptions = IfStatementFormattingOptions.builder().build(configs); + case QUERY -> queryFormattingOptions = QueryFormattingOptions.builder().build(configs); + case SPACING -> spacingFormattingOptions = SpacingFormattingOptions.builder().build(configs); + case IMPORT -> importFormattingOptions = ImportFormattingOptions.builder().build(configs); } } return build(); diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java index e1d31b31b7e5..9bd6a9896a25 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java @@ -261,24 +261,24 @@ private static String getDiffVerb(Diff diff) { } private static String getDiffName(Diff diff) { - if (diff instanceof PackageDiff diff1) { - return getPackageName(diff1); - } else if (diff instanceof ModuleDiff diff1) { - return getModuleName(diff1); - } else if (diff instanceof FunctionDiff diff1) { - return getFunctionName(diff1); - } else if (diff instanceof ServiceDiff diff1) { - return getServiceName(diff1); - } else if (diff instanceof ModuleVarDiff diff1) { - return getModuleVariableName(diff1); - } else if (diff instanceof ModuleConstantDiff diff1) { - return getModuleConstantName(diff1); - } else if (diff instanceof ClassDiff diff1) { - return getModuleClassName(diff1); - } else if (diff instanceof TypeDefinitionDiff diff1) { - return getModuleTypeDefName(diff1); - } else if (diff instanceof EnumDiff diff1) { - return getModuleEnumName(diff1); + if (diff instanceof PackageDiff packageDiff) { + return getPackageName(packageDiff); + } else if (diff instanceof ModuleDiff moduleDiff) { + return getModuleName(moduleDiff); + } else if (diff instanceof FunctionDiff funcDiff) { + return getFunctionName(funcDiff); + } else if (diff instanceof ServiceDiff serviceDiff) { + return getServiceName(serviceDiff); + } else if (diff instanceof ModuleVarDiff moduleVarDiff) { + return getModuleVariableName(moduleVarDiff); + } else if (diff instanceof ModuleConstantDiff moduleConstantDiff) { + return getModuleConstantName(moduleConstantDiff); + } else if (diff instanceof ClassDiff classDiff) { + return getModuleClassName(classDiff); + } else if (diff instanceof TypeDefinitionDiff typeDefDiff) { + return getModuleTypeDefName(typeDefDiff); + } else if (diff instanceof EnumDiff enumDiff) { + return getModuleEnumName(enumDiff); } else { return UNKNOWN; }