Skip to content

Commit

Permalink
Merge pull request #43371 from gimantha/master
Browse files Browse the repository at this point in the history
Improve code readability
  • Loading branch information
gimantha authored Sep 10, 2024
2 parents a0bceed + 13d1ed2 commit 50c50a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public FormattingOptions build() {
spacingFormattingOptions, forceFormattingOptions, importFormattingOptions, queryFormattingOptions);
}

@SuppressWarnings("unchecked")
public FormattingOptions build(Path root, Object formatSection) throws FormatterException {
Optional<String> path = getFormattingFilePath(formatSection, root.toString());
if (path.isEmpty()) {
Expand All @@ -187,33 +188,25 @@ public FormattingOptions build(Path root, Object formatSection) throws Formatter
Map<String, Object> configurations = getFormattingConfigurations(root, path.get());
for (Map.Entry<String, Object> entry : configurations.entrySet()) {
Object value = entry.getValue();
if (!(value instanceof Map<?, ?> configs)) {
if (!(value instanceof Map<?, ?>)) {
continue;
}
Map<String, Object> configs = (Map<String, Object>) value;
String key = entry.getKey();
FormatSection section = FormatSection.fromString(key);
switch (section) {
case INDENT -> indentFormattingOptions = IndentFormattingOptions.builder().build(
(Map<String, Object>) configs);
case WRAPPING -> wrappingFormattingOptions = WrappingFormattingOptions.builder().build(
(Map<String, Object>) configs);
case BRACES -> braceFormattingOptions = BraceFormattingOptions.builder().build(
(Map<String, Object>) 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<String, Object>) configs);
functionDefFormattingOptions = FunctionDefFormattingOptions.builder().build(configs);
case FUNCTION_CALL ->
functionCallFormattingOptions = FunctionCallFormattingOptions.builder().build(
(Map<String, Object>) configs);
functionCallFormattingOptions = FunctionCallFormattingOptions.builder().build(configs);
case IF_STATEMENT ->
ifStatementFormattingOptions = IfStatementFormattingOptions.builder().build(
(Map<String, Object>) configs);
case QUERY -> queryFormattingOptions = QueryFormattingOptions.builder().build(
(Map<String, Object>) configs);
case SPACING -> spacingFormattingOptions = SpacingFormattingOptions.builder().build(
(Map<String, Object>) configs);
case IMPORT -> importFormattingOptions = ImportFormattingOptions.builder().build(
(Map<String, Object>) 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 50c50a8

Please sign in to comment.