chore(refactor): performed extract method code refactoring in SpdxLicenseTemplateHelper
@@ -59,6 +59,20 @@ public class SpdxLicenseTemplateHelper {
end = ruleMatcher.end();
String ruleString = ruleMatcher.group(1);
LicenseTemplateRule rule = new LicenseTemplateRule(ruleString);
+ optionalNestLevel = getOptionalNestLevel(templateOutputHandler, optionalNestLevel, upToTheFind, rule);
+ }
+ if (optionalNestLevel > 0) {
+ throw(new LicenseTemplateRuleException("Missing EndOptional rule and end of text"));
+ }
+ // copy the rest of the template to the end
+ String restOfTemplate = licenseTemplate.substring(end);
+ if (!restOfTemplate.isEmpty()) {
+ templateOutputHandler.text(restOfTemplate);
+ }
+ templateOutputHandler.completeParsing();
+ }
+
+ private static int getOptionalNestLevel(ILicenseTemplateOutputHandler templateOutputHandler, int optionalNestLevel, String upToTheFind, LicenseTemplateRule rule) throws LicenseTemplateRuleException {
if (rule.getType() == LicenseTemplateRule.RuleType.VARIABLE) {
templateOutputHandler.variableRule(rule);
} else if (rule.getType() == LicenseTemplateRule.RuleType.BEGIN_OPTIONAL) {
@@ -73,16 +87,7 @@ public class SpdxLicenseTemplateHelper {
} else {
throw(new LicenseTemplateRuleException("Unrecognized rule: "+ rule.getType().toString()+" after text '"+ upToTheFind +"'"));
}
- }
- if (optionalNestLevel > 0) {
- throw(new LicenseTemplateRuleException("Missing EndOptional rule and end of text"));
- }
- // copy the rest of the template to the end
- String restOfTemplate = licenseTemplate.substring(end);
- if (!restOfTemplate.isEmpty()) {
- templateOutputHandler.text(restOfTemplate);
- }
- templateOutputHandler.completeParsing();
+ return optionalNestLevel;
}
/**
