Skip to content

Commit

Permalink
Issue #41: Improve exception handing
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush kumar sadangi authored and piyush kumar sadangi committed Jun 19, 2024
1 parent 2cd0b2d commit 37bbf16
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions extractor/src/main/java/com/example/extractor/ConfigSerializer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.example.extractor;

import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
Expand Down Expand Up @@ -117,7 +116,7 @@ public Configuration[] getChildren() {
};
}

private static String buildCombinedTreeWalkerChildren(List<Configuration> children, String indent) {
private static String buildCombinedTreeWalkerChildren(List<Configuration> children, String indent) throws CheckstyleException {
StringBuilder builder = new StringBuilder();

for (Configuration child : children) {
Expand All @@ -135,23 +134,19 @@ private static String buildCombinedTreeWalkerChildren(List<Configuration> childr
return builder.toString().trim();
}

private static String buildProperties(Configuration config, String indent) {
private static String buildProperties(Configuration config, String indent) throws CheckstyleException {
StringBuilder builder = new StringBuilder();
boolean firstProperty = true;
List<String> sortedPropertyNames = new ArrayList<>(Arrays.asList(config.getPropertyNames()));
Collections.sort(sortedPropertyNames);
for (String propertyName : sortedPropertyNames) {
try {
String propertyValue = config.getProperty(propertyName);
if (!firstProperty) {
builder.append("\n");
}
builder.append(indent).append("<property name=\"").append(propertyName)
.append("\" value=\"").append(propertyValue).append("\"/>");
firstProperty = false;
} catch (CheckstyleException e) {
System.err.println("Error retrieving property: " + e.getMessage());
String propertyValue = config.getProperty(propertyName);
if (!firstProperty) {
builder.append("\n");
}
builder.append(indent).append("<property name=\"").append(propertyName)
.append("\" value=\"").append(propertyValue).append("\"/>");
firstProperty = false;
}
return builder.toString();
}
Expand Down Expand Up @@ -193,7 +188,7 @@ public static String sortProperties(String configContent) {
return sortedContent.toString().trim();
}

private static String buildModuleContent(Configuration config, String indent) {
private static String buildModuleContent(Configuration config, String indent) throws CheckstyleException {
StringBuilder builder = new StringBuilder();
for (Configuration child : config.getChildren()) {
String childProperties = buildProperties(child, indent + " ");
Expand All @@ -208,4 +203,4 @@ private static String buildModuleContent(Configuration config, String indent) {
}
return builder.toString().trim();
}
}
}

0 comments on commit 37bbf16

Please sign in to comment.