diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-08-31 22:50:14 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-08-31 22:50:14 +0200 |
commit | adcb1d4d55e71d78c662f798b033d3abea0d4b9e (patch) | |
tree | 5867c3ac85792c1578d6ce463e8e24dd2aea7fb0 /configgen/src/main/java/com/yahoo | |
parent | 2b83da619a3ee2f38a1a3b05576f44d7451b3daf (diff) |
Add 'model' config type
Diffstat (limited to 'configgen/src/main/java/com/yahoo')
12 files changed, 48 insertions, 40 deletions
diff --git a/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java b/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java index a0717a1060f..e7b6455f3e0 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/BuilderGenerator.java @@ -4,6 +4,7 @@ package com.yahoo.config.codegen; import com.yahoo.config.codegen.LeafCNode.FileLeaf; import com.yahoo.config.codegen.LeafCNode.PathLeaf; import com.yahoo.config.codegen.LeafCNode.UrlLeaf; +import com.yahoo.config.codegen.LeafCNode.ModelLeaf; import java.util.ArrayList; import java.util.List; @@ -274,7 +275,7 @@ public class BuilderGenerator { String type = boxedDataType(n); if ("UrlReference".equals(bType)) type = bType; - stringSetter = String.format("\nprivate Builder %s(String %svalue) {\n" + // + stringSetter = String.format("\nprivate Builder %s(String %svalue) {\n" + " return %s(%s.valueOf(%svalue));\n" + // "}", name, INTERNAL_PREFIX, name, type, INTERNAL_PREFIX); } @@ -282,9 +283,9 @@ public class BuilderGenerator { String getNullGuard = bType.equals(boxedBuilderType(n)) ? String.format( "\nif (%svalue == null) throw new IllegalArgumentException(\"Null value is not allowed.\");", INTERNAL_PREFIX) : ""; - return String.format("public Builder %s(%s %svalue) {%s\n" + // + return String.format("public Builder %s(%s %svalue) {%s\n" + " %s = %svalue;\n" + // - "%s", name, bType, INTERNAL_PREFIX, getNullGuard, name, INTERNAL_PREFIX, signalInitialized) + // + "%s", name, bType, INTERNAL_PREFIX, getNullGuard, name, INTERNAL_PREFIX, signalInitialized) + " return this;" + "\n}\n" + stringSetter; } } @@ -312,6 +313,12 @@ public class BuilderGenerator { return name + "(" + nodeClass(child) + ".toUrlReferenceMap(config." + name + "));"; } else if (child instanceof UrlLeaf) { return name + "(config." + name + ".getUrlReference());"; + } else if (child instanceof ModelLeaf && isArray) { + return name + "(" + nodeClass(child) + ".toModelReferences(config." + name + "));"; + } else if (child instanceof ModelLeaf && isMap) { + return name + "(" + nodeClass(child) + ".toModelReferenceMap(config." + name + "));"; + } else if (child instanceof ModelLeaf) { + return name + "(config." + name + ".getModelReference());"; } else if (child instanceof LeafCNode) { return name + "(config." + name + "());"; } else if (child instanceof InnerCNode && isArray) { @@ -403,6 +410,8 @@ public class BuilderGenerator { return "FileReference"; } else if (node instanceof UrlLeaf) { return "UrlReference"; + } else if (node instanceof ModelLeaf) { + return "ModelReference"; } else if (node instanceof LeafCNode && (node.isArray || node.isMap)) { return boxedDataType(node); } else { @@ -417,6 +426,8 @@ public class BuilderGenerator { return "FileReference"; } else if (node instanceof UrlLeaf) { return "UrlReference"; + } else if (node instanceof ModelLeaf) { + return "ModelReference"; } else { return boxedDataType(node); } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/ClassBuilder.java b/configgen/src/main/java/com/yahoo/config/codegen/ClassBuilder.java index 1ac817e7091..3732791740c 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/ClassBuilder.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/ClassBuilder.java @@ -7,6 +7,6 @@ package com.yahoo.config.codegen; public interface ClassBuilder { /** Generate config class file(s). */ - public void createConfigClasses(); + void createConfigClasses(); } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/ConfigGenerator.java b/configgen/src/main/java/com/yahoo/config/codegen/ConfigGenerator.java index 61bae00e517..fd3aa388ed6 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/ConfigGenerator.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/ConfigGenerator.java @@ -167,6 +167,8 @@ public class ConfigGenerator { return name + " = LeafNodeVector.createPathNodeVector(builder." + name + ");"; } else if (child instanceof UrlLeaf && isArray) { return name + " = LeafNodeVector.createUrlNodeVector(builder." + name + ");"; + } else if (child instanceof ModelLeaf && isArray) { + return name + " = LeafNodeVector.createModelNodeVector(builder." + name + ");"; } else if (child instanceof LeafCNode && isArray) { return name + " = new LeafNodeVector<>(builder." + name + ", new " + className + "());"; } else if (child instanceof FileLeaf && isMap) { @@ -175,6 +177,8 @@ public class ConfigGenerator { return name + " = LeafNodeMaps.asPathNodeMap(builder." + name + ");"; } else if (child instanceof UrlLeaf && isMap) { return name + " = LeafNodeMaps.asUrlNodeMap(builder." + name + ");"; + } else if (child instanceof ModelLeaf && isMap) { + return name + " = LeafNodeMaps.asModelNodeMap(builder." + name + ");"; } else if (child instanceof LeafCNode && isMap) { return name + " = LeafNodeMaps.asNodeMap(builder." + name + ", new " + className + "());"; } else if (child instanceof InnerCNode && isArray) { @@ -399,6 +403,8 @@ public class ConfigGenerator { return "PathNode"; } else if (node instanceof UrlLeaf) { return "UrlNode"; + } else if (node instanceof ModelLeaf) { + return "ModelNode"; } else if (node instanceof IntegerLeaf) { return "IntegerNode"; } else if (node instanceof LongLeaf) { @@ -427,6 +433,8 @@ public class ConfigGenerator { return "Path"; } else if (node instanceof UrlLeaf) { return "File"; + } else if (node instanceof ModelLeaf) { + return "ModelReference"; } else if (node instanceof IntegerLeaf) { return "int"; } else if (node instanceof LongLeaf) { @@ -434,7 +442,7 @@ public class ConfigGenerator { } else if (node instanceof StringLeaf) { return "String"; } else { - throw new IllegalStateException("Cannot determine user data type for node"); // should not occur + throw new IllegalStateException("Cannot determine user data type for node '" + node + "'"); // should not occur } } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/DefLine.java b/configgen/src/main/java/com/yahoo/config/codegen/DefLine.java index eeca50201b7..753fad0d41a 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/DefLine.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/DefLine.java @@ -251,7 +251,7 @@ public class DefLine { } else if (whitespaceMatcher.matches()) { break; } else { - throw new IllegalArgumentException(name + " contains unexpected character"); + throw new IllegalArgumentException("'" + name + "' contains an unexpected character"); } } } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/DefParser.java b/configgen/src/main/java/com/yahoo/config/codegen/DefParser.java index cebb7ca8108..2be824658b4 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/DefParser.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/DefParser.java @@ -210,7 +210,7 @@ public class DefParser { sb.append(" = ").append(((LeafCNode)root).getDefaultValue().getValue()); } } - System.out.println(sb.toString()); + System.out.println(sb); if (!root.getComment().isEmpty()) { String comment = root.getComment(); if (comment.contains("\n")) { diff --git a/configgen/src/main/java/com/yahoo/config/codegen/DefaultValue.java b/configgen/src/main/java/com/yahoo/config/codegen/DefaultValue.java index 9d8ee58f364..ed68bb7d9d8 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/DefaultValue.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/DefaultValue.java @@ -13,30 +13,22 @@ public class DefaultValue { // The variable type. Always set UNLESS the value is null. private DefLine.Type type = null; - /** - * Null value - */ + /** Null value. */ public DefaultValue() { } - /** - * A default value with the given value and type. - */ + /** A default value with the given value and type. */ public DefaultValue(String value, DefLine.Type type) { this.value = value; this.type = type; } - /** - * Returns the toString of the default value. - */ + /** Returns the toString of the default value. */ public String getValue() { return value; } - /** - * Returns the string representation of this value - */ + /** Returns the string representation of this value. */ public String getStringRepresentation() { if (value == null) return "null"; @@ -60,7 +52,7 @@ public class DefaultValue { sb.append(c); } } - return "\"" + sb.toString() + "\""; + return "\"" + sb + "\""; } } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/InnerCNode.java b/configgen/src/main/java/com/yahoo/config/codegen/InnerCNode.java index 74b0bbf7bba..295558a469c 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/InnerCNode.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/InnerCNode.java @@ -15,7 +15,7 @@ public class InnerCNode extends CNode { * The children of this Node. Mapped using their short name as * string. This variable is null only if Node is a leaf Node. */ - private final Map<String, CNode> children = new LinkedHashMap<String, CNode>(); + private final Map<String, CNode> children = new LinkedHashMap<>(); private boolean restart = false; /** @@ -66,8 +66,7 @@ public class InnerCNode extends CNode { } else { newChild = LeafCNode.newInstance(type, this, key); if (newChild == null) - throw new IllegalArgumentException - ("Could not create " + type.name + " " + name); + throw new IllegalArgumentException("Could not create " + type.name + " " + name); } return children.containsKey(newChild.getName()) ? children.get(newChild.getName()) @@ -77,6 +76,7 @@ public class InnerCNode extends CNode { /** * Adds a child to this node with the given type, name and value. Necessary children on the path * to the given leaf node will be added as well. + * * @param name the full name/path of the node to add. * @param defLine the parsed .def-file line to add. * @param comment comment extracted from the .def-file. diff --git a/configgen/src/main/java/com/yahoo/config/codegen/JavaClassBuilder.java b/configgen/src/main/java/com/yahoo/config/codegen/JavaClassBuilder.java index fe1566aa133..4141a3b6e09 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/JavaClassBuilder.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/JavaClassBuilder.java @@ -105,12 +105,9 @@ public class JavaClassBuilder implements ClassBuilder { } /** - * @param rootDir - * The root directory for the destination path. - * @param javaPackage - * The java package - * @return the destination path for the generated config file, including the - * given rootDir. + * @param rootDir the root directory for the destination path. + * @param javaPackage the java package + * @return the destination path for the generated config file, including the given rootDir. */ private File getDestPath(File rootDir, String javaPackage) { File dir = rootDir; diff --git a/configgen/src/main/java/com/yahoo/config/codegen/LeafCNode.java b/configgen/src/main/java/com/yahoo/config/codegen/LeafCNode.java index e3d2cdb5a36..1395c6814df 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/LeafCNode.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/LeafCNode.java @@ -74,8 +74,7 @@ public abstract class LeafCNode extends CNode { } @Override - protected void setLeaf(String name, DefLine defLine, String comment) - throws IllegalArgumentException { + protected void setLeaf(String name, DefLine defLine, String comment) throws IllegalArgumentException { DefLine.Type type = defLine.getType(); // TODO: why the !is... conditions? if (!isMap && !isArray && isInitialized) { @@ -101,8 +100,7 @@ public abstract class LeafCNode extends CNode { checkDefaultValue(defaultValue); setDefaultValue(defaultValue); } catch (IllegalArgumentException e) { - throw new IllegalArgumentException - ("Invalid default value", e); + throw new IllegalArgumentException("Invalid default value", e); } } diff --git a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java index 04f7c90c9b9..a24d88102bd 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/MakeConfig.java @@ -98,9 +98,9 @@ public class MakeConfig { static class Exceptions { /** - * <p>Returns a use friendly error message string which includes information from all nested exceptions. + * Returns a use friendly error message string which includes information from all nested exceptions. * - * <p>The form of this string is + * The form of this string is * <code>e.getMessage(): e.getCause().getMessage(): e.getCause().getCause().getMessage()...</code> * In addition, some heuristics are used to clean up common cases where exception nesting causes bad messages. */ diff --git a/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java b/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java index fde9c171546..5d36b3cb77d 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java @@ -23,7 +23,7 @@ public class NormalizedDefinition { // Patterns used for finding ranges in config definitions private static final Pattern intPattern = Pattern.compile(".*int.*range.*"); private static final Pattern doublePattern = Pattern.compile(".*double.*range.*"); - private MessageDigest md5; + private final MessageDigest md5; String defMd5 = null; List<String> normalizedContent = null; @@ -61,8 +61,8 @@ public class NormalizedDefinition { * </ul> * The supplied list is changed in-place * - * @param line A config definition line - * @return a normalized config definition line + * @param line a config definition line + * @return a normalized config definition line */ public static String normalize(String line) { //System.out.println("before line=" + line + ";"); @@ -150,7 +150,8 @@ public class NormalizedDefinition { } /** - * Replaces sequences of spaces with 1 space, unless inside quotes. Public for testing; + * Replaces sequences of spaces with 1 space, unless inside quotes. Public for testing. + * * @param str String to strip spaces from * @return String with spaces stripped */ @@ -186,6 +187,7 @@ public class NormalizedDefinition { return normalizedContent; } + @Override public String toString() { StringBuilder builder = new StringBuilder(); for (String line : normalizedContent) { diff --git a/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java b/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java index 3310ceb30f5..15465bccae3 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java @@ -44,7 +44,7 @@ public class ReservedWords { private static final HashMap<String, String> allKeyWords; static { - allKeyWords = new HashMap<String, String>(); + allKeyWords = new HashMap<>(); for (String s : cKeywords) { allKeyWords.put(s, "C"); } |