diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java index bae9790..bf49762 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -2,6 +2,7 @@ package bjc.utils.components; import java.io.InputStream; +import bjc.utils.exceptions.PragmaFormatException; import bjc.utils.funcutils.ListUtils; import bjc.utils.parserutils.RuleBasedConfigReader; @@ -23,20 +24,50 @@ public class ComponentDescriptionFileParser { }); reader.addPragma("name", (fst, stat) -> { - stat.setName(ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma name requires at least one argument"); + } else { + stat.setName( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("author", (fst, stat) -> { - stat.setAuthor(ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma author requires at least one argument"); + } else { + stat.setAuthor( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("description", (fst, stat) -> { - stat.setDescription( - ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma description requires at least one argument"); + } else { + stat.setDescription( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("version", (fst, stat) -> { - stat.setVersion(Integer.parseInt(fst.nextToken())); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma name requires at least one argument"); + } else { + String token = fst.nextToken(); + + try { + stat.setVersion(Integer.parseInt(token)); + } catch (NumberFormatException nfex) { + throw new PragmaFormatException("Argument " + token + + " to version pragma isn't a valid integer. " + + "This pragma requires a integer argument"); + } + } }); } |
